Search in sources :

Example 1 with PortletNode

use of com.liferay.ide.portlet.ui.navigator.PortletNode in project liferay-ide by liferay.

the class OpenPortletResourceAction method selectAndRevealItem.

/**
 * @param editor
 *            TODO: need to work on to fix to reveal the selected node
 */
protected void selectAndRevealItem(IEditorPart editorPart) {
    if (this.editorPart instanceof SapphireEditor) {
        SapphireEditorForXml editor = (SapphireEditorForXml) editorPart;
        PortletNode portletNavigatorNode = (PortletNode) selectedNode;
        Element selectedModelElement = portletNavigatorNode.getModel();
        if (selectedModelElement != null) {
            MasterDetailsEditorPage mdepDetailsEditorPage = (MasterDetailsEditorPage) editor.getActivePageInstance();
            if (mdepDetailsEditorPage != null) {
                MasterDetailsContentOutline contentOutline = mdepDetailsEditorPage.outline();
                MasterDetailsContentNodePart rootNode = contentOutline.getRoot();
                if (rootNode != null) {
                    MasterDetailsContentNodeList nodes = rootNode.nodes();
                    MasterDetailsContentNodePart portletAppNode = nodes.visible().get(0);
                    MasterDetailsContentNodePart portletsNode = portletAppNode.findNode(_PORTLETS_NODE_LABEL);
                    if (portletsNode != null) {
                        if (selectedModelElement instanceof Portlet) {
                            Portlet selectedPortlet = (Portlet) selectedModelElement;
                            for (MasterDetailsContentNodePart childNode : portletsNode.nodes().visible()) {
                                String selectedPortletName = selectedPortlet.getPortletName().content();
                                if (childNode.getModelElement() instanceof Portlet) {
                                    Portlet mpContentNodePortlet = (Portlet) childNode.getModelElement();
                                    String mpContentNodePortletName = mpContentNodePortlet.getPortletName().content();
                                    if (selectedPortletName.equals(mpContentNodePortletName)) {
                                        childNode.select();
                                        childNode.setExpanded(true);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : MasterDetailsContentNodeList(org.eclipse.sapphire.ui.forms.MasterDetailsContentNodeList) MasterDetailsContentNodePart(org.eclipse.sapphire.ui.forms.MasterDetailsContentNodePart) Portlet(com.liferay.ide.portlet.core.model.Portlet) SapphireEditorForXml(org.eclipse.sapphire.ui.swt.xml.editor.SapphireEditorForXml) MasterDetailsEditorPage(org.eclipse.sapphire.ui.forms.swt.MasterDetailsEditorPage) SapphireEditor(org.eclipse.sapphire.ui.SapphireEditor) Element(org.eclipse.sapphire.Element) MasterDetailsContentOutline(org.eclipse.sapphire.ui.forms.MasterDetailsContentOutline) PortletNode(com.liferay.ide.portlet.ui.navigator.PortletNode)

Example 2 with PortletNode

use of com.liferay.ide.portlet.ui.navigator.PortletNode in project liferay-ide by liferay.

the class OpenPortletResourceAction method openPortletJavaClass.

/**
 * @param file
 */
protected void openPortletJavaClass(IFile file) {
    Element modelElement = ((PortletNode) selectedNode).getModel();
    if (modelElement instanceof Portlet) {
        Portlet portlet = (Portlet) modelElement;
        JavaTypeName portletClassFile = portlet.getPortletClass().content();
        Runnable run = new Runnable() {

            public void run() {
                IJavaProject project = JavaCore.create(file.getProject());
                String fullyQualifiedName = portletClassFile.qualified();
                try {
                    IType type = project.findType(fullyQualifiedName);
                    if ((type != null) && type.exists()) {
                        IResource resource = type.getResource();
                        if (resource instanceof IFile) {
                            IFile javaFile = (IFile) resource;
                            IEditorDescriptor editorDescriptor = findEditor(javaFile);
                            IEditorPart editorPart = null;
                            if (editorDescriptor != null) {
                                IWorkbench workbench = PlatformUI.getWorkbench();
                                IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
                                try {
                                    editorPart = page.findEditor(new FileEditorInput(javaFile));
                                    if (editorPart == null) {
                                        editorPart = page.openEditor(new FileEditorInput(javaFile), editorDescriptor.getId());
                                    }
                                } catch (Exception e) {
                                    MessageDialog.openError(page.getWorkbenchWindow().getShell(), Msgs.errorOpeningFile, e.getMessage());
                                }
                            }
                        }
                    }
                } catch (JavaModelException jme) {
                    PortletUIPlugin.logError(jme);
                }
            }
        };
        Display.getDefault().asyncExec(run);
    }
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) Portlet(com.liferay.ide.portlet.core.model.Portlet) IFile(org.eclipse.core.resources.IFile) Element(org.eclipse.sapphire.Element) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) IEditorPart(org.eclipse.ui.IEditorPart) JavaModelException(org.eclipse.jdt.core.JavaModelException) PortletNode(com.liferay.ide.portlet.ui.navigator.PortletNode) IType(org.eclipse.jdt.core.IType) IWorkbench(org.eclipse.ui.IWorkbench) IJavaProject(org.eclipse.jdt.core.IJavaProject) JavaTypeName(org.eclipse.sapphire.java.JavaTypeName) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IResource(org.eclipse.core.resources.IResource)

Example 3 with PortletNode

use of com.liferay.ide.portlet.ui.navigator.PortletNode in project liferay-ide by liferay.

the class OpenPortletResourceAction method run.

@Override
public void run() {
    if (isEnabled()) {
        IFile file = initEditorPart();
        if ((file != null) && file.exists()) {
            editorPart = openEditor(file);
            if ((editorPart != null) && selectedNode instanceof PortletNode) {
                selectAndRevealItem(editorPart);
                openPortletJavaClass(file);
            }
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) PortletNode(com.liferay.ide.portlet.ui.navigator.PortletNode)

Example 4 with PortletNode

use of com.liferay.ide.portlet.ui.navigator.PortletNode in project liferay-ide by liferay.

the class OpenPortletResourceAction method initEditorPart.

protected IFile initEditorPart() {
    IFile file = null;
    if (selectedNode instanceof PortletsNode) {
        PortletsNode portletsNode = (PortletsNode) selectedNode;
        PortletResourcesRootNode rootNode = portletsNode.getParent();
        file = ProjectUtil.getPortletXmlFile(rootNode.getProject());
    } else if (selectedNode instanceof PortletNode) {
        PortletNode portletNode = (PortletNode) selectedNode;
        PortletResourcesRootNode rootNode = portletNode.getParent().getParent();
        file = ProjectUtil.getPortletXmlFile(rootNode.getProject());
    }
    if ((editorPart == null) && (file != null)) {
        IWorkbench workbench = PlatformUI.getWorkbench();
        IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
        IEditorReference[] editorReferences = page.getEditorReferences();
        for (IEditorReference iEditorReference : editorReferences) {
            if (file.getName().equals(iEditorReference.getName())) {
                editorPart = iEditorReference.getEditor(false);
            }
        }
    }
    return file;
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IFile(org.eclipse.core.resources.IFile) IEditorReference(org.eclipse.ui.IEditorReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PortletsNode(com.liferay.ide.portlet.ui.navigator.PortletsNode) PortletResourcesRootNode(com.liferay.ide.portlet.ui.navigator.PortletResourcesRootNode) PortletNode(com.liferay.ide.portlet.ui.navigator.PortletNode)

Aggregations

PortletNode (com.liferay.ide.portlet.ui.navigator.PortletNode)4 IFile (org.eclipse.core.resources.IFile)3 Portlet (com.liferay.ide.portlet.core.model.Portlet)2 Element (org.eclipse.sapphire.Element)2 IWorkbench (org.eclipse.ui.IWorkbench)2 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)2 PortletResourcesRootNode (com.liferay.ide.portlet.ui.navigator.PortletResourcesRootNode)1 PortletsNode (com.liferay.ide.portlet.ui.navigator.PortletsNode)1 IResource (org.eclipse.core.resources.IResource)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 IType (org.eclipse.jdt.core.IType)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 JavaTypeName (org.eclipse.sapphire.java.JavaTypeName)1 SapphireEditor (org.eclipse.sapphire.ui.SapphireEditor)1 MasterDetailsContentNodeList (org.eclipse.sapphire.ui.forms.MasterDetailsContentNodeList)1 MasterDetailsContentNodePart (org.eclipse.sapphire.ui.forms.MasterDetailsContentNodePart)1 MasterDetailsContentOutline (org.eclipse.sapphire.ui.forms.MasterDetailsContentOutline)1 MasterDetailsEditorPage (org.eclipse.sapphire.ui.forms.swt.MasterDetailsEditorPage)1 SapphireEditorForXml (org.eclipse.sapphire.ui.swt.xml.editor.SapphireEditorForXml)1 IEditorDescriptor (org.eclipse.ui.IEditorDescriptor)1