use of org.eclipse.sapphire.ui.diagram.ConnectionService 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 org.eclipse.sapphire.ui.diagram.ConnectionService in project liferay-ide by liferay.
the class WorkflowDefinitionLayoutPersistenceService method _isDiagramLayoutChanged.
private boolean _isDiagramLayoutChanged() {
boolean changed = false;
SapphireDiagramEditorPagePart part = _part();
if (!part.disposed()) {
ConnectionService connService = part.service(ConnectionService.class);
for (DiagramNodePart nodePart : part.getNodes()) {
if (!nodePart.getLocalModelElement().disposed() && _isNodeLayoutChanged(nodePart)) {
changed = true;
break;
}
}
for (DiagramConnectionPart connPart : connService.list()) {
if (!connPart.getLocalModelElement().disposed() && _isConnectionLayoutChanged(connPart)) {
changed = true;
break;
}
}
}
return changed;
}
use of org.eclipse.sapphire.ui.diagram.ConnectionService 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 org.eclipse.sapphire.ui.diagram.ConnectionService in project liferay-ide by liferay.
the class WorkflowDefinitionLayoutPersistenceService method _refreshPersistedPartsCache.
private void _refreshPersistedPartsCache() {
_nodeBounds.clear();
_connectionBendPoints.clear();
ConnectionService connService = _part().service(ConnectionService.class);
for (DiagramConnectionPart connPart : connService.list()) {
_addConnectionToPersistenceCache(connPart);
}
for (DiagramNodePart nodePart : _part().getNodes()) {
_addNodeToPersistenceCache(nodePart);
}
}
use of org.eclipse.sapphire.ui.diagram.ConnectionService 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);
}
}
Aggregations