Search in sources :

Example 1 with SapphireDiagramEditorPagePart

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

the class WorkflowDefinitionLayoutPersistenceService method _isDiagramLayoutChanged.

private boolean _isDiagramLayoutChanged() {
    boolean changed = false;
    SapphireDiagramEditorPagePart part = _part();
    if (!part.disposed()) {
        ConnectionService connService = part.service(ConnectionService.class);
        for (DiagramNodePart nodePart : part.getNodes()) {
            if (!nodePart.getLocalModelElement().disposed() && _isNodeLayoutChanged(nodePart)) {
                changed = true;
                break;
            }
        }
        for (DiagramConnectionPart connPart : connService.list()) {
            if (!connPart.getLocalModelElement().disposed() && _isConnectionLayoutChanged(connPart)) {
                changed = true;
                break;
            }
        }
    }
    return changed;
}
Also used : ConnectionService(org.eclipse.sapphire.ui.diagram.ConnectionService) SapphireDiagramEditorPagePart(org.eclipse.sapphire.ui.diagram.editor.SapphireDiagramEditorPagePart) DiagramConnectionPart(org.eclipse.sapphire.ui.diagram.DiagramConnectionPart) DiagramNodePart(org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart)

Example 2 with SapphireDiagramEditorPagePart

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

the class WorkflowDefinitionLayoutPersistenceService method _read.

private void _read(DiagramNodePart nodePart) {
    WorkflowNode workflowNode = nodePart.getLocalModelElement().nearest(WorkflowNode.class);
    if (!workflowNode.disposed()) {
        WorkflowNodeMetadata metadata = workflowNode.getMetadata().content();
        Position position = metadata.getPosition();
        Value<Integer> valueX = position.getX();
        Value<Integer> valueY = position.getY();
        if ((valueX.content() != -1) && (valueY.content() != -1)) {
            _writeWorkflowNodeMetaDataToBounds(metadata, nodePart);
        }
        String nodeId = nodePart.getId();
        if (_nodeBounds.containsKey(nodeId) && (_nodeBounds.get(nodeId) != null)) {
            nodePart.setNodeBounds(_nodeBounds.get(nodeId));
        } else {
            _nodeBounds.put(nodeId, nodePart.getNodeBounds());
        }
    }
    /*
		 * handle the case where a transition is added and its target node
		 * hasn't been. keep the transitions in a map and every time a new node
		 * is added, check if it is a target of unconnected transitions,
		 * reconnect the DiagramConnectionPart
		 */
    SapphireDiagramEditorPagePart part = _part();
    ConnectionService connService = part.service(ConnectionService.class);
    if (workflowNode instanceof CanTransition) {
        CanTransition canTransition = (CanTransition) workflowNode;
        for (Transition transition : canTransition.getTransitions()) {
            if (transition.getTarget().target() == null) {
                if (!_unconnectedTransitions.containsKey(transition.getTarget().content())) {
                    _unconnectedTransitions.put(transition.getTarget().content(), new LinkedList<Transition>());
                }
                if (!transition.disposed()) {
                    _unconnectedTransitions.get(transition.getTarget().content()).add(transition);
                }
            }
        }
    }
    if (_unconnectedTransitions.containsKey(workflowNode.getName().content())) {
        List<Transition> transitions = _unconnectedTransitions.get(workflowNode.getName().content());
        for (Transition transition : transitions) {
            DiagramConnectionPart connPart = _getConnectionPart(connService, transition);
            DiagramNodePart nodePart1 = part.getDiagramNodePart(transition.nearest(WorkflowNode.class));
            DiagramNodePart nodePart2 = part.getDiagramNodePart(workflowNode);
            connPart.reconnect(nodePart1, nodePart2);
        /*
				 * sometimes the reconnect doesn't work, an alternative way is
				 * to remove it and create a new one if( connPart != null ) {
				 * connPart.remove(); }
				 *
				 * connService.connect( nodePart1, nodePart2, "Transition" );
				 */
        }
        _unconnectedTransitions.remove(workflowNode.getName().content());
    }
}
Also used : ConnectionService(org.eclipse.sapphire.ui.diagram.ConnectionService) Position(com.liferay.ide.kaleo.core.model.Position) CanTransition(com.liferay.ide.kaleo.core.model.CanTransition) WorkflowNodeMetadata(com.liferay.ide.kaleo.core.model.WorkflowNodeMetadata) WorkflowNode(com.liferay.ide.kaleo.core.model.WorkflowNode) 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 3 with SapphireDiagramEditorPagePart

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

the class KaleoNodeAddActionHandlerFactory method create.

@Override
public List<SapphireActionHandler> create() {
    List<SapphireActionHandler> handlers = new ArrayList<>();
    SapphireDiagramEditorPagePart diagramPart = (SapphireDiagramEditorPagePart) getPart();
    for (DiagramNodeTemplate nodeTemplate : diagramPart.getVisibleNodeTemplates()) {
        NewNodeAddActionHandler addNodeHandler = _createKaleoNodeActionHandlerForTemplate(nodeTemplate);
        handlers.add(addNodeHandler);
    }
    return handlers;
}
Also used : SapphireDiagramEditorPagePart(org.eclipse.sapphire.ui.diagram.editor.SapphireDiagramEditorPagePart) DiagramNodeTemplate(org.eclipse.sapphire.ui.diagram.editor.DiagramNodeTemplate) ArrayList(java.util.ArrayList) SapphireActionHandler(org.eclipse.sapphire.ui.SapphireActionHandler)

Example 4 with SapphireDiagramEditorPagePart

use of org.eclipse.sapphire.ui.diagram.editor.SapphireDiagramEditorPagePart 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 5 with SapphireDiagramEditorPagePart

use of org.eclipse.sapphire.ui.diagram.editor.SapphireDiagramEditorPagePart 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)

Aggregations

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