Search in sources :

Example 1 with WorkflowNodeMetadata

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

the class WorkflowDefinitionLayoutPersistenceService method _handleConnectionBendpointChange.

private void _handleConnectionBendpointChange(Transition transition) {
    ConnectionService connService = _part().service(ConnectionService.class);
    DiagramConnectionPart connPart = _getConnectionPart(connService, transition);
    if (connPart != null) {
        List<Point> bendpoints = new ArrayList<>();
        WorkflowNode wfNode = transition.nearest(WorkflowNode.class);
        ElementHandle<WorkflowNodeMetadata> nodeMetadata = wfNode.getMetadata();
        WorkflowNodeMetadata metadata = nodeMetadata.content(false);
        TransitionMetadata transitionMetadata = _getTransitionMetadata(transition, metadata);
        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) TransitionMetadata(com.liferay.ide.kaleo.core.model.TransitionMetadata) DiagramConnectionPart(org.eclipse.sapphire.ui.diagram.DiagramConnectionPart) ArrayList(java.util.ArrayList) WorkflowNodeMetadata(com.liferay.ide.kaleo.core.model.WorkflowNodeMetadata) Point(org.eclipse.sapphire.ui.Point) WorkflowNode(com.liferay.ide.kaleo.core.model.WorkflowNode)

Example 2 with WorkflowNodeMetadata

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

the class WorkflowDefinitionLayoutPersistenceService method _writeTransitionBendPoints.

private void _writeTransitionBendPoints(Transition transition, DiagramConnectionPart connPart) {
    WorkflowNode workflowNode = transition.nearest(WorkflowNode.class);
    ElementHandle<WorkflowNodeMetadata> nodeMetadata = workflowNode.getMetadata();
    WorkflowNodeMetadata metadata = nodeMetadata.content(true);
    TransitionMetadata transitionMetadata = _getTransitionMetadata(transition, metadata, true);
    transitionMetadata.setName(transition.getName().content());
    ElementList<ConnectionBendpoint> bendpointsInMetadataList = transitionMetadata.getBendpoints();
    int bendpointsInMetadataSize = bendpointsInMetadataList.size();
    List<Point> bendpointsInPartList = connPart.getBendpoints();
    int bendpointsInPartSize = bendpointsInPartList.size();
    for (int i = 0, n = min(bendpointsInMetadataSize, bendpointsInPartSize); i < n; i++) {
        ConnectionBendpoint bendpointInMetadata = bendpointsInMetadataList.get(i);
        Point bendpointInPart = bendpointsInPartList.get(i);
        if (bendpointInMetadata.getX().content() != bendpointInPart.getX()) {
            bendpointInMetadata.setX(bendpointInPart.getX());
        }
        if (bendpointInMetadata.getY().content() != bendpointInPart.getY()) {
            bendpointInMetadata.setY(bendpointInPart.getY());
        }
    }
    if (bendpointsInMetadataSize < bendpointsInPartSize) {
        for (int i = bendpointsInMetadataSize; i < bendpointsInPartSize; i++) {
            ConnectionBendpoint bendpointInMetadata = bendpointsInMetadataList.insert();
            Point bendpointInPart = bendpointsInPartList.get(i);
            bendpointInMetadata.setX(bendpointInPart.getX());
            bendpointInMetadata.setY(bendpointInPart.getY());
        }
    } else if (bendpointsInMetadataSize > bendpointsInPartSize) {
        for (int i = bendpointsInMetadataSize - 1; i >= bendpointsInPartSize; i--) {
            bendpointsInMetadataList.remove(i);
        }
    }
    if ((connPart.getLabelPosition() != null) && !connPart.getLabelPosition().equals(DEFAULT_POINT)) {
        transitionMetadata.getLabelLocation().setX(connPart.getLabelPosition().getX());
        transitionMetadata.getLabelLocation().setY(connPart.getLabelPosition().getY());
    }
}
Also used : ConnectionBendpoint(com.liferay.ide.kaleo.core.model.ConnectionBendpoint) TransitionMetadata(com.liferay.ide.kaleo.core.model.TransitionMetadata) 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)

Example 3 with WorkflowNodeMetadata

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

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

the class WorkflowDefinitionLayoutPersistenceService method _writeWorkflowNodeBoundsToMetaData.

private void _writeWorkflowNodeBoundsToMetaData(WorkflowNode workflowNode, DiagramNodePart nodePart) {
    Bounds bounds = nodePart.getNodeBounds();
    ElementHandle<WorkflowNodeMetadata> nodeMetadata = workflowNode.getMetadata();
    WorkflowNodeMetadata metadata = nodeMetadata.content(true);
    Position position = metadata.getPosition();
    Value<Integer> valueX = position.getX();
    if (bounds.getX() != valueX.content()) {
        position.setX(bounds.getX());
    }
    Value<Integer> valueY = position.getY();
    if (bounds.getY() != valueY.content()) {
        position.setY(bounds.getY());
    }
}
Also used : Position(com.liferay.ide.kaleo.core.model.Position) DiagramNodeBounds(org.eclipse.sapphire.ui.diagram.editor.DiagramNodeBounds) Bounds(org.eclipse.sapphire.ui.Bounds) WorkflowNodeMetadata(com.liferay.ide.kaleo.core.model.WorkflowNodeMetadata)

Example 5 with WorkflowNodeMetadata

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

the class WorkflowDefinitionLayoutPersistenceService method _handleNodeLayoutChange.

private void _handleNodeLayoutChange(WorkflowNode workflowNode) {
    DiagramNodePart nodePart = _part().getDiagramNodePart(workflowNode);
    WorkflowNodeMetadata metadata = workflowNode.getMetadata().content();
    Position position = metadata.getPosition();
    Value<Integer> valueX = position.getX();
    Value<Integer> valueY = position.getY();
    DiagramNodeBounds nodeBounds = new DiagramNodeBounds(valueX.content(), valueY.content());
    nodePart.setNodeBounds(nodeBounds);
}
Also used : Position(com.liferay.ide.kaleo.core.model.Position) WorkflowNodeMetadata(com.liferay.ide.kaleo.core.model.WorkflowNodeMetadata) DiagramNodePart(org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart) DiagramNodeBounds(org.eclipse.sapphire.ui.diagram.editor.DiagramNodeBounds)

Aggregations

WorkflowNodeMetadata (com.liferay.ide.kaleo.core.model.WorkflowNodeMetadata)9 Position (com.liferay.ide.kaleo.core.model.Position)5 TransitionMetadata (com.liferay.ide.kaleo.core.model.TransitionMetadata)4 WorkflowNode (com.liferay.ide.kaleo.core.model.WorkflowNode)4 ConnectionBendpoint (com.liferay.ide.kaleo.core.model.ConnectionBendpoint)3 Transition (com.liferay.ide.kaleo.core.model.Transition)3 Point (org.eclipse.sapphire.ui.Point)3 ConnectionService (org.eclipse.sapphire.ui.diagram.ConnectionService)3 DiagramConnectionPart (org.eclipse.sapphire.ui.diagram.DiagramConnectionPart)3 DiagramNodeBounds (org.eclipse.sapphire.ui.diagram.editor.DiagramNodeBounds)3 DiagramNodePart (org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart)3 CanTransition (com.liferay.ide.kaleo.core.model.CanTransition)2 SapphireDiagramEditorPagePart (org.eclipse.sapphire.ui.diagram.editor.SapphireDiagramEditorPagePart)2 Action (com.liferay.ide.kaleo.core.model.Action)1 ScriptLanguageType (com.liferay.ide.kaleo.core.model.ScriptLanguageType)1 State (com.liferay.ide.kaleo.core.model.State)1 Task (com.liferay.ide.kaleo.core.model.Task)1 TemplateLanguageType (com.liferay.ide.kaleo.core.model.TemplateLanguageType)1 WorkflowDefinition (com.liferay.ide.kaleo.core.model.WorkflowDefinition)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1