Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaxime Porhel2015-03-27 13:48:01 +0000
committerMaxime Porhel2015-03-31 15:06:18 +0000
commit4cc9ad385412215a239f0709b815bd9ecc3e181e (patch)
tree8f835106d8301e0fc47c2937a6d2174092cc2558
parent2fad4c24ec101d2547fd1880c672d51c0dcffdbb (diff)
downloadorg.eclipse.sirius-4cc9ad385412215a239f0709b815bd9ecc3e181e.tar.gz
org.eclipse.sirius-4cc9ad385412215a239f0709b815bd9ecc3e181e.tar.xz
org.eclipse.sirius-4cc9ad385412215a239f0709b815bd9ecc3e181e.zip
[463299] Extract ComparisonHelper from DNodeListElement & Regions sorts
Bug: 463299 Change-Id: Id703288ea217cd7f71c04d09efd2427ca0bdc44a Signed-off-by: Maxime Porhel <maxime.porhel@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/parts/AbstractDNodeListCompartmentEditPart.java83
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/operation/ComparisonHelper.java98
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/operation/RegionContainerUpdateLayoutOperation.java76
3 files changed, 121 insertions, 136 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/parts/AbstractDNodeListCompartmentEditPart.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/parts/AbstractDNodeListCompartmentEditPart.java
index eaf8c878dd..49115c30f9 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/parts/AbstractDNodeListCompartmentEditPart.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/edit/parts/AbstractDNodeListCompartmentEditPart.java
@@ -15,15 +15,12 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
-import java.util.Map;
import java.util.Set;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.MarginBorder;
import org.eclipse.draw2d.geometry.Insets;
import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.ecore.EObject;
import org.eclipse.gef.ConnectionEditPart;
import org.eclipse.gef.DragTracker;
import org.eclipse.gef.EditPart;
@@ -31,7 +28,6 @@ import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.UnexecutableCommand;
-import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IBorderItemEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.INotableEditPart;
@@ -43,8 +39,6 @@ import org.eclipse.gmf.runtime.diagram.ui.internal.editparts.ISurfaceEditPart;
import org.eclipse.gmf.runtime.draw2d.ui.figures.ConstrainedToolbarLayout;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.sirius.diagram.DNodeList;
-import org.eclipse.sirius.diagram.DNodeListElement;
-import org.eclipse.sirius.diagram.description.NodeMapping;
import org.eclipse.sirius.diagram.ui.business.internal.query.RequestQuery;
import org.eclipse.sirius.diagram.ui.edit.api.part.ISiriusEditPart;
import org.eclipse.sirius.diagram.ui.edit.internal.part.DiagramElementEditPartOperation;
@@ -53,15 +47,13 @@ import org.eclipse.sirius.diagram.ui.graphical.edit.policies.NodeCreationEditPol
import org.eclipse.sirius.diagram.ui.graphical.edit.policies.SiriusContainerDropPolicy;
import org.eclipse.sirius.diagram.ui.internal.edit.policies.DNodeListViewNodeListCompartmentItemSemanticEditPolicy;
import org.eclipse.sirius.diagram.ui.internal.edit.policies.canonicals.DumnySiriusCanonicalEditPolicy;
+import org.eclipse.sirius.diagram.ui.internal.operation.ComparisonHelper;
import org.eclipse.sirius.diagram.ui.tools.api.requests.RequestConstants;
-import org.eclipse.sirius.viewpoint.DMappingBased;
+import org.eclipse.sirius.viewpoint.DRepresentationElement;
import org.eclipse.sirius.viewpoint.description.RepresentationElementMapping;
-import com.google.common.base.Function;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Ordering;
/**
* <p>
@@ -78,70 +70,21 @@ public abstract class AbstractDNodeListCompartmentEditPart extends ListCompartme
*/
private boolean isSupportingViewActions = false;
- private static class ComparisonHelper {
+ private static class DNodeListElementComparisonHelper extends ComparisonHelper {
private DNodeList self;
- public ComparisonHelper(DNodeList self) {
+ public DNodeListElementComparisonHelper(DNodeList self) {
this.self = self;
}
- public void sort(List<View> views) {
- /*
- * The main sort criterion is based on the elements' mapping's
- * position in the VSM, so that all instances of the same mapping
- * are grouped together, and if a mapping M1 appears before another
- * M2 in the specification, all instances of M1 appear before those
- * of M2.
- */
- final EList<NodeMapping> allMappings = self.getActualMapping().getAllNodeMappings();
- Function<View, Integer> mappingIndex = new Function<View, Integer>() {
- @Override
- public Integer apply(View view) {
- if (view != null) {
- EObject element = view.getElement();
- if (element instanceof DMappingBased) {
- RepresentationElementMapping mapping = ((DMappingBased) element).getMapping();
- /*
- * Use a plain indexOf search here, assuming that in
- * practice there are never more than a handful of
- * mappings inside a list container.
- */
- return allMappings.indexOf(mapping);
- }
- }
- return Integer.MAX_VALUE;
- }
- };
- /*
- * Inside a group of elements from the same mapping, use the
- * DNodeListItem order. As opposed to the mappings, the number of
- * actual items can grow very large, so we pre-compute the elements'
- * indices with a linear scan to avoid repeated calls to indexOf for
- * each comparison.
- */
- final Map<DNodeListElement, Integer> indices = Maps.newHashMap();
- EList<DNodeListElement> listElements = self.getOwnedElements();
- int i = 0;
- for (DNodeListElement current : listElements) {
- indices.put(current, i);
- i++;
- }
- Function<View, Integer> nodeIndex = new Function<View, Integer>() {
- @Override
- public Integer apply(View view) {
- if (view != null) {
- EObject sem = ViewUtil.resolveSemanticElement(view);
- if (sem != null && indices.containsKey(sem)) {
- return indices.get(sem);
- }
- }
- return Integer.MAX_VALUE;
- }
- };
- /*
- * Perform the actual sort, combining the two criteria above.
- */
- Collections.sort(views, Ordering.natural().onResultOf(mappingIndex).compound(Ordering.natural().onResultOf(nodeIndex)));
+ @Override
+ protected List<? extends DRepresentationElement> getDElementsToSort() {
+ return self.getOwnedElements();
+ }
+
+ @Override
+ protected List<? extends RepresentationElementMapping> getMappingsToSort() {
+ return self.getActualMapping().getAllNodeMappings();
}
}
@@ -228,7 +171,7 @@ public abstract class AbstractDNodeListCompartmentEditPart extends ListCompartme
@SuppressWarnings("unchecked")
List<View> modelChildren = Lists.newArrayList(super.getModelChildren());
DiagramElementEditPartOperation.removeInvisibleElements(modelChildren);
- new ComparisonHelper((DNodeList) resolveSemanticElement()).sort(modelChildren);
+ new DNodeListElementComparisonHelper((DNodeList) resolveSemanticElement()).sort(modelChildren);
return modelChildren;
}
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/operation/ComparisonHelper.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/operation/ComparisonHelper.java
new file mode 100644
index 0000000000..497bb5092d
--- /dev/null
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/operation/ComparisonHelper.java
@@ -0,0 +1,98 @@
+/*******************************************************************************
+ * Copyright (c) 2011, 2015 THALES GLOBAL SERVICES and others.
+ * 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.operation;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.sirius.viewpoint.DMappingBased;
+import org.eclipse.sirius.viewpoint.DRepresentationElement;
+import org.eclipse.sirius.viewpoint.description.RepresentationElementMapping;
+
+import com.google.common.base.Function;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Ordering;
+
+/**
+ *
+ * @author pcdavid
+ *
+ */
+public abstract class ComparisonHelper {
+
+ public final void sort(List<? extends View> views) {
+ /*
+ * The main sort criterion is based on the elements' mapping's position
+ * in the VSM, so that all instances of the same mapping are grouped
+ * together, and if a mapping M1 appears before another M2 in the
+ * specification, all instances of M1 appear before those of M2.
+ */
+ final List<? extends RepresentationElementMapping> allMappings = getMappingsToSort();
+ Function<View, Integer> mappingIndex = new Function<View, Integer>() {
+ @Override
+ public Integer apply(View view) {
+ if (view != null) {
+ EObject element = view.getElement();
+ if (element instanceof DMappingBased) {
+ RepresentationElementMapping mapping = ((DMappingBased) element).getMapping();
+ /*
+ * Use a plain indexOf search here, assuming that in
+ * practice there are never more than a handful of
+ * mappings inside a list container.
+ */
+ return allMappings.indexOf(mapping);
+ }
+ }
+ return Integer.MAX_VALUE;
+ }
+ };
+ /*
+ * Inside a group of elements from the same mapping, use the
+ * DRepresentationElement order. As opposed to the mappings, the number
+ * of actual items can grow very large, so we pre-compute the elements'
+ * indices with a linear scan to avoid repeated calls to indexOf for
+ * each comparison.
+ */
+ final Map<DRepresentationElement, Integer> indices = Maps.newHashMap();
+ Collection<? extends DRepresentationElement> elements = getDElementsToSort();
+
+ int i = 0;
+ for (DRepresentationElement current : elements) {
+ indices.put(current, i);
+ i++;
+ }
+ Function<View, Integer> nodeIndex = new Function<View, Integer>() {
+ @Override
+ public Integer apply(View view) {
+ if (view != null) {
+ EObject sem = ViewUtil.resolveSemanticElement(view);
+ if (sem != null && indices.containsKey(sem)) {
+ return indices.get(sem);
+ }
+ }
+ return Integer.MAX_VALUE;
+ }
+ };
+ /*
+ * Perform the actual sort, combining the two criteria above.
+ */
+ Collections.sort(views, Ordering.natural().onResultOf(mappingIndex).compound(Ordering.natural().onResultOf(nodeIndex)));
+ }
+
+ protected abstract List<? extends DRepresentationElement> getDElementsToSort();
+
+ protected abstract List<? extends RepresentationElementMapping> getMappingsToSort();
+}
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/operation/RegionContainerUpdateLayoutOperation.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/operation/RegionContainerUpdateLayoutOperation.java
index 59cb045557..7fe6230e2c 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/operation/RegionContainerUpdateLayoutOperation.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/internal/operation/RegionContainerUpdateLayoutOperation.java
@@ -10,37 +10,30 @@
*******************************************************************************/
package org.eclipse.sirius.diagram.ui.internal.operation;
-import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
import org.eclipse.gmf.runtime.notation.LayoutConstraint;
import org.eclipse.gmf.runtime.notation.Location;
import org.eclipse.gmf.runtime.notation.Node;
import org.eclipse.gmf.runtime.notation.Size;
import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.sirius.diagram.DDiagramElement;
import org.eclipse.sirius.diagram.DNodeContainer;
import org.eclipse.sirius.diagram.business.internal.query.DNodeContainerExperimentalQuery;
-import org.eclipse.sirius.diagram.description.ContainerMapping;
import org.eclipse.sirius.diagram.ui.business.api.view.SiriusGMFHelper;
import org.eclipse.sirius.diagram.ui.business.internal.operation.AbstractModelChangeOperation;
import org.eclipse.sirius.diagram.ui.internal.edit.parts.DNodeContainerViewNodeContainerCompartment2EditPart;
import org.eclipse.sirius.diagram.ui.internal.edit.parts.DNodeContainerViewNodeContainerCompartmentEditPart;
import org.eclipse.sirius.diagram.ui.internal.refresh.GMFHelper;
import org.eclipse.sirius.diagram.ui.part.SiriusVisualIDRegistry;
-import org.eclipse.sirius.viewpoint.DMappingBased;
+import org.eclipse.sirius.viewpoint.DRepresentationElement;
import org.eclipse.sirius.viewpoint.description.RepresentationElementMapping;
-import com.google.common.base.Function;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
-import com.google.common.collect.Ordering;
/**
* Update and keep consistent the GMF Bounds of a Region Container and its
@@ -179,70 +172,21 @@ public class RegionContainerUpdateLayoutOperation extends AbstractModelChangeOpe
new RegionComparisonHelper(dNodeContainer).sort(modelChildren);
}
- private static class RegionComparisonHelper {
+ private static class RegionComparisonHelper extends ComparisonHelper {
private DNodeContainer self;
public RegionComparisonHelper(DNodeContainer self) {
this.self = self;
}
- public void sort(List<? extends View> views) {
- /*
- * The main sort criterion is based on the elements' mapping's
- * position in the VSM, so that all instances of the same mapping
- * are grouped together, and if a mapping M1 appears before another
- * M2 in the specification, all instances of M1 appear before those
- * of M2.
- */
- final EList<ContainerMapping> allMappings = self.getActualMapping().getAllContainerMappings();
- Function<View, Integer> mappingIndex = new Function<View, Integer>() {
- @Override
- public Integer apply(View view) {
- if (view != null) {
- EObject element = view.getElement();
- if (element instanceof DMappingBased) {
- RepresentationElementMapping mapping = ((DMappingBased) element).getMapping();
- /*
- * Use a plain indexOf search here, assuming that in
- * practice there are never more than a handful of
- * mappings inside a list container.
- */
- return allMappings.indexOf(mapping);
- }
- }
- return Integer.MAX_VALUE;
- }
- };
- /*
- * Inside a group of elements from the same mapping, use the
- * DNodeListItem order. As opposed to the mappings, the number of
- * actual items can grow very large, so we pre-compute the elements'
- * indices with a linear scan to avoid repeated calls to indexOf for
- * each comparison.
- */
- final Map<DDiagramElement, Integer> indices = Maps.newHashMap();
- EList<DDiagramElement> containers = self.getOwnedDiagramElements();
- int i = 0;
- for (DDiagramElement current : containers) {
- indices.put(current, i);
- i++;
- }
- Function<View, Integer> nodeIndex = new Function<View, Integer>() {
- @Override
- public Integer apply(View view) {
- if (view != null) {
- EObject sem = ViewUtil.resolveSemanticElement(view);
- if (sem != null && indices.containsKey(sem)) {
- return indices.get(sem);
- }
- }
- return Integer.MAX_VALUE;
- }
- };
- /*
- * Perform the actual sort, combining the two criteria above.
- */
- Collections.sort(views, Ordering.natural().onResultOf(mappingIndex).compound(Ordering.natural().onResultOf(nodeIndex)));
+ @Override
+ protected List<? extends DRepresentationElement> getDElementsToSort() {
+ return self.getOwnedDiagramElements();
+ }
+
+ @Override
+ protected List<? extends RepresentationElementMapping> getMappingsToSort() {
+ return self.getActualMapping().getAllContainerMappings();
}
}
}

Back to the top