diff options
| author | Florian Barbin | 2014-10-20 15:52:07 +0000 |
|---|---|---|
| committer | Florian Barbin | 2014-10-21 12:44:28 +0000 |
| commit | c7d3f03c9a8029ea281820de6520f377266aa20c (patch) | |
| tree | 894666ad4c6820a03de80835bf6a53b5a61f09e6 | |
| parent | d350f14bdfd1fdd5cf6489cf521c3325908b6f68 (diff) | |
| download | org.eclipse.sirius-c7d3f03c9a8029ea281820de6520f377266aa20c.tar.gz org.eclipse.sirius-c7d3f03c9a8029ea281820de6520f377266aa20c.tar.xz org.eclipse.sirius-c7d3f03c9a8029ea281820de6520f377266aa20c.zip | |
[437528] Handle edge centering during the arrange action.
* We now center the edge ends at the end of the arrange command.
* This commit fix the problem noticed in [1] (comment 15 of bug 437528).
[1] https://bugs.eclipse.org/bugs/show_bug.cgi?id=437528#c15
Bug: 437528
Change-Id: I71f06e71aeb89d53bc4d9deef21929c06ebcf4e5
Signed-off-by: Florian Barbin <florian.barbin@obeo.fr>
2 files changed, 97 insertions, 2 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/SiriusContainerEditPolicy.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/SiriusContainerEditPolicy.java index 0ff533d034..6a4750710b 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/SiriusContainerEditPolicy.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/graphical/edit/policies/SiriusContainerEditPolicy.java @@ -21,6 +21,7 @@ import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.draw2d.geometry.Rectangle; import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.EditPart; import org.eclipse.gef.Request; import org.eclipse.gef.commands.Command; import org.eclipse.gef.requests.GroupRequest; @@ -31,6 +32,7 @@ import org.eclipse.gmf.runtime.diagram.ui.actions.ActionIds; import org.eclipse.gmf.runtime.diagram.ui.commands.CommandProxy; import org.eclipse.gmf.runtime.diagram.ui.commands.DeferredLayoutCommand; import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy; +import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart; import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ContainerEditPolicy; import org.eclipse.gmf.runtime.diagram.ui.internal.properties.WorkspaceViewerProperties; @@ -45,6 +47,7 @@ import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalC import org.eclipse.gmf.runtime.notation.Node; import org.eclipse.gmf.runtime.notation.View; import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.sirius.diagram.ui.internal.edit.commands.CenterEdgeLayoutCommand; import org.eclipse.sirius.diagram.ui.internal.edit.commands.DistributeCommand; import org.eclipse.sirius.diagram.ui.tools.api.requests.DistributeRequest; import org.eclipse.sirius.diagram.ui.tools.internal.commands.SnapCommand; @@ -82,6 +85,7 @@ public class SiriusContainerEditPolicy extends ContainerEditPolicy { */ @Override protected Command getArrangeCommand(ArrangeRequest request) { + Command commandToReturn = null; if (GMFRuntimeCompatibility.hasGMFPluginReleaseBetween1_2_0_And_1_3_3()) { if (RequestConstants.REQ_ARRANGE_DEFERRED.equals(request.getType())) { String layoutType = request.getLayoutType(); @@ -168,10 +172,20 @@ public class SiriusContainerEditPolicy extends ContainerEditPolicy { ctc.add(new CommandProxy(getSnapCommand(request))); } } - return new ICommandProxy(ctc); + commandToReturn = new ICommandProxy(ctc); } else { - return super.getArrangeCommand(request); + commandToReturn = super.getArrangeCommand(request); } + + // We add a Command to center edges that need to be at the end of the + // layout. + EditPart host = getHost(); + if (host instanceof GraphicalEditPart) { + CenterEdgeLayoutCommand centerEdgeLayoutCommand = new CenterEdgeLayoutCommand((GraphicalEditPart) host); + commandToReturn = commandToReturn.chain(new ICommandProxy(centerEdgeLayoutCommand)); + } + + return commandToReturn; } /** diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/commands/CenterEdgeLayoutCommand.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/commands/CenterEdgeLayoutCommand.java new file mode 100644 index 0000000000..0412175d7d --- /dev/null +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/commands/CenterEdgeLayoutCommand.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * Copyright (c) 2014 THALES GLOBAL SERVICES. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Obeo - initial API and implementation + *******************************************************************************/ + +package org.eclipse.sirius.diagram.ui.internal.edit.commands; + +import java.util.HashSet; +import java.util.Set; + +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.gmf.runtime.common.core.command.CommandResult; +import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil; +import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart; +import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand; +import org.eclipse.gmf.runtime.notation.Diagram; +import org.eclipse.gmf.runtime.notation.Edge; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.sirius.diagram.ui.internal.operation.CenterEdgeEndModelChangeOperation; + +/** + * After an automatic layout, the edge centering could be broken. This command + * executes {@link CenterEdgeEndModelChangeOperation} on each edges potentially + * impacted by the given containerEditPart layout. + * + * @author Florian Barbin + * + */ +public class CenterEdgeLayoutCommand extends AbstractTransactionalCommand { + + private GraphicalEditPart editPart; + + /** + * Constructor. + * + * @param graphicalEditPart + * the graphical edit part layouted. + */ + public CenterEdgeLayoutCommand(GraphicalEditPart graphicalEditPart) { + super(graphicalEditPart.getEditingDomain(), "", null); + editPart = graphicalEditPart; + } + + @Override + protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { + Object model = editPart.getModel(); + if (model instanceof View) { + View view = (View) model; + Set<Edge> edges = new HashSet<Edge>(); + + // if the entire diagram is layouted. + if (view instanceof Diagram) { + edges.addAll(((Diagram) view).getEdges()); + } + // we select only related edges otherwise. + else { + ViewUtil.getAllRelatedEdgesForView(view, edges); + } + for (Edge edge : edges) { + CenterEdgeEndModelChangeOperation centerEdgeEndModelChangeOperation = new CenterEdgeEndModelChangeOperation(edge, false); + centerEdgeEndModelChangeOperation.execute(); + } + } + return CommandResult.newOKCommandResult(); + } + + @Override + public void dispose() { + editPart = null; + super.dispose(); + } + +} |
