Search in sources :

Example 41 with Element

use of org.eclipse.sapphire.Element 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)

Example 42 with Element

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

the class HierarchyJavaTypeBrowseActionHandler method browse.

@Override
public String browse(Presentation context) {
    Element element = getModelElement();
    Property property = property();
    IProject project = element.adapt(IProject.class);
    try {
        JavaTypeConstraintService typeService = property.service(JavaTypeConstraintService.class);
        EnumSet<JavaTypeKind> kinds = EnumSet.noneOf(JavaTypeKind.class);
        kinds.addAll(typeService.kinds());
        int browseDialogStyle = IJavaElementSearchConstants.CONSIDER_ALL_TYPES;
        int count = kinds.size();
        if (count == 1) {
            JavaTypeKind kind = kinds.iterator().next();
            switch(kind) {
                case CLASS:
                    browseDialogStyle = IJavaElementSearchConstants.CONSIDER_CLASSES;
                    break;
                case ABSTRACT_CLASS:
                    browseDialogStyle = IJavaElementSearchConstants.CONSIDER_CLASSES;
                    break;
                case INTERFACE:
                    browseDialogStyle = IJavaElementSearchConstants.CONSIDER_INTERFACES;
                    break;
                case ANNOTATION:
                    browseDialogStyle = IJavaElementSearchConstants.CONSIDER_ANNOTATION_TYPES;
                    break;
                case ENUM:
                    browseDialogStyle = IJavaElementSearchConstants.CONSIDER_ENUMS;
                    break;
                default:
                    throw new IllegalStateException();
            }
        } else if (count == 2) {
            if (kinds.contains(JavaTypeKind.CLASS) || kinds.contains(JavaTypeKind.ABSTRACT_CLASS)) {
                if (kinds.contains(JavaTypeKind.INTERFACE)) {
                    browseDialogStyle = IJavaElementSearchConstants.CONSIDER_CLASSES_AND_INTERFACES;
                } else if (kinds.contains(JavaTypeKind.ENUM)) {
                    browseDialogStyle = IJavaElementSearchConstants.CONSIDER_CLASSES_AND_ENUMS;
                }
            }
        }
        IJavaSearchScope scope = null;
        IType type = JavaCore.create(project).findType(_typeName);
        if (type != null) {
            scope = SearchEngine.createHierarchyScope(type);
        }
        SwtPresentation swt = (SwtPresentation) context;
        SelectionDialog dlg = JavaUI.createTypeDialog(swt.shell(), null, scope, browseDialogStyle, false, _filter, null);
        String title = property.definition().getLabel(true, CapitalizationType.TITLE_STYLE, false);
        dlg.setTitle(Msgs.select + title);
        if (dlg.open() == SelectionDialog.OK) {
            Object[] results = dlg.getResult();
            assert (results != null) && (results.length == 1);
            if (results[0] instanceof IType) {
                return ((IType) results[0]).getFullyQualifiedName();
            }
        }
    } catch (JavaModelException jme) {
        HookUI.logError(jme);
    }
    return null;
}
Also used : JavaTypeKind(org.eclipse.sapphire.java.JavaTypeKind) JavaModelException(org.eclipse.jdt.core.JavaModelException) Element(org.eclipse.sapphire.Element) SelectionDialog(org.eclipse.ui.dialogs.SelectionDialog) IProject(org.eclipse.core.resources.IProject) IType(org.eclipse.jdt.core.IType) JavaTypeConstraintService(org.eclipse.sapphire.java.JavaTypeConstraintService) IJavaSearchScope(org.eclipse.jdt.core.search.IJavaSearchScope) SwtPresentation(org.eclipse.sapphire.ui.forms.swt.SwtPresentation) Property(org.eclipse.sapphire.Property)

Example 43 with Element

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

the class PortalFilterNamesPossibleValuesService method compute.

@Override
protected void compute(Set<String> values) {
    if (_servletFilterNames == null) {
        Element element = context().find(Element.class);
        IFile hookFile = element.adapt(IFile.class);
        if (hookFile != null) {
            try {
                ILiferayProject liferayProject = LiferayCore.create(hookFile.getProject());
                if (liferayProject != null) {
                    ILiferayPortal portal = liferayProject.adapt(ILiferayPortal.class);
                    if (portal != null) {
                        IPath appServerPortalDir = portal.getAppServerPortalDir();
                        if (appServerPortalDir != null) {
                            _servletFilterNames = ServerUtil.getServletFilterNames(appServerPortalDir);
                        }
                    }
                }
            } catch (Exception e) {
            }
        }
    }
    if (_servletFilterNames != null) {
        Collections.addAll(values, _servletFilterNames);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) ILiferayProject(com.liferay.ide.core.ILiferayProject) Element(org.eclipse.sapphire.Element) ILiferayPortal(com.liferay.ide.core.ILiferayPortal)

Example 44 with Element

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

the class PortletColumnsListener method handleTypedEvent.

@Override
protected void handleTypedEvent(PropertyContentEvent event) {
    Property property = event.property();
    Element element = property.element();
    LayoutTplElement layouttpl = element.nearest(LayoutTplElement.class);
    updateColumns(layouttpl, 1);
}
Also used : LayoutTplElement(com.liferay.ide.layouttpl.core.model.LayoutTplElement) PortletColumnElement(com.liferay.ide.layouttpl.core.model.PortletColumnElement) Element(org.eclipse.sapphire.Element) PortletLayoutElement(com.liferay.ide.layouttpl.core.model.PortletLayoutElement) Property(org.eclipse.sapphire.Property) LayoutTplElement(com.liferay.ide.layouttpl.core.model.LayoutTplElement)

Example 45 with Element

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

the class PortletModeImageService method compute.

@Override
protected ImageData compute() {
    String portletMode = null;
    Element element = context(Element.class);
    ImageData imageData = null;
    if (element instanceof CustomPortletMode) {
        CustomPortletMode iCustomPortletMode = (CustomPortletMode) element;
        portletMode = String.valueOf(iCustomPortletMode.getPortletMode().content());
    } else if (element instanceof PortletMode) {
        PortletMode iPortletMode = (PortletMode) element;
        portletMode = iPortletMode.getPortletMode().content();
    }
    if (portletMode != null) {
        if ("VIEW".equalsIgnoreCase(portletMode)) {
            imageData = IMG_VIEW;
        } else if ("EDIT".equalsIgnoreCase(portletMode)) {
            imageData = IMG_EDIT;
        } else if ("HELP".equalsIgnoreCase(portletMode)) {
            imageData = IMG_HELP;
        }
    }
    if (imageData == null) {
        imageData = IMG_DEFAULT;
    }
    return imageData;
}
Also used : ImageData(org.eclipse.sapphire.ImageData) Element(org.eclipse.sapphire.Element) CustomPortletMode(com.liferay.ide.portlet.core.model.CustomPortletMode) CustomPortletMode(com.liferay.ide.portlet.core.model.CustomPortletMode) PortletMode(com.liferay.ide.portlet.core.model.PortletMode)

Aggregations

Element (org.eclipse.sapphire.Element)58 IProject (org.eclipse.core.resources.IProject)13 IFile (org.eclipse.core.resources.IFile)12 Property (org.eclipse.sapphire.Property)8 ValueProperty (org.eclipse.sapphire.ValueProperty)8 IPath (org.eclipse.core.runtime.IPath)7 Event (org.eclipse.sapphire.Event)6 PropertyEvent (org.eclipse.sapphire.PropertyEvent)6 FilteredListener (org.eclipse.sapphire.FilteredListener)5 Listener (org.eclipse.sapphire.Listener)5 Path (org.eclipse.sapphire.modeling.Path)5 IType (org.eclipse.jdt.core.IType)4 JavaModelException (org.eclipse.jdt.core.JavaModelException)4 DisposeEvent (org.eclipse.sapphire.DisposeEvent)4 SapphirePart (org.eclipse.sapphire.ui.SapphirePart)4 Task (com.liferay.ide.kaleo.core.model.Task)3 DynamicElement (com.liferay.ide.portal.core.structures.model.DynamicElement)3 ArrayList (java.util.ArrayList)3 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)3 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)3