Search in sources :

Example 6 with Portlet

use of com.liferay.ide.portlet.core.model.Portlet 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)

Aggregations

Portlet (com.liferay.ide.portlet.core.model.Portlet)6 IFile (org.eclipse.core.resources.IFile)3 Element (org.eclipse.sapphire.Element)3 PortletApp (com.liferay.ide.portlet.core.model.PortletApp)2 PortletInfo (com.liferay.ide.portlet.core.model.PortletInfo)2 SupportedLocales (com.liferay.ide.portlet.core.model.SupportedLocales)2 PortletNode (com.liferay.ide.portlet.ui.navigator.PortletNode)2 IProject (org.eclipse.core.resources.IProject)2 IPath (org.eclipse.core.runtime.IPath)2 Path (org.eclipse.sapphire.modeling.Path)2 MasterDetailsContentNodePart (org.eclipse.sapphire.ui.forms.MasterDetailsContentNodePart)2 Param (com.liferay.ide.portlet.core.model.Param)1 SecurityRoleRef (com.liferay.ide.portlet.core.model.SecurityRoleRef)1 Supports (com.liferay.ide.portlet.core.model.Supports)1 LocaleBundleValidationService (com.liferay.ide.portlet.core.model.internal.LocaleBundleValidationService)1 ArrayList (java.util.ArrayList)1 IFolder (org.eclipse.core.resources.IFolder)1 IResource (org.eclipse.core.resources.IResource)1 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1