Search in sources :

Example 6 with Transition

use of com.liferay.ide.kaleo.core.model.Transition 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 Transition

use of com.liferay.ide.kaleo.core.model.Transition 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 Transition

use of com.liferay.ide.kaleo.core.model.Transition 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 Transition

use of com.liferay.ide.kaleo.core.model.Transition in project liferay-ide by liferay.

the class StateNodeAddActionHandler method postDiagramNodePartAdded.

@Override
public void postDiagramNodePartAdded(NewNodeOp op, CanTransition newNodeFromWizard, CanTransition newNode) {
    NewStateNodeOp newStateNodeOp = op.nearest(NewStateNodeOp.class);
    NewStateNode newStateNode = newNodeFromWizard.nearest(NewStateNode.class);
    State state = newNode.nearest(State.class);
    if ((newStateNode != null) && (state != null)) {
        state.setName(newStateNode.getName().content());
        NewStateType newStateType = newStateNodeOp.getType().content();
        if (newStateType.equals(NewStateType.START)) {
            state.setInitial(true);
        } else if (newStateType.equals(NewStateType.END)) {
            state.setEnd(true);
        }
        String workflowStatus = newStateNodeOp.getWorkflowStatus().content(false);
        if (!empty(workflowStatus)) {
            Action newAction = state.getActions().insert();
            newAction.setName(state.getName().content());
            newAction.setScriptLanguage(KaleoModelUtil.getDefaultValue(state, KaleoCore.DEFAULT_SCRIPT_LANGUAGE_KEY, ScriptLanguageType.GROOVY));
            newAction.setExecutionType(Executable.DEFAULT_EXECUTION_TYPE);
            IKaleoEditorHelper editorHelper = KaleoUI.getKaleoEditorHelper(newAction.getScriptLanguage().text());
            if (editorHelper != null) {
                try {
                    File statusUpdatesFolder = new File(FileLocator.toFileURL(Platform.getBundle(editorHelper.getContributorName()).getEntry("palette/Status Updates")).getFile());
                    File statusSnippet = new File(statusUpdatesFolder, workflowStatus + "." + editorHelper.getFileExtension());
                    if (FileUtil.exists(statusSnippet)) {
                        newAction.setScript(FileUtil.readContents(statusSnippet, true));
                    }
                } catch (Exception e) {
                }
            }
        }
        if (!newStateType.equals(NewStateType.END) && (newStateNodeOp.getExitTransitionName().content() != null)) {
            Transition newTransition = state.getTransitions().insert();
            newTransition.setTarget(newStateNodeOp.getExitTransitionName().content());
            newTransition.setName(newStateNodeOp.getExitTransitionName().content());
        }
    }
}
Also used : Action(com.liferay.ide.kaleo.core.model.Action) NewStateNodeOp(com.liferay.ide.kaleo.core.op.NewStateNodeOp) State(com.liferay.ide.kaleo.core.model.State) IKaleoEditorHelper(com.liferay.ide.kaleo.ui.IKaleoEditorHelper) NewStateType(com.liferay.ide.kaleo.core.op.NewStateType) CanTransition(com.liferay.ide.kaleo.core.model.CanTransition) Transition(com.liferay.ide.kaleo.core.model.Transition) NewStateNode(com.liferay.ide.kaleo.core.op.NewStateNode) File(java.io.File)

Example 10 with Transition

use of com.liferay.ide.kaleo.core.model.Transition in project liferay-ide by liferay.

the class JoinNodeAddActionHandler method postDiagramNodePartAdded.

@Override
public void postDiagramNodePartAdded(NewNodeOp op, CanTransition newNodeFromWizard, CanTransition newNode) {
    NewJoinNodeOp newJoinNodeOp = op.nearest(NewJoinNodeOp.class);
    Join newJoin = newNode.nearest(Join.class);
    WorkflowDefinition workflowDefinition = newJoin.nearest(WorkflowDefinition.class);
    for (Node nodeName : newJoinNodeOp.getConnectedNodes()) {
        for (WorkflowNode diagramNode : workflowDefinition.getDiagramNodes()) {
            if (nodeName.getName().content() != null) {
                String name = nodeName.getName().content();
                if (name.equals(diagramNode.getName().content())) {
                    CanTransition canTransition = diagramNode.nearest(CanTransition.class);
                    Transition newTransition = canTransition.getTransitions().insert();
                    newTransition.setName(newJoin.getName().content());
                    newTransition.setTarget(newJoin.getName().content());
                }
            }
        }
    }
    if (newJoinNodeOp.getExitTransitionName().content() != null) {
        Transition newTransition = newJoin.getTransitions().insert();
        newTransition.setTarget(newJoinNodeOp.getExitTransitionName().content());
        newTransition.setName(newJoinNodeOp.getExitTransitionName().content());
    }
}
Also used : Node(com.liferay.ide.kaleo.core.model.Node) WorkflowNode(com.liferay.ide.kaleo.core.model.WorkflowNode) CanTransition(com.liferay.ide.kaleo.core.model.CanTransition) Transition(com.liferay.ide.kaleo.core.model.Transition) Join(com.liferay.ide.kaleo.core.model.Join) WorkflowDefinition(com.liferay.ide.kaleo.core.model.WorkflowDefinition) CanTransition(com.liferay.ide.kaleo.core.model.CanTransition) NewJoinNodeOp(com.liferay.ide.kaleo.core.op.NewJoinNodeOp) WorkflowNode(com.liferay.ide.kaleo.core.model.WorkflowNode)

Aggregations

Transition (com.liferay.ide.kaleo.core.model.Transition)13 CanTransition (com.liferay.ide.kaleo.core.model.CanTransition)11 WorkflowNode (com.liferay.ide.kaleo.core.model.WorkflowNode)7 WorkflowDefinition (com.liferay.ide.kaleo.core.model.WorkflowDefinition)6 Node (com.liferay.ide.kaleo.core.model.Node)5 Join (com.liferay.ide.kaleo.core.model.Join)4 Position (com.liferay.ide.kaleo.core.model.Position)4 State (com.liferay.ide.kaleo.core.model.State)4 DiagramConnectionPart (org.eclipse.sapphire.ui.diagram.DiagramConnectionPart)4 DiagramNodePart (org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart)4 Fork (com.liferay.ide.kaleo.core.model.Fork)3 Task (com.liferay.ide.kaleo.core.model.Task)3 TransitionMetadata (com.liferay.ide.kaleo.core.model.TransitionMetadata)3 WorkflowNodeMetadata (com.liferay.ide.kaleo.core.model.WorkflowNodeMetadata)3 ConnectionService (org.eclipse.sapphire.ui.diagram.ConnectionService)3 DiagramNodeBounds (org.eclipse.sapphire.ui.diagram.editor.DiagramNodeBounds)3 Action (com.liferay.ide.kaleo.core.model.Action)2 Condition (com.liferay.ide.kaleo.core.model.Condition)2 ConnectionBendpoint (com.liferay.ide.kaleo.core.model.ConnectionBendpoint)2 JoinXor (com.liferay.ide.kaleo.core.model.JoinXor)2