Search in sources :

Example 1 with WorkflowNode

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

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

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

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

the class WorkflowDefinitionLayoutPersistenceService method _write.

private void _write(DiagramNodePart nodePart) {
    WorkflowNode workflowNode = nodePart.getLocalModelElement().nearest(WorkflowNode.class);
    if (!workflowNode.disposed()) {
        if (_isNodeLayoutChanged(nodePart)) {
            _removeWorkflowNodeListeners();
            _writeWorkflowNodeBoundsToMetaData(workflowNode, nodePart);
            _addWorkflowNodeListeners();
        }
        _refreshDirtyState();
    }
}
Also used : WorkflowNode(com.liferay.ide.kaleo.core.model.WorkflowNode)

Example 5 with WorkflowNode

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

the class ChangeTaskAssignmentsActionHandler method run.

@Override
protected Object run(Presentation context) {
    Task task = _task(context);
    ChangeTaskAssignmentsOp op = ChangeTaskAssignmentsOp.TYPE.instantiate();
    for (WorkflowNode node : task.nearest(WorkflowDefinition.class).getDiagramNodes()) {
        Assignable assignable = node.nearest(Assignable.class);
        if (assignable != null) {
            for (Role role : assignable.getRoles()) {
                String name = role.getName().content(false);
                if (!isNullOrEmpty(name)) {
                    ElementList<RoleName> roleName = op.getRoleNames();
                    roleName.insert().setName(name);
                }
            }
        }
    }
    User existingUser = task.getUser().content(false);
    ElementList<Role> existingRoles = task.getRoles();
    ElementList<ResourceAction> existingActions = task.getResourceActions();
    Scriptable scriptedAssignment = task.getScriptedAssignment().content(false);
    if (existingUser != null) {
        op.getImpliedUser().copy(existingUser);
    } else if (ListUtil.isNotEmpty(existingRoles)) {
        op.getImpliedRole().copy(existingRoles.get(0));
        for (Role role : existingRoles) {
            Role newRole = op.getRoles().insert();
            newRole.copy(role);
            Boolean autoCreate = role.getAutoCreate().content(false);
            if (autoCreate != null) {
                newRole.setAutoCreate(role.getAutoCreate().content());
            }
        }
    } else if (ListUtil.isNotEmpty(existingActions)) {
        for (ResourceAction action : existingActions) {
            ElementList<ResourceAction> resourceActions = op.getResourceActions();
            ResourceAction resourceAction = resourceActions.insert();
            resourceAction.copy(action);
        }
    } else if (scriptedAssignment != null) {
        ElementHandle<Scriptable> scriptable = op.getScriptedAssignment();
        Scriptable content = scriptable.content(true);
        content.copy(scriptedAssignment);
    }
    DefinitionLoader loader = DefinitionLoader.context(NewWorkflowDefinitionWizard.class);
    DefinitionLoader loaderSdef = loader.sdef("WorkflowDefinitionWizards");
    SapphireWizard<ChangeTaskAssignmentsOp> wizard = new SapphireWizard<>(op, loaderSdef.wizard("changeTaskAssignmentsWizard"));
    int returnCode = new WizardDialog(((SwtPresentation) context).shell(), wizard).open();
    if (returnCode == IDialogConstants.OK_ID) {
        KaleoModelUtil.changeTaskAssignments(_task(context), op);
    }
    return null;
}
Also used : SapphireWizard(org.eclipse.sapphire.ui.forms.swt.SapphireWizard) Task(com.liferay.ide.kaleo.core.model.Task) User(com.liferay.ide.kaleo.core.model.User) WorkflowDefinition(com.liferay.ide.kaleo.core.model.WorkflowDefinition) Scriptable(com.liferay.ide.kaleo.core.model.Scriptable) WorkflowNode(com.liferay.ide.kaleo.core.model.WorkflowNode) Role(com.liferay.ide.kaleo.core.model.Role) RoleName(com.liferay.ide.kaleo.core.model.RoleName) DefinitionLoader(org.eclipse.sapphire.ui.def.DefinitionLoader) ElementHandle(org.eclipse.sapphire.ElementHandle) SwtPresentation(org.eclipse.sapphire.ui.forms.swt.SwtPresentation) WizardDialog(org.eclipse.jface.wizard.WizardDialog) ChangeTaskAssignmentsOp(com.liferay.ide.kaleo.core.op.ChangeTaskAssignmentsOp) Assignable(com.liferay.ide.kaleo.core.model.Assignable) ResourceAction(com.liferay.ide.kaleo.core.model.ResourceAction)

Aggregations

WorkflowNode (com.liferay.ide.kaleo.core.model.WorkflowNode)13 CanTransition (com.liferay.ide.kaleo.core.model.CanTransition)7 Transition (com.liferay.ide.kaleo.core.model.Transition)7 WorkflowDefinition (com.liferay.ide.kaleo.core.model.WorkflowDefinition)6 DiagramConnectionPart (org.eclipse.sapphire.ui.diagram.DiagramConnectionPart)5 ConnectionBendpoint (com.liferay.ide.kaleo.core.model.ConnectionBendpoint)4 TransitionMetadata (com.liferay.ide.kaleo.core.model.TransitionMetadata)4 WorkflowNodeMetadata (com.liferay.ide.kaleo.core.model.WorkflowNodeMetadata)4 Point (org.eclipse.sapphire.ui.Point)4 ConnectionService (org.eclipse.sapphire.ui.diagram.ConnectionService)4 DiagramNodePart (org.eclipse.sapphire.ui.diagram.editor.DiagramNodePart)4 Node (com.liferay.ide.kaleo.core.model.Node)3 Position (com.liferay.ide.kaleo.core.model.Position)3 DiagramNodeBounds (org.eclipse.sapphire.ui.diagram.editor.DiagramNodeBounds)3 Assignable (com.liferay.ide.kaleo.core.model.Assignable)2 Join (com.liferay.ide.kaleo.core.model.Join)2 Role (com.liferay.ide.kaleo.core.model.Role)2 RoleName (com.liferay.ide.kaleo.core.model.RoleName)2 ArrayList (java.util.ArrayList)2 SapphireDiagramEditorPagePart (org.eclipse.sapphire.ui.diagram.editor.SapphireDiagramEditorPagePart)2