use of com.liferay.ide.kaleo.core.op.NewStateType 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());
}
}
}
Aggregations