* @param selection the current selection
* @return a prototype search
*/
public static ISearch getExampleSearch( ISelection selection )
{
ISearch exampleSearch = new Search();
String oldName = exampleSearch.getSearchParameter().getName();
exampleSearch.getSearchParameter().setName( null );
exampleSearch.setScope( SearchScope.SUBTREE );
if ( selection != null && !selection.isEmpty() && selection instanceof StructuredSelection )
{
Object[] objects = ( ( IStructuredSelection ) selection ).toArray();
Comparator<Object> comparator = new Comparator<Object>()
{
public int compare( Object o1, Object o2 )
{
if ( ( o1 instanceof IValue ) && !( o2 instanceof IValue ) )
{
return -1;
}
else if ( !( o1 instanceof IValue ) && ( o2 instanceof IValue ) )
{
return 1;
}
else if ( ( o1 instanceof IAttribute ) && !( o2 instanceof IAttribute ) )
{
return -1;
}
else if ( !( o1 instanceof IAttribute ) && ( o2 instanceof IAttribute ) )
{
return 1;
}
else if ( ( o1 instanceof AttributeHierarchy ) && !( o2 instanceof AttributeHierarchy ) )
{
return -1;
}
else if ( !( o1 instanceof AttributeHierarchy ) && ( o2 instanceof AttributeHierarchy ) )
{
return 1;
}
return 0;
}
};
Arrays.sort( objects, comparator );
Object obj = objects[0];
if ( obj instanceof ISearch )
{
ISearch search = ( ISearch ) obj;
exampleSearch = ( ISearch ) search.clone();
exampleSearch.setName( null );
}
else if ( obj instanceof IEntry )
{
IEntry entry = ( IEntry ) obj;