diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/controller/.ratings b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/controller/.ratings index ba0f9515784cfa691eaa2dce481d006b0114604d..c856ab461e43d1267971dce11144a810b569bff4 100644 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/controller/.ratings +++ b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/controller/.ratings @@ -1,5 +1,6 @@ ContextMenuUtil.java 405387151d45b09dffb3b6ba44f980313c8edcaf GREEN -CurvedLinkLayoutedContentAnchorangeController.java 6d2b64c3d6c813ac001b1500ed0529ad6e561aaf GREEN +CurvedLinkLayoutedContentAnchorangeController.java a206a297cfc51281b31d02c751c3090b49fc7341 YELLOW +CurvedLinkLayoutedDiagramAnchorangeController.java 47122da96c51bc7517160ff3d9c735f81e0d082b YELLOW EObjectDiagramController.java 2b253941592ee25ead95223470f983f23ef9776f GREEN EObjectEllipticResizableContentControllerBase.java 7c862a03b97d2f2cfdcc2fcee7434de2e1e257d2 GREEN EObjectModelChangeProvider.java f4b60cebb088a5c81ca92a41614e1a5d40030502 GREEN diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/controller/CurvedLinkLayoutedContentAnchorangeController.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/controller/CurvedLinkLayoutedContentAnchorangeController.java index 6d2b64c3d6c813ac001b1500ed0529ad6e561aaf..a206a297cfc51281b31d02c751c3090b49fc7341 100644 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/controller/CurvedLinkLayoutedContentAnchorangeController.java +++ b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/controller/CurvedLinkLayoutedContentAnchorangeController.java @@ -17,8 +17,9 @@ package org.fortiss.tooling.base.ui.editor.fx.controller; import static org.fortiss.tooling.base.ui.utils.LayoutDataUIUtils.addConnectionPoint; -import org.fortiss.tooling.base.model.base.EntryConnectorBase; -import org.fortiss.tooling.base.model.base.ExitConnectorBase; +import org.eclipse.emf.common.util.BasicEList; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EObject; import org.fortiss.tooling.base.model.base.HierarchicElementBase; import org.fortiss.tooling.base.model.element.IConnection; import org.fortiss.tooling.base.model.element.IConnector; @@ -43,7 +44,7 @@ public class CurvedLinkLayoutedContentAnchorangeController<T extends IConnector } /** {@inheritDoc} */ - @SuppressWarnings("unchecked") + // TODO(3978): Resolve code duplication in the link-method of link visuals @Override protected void link(IMVCBundle startBundle, DiagramCoordinate startLocation, IMVCBundle endBundle, DiagramCoordinate endLocation) { @@ -53,18 +54,22 @@ public class CurvedLinkLayoutedContentAnchorangeController<T extends IConnector return; } - // Create the connection + // The call to `super.link` (see next lines) does not return a reference to the + // newly created connection. However, as it is needed in order to add the handles + // we get it by comparing the root element's connections before and after the + // creation of the new link: + // 1) Here we get the list of existing connections + EList<IConnection> connectionsBefore = new BasicEList<IConnection>( + ((HierarchicElementBase)(EObject)getViewer().getRootElement()).getConnections()); + // 2) Here we create the new connection super.link(startBundle, startLocation, endBundle, endLocation); - - // Fetch newly created connection by comparing incoming and outgoing connections of the - // given connectors. As only one connection is allowed between a pair of connectors, this - // 'findFirst' is safe. - T startConnector = (T)(startBundle.getModel() instanceof ExitConnectorBase - ? startBundle.getModel() : endBundle.getModel()); - T endConnector = (T)(endBundle.getModel() instanceof EntryConnectorBase - ? endBundle.getModel() : startBundle.getModel()); - IConnection connection = startConnector.getOutgoing().stream() - .filter(segment -> endConnector.getIncoming().contains(segment)).findFirst().get(); + // 3) Here we get the updated list of connections + EList<IConnection> connectionsAfter = new BasicEList<IConnection>( + ((HierarchicElementBase)(EObject)getViewer().getRootElement()).getConnections()); + // 4) We remove all existing ones + connectionsAfter.removeAll(connectionsBefore); + // 5) And we are left with the newly added one. + IConnection connection = connectionsAfter.stream().findFirst().get(); // Create handles DiagramCoordinate startPosition = diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/controller/CurvedLinkLayoutedDiagramAnchorangeController.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/controller/CurvedLinkLayoutedDiagramAnchorangeController.java new file mode 100644 index 0000000000000000000000000000000000000000..47122da96c51bc7517160ff3d9c735f81e0d082b --- /dev/null +++ b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/editor/fx/controller/CurvedLinkLayoutedDiagramAnchorangeController.java @@ -0,0 +1,87 @@ +/*-------------------------------------------------------------------------+ +| Copyright 2020 fortiss GmbH | +| | +| Licensed under the Apache License, Version 2.0 (the "License"); | +| you may not use this file except in compliance with the License. | +| You may obtain a copy of the License at | +| | +| http://www.apache.org/licenses/LICENSE-2.0 | +| | +| Unless required by applicable law or agreed to in writing, software | +| distributed under the License is distributed on an "AS IS" BASIS, | +| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | +| See the License for the specific language governing permissions and | +| limitations under the License. | ++--------------------------------------------------------------------------*/ +package org.fortiss.tooling.base.ui.editor.fx.controller; + +import static org.fortiss.tooling.base.ui.utils.LayoutDataUIUtils.addConnectionPoint; + +import org.eclipse.emf.common.util.BasicEList; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EObject; +import org.fortiss.tooling.base.model.base.HierarchicElementBase; +import org.fortiss.tooling.base.model.element.IConnection; +import org.fortiss.tooling.base.model.element.IConnector; +import org.fortiss.tooling.base.model.layout.ILayoutedModelElement; +import org.fortiss.tooling.common.ui.javafx.lwfxef.DiagramCoordinate; +import org.fortiss.tooling.common.ui.javafx.lwfxef.mvc.IMVCBundle; + +/** + * {@link LayoutedDiagramAnchorageController} for diagrams with curved links. + * + * @author munaro + */ +public class CurvedLinkLayoutedDiagramAnchorangeController<T extends IConnector & ILayoutedModelElement> + extends LayoutedDiagramAnchorageController<T> { + + /** Constructor. */ + public CurvedLinkLayoutedDiagramAnchorangeController(IMVCBundle mvcb, Class<T> modelType) { + super(mvcb, modelType); + // TODO Auto-generated constructor stub + } + + /** {@inheritDoc} */ + // TODO(3978): Resolve code duplication in the link-method of link visuals + @Override + protected void link(IMVCBundle startBundle, DiagramCoordinate startLocation, + IMVCBundle endBundle, DiagramCoordinate endLocation) { + // Disable direct links between hierarchic element bases + if(startBundle.getModel() instanceof HierarchicElementBase || + endBundle.getModel() instanceof HierarchicElementBase) { + return; + } + + // The call to `super.link` (see next lines) does not return a reference to the + // newly created connection. However, as it is needed in order to add the handles + // we get it by comparing the root element's connections before and after the + // creation of the new link: + // 1) Here we get the list of existing connections + EList<IConnection> connectionsBefore = new BasicEList<IConnection>( + ((HierarchicElementBase)(EObject)getViewer().getRootElement()).getConnections()); + // 2) Here we create the new connection + super.link(startBundle, startLocation, endBundle, endLocation); + // 3) Here we get the updated list of connections + EList<IConnection> connectionsAfter = new BasicEList<IConnection>( + ((HierarchicElementBase)(EObject)getViewer().getRootElement()).getConnections()); + // 4) We remove all existing ones + connectionsAfter.removeAll(connectionsBefore); + // 5) And we are left with the newly added one. + IConnection connection = connectionsAfter.stream().findFirst().get(); + + // Create handles + DiagramCoordinate startPosition = + new DiagramCoordinate(startBundle.getVisual().getCurrentBounds().getMaxX(), + startBundle.getVisual().getCurrentBounds().getMaxY()); + DiagramCoordinate endPosition = + new DiagramCoordinate(endBundle.getVisual().getCurrentBounds().getMaxX(), + endBundle.getVisual().getCurrentBounds().getMaxY()); + DiagramCoordinate middle = + new DiagramCoordinate((startPosition.getX() + endPosition.getX()) / 2, + (startPosition.getY() + endPosition.getY()) / 2); + addConnectionPoint((ILayoutedModelElement)connection, 0, (int)middle.getX(), + (int)middle.getY()); + addConnectionPoint((ILayoutedModelElement)connection, 1, (int)middle.getX(), + (int)middle.getY()); + } +}