Search in sources :

Example 1 with CanTransition

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

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

the class ForkNodeAddActionHandler method postDiagramNodePartAdded.

@Override
public void postDiagramNodePartAdded(NewNodeOp op, CanTransition newNodeFromWizard, CanTransition newNode) {
    NewForkNodeOp newForkOp = op.nearest(NewForkNodeOp.class);
    NewForkNode newForkNodeFromWizard = newNodeFromWizard.nearest(NewForkNode.class);
    Fork newFork = newNode.nearest(Fork.class);
    WorkflowDefinition workflowDefinition = newFork.nearest(WorkflowDefinition.class);
    if (newForkOp.isAddJoin().content(true)) {
        Join newJoin = workflowDefinition.getJoins().insert();
        String newJoinName = newForkNodeFromWizard.getName().content() + " Join";
        newJoin.setName(newJoinName);
        for (Node connectedNode : op.getConnectedNodes()) {
            for (WorkflowNode diagramNode : workflowDefinition.getDiagramNodes()) {
                Value<String> nodeName = connectedNode.getName();
                if (nodeName.content().equals(diagramNode.getName().content())) {
                    CanTransition canTransition = diagramNode.nearest(CanTransition.class);
                    ElementList<Transition> transitions = canTransition.getTransitions();
                    Transition newTransition = transitions.insert();
                    newTransition.setName(newJoinName);
                    newTransition.setTarget(newJoinName);
                }
            }
        }
    }
}
Also used : Fork(com.liferay.ide.kaleo.core.model.Fork) Node(com.liferay.ide.kaleo.core.model.Node) NewForkNode(com.liferay.ide.kaleo.core.op.NewForkNode) WorkflowNode(com.liferay.ide.kaleo.core.model.WorkflowNode) CanTransition(com.liferay.ide.kaleo.core.model.CanTransition) Transition(com.liferay.ide.kaleo.core.model.Transition) WorkflowDefinition(com.liferay.ide.kaleo.core.model.WorkflowDefinition) Join(com.liferay.ide.kaleo.core.model.Join) CanTransition(com.liferay.ide.kaleo.core.model.CanTransition) NewForkNode(com.liferay.ide.kaleo.core.op.NewForkNode) NewForkNodeOp(com.liferay.ide.kaleo.core.op.NewForkNodeOp) WorkflowNode(com.liferay.ide.kaleo.core.model.WorkflowNode)

Example 3 with CanTransition

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

the class TransitionTargetListener method handleTypedEvent.

@Override
protected void handleTypedEvent(PropertyContentEvent event) {
    Property property = event.property();
    Transition transition = property.nearest(Transition.class);
    if (transition != null) {
        ReferenceValue<String, Node> targe = transition.getTarget();
        Value<String> transitionName = transition.getName();
        if ((targe.content() != null) && (transitionName.content(false) == null)) {
            String targetName = targe.content();
            String defaultName = targetName;
            Set<String> existingNames = new HashSet<>();
            CanTransition camtransition = transition.nearest(CanTransition.class);
            for (Transition t : camtransition.getTransitions()) {
                Value<String> tName = t.getName();
                if (tName.content() != null) {
                    existingNames.add(tName.content());
                }
            }
            int count = 1;
            while (existingNames.contains(defaultName)) {
                defaultName = targetName + "_" + count++;
            }
            transition.setName(defaultName);
        }
    }
}
Also used : Node(com.liferay.ide.kaleo.core.model.Node) CanTransition(com.liferay.ide.kaleo.core.model.CanTransition) Transition(com.liferay.ide.kaleo.core.model.Transition) CanTransition(com.liferay.ide.kaleo.core.model.CanTransition) Property(org.eclipse.sapphire.Property) HashSet(java.util.HashSet)

Example 4 with CanTransition

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

the class NewNodeOpWizard method performPostDiagramNodeAdded.

protected void performPostDiagramNodeAdded() {
    NewNodeOp newNodeOp = element().nearest(NewNodeOp.class);
    CanTransition newNode = newNodeOp.adapt(CanTransition.class);
    CanTransition node = _diagramNodePart.getLocalModelElement().nearest(CanTransition.class);
    WorkflowDefinition workflowDefinition = node.nearest(WorkflowDefinition.class);
    if ((newNode != null) && (node != null)) {
        Value<String> newNodeName = newNode.getName();
        node.setName(newNodeName.content());
        if (newNodeOp.getConnectedNodes().size() > 0) {
            for (Node diagramNode : newNodeOp.getConnectedNodes()) {
                Value<String> nodeName = diagramNode.getName();
                String diagramNodeName = nodeName.content(true);
                if (diagramNode instanceof ConditionForOp) {
                    ElementList<Condition> conditions = workflowDefinition.getConditions();
                    Condition insertCondition = conditions.insert();
                    insertCondition.setName(diagramNodeName);
                } else if (diagramNode instanceof ForkForOp) {
                    ElementList<Fork> forks = workflowDefinition.getForks();
                    Fork insertFork = forks.insert();
                    insertFork.setName(diagramNodeName);
                } else if (diagramNode instanceof JoinForOp) {
                    ElementList<Join> joins = workflowDefinition.getJoins();
                    Join insertJoin = joins.insert();
                    insertJoin.setName(diagramNodeName);
                } else if (diagramNode instanceof JoinXorForOp) {
                    ElementList<JoinXor> joinXors = workflowDefinition.getJoinXors();
                    JoinXor insertJoinXor = joinXors.insert();
                    insertJoinXor.setName(diagramNodeName);
                } else if (diagramNode instanceof StateForOp) {
                    ElementList<State> states = workflowDefinition.getStates();
                    State insertState = states.insert();
                    insertState.setName(diagramNodeName);
                } else if (diagramNode instanceof TaskForOp) {
                    ElementList<Task> tasks = workflowDefinition.getTasks();
                    Task insertTask = tasks.insert();
                    insertTask.setName(diagramNodeName);
                }
                if (diagramNode instanceof ChooseDiagramNode || node instanceof Condition || node instanceof Fork || node instanceof State || node instanceof Task) {
                    Transition newTransition = node.getTransitions().insert();
                    newTransition.setName(diagramNodeName);
                    newTransition.setTarget(diagramNodeName);
                } else {
                    CanTransition canTransition = diagramNode.nearest(CanTransition.class);
                    ElementList<Transition> transition = canTransition.getTransitions();
                    Transition joinTransition = transition.insert();
                    joinTransition.setName(node.getName().content());
                    joinTransition.setTarget(node.getName().content());
                }
            }
        }
    }
    _actionHandler.postDiagramNodePartAdded(element(), newNode, node);
}
Also used : Task(com.liferay.ide.kaleo.core.model.Task) Fork(com.liferay.ide.kaleo.core.model.Fork) JoinXor(com.liferay.ide.kaleo.core.model.JoinXor) JoinXorForOp(com.liferay.ide.kaleo.core.op.NewNodeOp.JoinXorForOp) ChooseDiagramNode(com.liferay.ide.kaleo.core.op.ChooseDiagramNode) Node(com.liferay.ide.kaleo.core.model.Node) StateForOp(com.liferay.ide.kaleo.core.op.NewNodeOp.StateForOp) CanTransition(com.liferay.ide.kaleo.core.model.CanTransition) ElementList(org.eclipse.sapphire.ElementList) ForkForOp(com.liferay.ide.kaleo.core.op.NewNodeOp.ForkForOp) ConditionForOp(com.liferay.ide.kaleo.core.op.NewNodeOp.ConditionForOp) Condition(com.liferay.ide.kaleo.core.model.Condition) WorkflowDefinition(com.liferay.ide.kaleo.core.model.WorkflowDefinition) Join(com.liferay.ide.kaleo.core.model.Join) ChooseDiagramNode(com.liferay.ide.kaleo.core.op.ChooseDiagramNode) State(com.liferay.ide.kaleo.core.model.State) NewNodeOp(com.liferay.ide.kaleo.core.op.NewNodeOp) CanTransition(com.liferay.ide.kaleo.core.model.CanTransition) Transition(com.liferay.ide.kaleo.core.model.Transition) JoinForOp(com.liferay.ide.kaleo.core.op.NewNodeOp.JoinForOp) TaskForOp(com.liferay.ide.kaleo.core.op.NewNodeOp.TaskForOp)

Example 5 with CanTransition

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

Aggregations

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