Search in sources :

Example 1 with NewStateNode

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

Aggregations

Action (com.liferay.ide.kaleo.core.model.Action)1 CanTransition (com.liferay.ide.kaleo.core.model.CanTransition)1 State (com.liferay.ide.kaleo.core.model.State)1 Transition (com.liferay.ide.kaleo.core.model.Transition)1 NewStateNode (com.liferay.ide.kaleo.core.op.NewStateNode)1 NewStateNodeOp (com.liferay.ide.kaleo.core.op.NewStateNodeOp)1 NewStateType (com.liferay.ide.kaleo.core.op.NewStateType)1 IKaleoEditorHelper (com.liferay.ide.kaleo.ui.IKaleoEditorHelper)1 File (java.io.File)1