use of com.liferay.ide.kaleo.core.model.CanTransition 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());
}
}
use of com.liferay.ide.kaleo.core.model.CanTransition in project liferay-ide by liferay.
the class ForkNodeAddActionHandler method postDiagramNodePartAdded.
@Override
public void postDiagramNodePartAdded(NewNodeOp op, CanTransition newNodeFromWizard, CanTransition newNode) {
NewForkNodeOp newForkOp = op.nearest(NewForkNodeOp.class);
NewForkNode newForkNodeFromWizard = newNodeFromWizard.nearest(NewForkNode.class);
Fork newFork = newNode.nearest(Fork.class);
WorkflowDefinition workflowDefinition = newFork.nearest(WorkflowDefinition.class);
if (newForkOp.isAddJoin().content(true)) {
Join newJoin = workflowDefinition.getJoins().insert();
String newJoinName = newForkNodeFromWizard.getName().content() + " Join";
newJoin.setName(newJoinName);
for (Node connectedNode : op.getConnectedNodes()) {
for (WorkflowNode diagramNode : workflowDefinition.getDiagramNodes()) {
Value<String> nodeName = connectedNode.getName();
if (nodeName.content().equals(diagramNode.getName().content())) {
CanTransition canTransition = diagramNode.nearest(CanTransition.class);
ElementList<Transition> transitions = canTransition.getTransitions();
Transition newTransition = transitions.insert();
newTransition.setName(newJoinName);
newTransition.setTarget(newJoinName);
}
}
}
}
}
use of com.liferay.ide.kaleo.core.model.CanTransition in project liferay-ide by liferay.
the class TransitionTargetListener method handleTypedEvent.
@Override
protected void handleTypedEvent(PropertyContentEvent event) {
Property property = event.property();
Transition transition = property.nearest(Transition.class);
if (transition != null) {
ReferenceValue<String, Node> targe = transition.getTarget();
Value<String> transitionName = transition.getName();
if ((targe.content() != null) && (transitionName.content(false) == null)) {
String targetName = targe.content();
String defaultName = targetName;
Set<String> existingNames = new HashSet<>();
CanTransition camtransition = transition.nearest(CanTransition.class);
for (Transition t : camtransition.getTransitions()) {
Value<String> tName = t.getName();
if (tName.content() != null) {
existingNames.add(tName.content());
}
}
int count = 1;
while (existingNames.contains(defaultName)) {
defaultName = targetName + "_" + count++;
}
transition.setName(defaultName);
}
}
}
use of com.liferay.ide.kaleo.core.model.CanTransition in project liferay-ide by liferay.
the class NewNodeOpWizard method performPostDiagramNodeAdded.
protected void performPostDiagramNodeAdded() {
NewNodeOp newNodeOp = element().nearest(NewNodeOp.class);
CanTransition newNode = newNodeOp.adapt(CanTransition.class);
CanTransition node = _diagramNodePart.getLocalModelElement().nearest(CanTransition.class);
WorkflowDefinition workflowDefinition = node.nearest(WorkflowDefinition.class);
if ((newNode != null) && (node != null)) {
Value<String> newNodeName = newNode.getName();
node.setName(newNodeName.content());
if (newNodeOp.getConnectedNodes().size() > 0) {
for (Node diagramNode : newNodeOp.getConnectedNodes()) {
Value<String> nodeName = diagramNode.getName();
String diagramNodeName = nodeName.content(true);
if (diagramNode instanceof ConditionForOp) {
ElementList<Condition> conditions = workflowDefinition.getConditions();
Condition insertCondition = conditions.insert();
insertCondition.setName(diagramNodeName);
} else if (diagramNode instanceof ForkForOp) {
ElementList<Fork> forks = workflowDefinition.getForks();
Fork insertFork = forks.insert();
insertFork.setName(diagramNodeName);
} else if (diagramNode instanceof JoinForOp) {
ElementList<Join> joins = workflowDefinition.getJoins();
Join insertJoin = joins.insert();
insertJoin.setName(diagramNodeName);
} else if (diagramNode instanceof JoinXorForOp) {
ElementList<JoinXor> joinXors = workflowDefinition.getJoinXors();
JoinXor insertJoinXor = joinXors.insert();
insertJoinXor.setName(diagramNodeName);
} else if (diagramNode instanceof StateForOp) {
ElementList<State> states = workflowDefinition.getStates();
State insertState = states.insert();
insertState.setName(diagramNodeName);
} else if (diagramNode instanceof TaskForOp) {
ElementList<Task> tasks = workflowDefinition.getTasks();
Task insertTask = tasks.insert();
insertTask.setName(diagramNodeName);
}
if (diagramNode instanceof ChooseDiagramNode || node instanceof Condition || node instanceof Fork || node instanceof State || node instanceof Task) {
Transition newTransition = node.getTransitions().insert();
newTransition.setName(diagramNodeName);
newTransition.setTarget(diagramNodeName);
} else {
CanTransition canTransition = diagramNode.nearest(CanTransition.class);
ElementList<Transition> transition = canTransition.getTransitions();
Transition joinTransition = transition.insert();
joinTransition.setName(node.getName().content());
joinTransition.setTarget(node.getName().content());
}
}
}
}
_actionHandler.postDiagramNodePartAdded(element(), newNode, node);
}
use of com.liferay.ide.kaleo.core.model.CanTransition 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);
}
}
}
}
}
Aggregations