Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraradermache2013-04-02 14:40:33 +0000
committeraradermache2013-04-02 14:40:33 +0000
commit04bcc891505d54b20a669bc671ad838a364c2b66 (patch)
treea0e7c5303dac50562b70e22d70907b1e28994c5d /plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd
parent09755bc6e0a90f0726f9f057bf113c3825c7b143 (diff)
downloadorg.eclipse.papyrus-04bcc891505d54b20a669bc671ad838a364c2b66.tar.gz
org.eclipse.papyrus-04bcc891505d54b20a669bc671ad838a364c2b66.tar.xz
org.eclipse.papyrus-04bcc891505d54b20a669bc671ad838a364c2b66.zip
402717: [Composite structure diagram] Dragging a classifier always creates property + 404617: NPE when trying to drag elements into invisble structure compartment
Diffstat (limited to 'plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd')
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/META-INF/MANIFEST.MF3
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/plugin.xml4
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/classifier/ClassifierAsClassifierToStructureCompartmentDropStrategy.java110
3 files changed, 115 insertions, 2 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/META-INF/MANIFEST.MF b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/META-INF/MANIFEST.MF
index 48d13ba84d4..e291f816c99 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/META-INF/MANIFEST.MF
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/META-INF/MANIFEST.MF
@@ -10,7 +10,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.papyrus.uml.tools;bundle-version="0.10.0",
org.eclipse.papyrus.uml.diagram.clazz;bundle-version="0.10.0",
org.eclipse.emf.facet.infra.browser.uicore;bundle-version="0.2.0",
- org.eclipse.papyrus.infra.services.labelprovider;bundle-version="0.10.0"
+ org.eclipse.papyrus.infra.services.labelprovider;bundle-version="0.10.0",
+ org.eclipse.papyrus.uml.diagram.composite;bundle-version="0.10.0"
Export-Package: org.eclipse.papyrus.uml.diagram.dnd,
org.eclipse.papyrus.uml.diagram.dnd.strategy.instancespecification,
org.eclipse.papyrus.uml.diagram.dnd.strategy.instancespecification.command,
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/plugin.xml b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/plugin.xml
index 5a4d85c55c2..a74f5c993ec 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/plugin.xml
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/plugin.xml
@@ -6,6 +6,8 @@
<strategy
strategy="org.eclipse.papyrus.uml.diagram.dnd.strategy.instancespecification.ClassifierToSlotsDropStrategy">
</strategy>
+ <strategy
+ strategy="org.eclipse.papyrus.uml.diagram.dnd.strategy.classifier.ClassifierAsClassifierToStructureCompartmentDropStrategy">
+ </strategy>
</extension>
-
</plugin>
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/classifier/ClassifierAsClassifierToStructureCompartmentDropStrategy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/classifier/ClassifierAsClassifierToStructureCompartmentDropStrategy.java
new file mode 100644
index 00000000000..52945db675a
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/classifier/ClassifierAsClassifierToStructureCompartmentDropStrategy.java
@@ -0,0 +1,110 @@
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.dnd.strategy.classifier;
+
+import java.util.Map;
+
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.emf.ecore.EObject;
+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.commands.CompoundCommand;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.requests.DropObjectsRequest;
+import org.eclipse.papyrus.infra.gmfdiag.dnd.strategy.TransactionalDropStrategy;
+import org.eclipse.papyrus.uml.diagram.composite.custom.helper.TypeHelper;
+import org.eclipse.papyrus.uml.diagram.dnd.Activator;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.uml2.uml.StructuredClassifier;
+import org.eclipse.uml2.uml.Type;
+
+/**
+ * A strategy to drop a classifier into the structure compartment (composite structure diagram). There are two options to do this.
+ * (1) Drop the classifier itself. It is more likely that the user wants to do this, if the classifier is also a behavior.
+ * (2) Create an property typed with the classifier.
+ *
+ * @author Ansgar Radermacher
+ *
+ */
+public class ClassifierAsClassifierToStructureCompartmentDropStrategy extends TransactionalDropStrategy {
+
+ public String getLabel() {
+ return "Classifier into structure compartment"; //$NON-NLS-1$
+ }
+
+ public String getID() {
+ return Activator.PLUGIN_ID + ".ClassifierToStructureCompDrop"; //$NON-NLS-1$
+ }
+
+ public String getDescription() {
+ return "Drops a classifier into the structure compartment of a class."; //$NON-NLS-1$
+ }
+
+ public Image getImage() {
+ return null;
+ }
+
+ public int getPriority() {
+ return 0;
+ }
+
+ public void setOptions(Map<String, Object> options) {
+ //Nothing
+ }
+
+ @Override
+ public Command doGetCommand(Request request, EditPart targetEditPart) {
+
+ if(!(request instanceof DropObjectsRequest)) {
+ return null;
+ }
+ DropObjectsRequest dropRequest = (DropObjectsRequest)request;
+ EObject targetSemanticElement = getTargetSemanticElement(targetEditPart);
+
+ if((targetSemanticElement instanceof StructuredClassifier) &&
+ (dropRequest.getLocation() != null) &&
+ (targetEditPart instanceof GraphicalEditPart)) {
+ GraphicalEditPart gtEditPart = (GraphicalEditPart)targetEditPart;
+
+ TypeHelper helper = new TypeHelper((TransactionalEditingDomain)getEditingDomain(targetEditPart));
+
+ Point location = dropRequest.getLocation().getCopy();
+ gtEditPart.getContentPane().translateToRelative(location);
+ gtEditPart.getContentPane().translateFromParent(location);
+ location.translate(gtEditPart.getContentPane().getClientArea().getLocation().getNegated());
+
+ CompoundCommand cc = new CompoundCommand();
+
+ for(EObject dropElement : getSourceEObjects(request)) {
+ if(dropElement instanceof Type) {
+ Type type = (Type) dropElement;
+ // check whether element is a nested classifier of the targetSemanticElement
+ if (type.allNamespaces().contains(targetSemanticElement)) {
+ cc.add(helper.dropTypeOnClassifier(gtEditPart, (Type)dropElement, location));
+ }
+ }
+ }
+ return cc.canExecute() ? cc : null;
+ }
+ return null;
+ }
+
+ public String getCategoryID() {
+ return "org.eclipse.papyrus.dnd.ClassifierToStructureCompDrop"; //$NON-NLS-1$
+ }
+
+ public String getCategoryLabel() {
+ return "Drop a classifier into the structure compartment of a class"; //$NON-NLS-1$
+ }
+}

Back to the top