Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoreperico2010-01-13 10:37:56 +0000
committereperico2010-01-13 10:37:56 +0000
commitcd91e569876d3ff3a746da26e67dbd3b0eb899a1 (patch)
treedbb3f022b8b36ddd07522ec0077d9bccf8a4e2bc
parent338ba8cdb240e45a5ca43bc265485b5b82fb6250 (diff)
downloadorg.eclipse.papyrus-cd91e569876d3ff3a746da26e67dbd3b0eb899a1.tar.gz
org.eclipse.papyrus-cd91e569876d3ff3a746da26e67dbd3b0eb899a1.tar.xz
org.eclipse.papyrus-cd91e569876d3ff3a746da26e67dbd3b0eb899a1.zip
NEW - bug 297809: [Activity Diagram] Provide an activity diagram based on Papyrus generator
https://bugs.eclipse.org/bugs/show_bug.cgi?id=297809 - provide a way to restrict available edit parts for source and target of the dropped link
-rw-r--r--plugins/uml/org.eclipse.papyrus.diagram.common/src/org/eclipse/papyrus/diagram/common/editpolicies/CommonDiagramDragDropEditPolicy.java178
1 files changed, 109 insertions, 69 deletions
diff --git a/plugins/uml/org.eclipse.papyrus.diagram.common/src/org/eclipse/papyrus/diagram/common/editpolicies/CommonDiagramDragDropEditPolicy.java b/plugins/uml/org.eclipse.papyrus.diagram.common/src/org/eclipse/papyrus/diagram/common/editpolicies/CommonDiagramDragDropEditPolicy.java
index d2d187d1918..3d82609f92e 100644
--- a/plugins/uml/org.eclipse.papyrus.diagram.common/src/org/eclipse/papyrus/diagram/common/editpolicies/CommonDiagramDragDropEditPolicy.java
+++ b/plugins/uml/org.eclipse.papyrus.diagram.common/src/org/eclipse/papyrus/diagram/common/editpolicies/CommonDiagramDragDropEditPolicy.java
@@ -21,6 +21,7 @@ import java.util.List;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gef.EditPart;
@@ -69,7 +70,7 @@ public abstract class CommonDiagramDragDropEditPolicy extends DiagramDragDropEdi
* Instantiates a new custom diagram drag drop edit policy.
*
* @param mappingHelper
- * the mapping helper
+ * the mapping helper
*/
public CommonDiagramDragDropEditPolicy(ILinkMappingHelper mappingHelper) {
linkmappingHelper = mappingHelper;
@@ -79,7 +80,7 @@ public abstract class CommonDiagramDragDropEditPolicy extends DiagramDragDropEdi
* Gets the UML element type for the specified
*
* @param elementID
- * the element id
+ * the element id
*
* @return the uML element type
*/
@@ -104,73 +105,73 @@ public abstract class CommonDiagramDragDropEditPolicy extends DiagramDragDropEdi
* target views do not exist, these views will be created.
*
* @param cc
- * the composite command that will contain the set of command to create the binary
- * link
+ * the composite command that will contain the set of command to create the binary
+ * link
* @param source
- * the source the element source of the link
+ * the source the element source of the link
* @param target
- * the target the element target of the link
+ * the target the element target of the link
* @param linkVISUALID
- * the link VISUALID used to create the view
+ * the link VISUALID used to create the view
* @param location
- * the location the location where the view will be be created
+ * the location the location where the view will be be created
* @param semanticLink
- * the semantic link that will be attached to the view
+ * the semantic link that will be attached to the view
*
* @return the composite command
*/
public CompositeCommand dropBinaryLink(CompositeCommand cc, Element source, Element target, int linkVISUALID,
Point location, Element semanticLink) {
// look for editpart
- GraphicalEditPart sourceEditPart = (GraphicalEditPart)lookForEditPart(source);
- GraphicalEditPart targetEditPart = (GraphicalEditPart)lookForEditPart(target);
+ GraphicalEditPart sourceEditPart = (GraphicalEditPart) lookForEditPart(source);
+ GraphicalEditPart targetEditPart = (GraphicalEditPart) lookForEditPart(target);
// descriptor of the link
CreateConnectionViewRequest.ConnectionViewDescriptor linkdescriptor = new CreateConnectionViewRequest.ConnectionViewDescriptor(
- getUMLElementType(linkVISUALID), ((IHintedType)getUMLElementType(linkVISUALID)).getSemanticHint(),
+ getUMLElementType(linkVISUALID), ((IHintedType) getUMLElementType(linkVISUALID)).getSemanticHint(),
getDiagramPreferencesHint());
IAdaptable sourceAdapter = null;
IAdaptable targetAdapter = null;
- if(sourceEditPart == null) {
+ if (sourceEditPart == null) {
// creation of the node
ViewDescriptor descriptor = new ViewDescriptor(new EObjectAdapter(source), Node.class, null,
- ViewUtil.APPEND, false, ((IGraphicalEditPart)getHost()).getDiagramPreferencesHint());
+ ViewUtil.APPEND, false, ((IGraphicalEditPart) getHost()).getDiagramPreferencesHint());
// get the command and execute it.
- CreateCommand nodeCreationCommand = new CreateCommand(((IGraphicalEditPart)getHost()).getEditingDomain(),
- descriptor, ((View)getHost().getModel()));
+ CreateCommand nodeCreationCommand = new CreateCommand(((IGraphicalEditPart) getHost()).getEditingDomain(),
+ descriptor, ((View) getHost().getModel()));
cc.compose(nodeCreationCommand);
SetBoundsCommand setBoundsCommand = new SetBoundsCommand(getEditingDomain(), "move",
- (IAdaptable)nodeCreationCommand.getCommandResult().getReturnValue(), new Point(location.x,
- location.y + 100));
+ (IAdaptable) nodeCreationCommand.getCommandResult().getReturnValue(), new Point(location.x,
+ location.y + 100));
cc.compose(setBoundsCommand);
- sourceAdapter = (IAdaptable)nodeCreationCommand.getCommandResult().getReturnValue();
+ sourceAdapter = (IAdaptable) nodeCreationCommand.getCommandResult().getReturnValue();
} else {
sourceAdapter = new SemanticAdapter(null, sourceEditPart.getModel());
}
- if(targetEditPart == null) {
+ if (targetEditPart == null) {
// creation of the node
ViewDescriptor descriptor = new ViewDescriptor(new EObjectAdapter(target), Node.class, null,
- ViewUtil.APPEND, false, ((IGraphicalEditPart)getHost()).getDiagramPreferencesHint());
+ ViewUtil.APPEND, false, ((IGraphicalEditPart) getHost()).getDiagramPreferencesHint());
// get the command and execute it.
- CreateCommand nodeCreationCommand = new CreateCommand(((IGraphicalEditPart)getHost()).getEditingDomain(),
- descriptor, ((View)getHost().getModel()));
+ CreateCommand nodeCreationCommand = new CreateCommand(((IGraphicalEditPart) getHost()).getEditingDomain(),
+ descriptor, ((View) getHost().getModel()));
cc.compose(nodeCreationCommand);
SetBoundsCommand setBoundsCommand = new SetBoundsCommand(getEditingDomain(), "move",
- (IAdaptable)nodeCreationCommand.getCommandResult().getReturnValue(), new Point(location.x,
- location.y - 100));
+ (IAdaptable) nodeCreationCommand.getCommandResult().getReturnValue(), new Point(location.x,
+ location.y - 100));
cc.compose(setBoundsCommand);
- targetAdapter = (IAdaptable)nodeCreationCommand.getCommandResult().getReturnValue();
+ targetAdapter = (IAdaptable) nodeCreationCommand.getCommandResult().getReturnValue();
} else {
targetAdapter = new SemanticAdapter(null, targetEditPart.getModel());
}
CommonDeferredCreateConnectionViewCommand aLinkCommand = new CommonDeferredCreateConnectionViewCommand(
- getEditingDomain(), ((IHintedType)getUMLElementType(linkVISUALID)).getSemanticHint(), sourceAdapter,
+ getEditingDomain(), ((IHintedType) getUMLElementType(linkVISUALID)).getSemanticHint(), sourceAdapter,
targetAdapter, getViewer(), getDiagramPreferencesHint(), linkdescriptor, null);
aLinkCommand.setElement(semanticLink);
cc.compose(aLinkCommand);
@@ -184,7 +185,7 @@ public abstract class CommonDiagramDragDropEditPolicy extends DiagramDragDropEdi
* @return the diagram preferences hint
*/
protected PreferencesHint getDiagramPreferencesHint() {
- return ((IGraphicalEditPart)getHost()).getDiagramPreferencesHint();
+ return ((IGraphicalEditPart) getHost()).getDiagramPreferencesHint();
}
/**
@@ -196,52 +197,52 @@ public abstract class CommonDiagramDragDropEditPolicy extends DiagramDragDropEdi
CompositeCommand cc = new CompositeCommand("Drop");
List viewDescriptors = new ArrayList();
Iterator iter = dropRequest.getObjects().iterator();
- if(dropRequest.getObjects().size() > 0 && dropRequest.getObjects().get(0) instanceof String) {
+ if (dropRequest.getObjects().size() > 0 && dropRequest.getObjects().get(0) instanceof String) {
return getDropFileCommand(dropRequest);
}
Point location = dropRequest.getLocation().getCopy();
- ((GraphicalEditPart)getHost()).getContentPane().translateToRelative(location);
- ((GraphicalEditPart)getHost()).getContentPane().translateFromParent(location);
- location.translate(((GraphicalEditPart)getHost()).getContentPane().getClientArea().getLocation().getNegated());
- while(iter.hasNext()) {
- EObject droppedObject = (EObject)iter.next();
- int nodeVISUALID = getNodeVisualID(((IGraphicalEditPart)getHost()).getNotationView(), droppedObject);
+ ((GraphicalEditPart) getHost()).getContentPane().translateToRelative(location);
+ ((GraphicalEditPart) getHost()).getContentPane().translateFromParent(location);
+ location.translate(((GraphicalEditPart) getHost()).getContentPane().getClientArea().getLocation().getNegated());
+ while (iter.hasNext()) {
+ EObject droppedObject = (EObject) iter.next();
+ int nodeVISUALID = getNodeVisualID(((IGraphicalEditPart) getHost()).getNotationView(), droppedObject);
int linkVISUALID = getLinkWithClassVisualID(droppedObject);
- if(specificDrop.contains(nodeVISUALID) || specificDrop.contains(linkVISUALID)) {
- return getSpecificDropCommand(dropRequest, (Element)droppedObject, nodeVISUALID, linkVISUALID);
+ if (specificDrop.contains(nodeVISUALID) || specificDrop.contains(linkVISUALID)) {
+ return getSpecificDropCommand(dropRequest, (Element) droppedObject, nodeVISUALID, linkVISUALID);
}
- if(linkVISUALID == -1 && nodeVISUALID != -1) {
+ if (linkVISUALID == -1 && nodeVISUALID != -1) {
// The element to drop is a node
// Retrieve it's expected graphical parent
- EObject graphicalParent = ((GraphicalEditPart)getHost()).resolveSemanticElement();
+ EObject graphicalParent = ((GraphicalEditPart) getHost()).resolveSemanticElement();
// Restrict the default node creation to the following cases:
// . Take the containment relationship into consideration
// . Release the constraint when GraphicalParent is a Package (Canvas for most
// diagrams)
- if(graphicalParent instanceof Package) {
+ if (graphicalParent instanceof Package) {
cc = getDefaultDropNodeCommand(nodeVISUALID, location, droppedObject);
- } else if((graphicalParent instanceof Element)
- && ((Element)graphicalParent).getOwnedElements().contains(droppedObject)) {
+ } else if ((graphicalParent instanceof Element)
+ && ((Element) graphicalParent).getOwnedElements().contains(droppedObject)) {
cc = getDefaultDropNodeCommand(nodeVISUALID, location, droppedObject);
} else {
return UnexecutableCommand.INSTANCE;
}
- } else if(linkVISUALID != -1) {
- Collection sources = linkmappingHelper.getSource((Element)droppedObject);
- Collection targets = linkmappingHelper.getTarget((Element)droppedObject);
- if(sources.size() == 0 || targets.size() == 0) {
+ } else if (linkVISUALID != -1) {
+ Collection sources = linkmappingHelper.getSource((Element) droppedObject);
+ Collection targets = linkmappingHelper.getTarget((Element) droppedObject);
+ if (sources.size() == 0 || targets.size() == 0) {
return UnexecutableCommand.INSTANCE;
}
// binary association
- Element source = (Element)sources.toArray()[0];
- Element target = (Element)targets.toArray()[0];
+ Element source = (Element) sources.toArray()[0];
+ Element target = (Element) targets.toArray()[0];
cc = dropBinaryLink(cc, source, target, linkVISUALID, dropRequest.getLocation(),
- (Element)droppedObject);
+ (Element) droppedObject);
}
}
return new ICommandProxy(cc);
@@ -253,11 +254,11 @@ public abstract class CommonDiagramDragDropEditPolicy extends DiagramDragDropEdi
* created where expected.
*
* @param nodeVISUALID
- * the node visual identifier
+ * the node visual identifier
* @param location
- * the drop location
+ * the drop location
* @param droppedObject
- * the object to drop
+ * the object to drop
* @return a CompositeCommand for Drop
*/
protected CompositeCommand getDefaultDropNodeCommand(int nodeVISUALID, Point location, EObject droppedObject) {
@@ -265,12 +266,12 @@ public abstract class CommonDiagramDragDropEditPolicy extends DiagramDragDropEdi
IAdaptable elementAdapter = new EObjectAdapter(droppedObject);
ViewDescriptor descriptor = new ViewDescriptor(elementAdapter, Node.class,
- ((IHintedType)getUMLElementType(nodeVISUALID)).getSemanticHint(), ViewUtil.APPEND, false,
+ ((IHintedType) getUMLElementType(nodeVISUALID)).getSemanticHint(), ViewUtil.APPEND, false,
getDiagramPreferencesHint());
- CreateCommand createCommand = new CreateCommand(getEditingDomain(), descriptor, ((View)(getHost().getModel())));
+ CreateCommand createCommand = new CreateCommand(getEditingDomain(), descriptor, ((View) (getHost().getModel())));
cc.compose(createCommand);
- SetBoundsCommand setBoundsCommand = new SetBoundsCommand(getEditingDomain(), "move", (IAdaptable)createCommand
+ SetBoundsCommand setBoundsCommand = new SetBoundsCommand(getEditingDomain(), "move", (IAdaptable) createCommand
.getCommandResult().getReturnValue(), location);
cc.compose(setBoundsCommand);
return cc;
@@ -282,7 +283,7 @@ public abstract class CommonDiagramDragDropEditPolicy extends DiagramDragDropEdi
* @return the editing domain
*/
protected TransactionalEditingDomain getEditingDomain() {
- return ((IGraphicalEditPart)getHost()).getEditingDomain();
+ return ((IGraphicalEditPart) getHost()).getEditingDomain();
}
/**
@@ -290,13 +291,13 @@ public abstract class CommonDiagramDragDropEditPolicy extends DiagramDragDropEdi
* example case of associationClass, multi dependency etc....
*
* @param dropRequest
- * the drop request
+ * the drop request
* @param nodeVISUALID
- * the node visualid
+ * the node visualid
* @param linkVISUALID
- * the link visualid
+ * the link visualid
* @param semanticLink
- * the semantic link
+ * the semantic link
*
* @return the specific drop command
*/
@@ -311,17 +312,17 @@ public abstract class CommonDiagramDragDropEditPolicy extends DiagramDragDropEdi
* @return the viewer
*/
protected EditPartViewer getViewer() {
- return ((IGraphicalEditPart)getHost()).getViewer();
+ return ((IGraphicalEditPart) getHost()).getViewer();
}
/**
* Inits the.
*
* @param arraySpecificDrop
- * the array specific drop
+ * the array specific drop
*/
public void init(int[] arraySpecificDrop) {
- for(int i = 0; i < arraySpecificDrop.length; i++) {
+ for (int i = 0; i < arraySpecificDrop.length; i++) {
specificDrop.add(new Integer(arraySpecificDrop[i]));
}
}
@@ -330,7 +331,7 @@ public abstract class CommonDiagramDragDropEditPolicy extends DiagramDragDropEdi
* Look for editPart from its semantic.
*
* @param semantic
- * the semantic
+ * the semantic
*
* @return the edits the part or null if not found
*/
@@ -338,17 +339,56 @@ public abstract class CommonDiagramDragDropEditPolicy extends DiagramDragDropEdi
Collection<EditPart> editPartSet = getHost().getViewer().getEditPartRegistry().values();
Iterator<EditPart> editPartIterator = editPartSet.iterator();
EditPart existedEditPart = null;
- while(editPartIterator.hasNext() && existedEditPart == null) {
-
+ while (editPartIterator.hasNext() && existedEditPart == null) {
EditPart currentEditPart = editPartIterator.next();
- if((!(currentEditPart instanceof DiagramEditPart)) && (!(currentEditPart instanceof CompartmentEditPart))
- && currentEditPart instanceof GraphicalEditPart
- && semantic.equals(((GraphicalEditPart)currentEditPart).resolveSemanticElement())) {
+ if (isEditPartTypeAdapted(currentEditPart.getClass(), semantic.eClass())
+ && semantic.equals(((GraphicalEditPart) currentEditPart).resolveSemanticElement())) {
existedEditPart = currentEditPart;
}
}
return existedEditPart;
}
+ /**
+ * Check if the edit part type is the best one to represent an object of the given EClass type
+ *
+ * @param editPartClass
+ * the type of EditPart which may represent a semantic element
+ * @param eClass
+ * the EClass type of the represented semantic element
+ * @return true if an edit part of this type should be selected
+ */
+ private boolean isEditPartTypeAdapted(Class<? extends EditPart> editPartClass, EClass eClass) {
+ if (DiagramEditPart.class.isAssignableFrom(editPartClass)
+ || CompartmentEditPart.class.isAssignableFrom(editPartClass)) {
+ // the edit part is disqualified, as a compartment or a diagram can not be dropped
+ return false;
+ } else if (GraphicalEditPart.class.isAssignableFrom(editPartClass)) {
+ // check the edit part type against advised ones
+ return isEditPartTypeSuitableForEClass(editPartClass.asSubclass(GraphicalEditPart.class), eClass);
+ } else {
+ // only a GraphicalEditPart must be selected
+ return false;
+ }
+ }
+
+ /**
+ * Check if an edit part type correctly represent a semantic element of the given EClass.
+ * Subclasses should implement this method to restrict the possibilities during drop of a link.
+ * If an edit part is not of a suitable type, returning false will eliminate it to represent the
+ * element as a source or target edit part. This can be used for example to disable label edit
+ * parts, which may represent the same model element as the main node.
+ *
+ * @param editPartClass
+ * the type of EditPart which must be checked
+ * @param eClass
+ * the EClass type of the element which the edit part must represent
+ * @return the only edit part type which can be selected (return a common super type if several
+ * edit parts can be chosen)
+ */
+ protected boolean isEditPartTypeSuitableForEClass(Class<? extends GraphicalEditPart> editPartClass, EClass eClass) {
+ return true;
+ }
+
}

Back to the top