}
@Override
public String browse( final Presentation context )
{
final Property property = property();
final EnumSet<JavaTypeKind> kinds = EnumSet.noneOf( JavaTypeKind.class );
if( this.paramKinds != null )
{
for( String kindString : this.paramKinds.split( "," ) )
{
kindString = kindString.trim();
if( kindString.equalsIgnoreCase( JavaTypeKind.CLASS.name() ) )
{
kinds.add( JavaTypeKind.CLASS );
}
else if( kindString.equalsIgnoreCase( JavaTypeKind.ABSTRACT_CLASS.name() ) )
{
kinds.add( JavaTypeKind.ABSTRACT_CLASS );
}
else if( kindString.equalsIgnoreCase( JavaTypeKind.INTERFACE.name() ) )
{
kinds.add( JavaTypeKind.INTERFACE );
}
else if( kindString.equalsIgnoreCase( JavaTypeKind.ANNOTATION.name() ) )
{
kinds.add( JavaTypeKind.ANNOTATION );
}
else if( kindString.equalsIgnoreCase( JavaTypeKind.ENUM.name() ) )
{
kinds.add( JavaTypeKind.ENUM );
}
else
{
final String msg = typeKindNotRecognized.format( kindString );
Sapphire.service( LoggingService.class ).logError( msg );
}
}
}
else
{
final JavaTypeConstraintService javaTypeConstraintService = property.service( JavaTypeConstraintService.class );
if( javaTypeConstraintService != null )
{
kinds.addAll( javaTypeConstraintService.kinds() );
}
}
int browseDialogStyle = IJavaElementSearchConstants.CONSIDER_ALL_TYPES;
int count = kinds.size();
if( count == 1 )
{
final JavaTypeKind kind = kinds.iterator().next();
switch( kind )
{
case CLASS: browseDialogStyle = IJavaElementSearchConstants.CONSIDER_CLASSES; break;
case ABSTRACT_CLASS: browseDialogStyle = IJavaElementSearchConstants.CONSIDER_CLASSES; break;
case INTERFACE: browseDialogStyle = IJavaElementSearchConstants.CONSIDER_INTERFACES; break;
case ANNOTATION: browseDialogStyle = IJavaElementSearchConstants.CONSIDER_ANNOTATION_TYPES; break;
case ENUM: browseDialogStyle = IJavaElementSearchConstants.CONSIDER_ENUMS; break;
default: throw new IllegalStateException();
}
}
else if( count == 2 )
{
if( kinds.contains( JavaTypeKind.CLASS ) || kinds.contains( JavaTypeKind.ABSTRACT_CLASS ) )
{
if( kinds.contains( JavaTypeKind.INTERFACE ) )
{
browseDialogStyle = IJavaElementSearchConstants.CONSIDER_CLASSES_AND_INTERFACES;
}
else if( kinds.contains( JavaTypeKind.ENUM ) )
{
browseDialogStyle = IJavaElementSearchConstants.CONSIDER_CLASSES_AND_ENUMS;
}
}
}
final IProject project = property.element().adapt( IProject.class );
try
{
final SelectionDialog dlg
= JavaUI.createTypeDialog( ( (FormComponentPresentation) context ).shell(), null, project, browseDialogStyle, false );
dlg.setTitle( dialogTitle.format( property.definition().getLabel( true, CapitalizationType.TITLE_STYLE, false ) ) );
if (dlg.open() == SelectionDialog.OK) {
Object results[] = dlg.getResult();
assert results != null && results.length == 1;
if (results[0] instanceof IType) {