Search in sources :

Example 1 with Portlet

use of com.liferay.ide.portlet.core.model.Portlet in project liferay-ide by liferay.

the class LocaleBundleValidationService method compute.

public Status compute() {
    Element modelElement = context(Element.class);
    if (!modelElement.disposed() && modelElement instanceof SupportedLocales) {
        IProject project = modelElement.adapt(IProject.class);
        Portlet portlet = modelElement.nearest(Portlet.class);
        IWorkspaceRoot wroot = ResourcesPlugin.getWorkspace().getRoot();
        IClasspathEntry[] cpEntries = CoreUtil.getClasspathEntries(project);
        if (cpEntries != null) {
            String locale = modelElement.property(context(ValueProperty.class)).text(false);
            Value<Path> resourceBundle = portlet.getResourceBundle();
            if (locale == null) {
                return Status.createErrorStatus(Resources.localeMustNotEmpty);
            } else {
                String bundleName = resourceBundle.text();
                if ((resourceBundle != null) && (bundleName != null)) {
                    String localeString = PortletUtil.localeString(locale);
                    String ioFileName = PortletUtil.convertJavaToIoFileName(bundleName, RB_FILE_EXTENSION, localeString);
                    for (IClasspathEntry iClasspathEntry : cpEntries) {
                        if (IClasspathEntry.CPE_SOURCE == iClasspathEntry.getEntryKind()) {
                            IPath entryPath = wroot.getFolder(iClasspathEntry.getPath()).getLocation();
                            entryPath = entryPath.append(ioFileName);
                            IFile resourceBundleFile = wroot.getFileForLocation(entryPath);
                            if ((resourceBundleFile != null) && resourceBundleFile.exists()) {
                                return Status.createOkStatus();
                            } else {
                                return Status.createWarningStatus(Resources.bind(StringEscapeUtils.unescapeJava(Resources.noResourceBundle), new Object[] { locale, bundleName, localeString }));
                            }
                        }
                    }
                }
            }
        }
    }
    return Status.createOkStatus();
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.sapphire.modeling.Path) Portlet(com.liferay.ide.portlet.core.model.Portlet) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) Element(org.eclipse.sapphire.Element) SupportedLocales(com.liferay.ide.portlet.core.model.SupportedLocales) IProject(org.eclipse.core.resources.IProject) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot)

Example 2 with Portlet

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

use of com.liferay.ide.portlet.core.model.Portlet in project liferay-ide by liferay.

the class CreatePortletActionHandler method run.

/**
 * (non-Javadoc)
 *
 * @see
 * SapphireActionHandler#run(org.eclipse.sapphire.ui.
 * SapphireRenderingContext)
 */
@Override
protected Object run(Presentation context) {
    PortletApp rootModel = (PortletApp) context.part().getModelElement();
    Portlet portlet = rootModel.getPortlets().insert();
    // Open the dialog to capture the mandatory properties
    SapphireDialog dialog = new SapphireDialog(((SwtPresentation) context).shell(), portlet, DefinitionLoader.sdef(PortletXmlEditor.class).dialog());
    if ((dialog != null) && (Dialog.OK == dialog.open())) {
        // Select the node
        MasterDetailsEditorPagePart page = getPart().nearest(MasterDetailsEditorPagePart.class);
        MasterDetailsContentNodePart root = page.outline().getRoot();
        MasterDetailsContentNodePart node = root.findNode(portlet);
        if (node != null) {
            node.select();
        }
        try {
            rootModel.resource().save();
        } catch (ResourceStoreException rse) {
        // Log it in PorletUI Plugin
        }
        return portlet;
    } else {
        rootModel.getPortlets().remove(portlet);
        portlet = null;
        try {
            rootModel.resource().save();
        } catch (ResourceStoreException rse) {
        // Log it in PorletUI Plugin
        }
        return null;
    }
}
Also used : ResourceStoreException(org.eclipse.sapphire.modeling.ResourceStoreException) Portlet(com.liferay.ide.portlet.core.model.Portlet) MasterDetailsContentNodePart(org.eclipse.sapphire.ui.forms.MasterDetailsContentNodePart) MasterDetailsEditorPagePart(org.eclipse.sapphire.ui.forms.MasterDetailsEditorPagePart) SapphireDialog(org.eclipse.sapphire.ui.forms.swt.SapphireDialog) PortletApp(com.liferay.ide.portlet.core.model.PortletApp)

Example 4 with Portlet

use of com.liferay.ide.portlet.core.model.Portlet in project liferay-ide by liferay.

the class CreatePortletResourceBundleActionHandler method run.

/**
 * (non-Javadoc)
 *
 * @see
 * org.eclipse.sapphire.ui.SapphireActionHandler#run(org.eclipse.sapphire.ui.
 * SapphireRenderingContext)
 */
@Override
protected Object run(Presentation context) {
    ITextEditor editor = context.part().adapt(ITextEditor.class);
    editor.doSave(new NullProgressMonitor());
    List<IFile> missingRBFiles = new ArrayList<>();
    Portlet portlet = (Portlet) getModelElement();
    IProject project = portlet.adapt(IProject.class);
    Value<Path> resourceBundle = portlet.getResourceBundle();
    String text = resourceBundle.text();
    String defaultRBFileName = PortletUtil.convertJavaToIoFileName(text, GenericResourceBundlePathService.RB_FILE_EXTENSION);
    int index = text.lastIndexOf(".");
    String packageName = "";
    if (index == -1) {
        index = text.length();
        packageName = "";
    } else {
        packageName = text.substring(0, index);
    }
    IFolder rbSourceFolder = getResourceBundleFolderLocation(project, defaultRBFileName);
    IPath entryPath = rbSourceFolder.getLocation();
    PortletInfo portletInfo = portlet.getPortletInfo();
    StringBuilder rbFileBuffer = _buildDefaultRBContent(portletInfo);
    if (!getFileFromClasspath(project, defaultRBFileName)) {
        IFile drbFile = wroot.getFileForLocation(entryPath.append(defaultRBFileName));
        missingRBFiles.add(drbFile);
    }
    // Create bundles for each supported locale for which the resource bundle is
    // missing
    List<SupportedLocales> supportedLocales = portlet.getSupportedLocales();
    for (SupportedLocales iSupportedLocale : supportedLocales) {
        if (iSupportedLocale != null) {
            String locale = PortletUtil.localeString(iSupportedLocale.getSupportedLocale().text());
            String localizedIOFileName = PortletUtil.convertJavaToIoFileName(text, GenericResourceBundlePathService.RB_FILE_EXTENSION, locale);
            if (!getFileFromClasspath(project, localizedIOFileName)) {
                IFile rbFile = wroot.getFileForLocation(entryPath.append(localizedIOFileName));
                missingRBFiles.add(rbFile);
            }
        }
    }
    createFiles(context, project, packageName, missingRBFiles, rbFileBuffer);
    setEnabled(false);
    Portlet p = getModelElement().nearest(Portlet.class);
    for (SupportedLocales sl : p.getSupportedLocales()) {
        Value<String> locale = sl.getSupportedLocale();
        locale.service(LocaleBundleValidationService.class).forceRefresh();
    }
    return null;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.sapphire.modeling.Path) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IFile(org.eclipse.core.resources.IFile) Portlet(com.liferay.ide.portlet.core.model.Portlet) IPath(org.eclipse.core.runtime.IPath) SupportedLocales(com.liferay.ide.portlet.core.model.SupportedLocales) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject) LocaleBundleValidationService(com.liferay.ide.portlet.core.model.internal.LocaleBundleValidationService) PortletInfo(com.liferay.ide.portlet.core.model.PortletInfo) IFolder(org.eclipse.core.resources.IFolder)

Example 5 with Portlet

use of com.liferay.ide.portlet.core.model.Portlet in project liferay-ide by liferay.

the class PortletXmlTests method portletXmlRead.

@Test
public void portletXmlRead() throws Exception {
    final PortletApp portletApp = portletApp(PORTLET_XML);
    assertNotNull(portletApp);
    final ElementList<Portlet> portlets = portletApp.getPortlets();
    assertNotNull(portlets);
    assertEquals(1, portlets.size());
    final Portlet portlet = portlets.get(0);
    assertNotNull(portlet);
    assertEquals("1", portlet.getPortletName().content());
    assertEquals("Sample JSP", portlet.getDisplayName().content());
    assertEquals("com.liferay.samplejsp.portlet.JSPPortlet", portlet.getPortletClass().text());
    final Param param = portlet.getInitParams().get(0);
    assertNotNull(param);
    assertEquals("view-jsp", param.getName().content());
    assertEquals("/view.jsp", param.getValue().content());
    assertEquals(new Integer(0), portlet.getExpirationCache().content());
    final Supports supports = portlet.getSupports();
    assertNotNull(supports);
    assertEquals("text/html", supports.getMimeType().content());
    final PortletInfo info = portlet.getPortletInfo();
    assertEquals("Sample JSP", info.getTitle().content());
    assertEquals("Sample JSP", info.getShortTitle().content());
    assertEquals("Sample JSP", info.getKeywords().content());
    final ElementList<SecurityRoleRef> roles = portlet.getSecurityRoleRefs();
    assertEquals(4, roles.size());
    final SecurityRoleRef role = roles.get(1);
    assertNotNull(role);
    assertEquals("guest", role.getRoleName().content());
}
Also used : Portlet(com.liferay.ide.portlet.core.model.Portlet) Supports(com.liferay.ide.portlet.core.model.Supports) Param(com.liferay.ide.portlet.core.model.Param) PortletInfo(com.liferay.ide.portlet.core.model.PortletInfo) SecurityRoleRef(com.liferay.ide.portlet.core.model.SecurityRoleRef) PortletApp(com.liferay.ide.portlet.core.model.PortletApp) Test(org.junit.Test)

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