Search in sources :

Example 1 with TypeSelectionExtension

use of org.eclipse.jdt.ui.dialogs.TypeSelectionExtension in project liferay-ide by liferay.

the class ServiceTypeImplBrowseActionHandler method browse.

@Override
public String browse(Presentation context) {
    Element element = getModelElement();
    Property property = property();
    IProject project = element.adapt(IProject.class);
    try {
        IJavaSearchScope scope = null;
        TypeSelectionExtension extension = null;
        if ("type".equals(_kind)) {
            scope = SearchEngine.createJavaSearchScope(new IJavaProject[] { JavaCore.create(project) });
            extension = new TypeSelectionExtension() {

                @Override
                public ITypeInfoFilterExtension getFilterExtension() {
                    return new ITypeInfoFilterExtension() {

                        public boolean select(ITypeInfoRequestor typeInfoRequestor) {
                            if (typeInfoRequestor.getPackageName().startsWith("com.liferay") && typeInfoRequestor.getTypeName().endsWith("Service")) {
                                return true;
                            }
                            return false;
                        }
                    };
                }
            };
        } else if ("impl".equals(_kind)) {
            String serviceType = _getServiceType(element);
            if (serviceType != null) {
                String wrapperType = serviceType + "Wrapper";
                scope = SearchEngine.createHierarchyScope(JavaCore.create(project).findType(wrapperType));
            } else {
                Shell shell = ((SwtPresentation) context).shell();
                MessageDialog.openInformation(shell, Msgs.serviceImplBrowse, Msgs.validServiceTypeProperty);
                return null;
            }
        }
        Shell shell = ((SwtPresentation) context).shell();
        SelectionDialog dlg = JavaUI.createTypeDialog(shell, null, scope, _browseDialogStyle, false, StringPool.DOUBLE_ASTERISK, extension);
        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 : JavaModelException(org.eclipse.jdt.core.JavaModelException) Element(org.eclipse.sapphire.Element) ITypeInfoFilterExtension(org.eclipse.jdt.ui.dialogs.ITypeInfoFilterExtension) TypeSelectionExtension(org.eclipse.jdt.ui.dialogs.TypeSelectionExtension) SelectionDialog(org.eclipse.ui.dialogs.SelectionDialog) IProject(org.eclipse.core.resources.IProject) IType(org.eclipse.jdt.core.IType) Shell(org.eclipse.swt.widgets.Shell) IJavaProject(org.eclipse.jdt.core.IJavaProject) IJavaSearchScope(org.eclipse.jdt.core.search.IJavaSearchScope) SwtPresentation(org.eclipse.sapphire.ui.forms.swt.SwtPresentation) Property(org.eclipse.sapphire.Property) ITypeInfoRequestor(org.eclipse.jdt.ui.dialogs.ITypeInfoRequestor)

Example 2 with TypeSelectionExtension

use of org.eclipse.jdt.ui.dialogs.TypeSelectionExtension in project liferay-ide by liferay.

the class HierarchyBrowseActionHandler method browse.

@Override
public String browse(Presentation context) {
    Element element = getModelElement();
    Property property = property();
    IProject project = element.adapt(IProject.class);
    try {
        IJavaSearchScope scope = null;
        TypeSelectionExtension extension = null;
        String javaType = _getClassReferenceType(property);
        if (javaType != null) {
            scope = SearchEngine.createHierarchyScope(JavaCore.create(project).findType(javaType));
        } else {
            MessageDialog.openInformation(((SwtPresentation) context).shell(), Msgs.browseImplementation, Msgs.validClassImplProperty);
            return null;
        }
        SelectionDialog dlg = JavaUI.createTypeDialog(((SwtPresentation) context).shell(), null, scope, IJavaElementSearchConstants.CONSIDER_CLASSES, false, StringPool.DOUBLE_ASTERISK, extension);
        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) {
        PortletUIPlugin.logError(jme);
    }
    return null;
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) IJavaSearchScope(org.eclipse.jdt.core.search.IJavaSearchScope) Element(org.eclipse.sapphire.Element) TypeSelectionExtension(org.eclipse.jdt.ui.dialogs.TypeSelectionExtension) Property(org.eclipse.sapphire.Property) SelectionDialog(org.eclipse.ui.dialogs.SelectionDialog) IProject(org.eclipse.core.resources.IProject) IType(org.eclipse.jdt.core.IType)

Aggregations

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 TypeSelectionExtension (org.eclipse.jdt.ui.dialogs.TypeSelectionExtension)2 Element (org.eclipse.sapphire.Element)2 Property (org.eclipse.sapphire.Property)2 SelectionDialog (org.eclipse.ui.dialogs.SelectionDialog)2 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 ITypeInfoFilterExtension (org.eclipse.jdt.ui.dialogs.ITypeInfoFilterExtension)1 ITypeInfoRequestor (org.eclipse.jdt.ui.dialogs.ITypeInfoRequestor)1 SwtPresentation (org.eclipse.sapphire.ui.forms.swt.SwtPresentation)1 Shell (org.eclipse.swt.widgets.Shell)1