use of com.liferay.ide.kaleo.core.model.WorkflowNodeMetadata in project liferay-ide by liferay.
the class WorkflowDefinitionLayoutPersistenceService method _handleConnectionBendpointChange.
private void _handleConnectionBendpointChange(Transition transition) {
ConnectionService connService = _part().service(ConnectionService.class);
DiagramConnectionPart connPart = _getConnectionPart(connService, transition);
if (connPart != null) {
List<Point> bendpoints = new ArrayList<>();
WorkflowNode wfNode = transition.nearest(WorkflowNode.class);
ElementHandle<WorkflowNodeMetadata> nodeMetadata = wfNode.getMetadata();
WorkflowNodeMetadata metadata = nodeMetadata.content(false);
TransitionMetadata transitionMetadata = _getTransitionMetadata(transition, metadata);
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.WorkflowNodeMetadata in project liferay-ide by liferay.
the class WorkflowDefinitionLayoutPersistenceService method _writeTransitionBendPoints.
private void _writeTransitionBendPoints(Transition transition, DiagramConnectionPart connPart) {
WorkflowNode workflowNode = transition.nearest(WorkflowNode.class);
ElementHandle<WorkflowNodeMetadata> nodeMetadata = workflowNode.getMetadata();
WorkflowNodeMetadata metadata = nodeMetadata.content(true);
TransitionMetadata transitionMetadata = _getTransitionMetadata(transition, metadata, true);
transitionMetadata.setName(transition.getName().content());
ElementList<ConnectionBendpoint> bendpointsInMetadataList = transitionMetadata.getBendpoints();
int bendpointsInMetadataSize = bendpointsInMetadataList.size();
List<Point> bendpointsInPartList = connPart.getBendpoints();
int bendpointsInPartSize = bendpointsInPartList.size();
for (int i = 0, n = min(bendpointsInMetadataSize, bendpointsInPartSize); i < n; i++) {
ConnectionBendpoint bendpointInMetadata = bendpointsInMetadataList.get(i);
Point bendpointInPart = bendpointsInPartList.get(i);
if (bendpointInMetadata.getX().content() != bendpointInPart.getX()) {
bendpointInMetadata.setX(bendpointInPart.getX());
}
if (bendpointInMetadata.getY().content() != bendpointInPart.getY()) {
bendpointInMetadata.setY(bendpointInPart.getY());
}
}
if (bendpointsInMetadataSize < bendpointsInPartSize) {
for (int i = bendpointsInMetadataSize; i < bendpointsInPartSize; i++) {
ConnectionBendpoint bendpointInMetadata = bendpointsInMetadataList.insert();
Point bendpointInPart = bendpointsInPartList.get(i);
bendpointInMetadata.setX(bendpointInPart.getX());
bendpointInMetadata.setY(bendpointInPart.getY());
}
} else if (bendpointsInMetadataSize > bendpointsInPartSize) {
for (int i = bendpointsInMetadataSize - 1; i >= bendpointsInPartSize; i--) {
bendpointsInMetadataList.remove(i);
}
}
if ((connPart.getLabelPosition() != null) && !connPart.getLabelPosition().equals(DEFAULT_POINT)) {
transitionMetadata.getLabelLocation().setX(connPart.getLabelPosition().getX());
transitionMetadata.getLabelLocation().setY(connPart.getLabelPosition().getY());
}
}
use of com.liferay.ide.kaleo.core.model.WorkflowNodeMetadata 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.WorkflowNodeMetadata in project liferay-ide by liferay.
the class WorkflowDefinitionLayoutPersistenceService method _writeWorkflowNodeBoundsToMetaData.
private void _writeWorkflowNodeBoundsToMetaData(WorkflowNode workflowNode, DiagramNodePart nodePart) {
Bounds bounds = nodePart.getNodeBounds();
ElementHandle<WorkflowNodeMetadata> nodeMetadata = workflowNode.getMetadata();
WorkflowNodeMetadata metadata = nodeMetadata.content(true);
Position position = metadata.getPosition();
Value<Integer> valueX = position.getX();
if (bounds.getX() != valueX.content()) {
position.setX(bounds.getX());
}
Value<Integer> valueY = position.getY();
if (bounds.getY() != valueY.content()) {
position.setY(bounds.getY());
}
}
use of com.liferay.ide.kaleo.core.model.WorkflowNodeMetadata in project liferay-ide by liferay.
the class WorkflowDefinitionLayoutPersistenceService method _handleNodeLayoutChange.
private void _handleNodeLayoutChange(WorkflowNode workflowNode) {
DiagramNodePart nodePart = _part().getDiagramNodePart(workflowNode);
WorkflowNodeMetadata metadata = workflowNode.getMetadata().content();
Position position = metadata.getPosition();
Value<Integer> valueX = position.getX();
Value<Integer> valueY = position.getY();
DiagramNodeBounds nodeBounds = new DiagramNodeBounds(valueX.content(), valueY.content());
nodePart.setNodeBounds(nodeBounds);
}
Aggregations