Search in sources :

Example 21 with Element

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

the class ScriptableOpenActionHandler method scriptable.

protected Scriptable scriptable(Presentation context) {
    Scriptable retval = null;
    ISapphirePart part = context.part();
    if (part instanceof DetailSectionPart) {
        DetailSectionPart pageBook = part.nearest(DetailSectionPart.class);
        FormPart currentPage = pageBook.getCurrentPage();
        Element element = currentPage.getLocalModelElement();
        retval = element.nearest(Scriptable.class);
    } else {
        Element modelElement = context.part().getLocalModelElement();
        if (modelElement instanceof Task) {
            Task task = modelElement.nearest(Task.class);
            ElementHandle<Scriptable> scriptable = task.getScriptedAssignment();
            retval = scriptable.content(false);
        } else {
            retval = modelElement.nearest(Scriptable.class);
        }
    }
    return retval;
}
Also used : Task(com.liferay.ide.kaleo.core.model.Task) FormPart(org.eclipse.sapphire.ui.forms.FormPart) Element(org.eclipse.sapphire.Element) ISapphirePart(org.eclipse.sapphire.ui.ISapphirePart) Scriptable(com.liferay.ide.kaleo.core.model.Scriptable) DetailSectionPart(org.eclipse.sapphire.ui.forms.DetailSectionPart)

Example 22 with Element

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

the class WorkflowMetadataBindingImpl method readUnderlyingObject.

@Override
protected Object readUnderlyingObject() {
    WorkflowNodeMetadataObject metadataObject = null;
    Element element = property().element();
    Resource resource = element.resource();
    XmlResource xmlResource = resource.adapt(XmlResource.class);
    XmlElement xmlElement = xmlResource.getXmlElement();
    XmlElement metadataElement = xmlElement.getChildElement("metadata", false);
    if (metadataElement != null) {
        String metadata = metadataElement.getChildNodeText("");
        if (!CoreUtil.empty(metadata)) {
            metadataObject = new WorkflowNodeMetadataObject(metadata.trim());
        }
    }
    if (metadataObject == null) {
        metadataObject = new WorkflowNodeMetadataObject();
    }
    if (!metadataObject.equals(_underlyingObject)) {
        _underlyingObject = metadataObject;
    }
    return _underlyingObject;
}
Also used : XmlResource(org.eclipse.sapphire.modeling.xml.XmlResource) Element(org.eclipse.sapphire.Element) XmlElement(org.eclipse.sapphire.modeling.xml.XmlElement) XmlResource(org.eclipse.sapphire.modeling.xml.XmlResource) Resource(org.eclipse.sapphire.Resource) XmlElement(org.eclipse.sapphire.modeling.xml.XmlElement)

Example 23 with Element

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

the class WorkflowMetadataBindingImpl method createResource.

@Override
protected Resource createResource(Object obj) {
    Element element = property().element();
    Resource resource = element.resource();
    XmlResource xmlResource = resource.adapt(XmlResource.class);
    return new WorkflowNodeMetadataResource((WorkflowNodeMetadataObject) obj, xmlResource);
}
Also used : XmlResource(org.eclipse.sapphire.modeling.xml.XmlResource) Element(org.eclipse.sapphire.Element) XmlElement(org.eclipse.sapphire.modeling.xml.XmlElement) XmlResource(org.eclipse.sapphire.modeling.xml.XmlResource) Resource(org.eclipse.sapphire.Resource)

Example 24 with Element

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

the class EditorSiteAdapterService method convert.

@Override
public <A> A convert(Object object, Class<A> adapterType) {
    A retval = null;
    if (IEditorSite.class.equals(adapterType)) {
        SapphirePart sapphirePart = context(SapphirePart.class);
        Element localElement = sapphirePart.getLocalModelElement();
        ITextEditor editor = localElement.adapt(ITextEditor.class);
        IWorkbenchPartSite editorSite = editor.getSite();
        if (editorSite instanceof IEditorSite) {
            retval = adapterType.cast(editorSite);
        }
    }
    return retval;
}
Also used : IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) Element(org.eclipse.sapphire.Element) SapphirePart(org.eclipse.sapphire.ui.SapphirePart) IEditorSite(org.eclipse.ui.IEditorSite)

Example 25 with Element

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

the class ScriptPropertyEditorRenderer method createContents.

@Override
protected void createContents(Composite parent) {
    PropertyEditorPart part = part();
    Element element = part.getLocalModelElement();
    ValueProperty property = part.property().nearest(ValueProperty.class);
    CreateMainCompositeDelegate createMainCompositeDelegate = new CreateMainCompositeDelegate(part) {

        @Override
        public boolean canScaleVertically() {
            return true;
        }
    };
    Composite codeEditorParent = createMainComposite(parent, createMainCompositeDelegate);
    // context.adapt( codeEditorParent );
    int codeEditorParentColumns = 1;
    SapphireToolBarActionPresentation toolBarActionsPresentation = new SapphireToolBarActionPresentation(getActionPresentationManager());
    boolean actionsToolBarNeeded = toolBarActionsPresentation.hasActions();
    if (actionsToolBarNeeded) {
        codeEditorParentColumns++;
    }
    codeEditorParent.setLayout(glayout(codeEditorParentColumns, 0, 0, 0, 0));
    Composite nestedComposite = new Composite(codeEditorParent, SWT.NONE);
    nestedComposite.setLayoutData(gdfill());
    // nestedComposite.setLayout( glspacing( glayout( 2, 0, 0 ), 2 ) );
    addControl(nestedComposite);
    PropertyEditorAssistDecorator decorator = createDecorator(nestedComposite);
    decorator.control().setLayoutData(gdvalign(gd(), SWT.TOP));
    decorator.addEditorControl(nestedComposite);
    ScriptPropertyEditorInput editorInput = new ScriptPropertyEditorInput(element, property);
    List<Control> relatedControls = new ArrayList<>();
    try {
        IEditorSite editorSite = part().adapt(IEditorSite.class);
        _editorPart = createEditorPart(editorInput, editorSite);
        _editorPart.createPartControl(nestedComposite);
        Control editorControl = _editorPart.getAdapter(Control.class);
        // need to find the first child of nestedComposite to relayout
        // editor control
        Composite editorControlParent = null;
        Control control = editorControl;
        while ((editorControlParent == null) && (control != null) && !nestedComposite.equals(control.getParent())) {
            control = control.getParent();
        }
        nestedComposite.setLayout(glspacing(glayout(2, 0, 0), 2));
        control.setLayoutData(gdfill());
        decorator.addEditorControl(editorControl, true);
        editorControl.setData(RELATED_CONTROLS, relatedControls);
    } catch (Exception e) {
        KaleoUI.logError(e);
    }
    if (actionsToolBarNeeded) {
        ToolBar toolbar = new ToolBar(codeEditorParent, SWT.FLAT | SWT.HORIZONTAL);
        toolbar.setLayoutData(gdvfill());
        toolBarActionsPresentation.setToolBar(toolbar);
        toolBarActionsPresentation.render();
        addControl(toolbar);
        decorator.addEditorControl(toolbar);
        relatedControls.add(toolbar);
    }
    List<Class<?>> listenerClasses = part.getRenderingHint(PropertyEditorDef.HINT_LISTENERS, Collections.<Class<?>>emptyList());
    List<ValuePropertyEditorListener> listeners = new ArrayList<>();
    if (ListUtil.isNotEmpty(listenerClasses)) {
        for (Class<?> cl : listenerClasses) {
            try {
                ValuePropertyEditorListener listener = (ValuePropertyEditorListener) cl.newInstance();
                listener.initialize(this);
                listeners.add(listener);
            } catch (Exception e) {
                KaleoUI.logError(e);
            }
        }
    }
    ITextEditor textEditor = null;
    if (_editorPart instanceof ITextEditor) {
        textEditor = (ITextEditor) _editorPart;
    } else {
        ITextEditor textEdit = _editorPart.getAdapter(ITextEditor.class);
        textEditor = textEdit;
    }
    addControl((Control) textEditor.getAdapter(Control.class));
    IDocumentListener documentListener = new IDocumentListener() {

        public void documentAboutToBeChanged(DocumentEvent event) {
        }

        public void documentChanged(DocumentEvent event) {
            Value<Object> elementProperty = element.property(property);
            elementProperty.write(event.getDocument().get());
            if (ListUtil.isNotEmpty(listeners)) {
                for (ValuePropertyEditorListener listener : listeners) {
                    try {
                        listener.handleValueChanged();
                    } catch (Exception e) {
                        KaleoUI.logError(e);
                    }
                }
            }
        }
    };
    IDocumentProvider documentProvider = textEditor.getDocumentProvider();
    IDocument document = documentProvider.getDocument(_editorPart.getEditorInput());
    document.addDocumentListener(documentListener);
}
Also used : ITextEditor(org.eclipse.ui.texteditor.ITextEditor) Element(org.eclipse.sapphire.Element) ArrayList(java.util.ArrayList) ValueProperty(org.eclipse.sapphire.ValueProperty) PropertyEditorAssistDecorator(org.eclipse.sapphire.ui.assist.internal.PropertyEditorAssistDecorator) ValuePropertyEditorListener(org.eclipse.sapphire.ui.listeners.ValuePropertyEditorListener) Control(org.eclipse.swt.widgets.Control) PropertyEditorPart(org.eclipse.sapphire.ui.forms.PropertyEditorPart) Composite(org.eclipse.swt.widgets.Composite) IDocumentListener(org.eclipse.jface.text.IDocumentListener) DocumentEvent(org.eclipse.jface.text.DocumentEvent) SapphireToolBarActionPresentation(org.eclipse.sapphire.ui.forms.swt.SapphireToolBarActionPresentation) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) ToolBar(org.eclipse.swt.widgets.ToolBar) IEditorSite(org.eclipse.ui.IEditorSite) IDocument(org.eclipse.jface.text.IDocument)

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