Search in sources :

Example 46 with Element

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

Example 47 with Element

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

the class CreatePortletAppResourceBundleActionHandler method run.

/**
 * (non-Javadoc)
 *
 * @see
 * org.eclipse.sapphire.ui.SapphireActionHandler#run(org.eclipse.sapphire.ui.
 * SapphireRenderingContext)
 */
@Override
protected Object run(Presentation context) {
    Element element = getModelElement();
    IProject project = element.adapt(IProject.class);
    Property property = property();
    Value<Path> resourceBundle = element.property((ValueProperty) property.definition());
    String resourceBundleText = resourceBundle.text();
    int index = resourceBundleText.lastIndexOf(".");
    if (index == -1) {
        index = resourceBundleText.length();
    }
    String packageName = resourceBundleText.substring(0, index);
    String defaultRBFileName = PortletUtil.convertJavaToIoFileName(resourceBundleText, GenericResourceBundlePathService.RB_FILE_EXTENSION);
    IFolder rbSourecFolder = getResourceBundleFolderLocation(project, defaultRBFileName);
    IPath entryPath = rbSourecFolder.getLocation();
    if (getModelElement() instanceof PortletApp) {
        List<IFile> missingRBFiles = new ArrayList<>();
        StringBuilder rbFileBuffer = new StringBuilder("#Portlet Application Resource Bundle \n");
        IFile rbFile = wroot.getFileForLocation(entryPath.append(defaultRBFileName));
        missingRBFiles.add(rbFile);
        createFiles(context, project, packageName, missingRBFiles, rbFileBuffer);
        setEnabled(false);
        Property modelElement = getModelElement().property(property().definition());
        modelElement.refresh();
    }
    return null;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.sapphire.modeling.Path) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) Element(org.eclipse.sapphire.Element) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject) PortletApp(com.liferay.ide.portlet.core.model.PortletApp) ValueProperty(org.eclipse.sapphire.ValueProperty) Property(org.eclipse.sapphire.Property) IFolder(org.eclipse.core.resources.IFolder)

Example 48 with Element

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

the class CreatePortletAppResourceBundleActionHandler method init.

/**
 * (non-Javadoc)
 *
 * @see
 * org.eclipse.sapphire.ui.SapphirePropertyEditorActionHandler#init(org.eclipse.
 * sapphire.ui.SapphireAction, ActionHandlerDef)
 */
@Override
public void init(SapphireAction action, ActionHandlerDef def) {
    super.init(action, def);
    Element element = getModelElement();
    Property property = property();
    listener = new FilteredListener<PropertyEvent>() {

        @Override
        protected void handleTypedEvent(PropertyEvent event) {
            refreshEnablementState();
        }
    };
    element.attach(listener, property.definition().name());
    Listener listen = new Listener() {

        @Override
        public void handle(Event event) {
            if (event instanceof DisposeEvent) {
                PropertyDef definition = property().definition();
                getModelElement().detach(listener, definition.name());
            }
        }
    };
    attach(listen);
}
Also used : FilteredListener(org.eclipse.sapphire.FilteredListener) Listener(org.eclipse.sapphire.Listener) PropertyDef(org.eclipse.sapphire.PropertyDef) Element(org.eclipse.sapphire.Element) Event(org.eclipse.sapphire.Event) DisposeEvent(org.eclipse.sapphire.DisposeEvent) PropertyEvent(org.eclipse.sapphire.PropertyEvent) PropertyEvent(org.eclipse.sapphire.PropertyEvent) DisposeEvent(org.eclipse.sapphire.DisposeEvent) ValueProperty(org.eclipse.sapphire.ValueProperty) Property(org.eclipse.sapphire.Property)

Example 49 with Element

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

the class CreatePortletResourceBundleActionHandler method init.

/**
 * (non-Javadoc)
 *
 * @see
 * org.eclipse.sapphire.ui.SapphirePropertyEditorActionHandler#init(org.eclipse.
 * sapphire.ui.SapphireAction, ActionHandlerDef)
 */
@Override
public void init(SapphireAction action, ActionHandlerDef def) {
    super.init(action, def);
    Element element = getModelElement();
    listener = new FilteredListener<PropertyEvent>() {

        @Override
        protected void handleTypedEvent(PropertyEvent event) {
            refreshEnablementState();
        }
    };
    element.attach(listener, property().name());
    element.attach(listener, Portlet.PROP_SUPPORTED_LOCALES.name());
    element.attach(listener, Portlet.PROP_SUPPORTED_LOCALES.name() + "/" + SupportedLocales.PROP_SUPPORTED_LOCALE.name());
    Listener listen = new Listener() {

        public void handle(Event event) {
            if (event instanceof DisposeEvent) {
                getModelElement().detach(listener, property().name());
                getModelElement().detach(listener, Portlet.PROP_SUPPORTED_LOCALES.name());
                getModelElement().detach(listener, Portlet.PROP_SUPPORTED_LOCALES.name() + "/" + SupportedLocales.PROP_SUPPORTED_LOCALE.name());
            }
        }
    };
    attach(listen);
}
Also used : FilteredListener(org.eclipse.sapphire.FilteredListener) Listener(org.eclipse.sapphire.Listener) Element(org.eclipse.sapphire.Element) Event(org.eclipse.sapphire.Event) DisposeEvent(org.eclipse.sapphire.DisposeEvent) PropertyEvent(org.eclipse.sapphire.PropertyEvent) PropertyEvent(org.eclipse.sapphire.PropertyEvent) DisposeEvent(org.eclipse.sapphire.DisposeEvent)

Example 50 with Element

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

the class QNamesPossibleValuesService method compute.

/**
 * (non-Javadoc)
 *
 * @see org.eclipse.sapphire.modeling.PossibleValuesService#fillPossibleValues(java.
 *      util.SortedSet)
 */
@Override
protected void compute(Set<String> values) {
    Element Element = context(Element.class);
    // values.add( param( "0" ) );
    PortletApp portletApp = context(Element.class).nearest(PortletApp.class);
    if (Element instanceof EventDefinitionRef) {
        ElementList<EventDefinition> eventDefs = portletApp.getEventDefinitions();
        for (EventDefinition eventDefinition : eventDefs) {
            if ((eventDefinition.getNamespaceURI().content() != null) && (eventDefinition.getLocalPart().content() != null)) {
                values.add(getQName(eventDefinition.getNamespaceURI().content(false), eventDefinition.getLocalPart().content()));
            }
        }
    } else if (Element instanceof SupportedPublicRenderParameter) {
        ElementList<PublicRenderParameter> publicRenderParameters = portletApp.getPublicRenderParameters();
        for (PublicRenderParameter publicRenderParam : publicRenderParameters) {
            if ((publicRenderParam.getNamespaceURI().content() != null) && (publicRenderParam.getLocalPart().content() != null)) {
                values.add(getQName(publicRenderParam.getNamespaceURI().content(false), publicRenderParam.getLocalPart().content()));
            }
        }
    }
}
Also used : EventDefinitionRef(com.liferay.ide.portlet.core.model.EventDefinitionRef) Element(org.eclipse.sapphire.Element) ElementList(org.eclipse.sapphire.ElementList) EventDefinition(com.liferay.ide.portlet.core.model.EventDefinition) SupportedPublicRenderParameter(com.liferay.ide.portlet.core.model.SupportedPublicRenderParameter) SupportedPublicRenderParameter(com.liferay.ide.portlet.core.model.SupportedPublicRenderParameter) PublicRenderParameter(com.liferay.ide.portlet.core.model.PublicRenderParameter) PortletApp(com.liferay.ide.portlet.core.model.PortletApp)

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