Search in sources :

Example 6 with SwtPresentation

use of org.eclipse.sapphire.ui.forms.swt.SwtPresentation 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;
}
Also used : JavaTypeKind(org.eclipse.sapphire.java.JavaTypeKind) JavaModelException(org.eclipse.jdt.core.JavaModelException) Element(org.eclipse.sapphire.Element) SelectionDialog(org.eclipse.ui.dialogs.SelectionDialog) IProject(org.eclipse.core.resources.IProject) IType(org.eclipse.jdt.core.IType) JavaTypeConstraintService(org.eclipse.sapphire.java.JavaTypeConstraintService) IJavaSearchScope(org.eclipse.jdt.core.search.IJavaSearchScope) SwtPresentation(org.eclipse.sapphire.ui.forms.swt.SwtPresentation) Property(org.eclipse.sapphire.Property)

Aggregations

SwtPresentation (org.eclipse.sapphire.ui.forms.swt.SwtPresentation)6 NewLiferayPluginProjectOp (com.liferay.ide.project.core.model.NewLiferayPluginProjectOp)3 IProject (org.eclipse.core.resources.IProject)2 IType (org.eclipse.jdt.core.IType)2 JavaModelException (org.eclipse.jdt.core.JavaModelException)2 IJavaSearchScope (org.eclipse.jdt.core.search.IJavaSearchScope)2 Element (org.eclipse.sapphire.Element)2 Property (org.eclipse.sapphire.Property)2 SelectionDialog (org.eclipse.ui.dialogs.SelectionDialog)2 Assignable (com.liferay.ide.kaleo.core.model.Assignable)1 ResourceAction (com.liferay.ide.kaleo.core.model.ResourceAction)1 Role (com.liferay.ide.kaleo.core.model.Role)1 RoleName (com.liferay.ide.kaleo.core.model.RoleName)1 Scriptable (com.liferay.ide.kaleo.core.model.Scriptable)1 Task (com.liferay.ide.kaleo.core.model.Task)1 User (com.liferay.ide.kaleo.core.model.User)1 WorkflowDefinition (com.liferay.ide.kaleo.core.model.WorkflowDefinition)1 WorkflowNode (com.liferay.ide.kaleo.core.model.WorkflowNode)1 ChangeTaskAssignmentsOp (com.liferay.ide.kaleo.core.op.ChangeTaskAssignmentsOp)1 NewLiferayProfile (com.liferay.ide.project.core.model.NewLiferayProfile)1