summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenoit Maggi2014-01-20 11:01:06 (EST)
committervlorenzo2014-01-30 10:13:04 (EST)
commitb23aaf84507b554e9962d21490c6b0a87aa167e3 (patch)
treec1c9879d6e5a11f4f3ffd34648d56ab3cd5ffe5d
parentdb55cf8552d4a50ffb4bce62f5893a9d34badf80 (diff)
downloadorg.eclipse.papyrus-b23aaf84507b554e9962d21490c6b0a87aa167e3.zip
org.eclipse.papyrus-b23aaf84507b554e9962d21490c6b0a87aa167e3.tar.gz
org.eclipse.papyrus-b23aaf84507b554e9962d21490c6b0a87aa167e3.tar.bz2
Bug 422835 - Problems with ports in internal block diagram when block is
specialized https://bugs.eclipse.org/bugs/show_bug.cgi?id=422835 Drag and drop on block is now allowed in IBD and BDD for all inherited elements. The test is done with this code : ((Classifier) dropTargetElement).getAllAttributes().contains(droppedObject), and not conformTo to avoid private attributes. Change-Id: Ifa966e491aa1142e34b5a39fa107f82e48153fc7 Signed-off-by: Benoit Maggi <benoit.maggi@cea.fr>
-rw-r--r--plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-gmf/org/eclipse/papyrus/gmf/diagram/common/edit/policy/CommonDiagramDragDropEditPolicy.java13
-rw-r--r--plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/utils/PortDropHelper.java200
2 files changed, 111 insertions, 102 deletions
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-gmf/org/eclipse/papyrus/gmf/diagram/common/edit/policy/CommonDiagramDragDropEditPolicy.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-gmf/org/eclipse/papyrus/gmf/diagram/common/edit/policy/CommonDiagramDragDropEditPolicy.java
index de2ba11..2b0ddf9 100644
--- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-gmf/org/eclipse/papyrus/gmf/diagram/common/edit/policy/CommonDiagramDragDropEditPolicy.java
+++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-gmf/org/eclipse/papyrus/gmf/diagram/common/edit/policy/CommonDiagramDragDropEditPolicy.java
@@ -62,6 +62,7 @@ import org.eclipse.papyrus.uml.diagram.common.commands.SemanticAdapter;
import org.eclipse.papyrus.uml.diagram.common.edit.part.AbstractElementBorderEditPart;
import org.eclipse.papyrus.uml.diagram.common.edit.part.AbstractElementLabelEditPart;
import org.eclipse.papyrus.uml.diagram.common.util.CrossReferencerUtil;
+import org.eclipse.uml2.uml.Classifier;
import org.eclipse.uml2.uml.Element;
/**
@@ -190,12 +191,16 @@ public abstract class CommonDiagramDragDropEditPolicy extends DiagramDragDropEdi
// Drop restriction:
// - no restriction when dropped on diagram
- // - require containment when dropped on any other EObject
- if((dropTargetView instanceof Diagram) || (dropTargetElement.eContents().contains(droppedObject))) {
+ // - require containment when dropped on any other EObject
+ if((dropTargetView instanceof Diagram) || dropTargetElement.eContents().contains(droppedObject)) {
return getDefaultDropNodeCommand(droppedNodeType, location, droppedObject);
- }
+ }
- return org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand.INSTANCE;
+ // Allow drop for inherited elements
+ if (dropTargetElement instanceof Classifier && ((Classifier) dropTargetElement).getAllAttributes().contains(droppedObject) ) {
+ return getDefaultDropNodeCommand(droppedNodeType, location, droppedObject);
+ }
+ return org.eclipse.gmf.runtime.common.core.command.UnexecutableCommand.INSTANCE;
}
// The dropped element is a edge
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/utils/PortDropHelper.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/utils/PortDropHelper.java
index 8ca6b3d..e47a663 100644
--- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/utils/PortDropHelper.java
+++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/utils/PortDropHelper.java
@@ -1,98 +1,102 @@
-/*****************************************************************************
- * Copyright (c) 2011 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.sysml.diagram.internalblock.utils;
-
-import org.eclipse.draw2d.geometry.Point;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-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.GraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest;
-import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest.ViewDescriptor;
-import org.eclipse.gmf.runtime.diagram.ui.requests.DropObjectsRequest;
-import org.eclipse.gmf.runtime.notation.Node;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.infra.gmfdiag.common.utils.ViewDescriptorUtil;
-import org.eclipse.papyrus.uml.diagram.common.commands.SemanticAdapter;
-import org.eclipse.papyrus.uml.diagram.common.helper.ElementHelper;
-import org.eclipse.uml2.uml.Port;
-import org.eclipse.uml2.uml.Type;
-import org.eclipse.uml2.uml.TypedElement;
-
-/**
- * This class provides convenience methods to create Type specific drop action (Show Port on BlockPropertyComposite).
- */
-public class PortDropHelper extends ElementHelper {
-
- public PortDropHelper(TransactionalEditingDomain editDomain) {
- this.editDomain = editDomain;
- }
-
- public Command getDropPortOnPart(DropObjectsRequest request, GraphicalEditPart host) {
-
- Object droppedEObject = request.getObjects().get(0);
- if(!isValidPort(droppedEObject, getHostEObject(host))) {
- return UnexecutableCommand.INSTANCE;
- }
-
- return getDropPortOnPart((Port)droppedEObject, request.getLocation().getCopy(), host);
- }
-
- public Command getDropPortOnPart(Port droppedPort, Point location, GraphicalEditPart host) {
-
- if(!isValidPort(droppedPort, getHostEObject(host))) {
- return UnexecutableCommand.INSTANCE;
- }
-
- // Prepare the view creation command
- ViewDescriptor descriptor = new ViewDescriptor(new SemanticAdapter((EObject)droppedPort, null), Node.class, /* explicit semantic hint is mandatory */ null, ViewDescriptorUtil.PERSISTED, host.getDiagramPreferencesHint());
- CreateViewRequest createViewRequest = new CreateViewRequest(descriptor);
- createViewRequest.setLocation(location);
- Command viewCreateCommand = host.getCommand(createViewRequest);
-
- return viewCreateCommand;
- }
-
- private boolean isValidPort(Object object, EObject dropTarget) {
- boolean isValid = false;
-
- // The drop object is supposed to be a Port (or FlowPort)
- if((object != null) && (object instanceof Port)) {
-
- // The dropTarget has to be a TypedElement with a non-null Type
- if((dropTarget != null) && (dropTarget instanceof TypedElement) && (((TypedElement)dropTarget).getType() != null)) {
-
- Type targetType = ((TypedElement)dropTarget).getType();
- // The dropped object is owned by the target type
- if(((Port)object).eContainer() == targetType) {
- isValid = true;
- }
- }
- }
-
- return isValid;
- }
-
- /**
- * return the host Edit Part's semantic element, if the semantic element
- * is <code>null</code> or unresolvable it will return <code>null</code>
- *
- * @return EObject
- */
- protected EObject getHostEObject(GraphicalEditPart host) {
- return ViewUtil.resolveSemanticElement((View)host.getModel());
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2011 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:
+ *
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.sysml.diagram.internalblock.utils;
+
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+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.GraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest;
+import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest.ViewDescriptor;
+import org.eclipse.gmf.runtime.diagram.ui.requests.DropObjectsRequest;
+import org.eclipse.gmf.runtime.notation.Node;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.gmfdiag.common.utils.ViewDescriptorUtil;
+import org.eclipse.papyrus.uml.diagram.common.commands.SemanticAdapter;
+import org.eclipse.papyrus.uml.diagram.common.helper.ElementHelper;
+import org.eclipse.uml2.uml.Classifier;
+import org.eclipse.uml2.uml.Port;
+import org.eclipse.uml2.uml.Type;
+import org.eclipse.uml2.uml.TypedElement;
+
+/**
+ * This class provides convenience methods to create Type specific drop action (Show Port on BlockPropertyComposite).
+ */
+public class PortDropHelper extends ElementHelper {
+
+ public PortDropHelper(TransactionalEditingDomain editDomain) {
+ this.editDomain = editDomain;
+ }
+
+ public Command getDropPortOnPart(DropObjectsRequest request, GraphicalEditPart host) {
+
+ Object droppedEObject = request.getObjects().get(0);
+ if(!isValidPort(droppedEObject, getHostEObject(host))) {
+ return UnexecutableCommand.INSTANCE;
+ }
+
+ return getDropPortOnPart((Port)droppedEObject, request.getLocation().getCopy(), host);
+ }
+
+ public Command getDropPortOnPart(Port droppedPort, Point location, GraphicalEditPart host) {
+
+ if(!isValidPort(droppedPort, getHostEObject(host))) {
+ return UnexecutableCommand.INSTANCE;
+ }
+
+ // Prepare the view creation command
+ ViewDescriptor descriptor = new ViewDescriptor(new SemanticAdapter((EObject)droppedPort, null), Node.class, /* explicit semantic hint is mandatory */ null, ViewDescriptorUtil.PERSISTED, host.getDiagramPreferencesHint());
+ CreateViewRequest createViewRequest = new CreateViewRequest(descriptor);
+ createViewRequest.setLocation(location);
+ Command viewCreateCommand = host.getCommand(createViewRequest);
+
+ return viewCreateCommand;
+ }
+
+ private boolean isValidPort(Object object, EObject dropTarget) {
+ boolean isValid = false;
+
+ // The drop object is supposed to be a Port (or FlowPort)
+ if((object != null) && (object instanceof Port)) {
+
+ Port port = (Port) object;
+ // The dropTarget has to be a TypedElement with a non-null Type
+ if((dropTarget != null) && (dropTarget instanceof TypedElement) && (((TypedElement)dropTarget).getType() != null)) {
+
+ Type targetType = ((TypedElement)dropTarget).getType();
+ // The dropped object is owned by the target type
+
+ if (targetType instanceof Classifier){
+ Classifier classifier = (Classifier) targetType;
+ isValid = classifier.getAllAttributes().contains(port);
+ }
+ }
+ }
+
+ return isValid;
+ }
+
+ /**
+ * return the host Edit Part's semantic element, if the semantic element
+ * is <code>null</code> or unresolvable it will return <code>null</code>
+ *
+ * @return EObject
+ */
+ protected EObject getHostEObject(GraphicalEditPart host) {
+ return ViewUtil.resolveSemanticElement((View)host.getModel());
+ }
+}