use of com.liferay.ide.kaleo.core.model.Transition 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);
}
}
use of com.liferay.ide.kaleo.core.model.Transition in project liferay-ide by liferay.
the class WorkflowDefinitionLayoutPersistenceService method _handleWorkflowNodeMetaChange.
private void _handleWorkflowNodeMetaChange(WorkflowNodeMetadata workflowNodeMetadata) {
WorkflowNode workflowNode = workflowNodeMetadata.nearest(WorkflowNode.class);
if (workflowNode == null) {
return;
}
DiagramNodePart nodePart = _part().getDiagramNodePart(workflowNode);
if (nodePart != null) {
Position position = workflowNodeMetadata.getPosition();
Value<Integer> valueX = position.getX();
Value<Integer> valueY = position.getY();
DiagramNodeBounds nodeBounds = nodePart.getNodeBounds();
if ((nodeBounds.getX() != valueX.content()) || (nodeBounds.getY() != valueY.content())) {
nodePart.setNodeBounds(new DiagramNodeBounds(valueX.content(), valueY.content()));
}
}
ConnectionService connService = _part().service(ConnectionService.class);
if (workflowNode instanceof CanTransition) {
CanTransition canTransition = (CanTransition) workflowNode;
ElementList<Transition> transitions = canTransition.getTransitions();
for (Transition transition : transitions) {
List<Point> bendpoints = new ArrayList<>();
DiagramConnectionPart connPart = _getConnectionPart(connService, transition);
if (connPart != null) {
TransitionMetadata transitionMetadata = _getTransitionMetadata(transition, workflowNodeMetadata);
if (transitionMetadata != null) {
for (ConnectionBendpoint bendpoint : transitionMetadata.getBendpoints()) {
bendpoints.add(new Point(bendpoint.getX().content(), bendpoint.getY().content()));
}
connPart.resetBendpoints(bendpoints);
}
}
}
}
}
use of com.liferay.ide.kaleo.core.model.Transition in project liferay-ide by liferay.
the class WorkflowDefinitionLayoutPersistenceService method _save.
private void _save() {
_refreshPersistedPartsCache();
/*
* For nodes that are placed using default node positions and connection
* bend points that are calculated using connection router, we don't
* modify the corresponding model properties in order to allow "revert"
* in source editor to work correctly. So we need to do an explicit save
* of the node bounds and connection bend points here.
*/
_removeWorkflowNodeListeners();
_removeBendpointListeners();
for (DiagramNodePart nodePart : _part().getNodes()) {
Element modelElement = nodePart.getLocalModelElement();
WorkflowNode workflowNode = (WorkflowNode) modelElement;
if (!workflowNode.disposed()) {
_writeWorkflowNodeBoundsToMetaData(workflowNode, nodePart);
DiagramNodeBounds nodePartBounds = nodePart.getNodeBounds();
nodePartBounds.setAutoLayout(false);
nodePart.setNodeBounds(nodePartBounds);
}
}
for (DiagramConnectionPart connPart : _part().getConnections()) {
Element modelElement = connPart.getLocalModelElement();
Transition transition = (Transition) modelElement;
if (!transition.disposed()) {
_writeTransitionBendPoints(transition, connPart);
}
}
_addWorkflowNodeListeners();
_addBendpointListeners();
}
use of com.liferay.ide.kaleo.core.model.Transition 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());
}
}
}
use of com.liferay.ide.kaleo.core.model.Transition in project liferay-ide by liferay.
the class JoinNodeAddActionHandler method postDiagramNodePartAdded.
@Override
public void postDiagramNodePartAdded(NewNodeOp op, CanTransition newNodeFromWizard, CanTransition newNode) {
NewJoinNodeOp newJoinNodeOp = op.nearest(NewJoinNodeOp.class);
Join newJoin = newNode.nearest(Join.class);
WorkflowDefinition workflowDefinition = newJoin.nearest(WorkflowDefinition.class);
for (Node nodeName : newJoinNodeOp.getConnectedNodes()) {
for (WorkflowNode diagramNode : workflowDefinition.getDiagramNodes()) {
if (nodeName.getName().content() != null) {
String name = nodeName.getName().content();
if (name.equals(diagramNode.getName().content())) {
CanTransition canTransition = diagramNode.nearest(CanTransition.class);
Transition newTransition = canTransition.getTransitions().insert();
newTransition.setName(newJoin.getName().content());
newTransition.setTarget(newJoin.getName().content());
}
}
}
}
if (newJoinNodeOp.getExitTransitionName().content() != null) {
Transition newTransition = newJoin.getTransitions().insert();
newTransition.setTarget(newJoinNodeOp.getExitTransitionName().content());
newTransition.setName(newJoinNodeOp.getExitTransitionName().content());
}
}
Aggregations