Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemi Schnekenburger2016-05-17 12:52:46 +0000
committerRemi Schnekenburger2016-05-17 12:52:46 +0000
commitafa5c9951797bb664c5e35da9a0c38dd4a02851e (patch)
treef9e6db80af22b73fa0a4418fd4e15f3df10951bb
parent9c823e68677588fa4caa2bf58654d0db605ac402 (diff)
downloadorg.eclipse.papyrus-rt-afa5c9951797bb664c5e35da9a0c38dd4a02851e.tar.gz
org.eclipse.papyrus-rt-afa5c9951797bb664c5e35da9a0c38dd4a02851e.tar.xz
org.eclipse.papyrus-rt-afa5c9951797bb664c5e35da9a0c38dd4a02851e.zip
Bug 472885: [tooling] Papyrus-RT shall support CapsulePart creation
using drag n drop from model explorer https://bugs.eclipse.org/bugs/show_bug.cgi?id=472885 - Fixing some missed class in previous merge and tests Change-Id: I92603e06f1c2c5d984f616164909676b9d1abc9f Signed-off-by: Remi Schnekenburger <remi.schnekenburger@cea.fr>
-rw-r--r--plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.diagram.common/src/org/eclipse/papyrusrt/umlrt/tooling/diagram/common/internal/drop/RTCapsuleStructureDiagramDragDropEditPolicy.java49
-rw-r--r--tests/junit/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.diagram.common.tests/src/org/eclipse/papyrusrt/umlrt/tooling/diagram/common/drop/tests/CapsuleToCapsulePartOnCapsuleDropStrategyTest.java9
2 files changed, 43 insertions, 15 deletions
diff --git a/plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.diagram.common/src/org/eclipse/papyrusrt/umlrt/tooling/diagram/common/internal/drop/RTCapsuleStructureDiagramDragDropEditPolicy.java b/plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.diagram.common/src/org/eclipse/papyrusrt/umlrt/tooling/diagram/common/internal/drop/RTCapsuleStructureDiagramDragDropEditPolicy.java
index 49453b8f6..142f99f45 100644
--- a/plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.diagram.common/src/org/eclipse/papyrusrt/umlrt/tooling/diagram/common/internal/drop/RTCapsuleStructureDiagramDragDropEditPolicy.java
+++ b/plugins/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.diagram.common/src/org/eclipse/papyrusrt/umlrt/tooling/diagram/common/internal/drop/RTCapsuleStructureDiagramDragDropEditPolicy.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2016 CEA LIST and others.
+ * Copyright (c) 2016 CEA LIST, Christian W. Damus, and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -8,10 +8,12 @@
*
* Contributors:
* CEA LIST - Initial API and implementation
+ * Christian W. Damus - bug 472885
*****************************************************************************/
package org.eclipse.papyrusrt.umlrt.tooling.diagram.common.internal.drop;
+import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -32,13 +34,14 @@ public class RTCapsuleStructureDiagramDragDropEditPolicy extends CustomizableDro
/** key for the specific edit policy that creates a property while dragging a classifier onto the structure compartment of a classifier. */
private static final String ORG_ECLIPSE_PAPYRUS_UML_DIAGRAM_DND_CLASSIFIER_TO_STRUCTURE_COMP_AS_PROPERTY_DROP = "org.eclipse.papyrus.uml.diagram.dnd.ClassifierToStructureCompAsPropertyDrop";
+ /** Prefix matching strategy IDs that we prefer over other contributions. */
+ private static final String PREFERRED_STRATEGY_PREFIX = "org.eclipse.papyrusrt."; //$NON-NLS-1$
+
/**
* Constructor.
*
* @param defaultDropEditPolicy
- * The default editPolicy, to be called when no custom Drop strategy is available.
* @param defaultCreationEditPolicy
- * The default creation edit policy replaced by this {@link CustomizableDropEditPolicy}
*/
public RTCapsuleStructureDiagramDragDropEditPolicy(EditPolicy defaultDropEditPolicy, EditPolicy defaultCreationEditPolicy) {
super(defaultDropEditPolicy, defaultCreationEditPolicy);
@@ -49,18 +52,40 @@ public class RTCapsuleStructureDiagramDragDropEditPolicy extends CustomizableDro
*/
@Override
protected Map<DropStrategy, List<Command>> findExtendedStrategies(Request request) {
- Map<DropStrategy, List<Command>> unfilteredMap = super.findExtendedStrategies(request);
- Map<DropStrategy, List<Command>> filteredMap = new HashMap<>(unfilteredMap);
+ Map<DropStrategy, List<Command>> result = super.findExtendedStrategies(request);
- // remove the unwanted strategy, leaving all other accessible
- for (DropStrategy strategy : unfilteredMap.keySet()) {
- if (ORG_ECLIPSE_PAPYRUS_UML_DIAGRAM_DND_CLASSIFIER_TO_STRUCTURE_COMP_AS_PROPERTY_DROP.equals(strategy.getID())) {
- filteredMap.remove(strategy);
- } else if ("default".equals(strategy.getID())) {
- filteredMap.remove(strategy);
+ // Only filter out the strategies that we don't want if there are strategies
+ // in play that we prefer. This ensures that we don't prevent the correct
+ // drop behaviour in a delegation scenario, such as when a protocol-as-port
+ // drop converts the protocol drop into the dropping of a port, for which we
+ // don't have a preferred strategy
+ if (hasPreferredDropStrategies(result.keySet())) {
+ Map<DropStrategy, List<Command>> filteredMap = new HashMap<>(result);
+ for (DropStrategy strategy : result.keySet()) {
+ if (ORG_ECLIPSE_PAPYRUS_UML_DIAGRAM_DND_CLASSIFIER_TO_STRUCTURE_COMP_AS_PROPERTY_DROP.equals(strategy.getID())) {
+ filteredMap.remove(strategy);
+ } else if ("default".equals(strategy.getID())) {
+ filteredMap.remove(strategy);
+ }
}
+ result = filteredMap;
}
- return filteredMap;
+
+ return result;
}
+ /**
+ * Determines whether a group of drop strategies includes any that are preferred
+ * over others. These are typically those that are contributed by the UML-RT
+ * bundles.
+ *
+ * @param strategies
+ * a group of contributed drop strategies
+ * @return whether any of them are preferred over others
+ */
+ protected boolean hasPreferredDropStrategies(Collection<? extends DropStrategy> strategies) {
+ return strategies.stream()
+ .map(DropStrategy::getID)
+ .anyMatch(id -> id.startsWith(PREFERRED_STRATEGY_PREFIX));
+ }
}
diff --git a/tests/junit/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.diagram.common.tests/src/org/eclipse/papyrusrt/umlrt/tooling/diagram/common/drop/tests/CapsuleToCapsulePartOnCapsuleDropStrategyTest.java b/tests/junit/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.diagram.common.tests/src/org/eclipse/papyrusrt/umlrt/tooling/diagram/common/drop/tests/CapsuleToCapsulePartOnCapsuleDropStrategyTest.java
index 05002083b..484909440 100644
--- a/tests/junit/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.diagram.common.tests/src/org/eclipse/papyrusrt/umlrt/tooling/diagram/common/drop/tests/CapsuleToCapsulePartOnCapsuleDropStrategyTest.java
+++ b/tests/junit/umlrt/tooling/org.eclipse.papyrusrt.umlrt.tooling.diagram.common.tests/src/org/eclipse/papyrusrt/umlrt/tooling/diagram/common/drop/tests/CapsuleToCapsulePartOnCapsuleDropStrategyTest.java
@@ -62,8 +62,11 @@ public class CapsuleToCapsulePartOnCapsuleDropStrategyTest {
private Point capsuleCompartmentLocation = new Point(41, 70);
+ private Point dropLocation = new Point(46, 37);
// In the coordinate space of the capsule compartment
- private Point pointOnCompartmentLocation = new Point(46, 37).getTranslated(capsuleCompartmentLocation);
+ private Point pointOnCompartmentLocation = dropLocation.getTranslated(capsuleCompartmentLocation);
+
+
/**
* Initializes me.
@@ -88,8 +91,8 @@ public class CapsuleToCapsulePartOnCapsuleDropStrategyTest {
EditPart editPart = editor.requireEditPart(editor.getActiveDiagram(), property);
Location location = capsuleParts.requireLocation(editPart);
- assertThat(location.getX(), near(245, 5)); // 245 != pointOnCompartmentLocation.x()
- assertThat(location.getY(), near(109, 5)); // 109 != pointOnCompartmentLocation.y()
+ assertThat(location.getX(), near(dropLocation.x(), 5));
+ assertThat(location.getY(), near(dropLocation.y(), 5));
// Undo the edit
editor.activateDiagram(theDiagram);

Back to the top