diff options
| author | Laurent Redor | 2014-09-10 13:29:50 +0000 |
|---|---|---|
| committer | Laurent Redor | 2014-09-10 15:43:41 +0000 |
| commit | 966e92806299bab8ce65cfbe0b5b83cbd40884cc (patch) | |
| tree | 0d2b2b7a5fc75c03299e89b3c7f94823911267b7 | |
| parent | 8fe16522a864c6f222e771bd11c6f01a93dea404 (diff) | |
| download | org.eclipse.sirius-966e92806299bab8ce65cfbe0b5b83cbd40884cc.tar.gz org.eclipse.sirius-966e92806299bab8ce65cfbe0b5b83cbd40884cc.tar.xz org.eclipse.sirius-966e92806299bab8ce65cfbe0b5b83cbd40884cc.zip | |
[438649] Avoid to copy layout of label and of its parent
Before copying layout, the label is removed from the selection if its
parent's node is also selected.
This is not problematic in default implementation of Sirius PasteLayout
action but can be problematic with specific implementation of
SiriusLayoutDataManager.
Bug: 438649
Change-Id: Iccbeecc1201a0e9c38ed29c5bc3ca2e94d98b000
Signed-off-by: Laurent Redor <laurent.redor@obeo.fr>
| -rw-r--r-- | plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/actions/layout/CopyLayoutAction.java | 40 |
1 files changed, 33 insertions, 7 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/actions/layout/CopyLayoutAction.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/actions/layout/CopyLayoutAction.java index d421ef1c30..2746e5bca0 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/actions/layout/CopyLayoutAction.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/actions/layout/CopyLayoutAction.java @@ -11,7 +11,9 @@ package org.eclipse.sirius.diagram.ui.tools.internal.actions.layout; -import java.util.Iterator; +import java.util.HashSet; +import java.util.List; +import java.util.Set; import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.runtime.IAdaptable; @@ -26,6 +28,7 @@ import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand; import org.eclipse.sirius.diagram.DDiagram; import org.eclipse.sirius.diagram.ui.edit.api.part.IDDiagramEditPart; +import org.eclipse.sirius.diagram.ui.edit.api.part.IDiagramNameEditPart; import org.eclipse.sirius.diagram.ui.provider.DiagramUIPlugin; import org.eclipse.sirius.diagram.ui.tools.api.image.DiagramImagesPath; import org.eclipse.sirius.diagram.ui.tools.api.layout.SiriusLayoutDataManager; @@ -36,6 +39,8 @@ import org.eclipse.swt.SWT; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchPart; +import com.google.common.collect.Lists; + /** * Copy the layout of the selected diagram or of the selected diagram elements. * @@ -128,15 +133,15 @@ public class CopyLayoutAction extends AbstractCopyPasteLayoutAction { } } }); - // Create an iterator for the selection - final Iterator<?> iter = getSelectedObjects().iterator(); DiagramEditPart diagramEditPart = getDiagramEditPart(); if (diagramEditPart instanceof IDDiagramEditPart) { final Option<DDiagram> diagram = ((IDDiagramEditPart) diagramEditPart).resolveDDiagram(); - while (iter.hasNext() && diagram.some()) { - final Object next = iter.next(); - if (next instanceof IGraphicalEditPart) { - final IGraphicalEditPart toStore = (IGraphicalEditPart) next; + if (diagram.some()) { + // Clean the selection to keep only one data if both node and + // its label are selected. + List<IGraphicalEditPart> selectedEditParts = cleanSelectedObjects(getSelectedObjects()); + // For each selected edit part, store its layout. + for (final IGraphicalEditPart toStore : selectedEditParts) { doStoreLayoutsCmd.add(new ICommandProxy(new AbstractTransactionalCommand(toStore.getEditingDomain(), "Copy layout data", null) { @@ -168,4 +173,25 @@ public class CopyLayoutAction extends AbstractCopyPasteLayoutAction { return doStoreLayoutsCmd.unwrap(); } + + /** + * Remove label from selection if its parent's node is also selected. + * + * @param selectedObjects + * The current selected objects. + * @return The current selected {@link IGraphicalEditPart} + */ + private List<IGraphicalEditPart> cleanSelectedObjects(List<?> selectedObjects) { + List<IGraphicalEditPart> result = Lists.newArrayList(); + // Transform List to Set to optimize the contains() called in the below + // loop + final Set<Object> selection = new HashSet<Object>(selectedObjects); + for (Object selectedObject : selection) { + boolean isLabelOfSelectedParent = (selectedObject instanceof IDiagramNameEditPart) && selection.contains(((IDiagramNameEditPart) selectedObject).getParent()); + if (!isLabelOfSelectedParent) { + result.add((IGraphicalEditPart) selectedObject); + } + } + return result; + } } |
