Search in sources :

Example 1 with IWebProject

use of com.liferay.ide.core.IWebProject in project liferay-ide by liferay.

the class NewCustomJSPsHookWizardPage method handleFileBrowseButton.

protected void handleFileBrowseButton(Text text) {
    ISelectionStatusValidator validator = getContainerDialogSelectionValidator();
    ViewerFilter filter = getContainerDialogViewerFilter();
    ITreeContentProvider contentProvider = new WorkbenchContentProvider();
    IDecoratorManager decoratorManager = PlatformUI.getWorkbench().getDecoratorManager();
    ILabelProvider labelProvider = new DecoratingLabelProvider(new WorkbenchLabelProvider(), decoratorManager.getLabelDecorator());
    ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), labelProvider, contentProvider);
    dialog.setValidator(validator);
    dialog.setTitle(J2EEUIMessages.CONTAINER_SELECTION_DIALOG_TITLE);
    dialog.setMessage(J2EEUIMessages.CONTAINER_SELECTION_DIALOG_DESC);
    dialog.addFilter(filter);
    dialog.setInput(CoreUtil.getWorkspaceRoot());
    if (dialog.open() == Window.OK) {
        Object element = dialog.getFirstResult();
        try {
            if (element instanceof IFolder) {
                IFolder folder = (IFolder) element;
                IProject project = CoreUtil.getProject(getDataModel().getStringProperty(PROJECT_NAME));
                IWebProject webproject = LiferayCore.create(IWebProject.class, project);
                if (webproject != null) {
                    IFolder defaultWebappRootFolder = webproject.getDefaultDocrootFolder();
                    if (folder.equals(defaultWebappRootFolder)) {
                        folder = folder.getFolder("custom_jsps");
                    }
                    String defaultWebappRootFolderFullPath = defaultWebappRootFolder.getFullPath().toPortableString();
                    String folderFullPath = folder.getFullPath().toPortableString();
                    int index = folderFullPath.indexOf(defaultWebappRootFolderFullPath);
                    if (index != -1) {
                        folderFullPath = folderFullPath.substring(index + defaultWebappRootFolderFullPath.length());
                    }
                    text.setText(folderFullPath);
                }
            }
        } catch (Exception ex) {
        // Do nothing
        }
    }
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) IWebProject(com.liferay.ide.core.IWebProject) IDecoratorManager(org.eclipse.ui.IDecoratorManager) DecoratingLabelProvider(org.eclipse.jface.viewers.DecoratingLabelProvider) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) IProject(org.eclipse.core.resources.IProject) ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) ISelectionStatusValidator(org.eclipse.ui.dialogs.ISelectionStatusValidator) IFolder(org.eclipse.core.resources.IFolder)

Example 2 with IWebProject

use of com.liferay.ide.core.IWebProject in project liferay-ide by liferay.

the class HookXmlEditor method _copyCustomJspsToProject.

private void _copyCustomJspsToProject(IPath portalDir, ElementList<CustomJsp> customJsps) {
    try {
        Hook hook = getModelElement().nearest(Hook.class);
        ElementHandle<CustomJspDir> element = hook.getCustomJspDir();
        CustomJspDir customJspDirElement = element.content();
        if ((customJspDirElement != null) && customJspDirElement.validation().ok()) {
            Path customJspDir = customJspDirElement.getValue().content();
            IWebProject webproject = LiferayCore.create(IWebProject.class, getProject());
            if (webproject != null) {
                IFolder defaultDocroot = webproject.getDefaultDocrootFolder();
                IFolder customJspFolder = defaultDocroot.getFolder(customJspDir.toPortableString());
                for (CustomJsp customJsp : customJsps) {
                    String content = customJsp.getValue().content();
                    if (!empty(content)) {
                        IFile customJspFile = customJspFolder.getFile(content);
                        if (!customJspFile.exists()) {
                            IPath portalJsp = portalDir.append(content);
                            try {
                                CoreUtil.makeFolders((IFolder) customJspFile.getParent());
                                if (portalJsp.toFile().exists()) {
                                    customJspFile.create(Files.newInputStream(portalJsp.toFile().toPath()), true, null);
                                } else {
                                    CoreUtil.createEmptyFile(customJspFile);
                                }
                            } catch (Exception e) {
                                HookUI.logError(e);
                            }
                        }
                    }
                }
            }
        }
    } catch (Exception e) {
        HookUI.logError(e);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.sapphire.modeling.Path) Hook(com.liferay.ide.hook.core.model.Hook) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) IWebProject(com.liferay.ide.core.IWebProject) CustomJsp(com.liferay.ide.hook.core.model.CustomJsp) CustomJspDir(com.liferay.ide.hook.core.model.CustomJspDir) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) IFolder(org.eclipse.core.resources.IFolder)

Example 3 with IWebProject

use of com.liferay.ide.core.IWebProject in project liferay-ide by liferay.

the class NewHookDataModelProvider method getDefaultProperty.

@Override
public Object getDefaultProperty(String propertyName) {
    if (CUSTOM_JSPS_FOLDER.equals(propertyName)) {
        // check to see if there is an existing hook descriptor and read
        // custom_jsps out of that
        IProject targetProject = getTargetProject();
        IWebProject webproject = LiferayCore.create(IWebProject.class, targetProject);
        if (webproject != null) {
            IFolder defaultWebappRootFolder = webproject.getDefaultDocrootFolder();
            String defaultWebappRootPath = defaultWebappRootFolder.getFullPath().toPortableString();
            if (targetProject != null) {
                HookDescriptorHelper hookDescriptorHelper = new HookDescriptorHelper(targetProject);
                String customJspFolder = hookDescriptorHelper.getCustomJSPFolder(getDataModel());
                if (customJspFolder != null) {
                    // folder should be relative to the web app folder root
                    // IDE-110 IDE-648
                    IFolder defaultDocroot = webproject.getDefaultDocrootFolder();
                    if (defaultDocroot != null) {
                        IPath defaultDocrootPath = defaultDocroot.getFullPath();
                        String containerFullPath = defaultDocrootPath.append(customJspFolder).toPortableString();
                        int index = containerFullPath.indexOf(defaultWebappRootPath);
                        if (index != -1) {
                            int beginIndex = index + defaultWebappRootPath.length();
                            containerFullPath = containerFullPath.substring(beginIndex);
                        }
                        return containerFullPath;
                    }
                }
                if (defaultWebappRootFolder != null) {
                    return "/META-INF/custom_jsps";
                }
            }
        }
    } else if (PORTAL_PROPERTIES_FILE.equals(propertyName)) {
        IProject targetProject = getTargetProject();
        List<IFolder> sources = CoreUtil.getSourceFolders(JavaCore.create(targetProject));
        if ((targetProject != null) && ListUtil.isNotEmpty(sources)) {
            IPath sourcePath = sources.get(0).getFullPath();
            return sourcePath.append("portal.properties").toPortableString();
        }
    } else if (CONTENT_FOLDER.equals(propertyName)) {
        IProject targetProject = getTargetProject();
        List<IFolder> sources = CoreUtil.getSourceFolders(JavaCore.create(targetProject));
        if ((targetProject != null) && !sources.isEmpty()) {
            IPath sourcePath = sources.get(0).getFullPath();
            return sourcePath.append("content").toPortableString();
        }
    } else if (SELECTED_PROJECT.equals(propertyName)) {
        IProject targetProject = getTargetProject();
        if (targetProject != null) {
            return targetProject.getName();
        }
    } else if (WEB_ROOT_FOLDER.equals(propertyName)) {
        IProject targetProject = getTargetProject();
        IWebProject webproject = LiferayCore.create(IWebProject.class, targetProject);
        if ((targetProject != null) && (webproject != null)) {
            return webproject.getDefaultDocrootFolder().getName();
        }
    } else if (propertyName.equals(PROJECT)) {
        return getTargetProject();
    } else if (propertyName.equals(SOURCE_FOLDER)) {
        IFolder sourceFolder = getDefaultJavaSourceFolder();
        if (FileUtil.exists(sourceFolder)) {
            return sourceFolder.getFullPath().toPortableString();
        }
    } else if (propertyName.equals(JAVA_SOURCE_FOLDER)) {
        return getJavaSourceFolder();
    } else if (propertyName.equals(JAVA_PACKAGE_FRAGMENT_ROOT)) {
        return getJavaPackageFragmentRoot();
    } else if (CUSTOM_JSPS_FILES_CREATED.equals(propertyName)) {
        return new HashSet<>();
    } else if (LANGUAGE_PROPERTIES_FILES_CREATED.equals(propertyName)) {
        return new HashSet<>();
    } else if (DISABLE_CUSTOM_JSP_FOLDER_VALIDATION.equals(propertyName)) {
        return true;
    }
    return super.getDefaultProperty(propertyName);
}
Also used : IPath(org.eclipse.core.runtime.IPath) IWebProject(com.liferay.ide.core.IWebProject) HookDescriptorHelper(com.liferay.ide.hook.core.dd.HookDescriptorHelper) List(java.util.List) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder) HashSet(java.util.HashSet)

Example 4 with IWebProject

use of com.liferay.ide.core.IWebProject in project liferay-ide by liferay.

the class CustomJspsEnablementService method compute.

@Override
protected Boolean compute() {
    boolean enablement = true;
    ElementHandle<CustomJspDir> elementHandle = _hook().getCustomJspDir();
    CustomJspDir customJspDir = elementHandle.content();
    if (customJspDir != null) {
        IProject project = _hook().adapt(IProject.class);
        Path customJspDirPath = customJspDir.getValue().content(true);
        if ((project != null) && (customJspDirPath != null)) {
            IWebProject lrproject = LiferayCore.create(IWebProject.class, project);
            if (lrproject != null) {
                IFolder defaultWebappDir = lrproject.getDefaultDocrootFolder();
                if (FileUtil.exists(defaultWebappDir)) {
                    IFolder customJspFolder = defaultWebappDir.getFolder(PathBridge.create(customJspDirPath));
                    enablement = FileUtil.exists(customJspFolder);
                }
            }
        }
    }
    return enablement;
}
Also used : Path(org.eclipse.sapphire.modeling.Path) IWebProject(com.liferay.ide.core.IWebProject) CustomJspDir(com.liferay.ide.hook.core.model.CustomJspDir) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

Example 5 with IWebProject

use of com.liferay.ide.core.IWebProject in project liferay-ide by liferay.

the class NewPortletClassDataModelProvider method validate.

@Override
public IStatus validate(String propertyName) {
    if (PORTLET_NAME.equals(propertyName)) {
        // must have a valid portlet name
        String portletName = getStringProperty(PORTLET_NAME);
        if ((portletName == null) || (portletName.length() == 0)) {
            return PortletCore.createErrorStatus(Msgs.portletNameEmpty);
        }
        PortletDescriptorHelper portletDescriptorHelper = new PortletDescriptorHelper(getTargetProject());
        String[] portletNames = portletDescriptorHelper.getAllPortletNames();
        for (String name : portletNames) {
            if (name.equals(portletName)) {
                return PortletCore.createErrorStatus(Msgs.portletNameExists);
            }
        }
    } else if (CREATE_RESOURCE_BUNDLE_FILE_PATH.equals(propertyName)) {
        if (!getBooleanProperty(CREATE_RESOURCE_BUNDLE_FILE)) {
            return Status.OK_STATUS;
        }
        boolean validPath = false;
        boolean validFileName = false;
        String val = getStringProperty(propertyName);
        if (CoreUtil.isNullOrEmpty(val)) {
            return PortletCore.createErrorStatus(Msgs.resourceBundleFilePathValid);
        }
        try {
            IPath path = new Path(val);
            validPath = path.isValidPath(val);
            if ("properties".equals(path.getFileExtension())) {
                validFileName = true;
            }
        } catch (Exception e) {
        // eat errors
        }
        if (!validPath) {
            return PortletCore.createErrorStatus(Msgs.resourceBundleFilePathValid);
        }
        if (validFileName) {
            return super.validate(propertyName);
        } else {
            return PortletCore.createWarningStatus(Msgs.resourceBundleFilePathEndWithProperties);
        }
    } else if (CREATE_JSPS_FOLDER.equals(propertyName)) {
        if (!getBooleanProperty(CREATE_JSPS)) {
            return Status.OK_STATUS;
        }
        String folderValue = getStringProperty(propertyName);
        if (CoreUtil.isNullOrEmpty(folderValue)) {
            return PortletCore.createErrorStatus(Msgs.jspFolderNotEmpty);
        }
        IProject targetProject = getTargetProject();
        if (!CoreUtil.isNullOrEmpty(folderValue) && (targetProject != null)) {
            IWebProject webproject = LiferayCore.create(IWebProject.class, targetProject);
            if (webproject != null) {
                IFolder defaultDocroot = webproject.getDefaultDocrootFolder();
                IStatus validation = _validateFolder(defaultDocroot, folderValue);
                if ((validation != null) && !validation.isOK()) {
                    return validation;
                }
                // make sure path first segment isn't the same as the portlet name
                String path = new Path(folderValue).segment(0);
                if (!CoreUtil.isNullOrEmpty(path) && path.equals(getStringProperty(PORTLET_NAME))) {
                    return PortletCore.createErrorStatus(Msgs.jspFolderNotMatchPortletName);
                }
            }
        }
    } else if (SOURCE_FOLDER.equals(propertyName) && fragment) {
        return Status.OK_STATUS;
    } else if (SUPERCLASS.equals(propertyName)) {
        String superclass = getStringProperty(propertyName);
        if (CoreUtil.isNullOrEmpty(superclass)) {
            return PortletCore.createErrorStatus(Msgs.specifyPortletSuperclass);
        }
        if (fragment) {
            return JavaConventions.validateJavaTypeName(superclass, JavaCore.VERSION_1_5, JavaCore.VERSION_1_5);
        }
        if (!isValidPortletClass(superclass)) {
            return PortletCore.createErrorStatus(Msgs.portletSuperclassValid);
        }
    } else if (CATEGORY.equals(propertyName)) {
        String category = getStringProperty(propertyName);
        if (category.matches("\\s*")) {
            return PortletCore.createErrorStatus(Msgs.categoryNameEmpty);
        }
    } else if (ENTRY_WEIGHT.equals(propertyName)) {
        if (!getBooleanProperty(ADD_TO_CONTROL_PANEL)) {
            return Status.OK_STATUS;
        }
        String entryweight = getStringProperty(propertyName);
        if (!CoreUtil.isNumeric(entryweight)) {
            return PortletCore.createErrorStatus(Msgs.specifyValidDouble);
        }
        return Status.OK_STATUS;
    } else if (ENTRY_CLASS_NAME.equals(propertyName)) {
        if (!getBooleanProperty(ADD_TO_CONTROL_PANEL) || !getBooleanProperty(CREATE_ENTRY_CLASS)) {
            return Status.OK_STATUS;
        }
        String entryclasswrapper = getStringProperty(propertyName);
        if (validateJavaClassName(entryclasswrapper).getSeverity() != IStatus.ERROR) {
            IStatus existsStatus = canCreateTypeInClasspath(entryclasswrapper);
            if (existsStatus.matches(IStatus.ERROR | IStatus.WARNING)) {
                return existsStatus;
            }
        }
        return validateJavaClassName(entryclasswrapper);
    } else if (CLASS_NAME.equals(propertyName)) {
        if (getBooleanProperty(USE_DEFAULT_PORTLET_CLASS)) {
            return Status.OK_STATUS;
        }
    }
    return super.validate(propertyName);
}
Also used : PortletDescriptorHelper(com.liferay.ide.portlet.core.dd.PortletDescriptorHelper) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IStatus(org.eclipse.core.runtime.IStatus) IPath(org.eclipse.core.runtime.IPath) IWebProject(com.liferay.ide.core.IWebProject) CoreException(org.eclipse.core.runtime.CoreException) JavaModelException(org.eclipse.jdt.core.JavaModelException) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

IWebProject (com.liferay.ide.core.IWebProject)46 IFolder (org.eclipse.core.resources.IFolder)31 IFile (org.eclipse.core.resources.IFile)27 IProject (org.eclipse.core.resources.IProject)25 IPath (org.eclipse.core.runtime.IPath)24 Path (org.eclipse.core.runtime.Path)20 CoreException (org.eclipse.core.runtime.CoreException)15 IResource (org.eclipse.core.resources.IResource)10 IStatus (org.eclipse.core.runtime.IStatus)6 NewLiferayPluginProjectOp (com.liferay.ide.project.core.model.NewLiferayPluginProjectOp)5 IOException (java.io.IOException)5 Test (org.junit.Test)5 SDK (com.liferay.ide.sdk.core.SDK)4 Path (org.eclipse.sapphire.modeling.Path)4 CustomJspDir (com.liferay.ide.hook.core.model.CustomJspDir)3 InputStream (java.io.InputStream)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 HookDescriptorHelper (com.liferay.ide.hook.core.dd.HookDescriptorHelper)2 Hook (com.liferay.ide.hook.core.model.Hook)2 File (java.io.File)2