Search in sources :

Example 6 with DiagramNodePart

use of org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart in project liferay-ide by liferay.

the class WorkflowDefinitionLayoutPersistenceService method _load.

private void _load() {
    SapphireDiagramEditorPagePart part = _part();
    part.setGridVisible(part.adapt(WorkflowDefinitionEditor.class).isGridVisible());
    part.setShowGuides(part.adapt(WorkflowDefinitionEditor.class).isShowGuides());
    ConnectionService connService = part.service(ConnectionService.class);
    for (WorkflowNode workflowNode : _definition().getDiagramNodes()) {
        DiagramNodePart nodePart = part.getDiagramNodePart(workflowNode);
        if (nodePart != null) {
            WorkflowNodeMetadata metadata = workflowNode.getMetadata().content(false);
            Position position = metadata.getPosition();
            Value<Integer> valueX = position.getX();
            Value<Integer> valueY = position.getY();
            DiagramNodeBounds bounds = new DiagramNodeBounds(valueX.content(), valueY.content(), -1, -1, false, false);
            nodePart.setNodeBounds(bounds);
            ListFactory<Transition> transitionsList = ListFactory.start();
            for (Transition transition : workflowNode.nearest(CanTransition.class).getTransitions()) {
                transitionsList.add(transition);
            }
            List<Transition> transitions = transitionsList.result();
            for (Transition transition : transitions) {
                DiagramConnectionPart connPart = _getConnectionPart(connService, transition);
                if (connPart != null) {
                    TransitionMetadata transitionMetadata = _getTransitionMetadata(transition, metadata);
                    if (transitionMetadata == null) {
                        continue;
                    }
                    List<ConnectionBendpoint> bendpoints = transitionMetadata.getBendpoints();
                    if (ListUtil.isNotEmpty(bendpoints)) {
                        int index = 0;
                        for (ConnectionBendpoint bendpoint : bendpoints) {
                            connPart.addBendpoint(index++, bendpoint.getX().content(), bendpoint.getY().content());
                        }
                    }
                    Position labelPosition = transitionMetadata.getLabelLocation();
                    if (labelPosition != null) {
                        connPart.setLabelPosition(new Point(labelPosition.getX().content(), labelPosition.getY().content()));
                    }
                }
            }
        }
    }
    for (DiagramConnectionPart connPart : connService.list()) {
        connPart.attach(_connectionPartListener);
    }
}
Also used : ConnectionService(org.eclipse.sapphire.ui.diagram.ConnectionService) ConnectionBendpoint(com.liferay.ide.kaleo.core.model.ConnectionBendpoint) Position(com.liferay.ide.kaleo.core.model.Position) TransitionMetadata(com.liferay.ide.kaleo.core.model.TransitionMetadata) CanTransition(com.liferay.ide.kaleo.core.model.CanTransition) WorkflowNodeMetadata(com.liferay.ide.kaleo.core.model.WorkflowNodeMetadata) Point(org.eclipse.sapphire.ui.Point) WorkflowNode(com.liferay.ide.kaleo.core.model.WorkflowNode) ConnectionBendpoint(com.liferay.ide.kaleo.core.model.ConnectionBendpoint) Point(org.eclipse.sapphire.ui.Point) DiagramNodeBounds(org.eclipse.sapphire.ui.diagram.editor.DiagramNodeBounds) SapphireDiagramEditorPagePart(org.eclipse.sapphire.ui.diagram.editor.SapphireDiagramEditorPagePart) DiagramConnectionPart(org.eclipse.sapphire.ui.diagram.DiagramConnectionPart) CanTransition(com.liferay.ide.kaleo.core.model.CanTransition) Transition(com.liferay.ide.kaleo.core.model.Transition) DiagramNodePart(org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart)

Example 7 with DiagramNodePart

use of org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart in project liferay-ide by liferay.

the class WorkflowDefinitionLayoutPersistenceService method _handleWorkflowNodeMetaChange.

private void _handleWorkflowNodeMetaChange(WorkflowNodeMetadata workflowNodeMetadata) {
    WorkflowNode workflowNode = workflowNodeMetadata.nearest(WorkflowNode.class);
    if (workflowNode == null) {
        return;
    }
    DiagramNodePart nodePart = _part().getDiagramNodePart(workflowNode);
    if (nodePart != null) {
        Position position = workflowNodeMetadata.getPosition();
        Value<Integer> valueX = position.getX();
        Value<Integer> valueY = position.getY();
        DiagramNodeBounds nodeBounds = nodePart.getNodeBounds();
        if ((nodeBounds.getX() != valueX.content()) || (nodeBounds.getY() != valueY.content())) {
            nodePart.setNodeBounds(new DiagramNodeBounds(valueX.content(), valueY.content()));
        }
    }
    ConnectionService connService = _part().service(ConnectionService.class);
    if (workflowNode instanceof CanTransition) {
        CanTransition canTransition = (CanTransition) workflowNode;
        ElementList<Transition> transitions = canTransition.getTransitions();
        for (Transition transition : transitions) {
            List<Point> bendpoints = new ArrayList<>();
            DiagramConnectionPart connPart = _getConnectionPart(connService, transition);
            if (connPart != null) {
                TransitionMetadata transitionMetadata = _getTransitionMetadata(transition, workflowNodeMetadata);
                if (transitionMetadata != null) {
                    for (ConnectionBendpoint bendpoint : transitionMetadata.getBendpoints()) {
                        bendpoints.add(new Point(bendpoint.getX().content(), bendpoint.getY().content()));
                    }
                    connPart.resetBendpoints(bendpoints);
                }
            }
        }
    }
}
Also used : ConnectionService(org.eclipse.sapphire.ui.diagram.ConnectionService) ConnectionBendpoint(com.liferay.ide.kaleo.core.model.ConnectionBendpoint) Position(com.liferay.ide.kaleo.core.model.Position) TransitionMetadata(com.liferay.ide.kaleo.core.model.TransitionMetadata) ArrayList(java.util.ArrayList) CanTransition(com.liferay.ide.kaleo.core.model.CanTransition) Point(org.eclipse.sapphire.ui.Point) WorkflowNode(com.liferay.ide.kaleo.core.model.WorkflowNode) DiagramNodeBounds(org.eclipse.sapphire.ui.diagram.editor.DiagramNodeBounds) DiagramConnectionPart(org.eclipse.sapphire.ui.diagram.DiagramConnectionPart) CanTransition(com.liferay.ide.kaleo.core.model.CanTransition) Transition(com.liferay.ide.kaleo.core.model.Transition) DiagramNodePart(org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart)

Example 8 with DiagramNodePart

use of org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart in project liferay-ide by liferay.

the class WorkflowDefinitionLayoutPersistenceService method _save.

private void _save() {
    _refreshPersistedPartsCache();
    /*
		 * For nodes that are placed using default node positions and connection
		 * bend points that are calculated using connection router, we don't
		 * modify the corresponding model properties in order to allow "revert"
		 * in source editor to work correctly. So we need to do an explicit save
		 * of the node bounds and connection bend points here.
		 */
    _removeWorkflowNodeListeners();
    _removeBendpointListeners();
    for (DiagramNodePart nodePart : _part().getNodes()) {
        Element modelElement = nodePart.getLocalModelElement();
        WorkflowNode workflowNode = (WorkflowNode) modelElement;
        if (!workflowNode.disposed()) {
            _writeWorkflowNodeBoundsToMetaData(workflowNode, nodePart);
            DiagramNodeBounds nodePartBounds = nodePart.getNodeBounds();
            nodePartBounds.setAutoLayout(false);
            nodePart.setNodeBounds(nodePartBounds);
        }
    }
    for (DiagramConnectionPart connPart : _part().getConnections()) {
        Element modelElement = connPart.getLocalModelElement();
        Transition transition = (Transition) modelElement;
        if (!transition.disposed()) {
            _writeTransitionBendPoints(transition, connPart);
        }
    }
    _addWorkflowNodeListeners();
    _addBendpointListeners();
}
Also used : Element(org.eclipse.sapphire.Element) DiagramConnectionPart(org.eclipse.sapphire.ui.diagram.DiagramConnectionPart) CanTransition(com.liferay.ide.kaleo.core.model.CanTransition) Transition(com.liferay.ide.kaleo.core.model.Transition) WorkflowNode(com.liferay.ide.kaleo.core.model.WorkflowNode) DiagramNodePart(org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart) DiagramNodeBounds(org.eclipse.sapphire.ui.diagram.editor.DiagramNodeBounds)

Example 9 with DiagramNodePart

use of org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart in project liferay-ide by liferay.

the class StartTransitionActionHandler method run.

@Override
protected Object run(Presentation context) {
    WorkflowDefinitionEditor editor = context.part().adapt(WorkflowDefinitionEditor.class);
    SapphireDiagramEditor diagramEditor = editor.getDiagramEditor();
    ISapphirePart part = context.part();
    DiagramNodePart diagramPart = part.nearest(DiagramNodePart.class);
    SapphireDiagramEditorPagePart editorPart = part.nearest(SapphireDiagramEditorPagePart.class);
    ConnectionPalette connectionPalette = editorPart.getConnectionPalettes().get(0);
    CreationFactory factory = new ConnectionCreationFactory(connectionPalette.getConnectionDef());
    ConnectionCreationTool tool = new ConnectionCreationTool(factory);
    diagramEditor.getEditDomain().setActiveTool(tool);
    Event e = new Event();
    e.x = diagramPart.getNodeBounds().getX();
    e.y = diagramPart.getNodeBounds().getY();
    e.widget = diagramEditor.getGraphicalViewer().getControl();
    e.button = 1;
    MouseEvent me = new MouseEvent(e);
    tool.mouseDown(me, diagramEditor.getGraphicalViewer());
    return null;
}
Also used : SapphireDiagramEditorPagePart(org.eclipse.sapphire.ui.diagram.editor.SapphireDiagramEditorPagePart) MouseEvent(org.eclipse.swt.events.MouseEvent) ConnectionCreationTool(org.eclipse.gef.tools.ConnectionCreationTool) SapphireDiagramEditor(org.eclipse.sapphire.ui.swt.gef.SapphireDiagramEditor) ConnectionPalette(org.eclipse.sapphire.ui.diagram.editor.SapphireDiagramEditorPagePart.ConnectionPalette) ConnectionCreationFactory(org.eclipse.sapphire.ui.swt.gef.ConnectionCreationFactory) CreationFactory(org.eclipse.gef.requests.CreationFactory) Event(org.eclipse.swt.widgets.Event) MouseEvent(org.eclipse.swt.events.MouseEvent) ConnectionCreationFactory(org.eclipse.sapphire.ui.swt.gef.ConnectionCreationFactory) ISapphirePart(org.eclipse.sapphire.ui.ISapphirePart) DiagramNodePart(org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart) WorkflowDefinitionEditor(com.liferay.ide.kaleo.ui.editor.WorkflowDefinitionEditor)

Example 10 with DiagramNodePart

use of org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart in project liferay-ide by liferay.

the class NewNodeAddActionHandler method insertDiagramPart.

public Object insertDiagramPart(Presentation context, boolean enableDirectEditing) {
    ISapphirePart spPart = getNodeTemplate().parent();
    SapphireDiagramEditorPagePart diagramPart = (SapphireDiagramEditorPagePart) spPart;
    DiagramNodePart nodePart = getNodeTemplate().createNewDiagramNode();
    Point pt = diagramPart.getMouseLocation();
    nodePart.setNodeBounds(pt.getX(), pt.getY());
    if (enableDirectEditing) {
        // Select the new node and put it in direct-edit mode
        diagramPart.selectAndDirectEdit(nodePart);
    }
    return nodePart;
}
Also used : SapphireDiagramEditorPagePart(org.eclipse.sapphire.ui.diagram.editor.SapphireDiagramEditorPagePart) ISapphirePart(org.eclipse.sapphire.ui.ISapphirePart) Point(org.eclipse.sapphire.ui.Point) DiagramNodePart(org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart)

Aggregations

DiagramNodePart (org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart)11 DiagramConnectionPart (org.eclipse.sapphire.ui.diagram.DiagramConnectionPart)7 SapphireDiagramEditorPagePart (org.eclipse.sapphire.ui.diagram.editor.SapphireDiagramEditorPagePart)6 ConnectionService (org.eclipse.sapphire.ui.diagram.ConnectionService)5 DiagramNodeBounds (org.eclipse.sapphire.ui.diagram.editor.DiagramNodeBounds)5 CanTransition (com.liferay.ide.kaleo.core.model.CanTransition)4 Position (com.liferay.ide.kaleo.core.model.Position)4 Transition (com.liferay.ide.kaleo.core.model.Transition)4 WorkflowNode (com.liferay.ide.kaleo.core.model.WorkflowNode)4 WorkflowNodeMetadata (com.liferay.ide.kaleo.core.model.WorkflowNodeMetadata)3 ISapphirePart (org.eclipse.sapphire.ui.ISapphirePart)3 Point (org.eclipse.sapphire.ui.Point)3 ConnectionBendpoint (com.liferay.ide.kaleo.core.model.ConnectionBendpoint)2 TransitionMetadata (com.liferay.ide.kaleo.core.model.TransitionMetadata)2 ArrayList (java.util.ArrayList)2 Element (org.eclipse.sapphire.Element)2 SapphireDiagramEditor (org.eclipse.sapphire.ui.swt.gef.SapphireDiagramEditor)2 WorkflowDefinitionEditor (com.liferay.ide.kaleo.ui.editor.WorkflowDefinitionEditor)1 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)1 GraphicalViewer (org.eclipse.gef.GraphicalViewer)1