Search in sources :

Example 1 with JavaTypeKind

use of org.eclipse.sapphire.java.JavaTypeKind 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)

Example 2 with JavaTypeKind

use of org.eclipse.sapphire.java.JavaTypeKind in project liferay-ide by liferay.

the class ServiceImplJavaTypeConstraintService method initJavaTypeConstraintService.

@Override
protected void initJavaTypeConstraintService() {
    super.initJavaTypeConstraintService();
    Property property = context().find(Property.class);
    JavaTypeConstraint javaTypeConstraintAnnotation = property.definition().getAnnotation(JavaTypeConstraint.class);
    Set<JavaTypeKind> kind = EnumSet.noneOf(JavaTypeKind.class);
    for (JavaTypeKind k : javaTypeConstraintAnnotation.kind()) {
        kind.add(k);
    }
    _kinds = kind;
    _behavior = javaTypeConstraintAnnotation.behavior();
    _service = context(ServiceWrapper.class);
    Listener listener = new FilteredListener<PropertyContentEvent>() {

        @Override
        public void handleTypedEvent(PropertyContentEvent event) {
            refresh();
        }
    };
    _service.attach(listener, "ServiceType");
}
Also used : JavaTypeKind(org.eclipse.sapphire.java.JavaTypeKind) FilteredListener(org.eclipse.sapphire.FilteredListener) PropertyContentEvent(org.eclipse.sapphire.PropertyContentEvent) JavaTypeConstraint(org.eclipse.sapphire.java.JavaTypeConstraint) ServiceWrapper(com.liferay.ide.hook.core.model.ServiceWrapper) FilteredListener(org.eclipse.sapphire.FilteredListener) Listener(org.eclipse.sapphire.Listener) Property(org.eclipse.sapphire.Property)

Aggregations

Property (org.eclipse.sapphire.Property)2 JavaTypeKind (org.eclipse.sapphire.java.JavaTypeKind)2 ServiceWrapper (com.liferay.ide.hook.core.model.ServiceWrapper)1 IProject (org.eclipse.core.resources.IProject)1 IType (org.eclipse.jdt.core.IType)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 IJavaSearchScope (org.eclipse.jdt.core.search.IJavaSearchScope)1 Element (org.eclipse.sapphire.Element)1 FilteredListener (org.eclipse.sapphire.FilteredListener)1 Listener (org.eclipse.sapphire.Listener)1 PropertyContentEvent (org.eclipse.sapphire.PropertyContentEvent)1 JavaTypeConstraint (org.eclipse.sapphire.java.JavaTypeConstraint)1 JavaTypeConstraintService (org.eclipse.sapphire.java.JavaTypeConstraintService)1 SwtPresentation (org.eclipse.sapphire.ui.forms.swt.SwtPresentation)1 SelectionDialog (org.eclipse.ui.dialogs.SelectionDialog)1