diff options
| author | Laurent Redor | 2014-11-17 16:26:24 +0000 |
|---|---|---|
| committer | Esteban DUGUEPEROUX | 2015-08-20 14:14:46 +0000 |
| commit | 78d6c23282ab364dcb70a71f9274ac6066e37f5b (patch) | |
| tree | 6c6c3115a6967c82816d1430c7ecb095a853bfdf | |
| parent | 541a8f8fc415b26c562df2a9bfc6778bd761be6b (diff) | |
| download | org.eclipse.sirius-78d6c23282ab364dcb70a71f9274ac6066e37f5b.tar.gz org.eclipse.sirius-78d6c23282ab364dcb70a71f9274ac6066e37f5b.tar.xz org.eclipse.sirius-78d6c23282ab364dcb70a71f9274ac6066e37f5b.zip | |
[475380] Also arrange edges during the arrange of linked border nodes
Currently, there is no specific layout for edge during an arrange of
linked border nodes (with action Arrange All or with specific action
Arrange Linked Border Nodes). The result is strange.
This commit removes all bendpoints (except the first and the last) of
edges connected to a moved border node. The first and the last point are
set to the anchor location.
Bug: 475380
Change-Id: Iab5436a42103b3a711bfe1b751ea70c9fbe50249
Signed-off-by: Laurent Redor <laurent.redor@obeo.fr>
2 files changed, 116 insertions, 2 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/layout/provider/BorderItemAwareLayoutProvider.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/layout/provider/BorderItemAwareLayoutProvider.java index b3a9e8df60..5389ff500f 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/layout/provider/BorderItemAwareLayoutProvider.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/layout/provider/BorderItemAwareLayoutProvider.java @@ -15,6 +15,7 @@ import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; +import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -26,6 +27,7 @@ import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.PositionConstants; import org.eclipse.draw2d.geometry.Dimension; import org.eclipse.draw2d.geometry.Point; +import org.eclipse.draw2d.geometry.PointList; import org.eclipse.draw2d.geometry.PrecisionPoint; import org.eclipse.draw2d.geometry.Rectangle; import org.eclipse.draw2d.geometry.Vector; @@ -80,6 +82,7 @@ import org.eclipse.sirius.diagram.ui.edit.api.part.IDiagramElementEditPart; import org.eclipse.sirius.diagram.ui.internal.edit.parts.AbstractDNodeContainerCompartmentEditPart; import org.eclipse.sirius.diagram.ui.internal.edit.parts.DEdgeEditPart; import org.eclipse.sirius.diagram.ui.internal.operation.RegionContainerUpdateLayoutOperation; +import org.eclipse.sirius.diagram.ui.internal.refresh.GMFHelper; import org.eclipse.sirius.diagram.ui.internal.refresh.borderednode.CanonicalDBorderItemLocator; import org.eclipse.sirius.diagram.ui.tools.api.figure.locator.DBorderItemLocator; import org.eclipse.sirius.diagram.ui.tools.api.graphical.edit.styles.IBorderItemOffsets; @@ -88,6 +91,9 @@ import org.eclipse.sirius.diagram.ui.tools.internal.edit.command.CommandFactory; import org.eclipse.sirius.diagram.ui.tools.internal.graphical.edit.policies.ChangeBoundRequestRecorder; import org.eclipse.sirius.diagram.ui.tools.internal.layout.ArrangeAllWithAutoSize; import org.eclipse.sirius.diagram.ui.tools.internal.part.SiriusDiagramGraphicalViewer; +import org.eclipse.sirius.ext.base.Option; +import org.eclipse.sirius.ext.base.Options; +import org.eclipse.sirius.ext.gmf.runtime.editparts.GraphicalHelper; import org.eclipse.sirius.viewpoint.DSemanticDecorator; import com.google.common.base.Predicate; @@ -696,11 +702,110 @@ public class BorderItemAwareLayoutProvider extends AbstractLayoutProvider { // compute locations (record in cc = (CompoundCommand) layoutBorderItems(selectedObjects, nbIterations + 1, elementsToKeepFixed); } + // Keep only first and last points of edges linked to at least one of + // moved border nodes. + for (Entry<View, List<Request>> requestByView : getViewsToChangeBoundsRequest().entrySet()) { + View view = requestByView.getKey(); + // Get corresponding edit part + Option<IBorderItemEditPart> optionalPart = getCorrespondingEditPart(view); + if (optionalPart.some()) { + // In theory we are always in this case... + IBorderItemEditPart borderItemEditPart = optionalPart.get(); + List<Request> requests = requestByView.getValue(); + if (!(view.getSourceEdges().isEmpty() && view.getTargetEdges().isEmpty())) { + // For each edge starting from this view + for (Iterator<Edge> iterator = Iterables.filter(view.getSourceEdges(), Edge.class).iterator(); iterator.hasNext(); /* */) { + resetBendpoints(iterator.next(), cc, borderItemEditPart, requests, true); + } + // For each edge ending to this view + for (Iterator<Edge> iterator = Iterables.filter(view.getTargetEdges(), Edge.class).iterator(); iterator.hasNext(); /* */) { + resetBendpoints(iterator.next(), cc, borderItemEditPart, requests, false); + } + } + } + } clearBorderItemLocations(); return cc; } /** + * Add command to the <code>cc</code> to reset the bendpoints of the current + * <code>edge</code> if needed. + * + * @param edge + * The edge to deal with + * @param cc + * CompoundCommand to complete to reset bendpoints of + * <code>edge</code> if needed. + * @param borderItemEditPart + * The moved border node edit part (source of edge if + * <code>sourceEdge</code> equals true, target of edge + * otherwise). + * @param requests + * Request concerning the moved edit part + * @param sourceEdge + * true if the <code>borderItemEditPart</code> is the source of + * the edge, false otherwise. + */ + public void resetBendpoints(Edge edge, CompoundCommand cc, IBorderItemEditPart borderItemEditPart, List<Request> requests, boolean sourceEdge) { + Point firstAnchorLocation; + if (sourceEdge) { + firstAnchorLocation = GraphicalHelper.getAnchorPoint(borderItemEditPart, edge.getSourceAnchor()); + } else { + firstAnchorLocation = GraphicalHelper.getAnchorPoint(borderItemEditPart, edge.getTargetAnchor()); + } + // The first extremity of the edge has been moved, so we must + // apply the same move delta on the corresponding anchor. + for (Request request : requests) { + if (request instanceof ChangeBoundsRequest) { + firstAnchorLocation.translate(((ChangeBoundsRequest) request).getMoveDelta()); + } + } + View edgeOtherExtremityView; + if (sourceEdge) { + edgeOtherExtremityView = edge.getTarget(); + } else { + edgeOtherExtremityView = edge.getSource(); + } + Option<? extends GraphicalEditPart> optionalOtherExtremityPart = getCorrespondingEditPart(edgeOtherExtremityView); + if (!(optionalOtherExtremityPart.some())) { + optionalOtherExtremityPart = GMFHelper.getGraphicalEditPart(edgeOtherExtremityView); + } + if (optionalOtherExtremityPart.some()) { + Point secondAnchorLocation; + if (sourceEdge) { + secondAnchorLocation = GraphicalHelper.getAnchorPoint(optionalOtherExtremityPart.get(), edge.getTargetAnchor()); + } else { + secondAnchorLocation = GraphicalHelper.getAnchorPoint(optionalOtherExtremityPart.get(), edge.getSourceAnchor()); + } + boolean otherExtremityMove = getViewsToChangeBoundsRequest().keySet().contains(edgeOtherExtremityView); + if (otherExtremityMove) { + // The other extremity of the edge has also moved, so the + // future second location must be computed. + for (Request request : getViewsToChangeBoundsRequest().get(edgeOtherExtremityView)) { + if (request instanceof ChangeBoundsRequest) { + secondAnchorLocation.translate(((ChangeBoundsRequest) request).getMoveDelta()); + } + } + } + if (sourceEdge || (!sourceEdge && !otherExtremityMove)) { + // in case of targetEdge, if source of the edge has also moved + // we ignore + // this edge because it has also handled with sourceEdges of + // opposite node. + TransactionalEditingDomain editingDomain = TransactionUtil.getEditingDomain(edge.getElement()); + SetConnectionBendpointsCommand resetBendpoinsCmd = new SetConnectionBendpointsCommand(editingDomain); + resetBendpoinsCmd.setEdgeAdapter(new EObjectAdapter(edge)); + PointList newPointList = new PointList(2); + newPointList.addPoint(firstAnchorLocation); + newPointList.addPoint(secondAnchorLocation); + resetBendpoinsCmd.setNewPointList(newPointList, firstAnchorLocation, secondAnchorLocation); + cc.add(new ICommandProxy(resetBendpoinsCmd)); + } + } + } + + /** * Remove the request corresponding to this command of the map that maps all * views with a its associated {@link ChangeBoundsRequest}. * @@ -744,6 +849,15 @@ public class BorderItemAwareLayoutProvider extends AbstractLayoutProvider { previousIterationDatasbyEditPart.clear(); } + private Option<IBorderItemEditPart> getCorrespondingEditPart(View view) { + for (IBorderItemEditPart borderItemEditPart : previousIterationDatasbyEditPart.keySet()) { + if (view.equals(borderItemEditPart.getModel())) { + return Options.newSome(borderItemEditPart); + } + } + return Options.newNone(); + } + /** * Layout all the border items of this graphicalEditPart. * diff --git a/plugins/org.eclipse.sirius.ext.gmf.runtime/src/org/eclipse/sirius/ext/gmf/runtime/editparts/GraphicalHelper.java b/plugins/org.eclipse.sirius.ext.gmf.runtime/src/org/eclipse/sirius/ext/gmf/runtime/editparts/GraphicalHelper.java index c50bbaf855..0ffafa9ea8 100644 --- a/plugins/org.eclipse.sirius.ext.gmf.runtime/src/org/eclipse/sirius/ext/gmf/runtime/editparts/GraphicalHelper.java +++ b/plugins/org.eclipse.sirius.ext.gmf.runtime/src/org/eclipse/sirius/ext/gmf/runtime/editparts/GraphicalHelper.java @@ -297,7 +297,7 @@ public final class GraphicalHelper { * The anchor * @return The corresponding point to this anchor */ - public static Point getAnchorPoint(IGraphicalEditPart parent, Anchor anchor) { + public static Point getAnchorPoint(GraphicalEditPart parent, Anchor anchor) { if (anchor instanceof IdentityAnchor) { return getAnchorPoint(parent, (IdentityAnchor) anchor); } else { @@ -315,7 +315,7 @@ public final class GraphicalHelper { * The anchor * @return The corresponding point to this anchor */ - public static Point getAnchorPoint(IGraphicalEditPart parent, IdentityAnchor anchor) { + public static Point getAnchorPoint(GraphicalEditPart parent, IdentityAnchor anchor) { PrecisionRectangle bounds; if (parent.getFigure() instanceof HandleBounds) { bounds = new PrecisionRectangle(((HandleBounds) parent.getFigure()).getHandleBounds()); |
