Search in sources :

Example 1 with RelativePathService

use of org.eclipse.sapphire.services.RelativePathService in project liferay-ide by liferay.

the class LiferayPortletXmlTest method testIconRelativePathService.

@Test
public void testIconRelativePathService() throws Exception {
    if (shouldSkipBundleTests())
        return;
    NewLiferayPluginProjectOp newProjectOp = NewLiferayPluginProjectOp.TYPE.instantiate();
    newProjectOp.setProjectName("test-path");
    newProjectOp.setPluginType(PluginType.portlet);
    newProjectOp.setIncludeSampleCode(true);
    newProjectOp.setPortletFramework("mvc");
    newProjectOp.setPortletName("testPortlet");
    final IProject testProject = createAntProject(newProjectOp);
    LiferayPortletXml liferayPortletApp = op(testProject);
    for (LiferayPortlet liferayPortlet : liferayPortletApp.getPortlets()) {
        final RelativePathService pathService = liferayPortlet.getIcon().service(RelativePathService.class);
        List<Path> iconPaths = pathService.roots();
        assertEquals(true, iconPaths.size() > 0);
    }
}
Also used : Path(org.eclipse.sapphire.modeling.Path) LiferayPortletXml(com.liferay.ide.portlet.core.lfportlet.model.LiferayPortletXml) RelativePathService(org.eclipse.sapphire.services.RelativePathService) NewLiferayPluginProjectOp(com.liferay.ide.project.core.model.NewLiferayPluginProjectOp) LiferayPortlet(com.liferay.ide.portlet.core.lfportlet.model.LiferayPortlet) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Example 2 with RelativePathService

use of org.eclipse.sapphire.services.RelativePathService in project liferay-ide by liferay.

the class CreateDirectoryActionHandler method computeEnablementState.

@Override
protected boolean computeEnablementState() {
    boolean enabled = super.computeEnablementState();
    if (enabled) {
        @SuppressWarnings("unchecked") Value<Path> value = (Value<Path>) getModelElement().property(property().definition());
        Path path = value.content();
        RelativePathService service = property().service(RelativePathService.class);
        Path absolutePath = service.convertToAbsolute(path);
        enabled = (absolutePath != null) && (!absolutePath.toFile().exists());
    }
    return enabled;
}
Also used : Path(org.eclipse.sapphire.modeling.Path) RelativePathService(org.eclipse.sapphire.services.RelativePathService) Value(org.eclipse.sapphire.Value)

Example 3 with RelativePathService

use of org.eclipse.sapphire.services.RelativePathService in project liferay-ide by liferay.

the class CreateDirectoryActionHandler method run.

@Override
protected Object run(Presentation context) {
    try {
        Element element = getModelElement();
        IProject project = element.adapt(IProject.class);
        CustomJspDir customJspDir = (CustomJspDir) element;
        Path customJspDirValue = customJspDir.getValue().content(false);
        if (customJspDirValue == null) {
            customJspDirValue = customJspDir.getValue().content(true);
            customJspDir.setValue(customJspDirValue);
        }
        customJspDir.setValue(customJspDirValue);
        RelativePathService service = property().service(RelativePathService.class);
        Path absolutePath = service.convertToAbsolute(customJspDirValue);
        if (FileUtil.notExists(absolutePath)) {
            IWebProject webproject = LiferayCore.create(IWebProject.class, project);
            if ((webproject != null) && (webproject.getDefaultDocrootFolder() != null)) {
                IFolder defaultDocroot = webproject.getDefaultDocrootFolder();
                IFolder customJspFolder = defaultDocroot.getFolder(new org.eclipse.core.runtime.Path(customJspDirValue.toPortableString()));
                CoreUtil.makeFolders(customJspFolder);
                // force a refresh of validation
                customJspDir.setValue((Path) null);
                customJspDir.setValue(customJspDirValue);
                refreshEnablementState();
            }
        }
    } catch (Exception e) {
        HookUI.logError(e);
    }
    return null;
}
Also used : Path(org.eclipse.sapphire.modeling.Path) IWebProject(com.liferay.ide.core.IWebProject) Element(org.eclipse.sapphire.Element) RelativePathService(org.eclipse.sapphire.services.RelativePathService) CustomJspDir(com.liferay.ide.hook.core.model.CustomJspDir) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

Path (org.eclipse.sapphire.modeling.Path)3 RelativePathService (org.eclipse.sapphire.services.RelativePathService)3 IProject (org.eclipse.core.resources.IProject)2 IWebProject (com.liferay.ide.core.IWebProject)1 CustomJspDir (com.liferay.ide.hook.core.model.CustomJspDir)1 LiferayPortlet (com.liferay.ide.portlet.core.lfportlet.model.LiferayPortlet)1 LiferayPortletXml (com.liferay.ide.portlet.core.lfportlet.model.LiferayPortletXml)1 NewLiferayPluginProjectOp (com.liferay.ide.project.core.model.NewLiferayPluginProjectOp)1 IFolder (org.eclipse.core.resources.IFolder)1 Element (org.eclipse.sapphire.Element)1 Value (org.eclipse.sapphire.Value)1 Test (org.junit.Test)1