use of org.eclipse.sapphire.java.JavaTypeConstraintService in project liferay-ide by liferay.
the class HierarchyJavaTypeBrowseActionHandler method browse.
@Override
public String browse(Presentation context) {
Element element = getModelElement();
Property property = property();
IProject project = element.adapt(IProject.class);
try {
JavaTypeConstraintService typeService = property.service(JavaTypeConstraintService.class);
EnumSet<JavaTypeKind> kinds = EnumSet.noneOf(JavaTypeKind.class);
kinds.addAll(typeService.kinds());
int browseDialogStyle = IJavaElementSearchConstants.CONSIDER_ALL_TYPES;
int count = kinds.size();
if (count == 1) {
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;
}
}
}
IJavaSearchScope scope = null;
IType type = JavaCore.create(project).findType(_typeName);
if (type != null) {
scope = SearchEngine.createHierarchyScope(type);
}
SwtPresentation swt = (SwtPresentation) context;
SelectionDialog dlg = JavaUI.createTypeDialog(swt.shell(), null, scope, browseDialogStyle, false, _filter, null);
String title = property.definition().getLabel(true, CapitalizationType.TITLE_STYLE, false);
dlg.setTitle(Msgs.select + title);
if (dlg.open() == SelectionDialog.OK) {
Object[] results = dlg.getResult();
assert (results != null) && (results.length == 1);
if (results[0] instanceof IType) {
return ((IType) results[0]).getFullyQualifiedName();
}
}
} catch (JavaModelException jme) {
HookUI.logError(jme);
}
return null;
}
Aggregations