Search in sources :

Example 36 with Element

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

the class ActionsDiagramNodeEditHandlerFactory method create.

@Override
public List<SapphireActionHandler> create() {
    ListFactory<SapphireActionHandler> factory = ListFactory.start();
    Element element = getElement();
    if (element == null) {
        return factory.result();
    }
    ElementList<Action> actions = getActions();
    if (_listener == null) {
        _listener = new FilteredListener<PropertyEvent>() {

            @Override
            public void handleTypedEvent(PropertyEvent event) {
                broadcast(new Event());
            }
        };
    }
    element.attach(_listener, getListPropertyName());
    for (Action action : actions) {
        action.getName().attach(_listener);
        factory.add(new ScriptableOpenActionHandler() {

            @Override
            public void init(SapphireAction sapphireAction, ActionHandlerDef def) {
                super.init(sapphireAction, def);
                String name = action.getName().content(true);
                setLabel(empty(name) ? "<null>" : name);
                addImage(Action.TYPE.image());
            }

            @Override
            protected Scriptable scriptable(Presentation context) {
                return action;
            }
        });
    }
    return factory.result();
}
Also used : Action(com.liferay.ide.kaleo.core.model.Action) SapphireAction(org.eclipse.sapphire.ui.SapphireAction) Element(org.eclipse.sapphire.Element) PropertyEvent(org.eclipse.sapphire.PropertyEvent) Presentation(org.eclipse.sapphire.ui.Presentation) Scriptable(com.liferay.ide.kaleo.core.model.Scriptable) SapphireActionHandler(org.eclipse.sapphire.ui.SapphireActionHandler) ActionHandlerDef(org.eclipse.sapphire.ui.def.ActionHandlerDef) SapphireAction(org.eclipse.sapphire.ui.SapphireAction) Event(org.eclipse.sapphire.Event) PropertyEvent(org.eclipse.sapphire.PropertyEvent)

Example 37 with Element

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

the class NotificationsDiagramNodeEditHandlerFactory method create.

@Override
public List<SapphireActionHandler> create() {
    ListFactory<SapphireActionHandler> factory = ListFactory.start();
    Element element = getElement();
    if (element == null) {
        return factory.result();
    }
    List<ActionNotification> notifications = getNotifications();
    if (_listener == null) {
        _listener = new FilteredListener<PropertyEvent>() {

            @Override
            public void handleTypedEvent(PropertyEvent event) {
                broadcast(new Event());
            }
        };
    }
    element.attach(_listener, getListPropertyName());
    for (Notification notification : notifications) {
        notification.getName().attach(_listener);
        factory.add(new TemplateOpenActionHandler() {

            @Override
            public void init(SapphireAction sapphireAction, ActionHandlerDef def) {
                super.init(sapphireAction, def);
                String name = notification.getName().content(true);
                setLabel(empty(name) ? "<null>" : name);
                addImage(ActionNotification.TYPE.image());
            }

            @Override
            protected Notification notification(Presentation context) {
                return notification;
            }
        });
    }
    return factory.result();
}
Also used : Element(org.eclipse.sapphire.Element) PropertyEvent(org.eclipse.sapphire.PropertyEvent) Presentation(org.eclipse.sapphire.ui.Presentation) SapphireActionHandler(org.eclipse.sapphire.ui.SapphireActionHandler) ActionNotification(com.liferay.ide.kaleo.core.model.ActionNotification) ActionNotification(com.liferay.ide.kaleo.core.model.ActionNotification) Notification(com.liferay.ide.kaleo.core.model.Notification) ActionHandlerDef(org.eclipse.sapphire.ui.def.ActionHandlerDef) SapphireAction(org.eclipse.sapphire.ui.SapphireAction) Event(org.eclipse.sapphire.Event) PropertyEvent(org.eclipse.sapphire.PropertyEvent)

Example 38 with Element

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

the class ShowDiagramPartActionHandler method run.

@Override
protected Object run(Presentation context) {
    SapphireDiagramEditorPagePart diagramPart = context.part().nearest(SapphireDiagramEditorPagePart.class);
    if (diagramPart != null) {
        LabelProvider labelProvider = new LabelProvider() {

            @Override
            public Image getImage(Object element) {
                if (element instanceof DiagramNodePart) {
                    DiagramNodePart diagramNodePart = (DiagramNodePart) element;
                    Element modelElement = diagramNodePart.getLocalModelElement();
                    return diagramPart.getSwtResourceCache().image(modelElement.type().image());
                } else if (element instanceof DiagramConnectionPart) {
                    return diagramPart.getSwtResourceCache().image(Transition.TYPE.image());
                } else {
                    return diagramPart.getSwtResourceCache().image(WorkflowNode.TYPE.image());
                }
            }

            @Override
            public String getText(Object element) {
                if (element instanceof DiagramNodePart) {
                    return ((DiagramNodePart) element).getId();
                } else if (element instanceof DiagramConnectionPart) {
                    return ((DiagramConnectionPart) element).getLabel();
                } else {
                    if (element != null) {
                        return element.toString();
                    }
                    return "";
                }
            }
        };
        ElementListSelectionDialog dialog = new ElementListSelectionDialog(((SwtPresentation) context).shell(), labelProvider);
        List<SapphirePart> parts = new ArrayList<>();
        parts.addAll(diagramPart.getNodes());
        parts.addAll(diagramPart.getConnections());
        dialog.setElements(parts.toArray());
        dialog.setMultipleSelection(false);
        dialog.setHelpAvailable(false);
        dialog.setTitle("Find Part");
        dialog.setMessage("Select part:");
        dialog.open();
        Object[] result = dialog.getResult();
        if ((result != null) && (result.length == 1)) {
            // select node in diagram
            ISapphirePart part = (ISapphirePart) result[0];
            if (part instanceof DiagramConnectionPart || part instanceof DiagramNodePart) {
                /*
					 * diagramPart.setSelections( ReadOnlyListFactory.create(
					 * part ) );
					 */
                SapphireDiagramEditor diagramEditor = diagramPart.adapt(SapphireDiagramEditor.class);
                GraphicalViewer viewer = diagramEditor.getGraphicalViewer();
                GraphicalEditPart editpart = diagramEditor.getGraphicalEditPart(part);
                if (editpart != null) {
                    // Force a layout first.
                    viewer.flush();
                    viewer.select(editpart);
                    viewer.reveal(editpart);
                }
            }
        }
    }
    return null;
}
Also used : GraphicalViewer(org.eclipse.gef.GraphicalViewer) Element(org.eclipse.sapphire.Element) ArrayList(java.util.ArrayList) SapphireDiagramEditor(org.eclipse.sapphire.ui.swt.gef.SapphireDiagramEditor) ISapphirePart(org.eclipse.sapphire.ui.ISapphirePart) SapphirePart(org.eclipse.sapphire.ui.SapphirePart) ISapphirePart(org.eclipse.sapphire.ui.ISapphirePart) SapphireDiagramEditorPagePart(org.eclipse.sapphire.ui.diagram.editor.SapphireDiagramEditorPagePart) ElementListSelectionDialog(org.eclipse.ui.dialogs.ElementListSelectionDialog) DiagramConnectionPart(org.eclipse.sapphire.ui.diagram.DiagramConnectionPart) LabelProvider(org.eclipse.jface.viewers.LabelProvider) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) DiagramNodePart(org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart)

Example 39 with Element

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

the class ActionsListAddActionHandler method run.

@Override
protected Object run(Presentation context) {
    Element newElement = (Element) super.run(context);
    Action newAction = newElement.nearest(Action.class);
    addActionDefaults(newAction);
    return newAction;
}
Also used : Action(com.liferay.ide.kaleo.core.model.Action) SapphireAction(org.eclipse.sapphire.ui.SapphireAction) Element(org.eclipse.sapphire.Element)

Example 40 with Element

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

the class AddServletFilterMappingAction method run.

@Override
protected Object run(Presentation context) {
    Element element = context.part().getLocalModelElement();
    Hook hook = element.nearest(Hook.class);
    return hook.getServletFilterMappings().insert();
}
Also used : Hook(com.liferay.ide.hook.core.model.Hook) 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