Search in sources :

Example 16 with Element

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

the class ResourceBundleJumpActionHandler 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();
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    ValueProperty property = (ValueProperty) property().definition();
    IProject project = element.adapt(IProject.class);
    Value<Path> value = element.property(property);
    String text = value.text(false);
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IWorkspaceRoot wroot = workspace.getRoot();
    IClasspathEntry[] cpEntries = CoreUtil.getClasspathEntries(project);
    String ioFileName = PortletUtil.convertJavaToIoFileName(text, RB_FILE_EXTENSION);
    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()) {
                if (window != null) {
                    IWorkbenchPage page = window.getActivePage();
                    IEditorDescriptor editorDescriptor = null;
                    try {
                        editorDescriptor = IDE.getEditorDescriptor(resourceBundleFile.getName());
                    } catch (PartInitException pie) {
                    // No editor was found for this file type.
                    }
                    if (editorDescriptor != null) {
                        try {
                            IDE.openEditor(page, resourceBundleFile, editorDescriptor.getId(), true);
                        } catch (PartInitException pie) {
                            PortletUIPlugin.logError(pie);
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.sapphire.modeling.Path) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) Element(org.eclipse.sapphire.Element) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) ValueProperty(org.eclipse.sapphire.ValueProperty) IProject(org.eclipse.core.resources.IProject) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IWorkspace(org.eclipse.core.resources.IWorkspace) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PartInitException(org.eclipse.ui.PartInitException)

Example 17 with Element

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

the class ResourceBundleJumpActionHandler method computeEnablementState.

/**
 * (non-Javadoc)
 *
 * @see org.eclipse.sapphire.ui.SapphirePropertyEditorActionHandler#
 * computeEnablementState()
 */
@Override
protected boolean computeEnablementState() {
    Element element = getModelElement();
    IProject project = element.adapt(IProject.class);
    ValueProperty property = (ValueProperty) property().definition();
    String text = element.property(property).text(true);
    boolean enabled = super.computeEnablementState();
    if (enabled && (text != null)) {
        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        IWorkspaceRoot wroot = workspace.getRoot();
        IClasspathEntry[] cpEntries = CoreUtil.getClasspathEntries(project);
        String ioFileName = PortletUtil.convertJavaToIoFileName(text, RB_FILE_EXTENSION);
        if (cpEntries != null) {
            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 true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : IFile(org.eclipse.core.resources.IFile) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) Element(org.eclipse.sapphire.Element) IWorkspace(org.eclipse.core.resources.IWorkspace) IProject(org.eclipse.core.resources.IProject) ValueProperty(org.eclipse.sapphire.ValueProperty)

Example 18 with Element

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

the class StructuresTests method testDocumentLibraryStructuresRead.

@Test
public void testDocumentLibraryStructuresRead() throws Exception {
    final Element element = getElementFromFile(getCurrentProject(), DOCUMENT_LIBRARY_STRUCTURES, Root.TYPE);
    setElement(element);
    final Root root = element.nearest(Root.class);
    assertNotNull(root);
    final ElementList<Structure> structures = root.getStructures();
    assertNotNull(structures);
    assertEquals(8, structures.size());
    final Structure structure = structures.get(2);
    assertNotNull(structure);
    assertEquals("Learning Module Metadata", structure.getName().content(false));
    assertEquals("Learning Module Metadata", structure.getDescription().content(false));
    final Root structureRoot = structure.getRoot().content(false);
    assertNotNull(structureRoot);
    assertEquals("[$LOCALE_DEFAULT$]", structureRoot.getAvailableLocales().content(false));
    assertEquals("[$LOCALE_DEFAULT$]", structureRoot.getDefaultLocale().content(false));
    final ElementList<DynamicElement> dynamicElements = structureRoot.getDynamicElements();
    assertNotNull(dynamicElements);
    assertEquals(4, dynamicElements.size());
    final DynamicElement dynamicElement = dynamicElements.get(1);
    assertNotNull(dynamicElement);
    assertEquals("string", dynamicElement.getDataType().content(false));
    assertEquals("keyword", dynamicElement.getIndexType().content(false));
    assertEquals(true, dynamicElement.isMultiple().content(false));
    assertEquals("select3212", dynamicElement.getName().content(false));
    assertEquals(false, dynamicElement.isReadOnly().content(false));
    assertEquals(false, dynamicElement.isRequired().content(false));
    assertEquals(true, dynamicElement.isShowLabel().content(false));
    assertEquals("select", dynamicElement.getType().content(false));
    final DynamicElementMetadata metadata = dynamicElement.getMetadata().content(false);
    assertNotNull(metadata);
    assertEquals("[$LOCALE_DEFAULT$]", metadata.getLocale().content(false));
    final ElementList<Entry> entries = metadata.getEntries();
    assertNotNull(entries);
    assertEquals(3, entries.size());
    final ElementList<DynamicElement> childDynamicElements = dynamicElement.getDynamicElements();
    assertNotNull(childDynamicElements);
    assertEquals(3, childDynamicElements.size());
    final DynamicElement childDynamicElement = childDynamicElements.get(1);
    assertNotNull(childDynamicElement);
    assertEquals("2_0", childDynamicElement.getName().content(false));
    assertEquals("option", childDynamicElement.getType().content(false));
    assertEquals("2", childDynamicElement.getValue().content(false));
    final DynamicElementMetadata childMetadata = childDynamicElement.getMetadata().content(false);
    assertNotNull(childMetadata);
    assertEquals("[$LOCALE_DEFAULT$]", childMetadata.getLocale().content(false));
    final ElementList<Entry> childEntries = childMetadata.getEntries();
    assertNotNull(childEntries);
    assertEquals(1, childEntries.size());
    final Entry childEntry = childEntries.get(0);
    assertNotNull(childEntry);
    assertEquals("label", childEntry.getName().content(false));
    assertEquals("2.0", childEntry.getValue().content(false));
}
Also used : Entry(com.liferay.ide.portal.core.structures.model.Entry) Root(com.liferay.ide.portal.core.structures.model.Root) DynamicElementMetadata(com.liferay.ide.portal.core.structures.model.DynamicElementMetadata) DynamicElement(com.liferay.ide.portal.core.structures.model.DynamicElement) DynamicElement(com.liferay.ide.portal.core.structures.model.DynamicElement) Element(org.eclipse.sapphire.Element) Structure(com.liferay.ide.portal.core.structures.model.Structure) Test(org.junit.Test)

Example 19 with Element

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

the class ChangeTaskAssignmentsActionHandler method _task.

private Task _task(Presentation context) {
    SapphirePart spPart = context.part();
    Element element = spPart.getLocalModelElement();
    return element.nearest(Task.class);
}
Also used : Element(org.eclipse.sapphire.Element) SapphirePart(org.eclipse.sapphire.ui.SapphirePart)

Example 20 with Element

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

the class NotificationsDiagramNodeEditHandlerFactory method dispose.

@Override
public void dispose() {
    super.dispose();
    Element element = getElement();
    element.detach(_listener, getListPropertyName());
}
Also used : Element(org.eclipse.sapphire.Element)

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