Search in sources :

Example 6 with WorkflowNodeMetadata

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

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

the class NewWorkflowDefinitionOpMethods method execute.

public static Status execute(NewWorkflowDefinitionOp op, ProgressMonitor monitor) {
    try {
        ReferenceValue<String, IProject> referProject = op.getProject();
        IProject project = referProject.target();
        Value<Path> opFolder = op.getFolder();
        Path projectPath = opFolder.content();
        IContainer folder = null;
        if (projectPath != null) {
            folder = project.getFolder(projectPath.toPortableString());
        } else {
            folder = project;
        }
        if (!folder.exists()) {
            folder = folder.getParent();
        }
        Value<String> opName = op.getName();
        String name = opName.content();
        String lowerCaseName = name.toLowerCase();
        String[] segments = lowerCaseName.split("\\s+");
        StringBuilder newName = new StringBuilder();
        for (String segment : segments) {
            StringBuilder segNewName = newName.append(segment);
            segNewName.append('-');
        }
        String fileNameBase = newName.toString() + "definition";
        String extension = ".xml";
        String fileName = fileNameBase + extension;
        IPath proRelativePath = folder.getProjectRelativePath();
        IFile newDefinitionFile = project.getFile(proRelativePath.append(fileName));
        int count = 1;
        while (newDefinitionFile.exists()) {
            fileName = fileNameBase + " (" + count + ")" + extension;
            newDefinitionFile = project.getFile(proRelativePath.append(fileName));
            count++;
        }
        newDefinitionFile.create(new ByteArrayInputStream("".getBytes()), true, null);
        Value<ScriptLanguageType> scLanguageType = op.getDefaultScriptLanguage();
        newDefinitionFile.setPersistentProperty(KaleoCore.DEFAULT_SCRIPT_LANGUAGE_KEY, scLanguageType.text(true));
        Value<TemplateLanguageType> deTemplateLanguage = op.getDefaultTemplateLanguage();
        newDefinitionFile.setPersistentProperty(KaleoCore.DEFAULT_TEMPLATE_LANGUAGE_KEY, deTemplateLanguage.text(true));
        RootXmlResource rootXmlResource = new RootXmlResource(new XmlResourceStore(new WorkspaceFileResourceStore(newDefinitionFile)));
        WorkflowDefinition workflowDefinition = WorkflowDefinition.TYPE.instantiate(rootXmlResource);
        workflowDefinition.setName(name);
        workflowDefinition.setVersion("1");
        Value<String> initStateName = op.getInitialStateName();
        String initialStateName = initStateName.content(true);
        ElementList<State> workflowState = workflowDefinition.getStates();
        State state = workflowState.insert();
        state.setName(initialStateName);
        state.setInitial(true);
        Value<String> initTaskName = op.getInitialTaskName();
        String initialTaskName = initTaskName.content(true);
        ElementList<Task> workflowTask = workflowDefinition.getTasks();
        Task task = workflowTask.insert();
        task.setName(initialTaskName);
        KaleoModelUtil.changeTaskAssignments(task, op);
        ElementList<Transition> transitions = state.getTransitions();
        Transition transition = transitions.insert();
        transition.setName(initialTaskName);
        transition.setTarget(initialTaskName);
        Value<String> opFinalName = op.getFinalStateName();
        String finalStateName = opFinalName.content(true);
        ElementList<State> states = workflowDefinition.getStates();
        State finalState = states.insert();
        finalState.setName(finalStateName);
        finalState.setEnd(true);
        ElementList<Action> actions = finalState.getActions();
        Action finalAction = actions.insert();
        finalAction.setName("approve");
        finalAction.setExecutionType(ExecutionType.ON_ENTRY);
        finalAction.setScriptLanguage(ScriptLanguageType.JAVASCRIPT);
        String updateStatus = "Packages.com.liferay.portal.kernel.workflow.WorkflowStatusManagerUtil.updateStatus";
        String workflowConstants = "(Packages.com.liferay.portal.kernel.workflow.WorkflowConstants.";
        String toStatus = "toStatus(\"approved\"), workflowContext);";
        finalAction.setScript(updateStatus + workflowConstants + toStatus);
        ElementList<Transition> taskTransitions = task.getTransitions();
        Transition taskTransition = taskTransitions.insert();
        taskTransition.setName(finalStateName);
        taskTransition.setTarget(finalStateName);
        ElementHandle<WorkflowNodeMetadata> wfMetadata = state.getMetadata();
        WorkflowNodeMetadata stateMetadata = wfMetadata.content();
        Position statePosition = stateMetadata.getPosition();
        statePosition.setX(100);
        statePosition.setY(50);
        ElementList<TransitionMetadata> transitionMetadata = stateMetadata.getTransitionsMetadata();
        TransitionMetadata insertTransitionMetadata = transitionMetadata.insert();
        insertTransitionMetadata.setName(initialTaskName);
        ElementHandle<WorkflowNodeMetadata> taskWorkflow = task.getMetadata();
        WorkflowNodeMetadata taskMetadata = taskWorkflow.content();
        Position taskPosition = taskMetadata.getPosition();
        taskPosition.setX(300);
        taskPosition.setY(35);
        ElementList<TransitionMetadata> transitionTask = taskMetadata.getTransitionsMetadata();
        TransitionMetadata transitionTaskMetadata = transitionTask.insert();
        transitionTaskMetadata.setName(finalStateName);
        ElementHandle<WorkflowNodeMetadata> finalMetadata = finalState.getMetadata();
        WorkflowNodeMetadata finalStateMetadata = finalMetadata.content();
        Position finalStatePosition = finalStateMetadata.getPosition();
        finalStatePosition.setX(520);
        finalStatePosition.setY(50);
        /*
			 * Document document = rootXmlResource.getDomDocument(); Element
			 * docElement = document.getDocumentElement(); Attr schemaLocation =
			 * docElement.getAttributeNode( "xsi:schemaLocation" ); =
			 * schemaLocation.getNodeValue(); String nodeValue =
			 * schemaLocation.getNodeValue(); schemaLocation.setNodeValue(
			 * nodeValue.replaceAll( " http://www.w3.org/XML/1998/namespace ",
			 * "" ) );
			 */
        rootXmlResource.save();
        IPath fullPath = newDefinitionFile.getFullPath();
        op.setNewFilePath(fullPath.toPortableString());
        return Status.createOkStatus();
    } catch (Exception e) {
        KaleoCore.logError("Error creating new kaleo workflow file.", e);
        return Status.createErrorStatus("Error creating new kaleo workflow file.", e);
    }
}
Also used : Task(com.liferay.ide.kaleo.core.model.Task) Action(com.liferay.ide.kaleo.core.model.Action) IFile(org.eclipse.core.resources.IFile) TransitionMetadata(com.liferay.ide.kaleo.core.model.TransitionMetadata) XmlResourceStore(org.eclipse.sapphire.modeling.xml.XmlResourceStore) ScriptLanguageType(com.liferay.ide.kaleo.core.model.ScriptLanguageType) WorkflowNodeMetadata(com.liferay.ide.kaleo.core.model.WorkflowNodeMetadata) WorkspaceFileResourceStore(org.eclipse.sapphire.workspace.WorkspaceFileResourceStore) TemplateLanguageType(com.liferay.ide.kaleo.core.model.TemplateLanguageType) IContainer(org.eclipse.core.resources.IContainer) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.sapphire.modeling.Path) IPath(org.eclipse.core.runtime.IPath) Position(com.liferay.ide.kaleo.core.model.Position) WorkflowDefinition(com.liferay.ide.kaleo.core.model.WorkflowDefinition) RootXmlResource(org.eclipse.sapphire.modeling.xml.RootXmlResource) IProject(org.eclipse.core.resources.IProject) ByteArrayInputStream(java.io.ByteArrayInputStream) State(com.liferay.ide.kaleo.core.model.State) Transition(com.liferay.ide.kaleo.core.model.Transition)

Example 8 with WorkflowNodeMetadata

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

the class StateEndValueBinding method read.

@Override
public String read() {
    ElementHandle<WorkflowNodeMetadata> nodeMetadata = state().getMetadata();
    WorkflowNodeMetadata metadata = nodeMetadata.content();
    if (metadata != null) {
        Value<Boolean> isTerminal = metadata.isTerminal();
        boolean terminal = isTerminal.content();
        if (terminal) {
            return "true";
        }
    }
    return null;
}
Also used : WorkflowNodeMetadata(com.liferay.ide.kaleo.core.model.WorkflowNodeMetadata)

Example 9 with WorkflowNodeMetadata

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

the class StateEndValueBinding method write.

@Override
public void write(String value) {
    ElementHandle<WorkflowNodeMetadata> nodeMetadata = state().getMetadata();
    WorkflowNodeMetadata workflowNodeMetadata = nodeMetadata.content(true);
    workflowNodeMetadata.setTerminal(Boolean.parseBoolean(value));
}
Also used : WorkflowNodeMetadata(com.liferay.ide.kaleo.core.model.WorkflowNodeMetadata)

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