Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvlorenzo2013-10-15 08:50:54 +0000
committerVincent Lorenzo2013-10-15 11:21:12 +0000
commit4b18e001f3bd14050af59c0600ed7df36def4825 (patch)
treedaa5a83dd16b87c932e5bf762aedcda0005b86f0
parente18bd9ffbce86944b1fd595a9a1e18438fb143e2 (diff)
downloadorg.eclipse.papyrus-4b18e001f3bd14050af59c0600ed7df36def4825.tar.gz
org.eclipse.papyrus-4b18e001f3bd14050af59c0600ed7df36def4825.tar.xz
org.eclipse.papyrus-4b18e001f3bd14050af59c0600ed7df36def4825.zip
419357: [Diagram][Palette] Diagram must provide a way to restore
existing links https://bugs.eclipse.org/bugs/show_bug.cgi?id=419357
-rw-r--r--plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/dnd/helper/CustomLinkMappingHelper.java5
-rw-r--r--plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/edit/policy/CustomBlockCompositeSemanticEditPolicy.java26
-rw-r--r--plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/edit/policy/CustomDefaultSemanticEditPolicy.java29
-rw-r--r--plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-gmf/org/eclipse/papyrus/gmf/diagram/common/edit/policy/CommonDiagramDragDropEditPolicy.java5
-rw-r--r--plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-gmf/org/eclipse/papyrus/gmf/diagram/common/edit/policy/ILinkMappingHelper.java37
-rw-r--r--plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-uml/org/eclipse/papyrus/uml/diagram/common/dnd/helper/LinkMappingHelper.java5
-rw-r--r--plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src/org/eclipse/papyrus/sysml/diagram/common/utils/SysMLCreateOrShowExistingElementHelper.java130
-rw-r--r--plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/dnd/helper/CustomLinkMappingHelper.java5
-rw-r--r--plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/edit/policy/CustomBlockPropertyCompositeSemanticEditPolicy.java17
-rw-r--r--plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/edit/policy/CustomDefaultSemanticEditPolicy.java19
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/icons/checkedRadioButton.gifbin0 -> 255 bytes
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/icons/uncheckedRadioButton.gifbin0 -> 1220 bytes
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/dialogs/CreateOrShowExistingLinkDialog.java346
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/helper/CreateOrShowExistingElementHelper.java262
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/helper/LinkMappingHelper.java49
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/messages/Messages.java46
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/messages/messages.properties9
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/util/EdgeEndsMapper.java107
-rw-r--r--plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/InterfaceRealizationEditHelper.java46
19 files changed, 1102 insertions, 41 deletions
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/dnd/helper/CustomLinkMappingHelper.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/dnd/helper/CustomLinkMappingHelper.java
index 4d65bcf9f09..567675882ce 100644
--- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/dnd/helper/CustomLinkMappingHelper.java
+++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/dnd/helper/CustomLinkMappingHelper.java
@@ -25,6 +25,7 @@ import org.eclipse.papyrus.gmf.diagram.common.edit.policy.ILinkMappingHelper;
import org.eclipse.papyrus.uml.diagram.common.dnd.helper.LinkMappingHelper.CommonSourceUMLSwitch;
import org.eclipse.papyrus.uml.diagram.common.dnd.helper.LinkMappingHelper.CommonTargetUMLSwitch;
import org.eclipse.uml2.uml.Classifier;
+import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Property;
import org.eclipse.uml2.uml.Type;
@@ -36,7 +37,7 @@ public class CustomLinkMappingHelper implements ILinkMappingHelper {
/**
* {@inheritDoc}
*/
- public Collection<?> getSource(EObject link) {
+ public Collection<?> getSource(Element link) {
CommonSourceUMLSwitch umlSwitch = new CommonSourceUMLSwitch() {
public java.util.Collection<?> caseAssociation(org.eclipse.uml2.uml.Association object) {
@@ -87,7 +88,7 @@ public class CustomLinkMappingHelper implements ILinkMappingHelper {
/**
* {@inheritDoc}
*/
- public Collection<?> getTarget(EObject link) {
+ public Collection<?> getTarget(Element link) {
CommonTargetUMLSwitch umlSwitch = new CommonTargetUMLSwitch() {
public java.util.Collection<?> caseAssociation(org.eclipse.uml2.uml.Association object) {
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/edit/policy/CustomBlockCompositeSemanticEditPolicy.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/edit/policy/CustomBlockCompositeSemanticEditPolicy.java
index 8ca2da8b05b..ca3002c4d0b 100644
--- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/edit/policy/CustomBlockCompositeSemanticEditPolicy.java
+++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/edit/policy/CustomBlockCompositeSemanticEditPolicy.java
@@ -13,21 +13,29 @@
*****************************************************************************/
package org.eclipse.papyrus.sysml.diagram.blockdefinition.edit.policy;
+import org.eclipse.emf.ecore.EClass;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.UnexecutableCommand;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientReferenceRelationshipRequest;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.gmf.diagram.common.provider.IGraphicalTypeRegistry;
+import org.eclipse.papyrus.sysml.diagram.blockdefinition.dnd.helper.CustomLinkMappingHelper;
import org.eclipse.papyrus.sysml.diagram.blockdefinition.provider.CustomGraphicalTypeRegistry;
import org.eclipse.papyrus.sysml.diagram.blockdefinition.provider.ElementTypes;
import org.eclipse.papyrus.sysml.diagram.blockdefinition.provider.GraphicalTypeRegistry;
import org.eclipse.papyrus.sysml.diagram.common.edit.policy.BlockCompositeSemanticEditPolicy;
+import org.eclipse.papyrus.sysml.diagram.common.utils.SysMLCreateOrShowExistingElementHelper;
+import org.eclipse.papyrus.sysml.service.types.element.SysMLElementTypes;
import org.eclipse.papyrus.uml.diagram.clazz.edit.commands.CommentAnnotatedElementCreateCommand;
import org.eclipse.papyrus.uml.diagram.clazz.edit.commands.CommentAnnotatedElementReorientCommand;
import org.eclipse.papyrus.uml.diagram.clazz.edit.commands.ConstraintConstrainedElementCreateCommand;
import org.eclipse.papyrus.uml.diagram.clazz.edit.commands.ConstraintConstrainedElementReorientCommand;
+import org.eclipse.papyrus.uml.diagram.common.helper.CreateOrShowExistingElementHelper;
+import org.eclipse.papyrus.uml.service.types.element.UMLElementTypes;
import org.eclipse.papyrus.uml.service.types.utils.RequestParameterConstants;
+import org.eclipse.uml2.uml.UMLPackage;
/**
* <pre>
@@ -44,6 +52,7 @@ public class CustomBlockCompositeSemanticEditPolicy extends BlockCompositeSemant
/** Local graphical type registry for inherited graphical elements */
private IGraphicalTypeRegistry inheritedRegistry = new GraphicalTypeRegistry();
+ private CreateOrShowExistingElementHelper existingElementHelper = new SysMLCreateOrShowExistingElementHelper();
/**
* {@inheritDoc}
*/
@@ -67,8 +76,21 @@ public class CustomBlockCompositeSemanticEditPolicy extends BlockCompositeSemant
if(!registry.isKnownEdgeType(newEdgeGraphicalType)) {
return UnexecutableCommand.INSTANCE;
}
-
- return super.getCreateRelationshipCommand(req);
+ final Command defaultCommand = super.getCreateRelationshipCommand(req);
+ final IElementType elementType = req.getElementType();
+ final EClass eClass = elementType.getEClass();
+ if(defaultCommand.canExecute()) {
+ if(elementType.getEClass() == UMLPackage.eINSTANCE.getAssociation()) {
+ return this.existingElementHelper.getCreateOrRestoreElementCommand(req, defaultCommand, elementType);
+ } else if(eClass == UMLPackage.eINSTANCE.getDependency()) {
+ return this.existingElementHelper.getCreateOrRestoreElementCommand(req, defaultCommand, elementType);
+ } else if(eClass == UMLPackage.eINSTANCE.getGeneralization()) {
+ return this.existingElementHelper.getCreateOrRestoreElementCommand(req, defaultCommand, elementType);
+ } else if(eClass == UMLPackage.eINSTANCE.getUsage()) {
+ return this.existingElementHelper.getCreateOrRestoreElementCommand(req, defaultCommand, elementType);
+ }
+ }
+ return defaultCommand;
}
/**
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/edit/policy/CustomDefaultSemanticEditPolicy.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/edit/policy/CustomDefaultSemanticEditPolicy.java
index 7871c24b529..3b2d9cb846b 100644
--- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/edit/policy/CustomDefaultSemanticEditPolicy.java
+++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.blockdefinition/src/org/eclipse/papyrus/sysml/diagram/blockdefinition/edit/policy/CustomDefaultSemanticEditPolicy.java
@@ -13,8 +13,10 @@
*****************************************************************************/
package org.eclipse.papyrus.sysml.diagram.blockdefinition.edit.policy;
+import org.eclipse.emf.ecore.EClass;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.UnexecutableCommand;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientReferenceRelationshipRequest;
import org.eclipse.gmf.runtime.notation.View;
@@ -23,11 +25,14 @@ import org.eclipse.papyrus.gmf.diagram.common.provider.IGraphicalTypeRegistry;
import org.eclipse.papyrus.sysml.diagram.blockdefinition.provider.CustomGraphicalTypeRegistry;
import org.eclipse.papyrus.sysml.diagram.blockdefinition.provider.ElementTypes;
import org.eclipse.papyrus.sysml.diagram.blockdefinition.provider.GraphicalTypeRegistry;
+import org.eclipse.papyrus.sysml.diagram.common.utils.SysMLCreateOrShowExistingElementHelper;
import org.eclipse.papyrus.uml.diagram.clazz.edit.commands.CommentAnnotatedElementCreateCommand;
import org.eclipse.papyrus.uml.diagram.clazz.edit.commands.CommentAnnotatedElementReorientCommand;
import org.eclipse.papyrus.uml.diagram.clazz.edit.commands.ConstraintConstrainedElementCreateCommand;
import org.eclipse.papyrus.uml.diagram.clazz.edit.commands.ConstraintConstrainedElementReorientCommand;
+import org.eclipse.papyrus.uml.diagram.common.helper.CreateOrShowExistingElementHelper;
import org.eclipse.papyrus.uml.service.types.utils.RequestParameterConstants;
+import org.eclipse.uml2.uml.UMLPackage;
/**
* <pre>
@@ -40,10 +45,11 @@ public class CustomDefaultSemanticEditPolicy extends DefaultSemanticEditPolicy {
/** Local graphical type registry for graphical elements */
private IGraphicalTypeRegistry registry = new CustomGraphicalTypeRegistry();
-
+
/** Local graphical type registry for inherited graphical elements */
private IGraphicalTypeRegistry inheritedRegistry = new GraphicalTypeRegistry();
-
+
+ private CreateOrShowExistingElementHelper existingElementHelper = new SysMLCreateOrShowExistingElementHelper();
/**
* {@inheritDoc}
*/
@@ -67,8 +73,23 @@ public class CustomDefaultSemanticEditPolicy extends DefaultSemanticEditPolicy {
if(!registry.isKnownEdgeType(newEdgeGraphicalType)) {
return UnexecutableCommand.INSTANCE;
}
-
- return super.getCreateRelationshipCommand(req);
+ final Command defaultCommand = super.getCreateRelationshipCommand(req);
+ if(defaultCommand.canExecute() && req.getSource()!=null && req.getTarget()!=null) {
+ final EClass eClass = req.getElementType().getEClass();
+ final IElementType elementType = req.getElementType();
+ if(UMLPackage.eINSTANCE.getInterfaceRealization()==eClass){
+ return this.existingElementHelper.getCreateOrRestoreElementCommand(req, defaultCommand,elementType);
+ }else if(elementType.getEClass() == UMLPackage.eINSTANCE.getAssociation()) {
+ return this.existingElementHelper.getCreateOrRestoreElementCommand(req, defaultCommand, elementType);
+ } else if(eClass == UMLPackage.eINSTANCE.getDependency()) {
+ return this.existingElementHelper.getCreateOrRestoreElementCommand(req, defaultCommand, elementType);
+ } else if(eClass == UMLPackage.eINSTANCE.getGeneralization()) {
+ return this.existingElementHelper.getCreateOrRestoreElementCommand(req, defaultCommand, elementType);
+ } else if(eClass == UMLPackage.eINSTANCE.getUsage()) {
+ return this.existingElementHelper.getCreateOrRestoreElementCommand(req, defaultCommand, elementType);
+ }
+ }
+ return defaultCommand;
}
/**
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 bc831f2b5f5..de2ba1122f8 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.Element;
/**
* Abstract DND edit policy delegating the choice of the view to create for an EObject to a local
@@ -200,8 +201,8 @@ public abstract class CommonDiagramDragDropEditPolicy extends DiagramDragDropEdi
// The dropped element is a edge
if(!UNDEFINED_TYPE.equals(droppedEdgeType)) {
- Collection<?> sources = linkMappingHelper.getSource(droppedObject);
- Collection<?> targets = linkMappingHelper.getTarget(droppedObject);
+ Collection<?> sources = linkMappingHelper.getSource((Element)droppedObject);
+ Collection<?> targets = linkMappingHelper.getTarget((Element)droppedObject);
// Only manage binary link during drop
if((sources.size() > 0) && (targets.size() > 0)) {
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-gmf/org/eclipse/papyrus/gmf/diagram/common/edit/policy/ILinkMappingHelper.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-gmf/org/eclipse/papyrus/gmf/diagram/common/edit/policy/ILinkMappingHelper.java
index d3a8c0fe667..cfa839dc4bb 100644
--- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-gmf/org/eclipse/papyrus/gmf/diagram/common/edit/policy/ILinkMappingHelper.java
+++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-gmf/org/eclipse/papyrus/gmf/diagram/common/edit/policy/ILinkMappingHelper.java
@@ -21,23 +21,24 @@ import org.eclipse.emf.ecore.EObject;
/**
* Interface to map links at semantic level.
*/
-public interface ILinkMappingHelper {
+@Deprecated
+public interface ILinkMappingHelper extends org.eclipse.papyrus.uml.diagram.common.helper.ILinkMappingHelper{
- /**
- * Get the sources.
- *
- * @param link
- * the link.
- * @return the sources.
- */
- public Collection<?> getSource(EObject link);
-
- /**
- * Get the targets.
- *
- * @param link
- * the link.
- * @return the targets.
- */
- public Collection<?> getTarget(EObject link);
+// /**
+// * Get the sources.
+// *
+// * @param link
+// * the link.
+// * @return the sources.
+// */
+// public Collection<?> getSource(EObject link);
+//
+// /**
+// * Get the targets.
+// *
+// * @param link
+// * the link.
+// * @return the targets.
+// */
+// public Collection<?> getTarget(EObject link);
}
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-uml/org/eclipse/papyrus/uml/diagram/common/dnd/helper/LinkMappingHelper.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-uml/org/eclipse/papyrus/uml/diagram/common/dnd/helper/LinkMappingHelper.java
index 93dbf89a877..cfa06fc0324 100644
--- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-uml/org/eclipse/papyrus/uml/diagram/common/dnd/helper/LinkMappingHelper.java
+++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src-common-uml/org/eclipse/papyrus/uml/diagram/common/dnd/helper/LinkMappingHelper.java
@@ -20,6 +20,7 @@ import java.util.Collections;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.papyrus.gmf.diagram.common.edit.policy.ILinkMappingHelper;
+import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.util.UMLSwitch;
/**
@@ -31,7 +32,7 @@ public class LinkMappingHelper implements ILinkMappingHelper {
/**
* {@inheritDoc}
*/
- public Collection<?> getSource(EObject link) {
+ public Collection<?> getSource(Element link) {
CommonSourceUMLSwitch umlSwitch = new CommonSourceUMLSwitch();
return umlSwitch.doSwitch(link);
}
@@ -39,7 +40,7 @@ public class LinkMappingHelper implements ILinkMappingHelper {
/**
* {@inheritDoc}
*/
- public Collection<?> getTarget(EObject link) {
+ public Collection<?> getTarget(Element link) {
CommonTargetUMLSwitch umlSwitch = new CommonTargetUMLSwitch();
return umlSwitch.doSwitch(link);
}
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src/org/eclipse/papyrus/sysml/diagram/common/utils/SysMLCreateOrShowExistingElementHelper.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src/org/eclipse/papyrus/sysml/diagram/common/utils/SysMLCreateOrShowExistingElementHelper.java
new file mode 100644
index 00000000000..b7bc1510c4f
--- /dev/null
+++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.common/src/org/eclipse/papyrus/sysml/diagram/common/utils/SysMLCreateOrShowExistingElementHelper.java
@@ -0,0 +1,130 @@
+/*****************************************************************************
+ * 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.common.utils;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.papyrus.sysml.service.types.element.SysMLElementTypes;
+import org.eclipse.papyrus.uml.diagram.common.helper.ILinkMappingHelper;
+import org.eclipse.papyrus.uml.diagram.common.helper.CreateOrShowExistingElementHelper;
+import org.eclipse.uml2.uml.AggregationKind;
+import org.eclipse.uml2.uml.Association;
+import org.eclipse.uml2.uml.Property;
+
+/**
+ * Show Existing Link Helper for SysML. This class provides specific management for SysML Association.
+ *
+ * @author VL222926
+ *
+ */
+public class SysMLCreateOrShowExistingElementHelper extends CreateOrShowExistingElementHelper {
+
+ /**
+ *
+ * Constructor.
+ *
+ */
+ public SysMLCreateOrShowExistingElementHelper() {
+ super();
+ }
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param linkHelper
+ */
+ public SysMLCreateOrShowExistingElementHelper(final ILinkMappingHelper linkHelper) {
+ super(linkHelper);
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.uml.diagram.common.helper.CreateOrShowExistingElementHelper#getIElementTypeNameToDisplay(org.eclipse.gmf.runtime.emf.type.core.IElementType)
+ *
+ * @param elementType
+ * @return
+ */
+ @Override
+ protected String getIElementTypeNameToDisplay(final IElementType elementType) {
+ if(SysMLElementTypes.ASSOCIATION_NONE.equals(elementType) || SysMLElementTypes.ASSOCIATION_NONE_DIRECTED.equals(elementType)){
+ return "Association/DirectAssociation"; //$NON-NLS-1$
+ }else if(SysMLElementTypes.ASSOCIATION_COMPOSITE.equals(elementType) || SysMLElementTypes.ASSOCIATION_COMPOSITE_DIRECTED.equals(elementType)){
+ return "Composition/DirectComposition"; //$NON-NLS-1$
+ }else if(SysMLElementTypes.ASSOCIATION_SHARED.equals(elementType) || SysMLElementTypes.ASSOCIATION_SHARED_DIRECTED.equals(elementType)){
+ return "Aggregation/DirectAggregation"; //$NON-NLS-1$
+ }
+ return super.getIElementTypeNameToDisplay(elementType);
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.uml.diagram.common.helper.CreateOrShowExistingElementHelper#hasWantedType(org.eclipse.emf.ecore.EObject,
+ * org.eclipse.gmf.runtime.emf.type.core.IElementType)
+ *
+ * @param eobject
+ * an eobject
+ * @param wantedType
+ * the wanted element type
+ * @return
+ * true if the eobject is an instance of the wanted element type.
+ *
+ * Add test for SysML Association
+ */
+ @Override
+ protected boolean hasWantedType(final EObject eobject, final IElementType wantedType) {
+ boolean result = super.hasWantedType(eobject, wantedType);
+ if(result) {
+ if(eobject instanceof Association) {
+ final AggregationKind current = getAssociationAggregationKind((Association)eobject);
+ if(current == AggregationKind.NONE_LITERAL) {
+ if(SysMLElementTypes.ASSOCIATION_NONE.equals(current) || SysMLElementTypes.ASSOCIATION_NONE_DIRECTED.equals(wantedType)) {
+ result = true;
+ }
+ } else if(current == AggregationKind.COMPOSITE_LITERAL) {
+ if(SysMLElementTypes.ASSOCIATION_COMPOSITE.equals(current) || SysMLElementTypes.ASSOCIATION_COMPOSITE_DIRECTED.equals(wantedType)) {
+ result = true;
+ }
+ } else if(current == AggregationKind.SHARED_LITERAL) {
+ if(SysMLElementTypes.ASSOCIATION_SHARED.equals(current) || SysMLElementTypes.ASSOCIATION_SHARED_DIRECTED.equals(wantedType)) {
+ result = true;
+ }
+ } else {
+ result = false;
+ }
+ }
+ }
+ return result;
+ }
+
+ /**
+ *
+ * @param association
+ * an association
+ * @return
+ * the association kind for the association
+ */
+ private static final AggregationKind getAssociationAggregationKind(final Association association) {
+ final Property source = association.getMemberEnds().get(0);
+ final Property target = association.getMemberEnds().get(1);
+ if(source.getAggregation() == AggregationKind.NONE_LITERAL && target.getAggregation() == AggregationKind.NONE_LITERAL) {
+ return AggregationKind.NONE_LITERAL;
+ } else if((source.getAggregation() == AggregationKind.COMPOSITE_LITERAL) || (target.getAggregation() == AggregationKind.COMPOSITE_LITERAL)) {
+ return AggregationKind.COMPOSITE_LITERAL;
+ } else {
+ return AggregationKind.SHARED_LITERAL;
+ }
+
+ }
+}
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/dnd/helper/CustomLinkMappingHelper.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/dnd/helper/CustomLinkMappingHelper.java
index 791172ac710..ea85d7a115f 100644
--- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/dnd/helper/CustomLinkMappingHelper.java
+++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/dnd/helper/CustomLinkMappingHelper.java
@@ -22,6 +22,7 @@ import org.eclipse.papyrus.gmf.diagram.common.edit.policy.ILinkMappingHelper;
import org.eclipse.papyrus.uml.diagram.common.dnd.helper.LinkMappingHelper.CommonSourceUMLSwitch;
import org.eclipse.papyrus.uml.diagram.common.dnd.helper.LinkMappingHelper.CommonTargetUMLSwitch;
import org.eclipse.uml2.uml.ConnectorEnd;
+import org.eclipse.uml2.uml.Element;
/**
* The Class LinkMappingHelper is specialization of the link mapping helper for the Class diagram
@@ -31,7 +32,7 @@ public class CustomLinkMappingHelper implements ILinkMappingHelper {
/**
* {@inheritDoc}
*/
- public Collection<?> getSource(EObject link) {
+ public Collection<?> getSource(Element link) {
CommonSourceUMLSwitch umlSwitch = new CommonSourceUMLSwitch() {
public java.util.Collection<?> caseConnector(org.eclipse.uml2.uml.Connector object) {
@@ -59,7 +60,7 @@ public class CustomLinkMappingHelper implements ILinkMappingHelper {
/**
* {@inheritDoc}
*/
- public Collection<?> getTarget(EObject link) {
+ public Collection<?> getTarget(Element link) {
CommonTargetUMLSwitch umlSwitch = new CommonTargetUMLSwitch() {
public java.util.Collection<?> caseConnector(org.eclipse.uml2.uml.Connector object) {
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/edit/policy/CustomBlockPropertyCompositeSemanticEditPolicy.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/edit/policy/CustomBlockPropertyCompositeSemanticEditPolicy.java
index a88d6f6658e..adff7be704f 100644
--- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/edit/policy/CustomBlockPropertyCompositeSemanticEditPolicy.java
+++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/edit/policy/CustomBlockPropertyCompositeSemanticEditPolicy.java
@@ -15,6 +15,7 @@ package org.eclipse.papyrus.sysml.diagram.internalblock.edit.policy;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.UnexecutableCommand;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientReferenceRelationshipRequest;
import org.eclipse.gmf.runtime.notation.View;
@@ -23,10 +24,12 @@ import org.eclipse.papyrus.sysml.diagram.common.edit.policy.BlockPropertyComposi
import org.eclipse.papyrus.sysml.diagram.internalblock.provider.CustomGraphicalTypeRegistry;
import org.eclipse.papyrus.sysml.diagram.internalblock.provider.ElementTypes;
import org.eclipse.papyrus.sysml.diagram.internalblock.provider.GraphicalTypeRegistry;
+import org.eclipse.papyrus.uml.diagram.common.helper.CreateOrShowExistingElementHelper;
import org.eclipse.papyrus.uml.diagram.composite.edit.commands.CommentAnnotatedElementCreateCommand;
import org.eclipse.papyrus.uml.diagram.composite.edit.commands.CommentAnnotatedElementReorientCommand;
import org.eclipse.papyrus.uml.diagram.composite.edit.commands.ConstraintConstrainedElementCreateCommand;
import org.eclipse.papyrus.uml.diagram.composite.edit.commands.ConstraintConstrainedElementReorientCommand;
+import org.eclipse.papyrus.uml.service.types.element.UMLElementTypes;
import org.eclipse.papyrus.uml.service.types.utils.RequestParameterConstants;
/**
@@ -44,6 +47,8 @@ public class CustomBlockPropertyCompositeSemanticEditPolicy extends BlockPropert
/** Local graphical type registry for inherited graphical elements */
private IGraphicalTypeRegistry inheritedRegistry = new GraphicalTypeRegistry();
+ private CreateOrShowExistingElementHelper linkHelper = new CreateOrShowExistingElementHelper();
+
/**
* {@inheritDoc}
*/
@@ -68,7 +73,17 @@ public class CustomBlockPropertyCompositeSemanticEditPolicy extends BlockPropert
return UnexecutableCommand.INSTANCE;
}
- return super.getCreateRelationshipCommand(req);
+ final Command defaultCommand = super.getCreateRelationshipCommand(req);
+ if(defaultCommand.canExecute()) {
+ final IElementType elementType = req.getElementType();
+ if(UMLElementTypes.CONNECTOR.equals(req.getElementType())) {
+ return this.linkHelper.getCreateOrRestoreElementCommand(req, defaultCommand, elementType);
+ }
+ if(UMLElementTypes.DEPENDENCY.equals(req.getElementType())) {
+ return this.linkHelper.getCreateOrRestoreElementCommand(req, defaultCommand, elementType);
+ }
+ }
+ return defaultCommand;
}
/**
diff --git a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/edit/policy/CustomDefaultSemanticEditPolicy.java b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/edit/policy/CustomDefaultSemanticEditPolicy.java
index 2e16e0f3bfd..515d6b1cc72 100644
--- a/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/edit/policy/CustomDefaultSemanticEditPolicy.java
+++ b/plugins/sysml/diagram/org.eclipse.papyrus.sysml.diagram.internalblock/src/org/eclipse/papyrus/sysml/diagram/internalblock/edit/policy/CustomDefaultSemanticEditPolicy.java
@@ -15,6 +15,7 @@ package org.eclipse.papyrus.sysml.diagram.internalblock.edit.policy;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.commands.UnexecutableCommand;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientReferenceRelationshipRequest;
import org.eclipse.gmf.runtime.notation.View;
@@ -23,10 +24,12 @@ import org.eclipse.papyrus.gmf.diagram.common.provider.IGraphicalTypeRegistry;
import org.eclipse.papyrus.sysml.diagram.internalblock.provider.CustomGraphicalTypeRegistry;
import org.eclipse.papyrus.sysml.diagram.internalblock.provider.ElementTypes;
import org.eclipse.papyrus.sysml.diagram.internalblock.provider.GraphicalTypeRegistry;
+import org.eclipse.papyrus.uml.diagram.common.helper.CreateOrShowExistingElementHelper;
import org.eclipse.papyrus.uml.diagram.composite.edit.commands.CommentAnnotatedElementCreateCommand;
import org.eclipse.papyrus.uml.diagram.composite.edit.commands.CommentAnnotatedElementReorientCommand;
import org.eclipse.papyrus.uml.diagram.composite.edit.commands.ConstraintConstrainedElementCreateCommand;
import org.eclipse.papyrus.uml.diagram.composite.edit.commands.ConstraintConstrainedElementReorientCommand;
+import org.eclipse.papyrus.uml.service.types.element.UMLElementTypes;
import org.eclipse.papyrus.uml.service.types.utils.RequestParameterConstants;
/**
@@ -44,6 +47,9 @@ public class CustomDefaultSemanticEditPolicy extends DefaultSemanticEditPolicy {
/** Local graphical type registry for inherited graphical elements */
private IGraphicalTypeRegistry inheritedRegistry = new GraphicalTypeRegistry();
+ /** the link helper to use */
+ private CreateOrShowExistingElementHelper linkHelper = new CreateOrShowExistingElementHelper();
+
/**
* {@inheritDoc}
*/
@@ -68,7 +74,18 @@ public class CustomDefaultSemanticEditPolicy extends DefaultSemanticEditPolicy {
return UnexecutableCommand.INSTANCE;
}
- return super.getCreateRelationshipCommand(req);
+ final Command defaultCommand = super.getCreateRelationshipCommand(req);
+ if(defaultCommand.canExecute()) {
+ final IElementType elementType = req.getElementType();
+ if(UMLElementTypes.CONNECTOR.equals(req.getElementType())) {
+ return this.linkHelper.getCreateOrRestoreElementCommand(req, defaultCommand, elementType);
+ }
+
+ if(UMLElementTypes.DEPENDENCY.equals(req.getElementType())) {
+ return this.linkHelper.getCreateOrRestoreElementCommand(req, defaultCommand, elementType);
+ }
+ }
+ return defaultCommand;
}
/**
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/icons/checkedRadioButton.gif b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/icons/checkedRadioButton.gif
new file mode 100644
index 00000000000..2a4e3066fcd
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/icons/checkedRadioButton.gif
Binary files differ
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/icons/uncheckedRadioButton.gif b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/icons/uncheckedRadioButton.gif
new file mode 100644
index 00000000000..6622affb80c
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/icons/uncheckedRadioButton.gif
Binary files differ
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/dialogs/CreateOrShowExistingLinkDialog.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/dialogs/CreateOrShowExistingLinkDialog.java
new file mode 100644
index 00000000000..8c30250ef25
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/dialogs/CreateOrShowExistingLinkDialog.java
@@ -0,0 +1,346 @@
+/*****************************************************************************
+ * Copyright (c) 2013 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.common.dialogs;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.CheckboxCellEditor;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.EditingSupport;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.ViewerColumn;
+import org.eclipse.papyrus.infra.widgets.Activator;
+import org.eclipse.papyrus.uml.diagram.common.messages.Messages;
+import org.eclipse.papyrus.uml.diagram.common.util.EdgeEndsMapper;
+import org.eclipse.papyrus.uml.tools.providers.UMLLabelProvider;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+
+
+
+/**
+ * This dialog is used to ask to the user if he wants create a new instance of a link, or show an existing link on the diagram
+ *
+ * @author VL222926
+ *
+ */
+public class CreateOrShowExistingLinkDialog extends MessageDialog {
+
+ /**
+ * indexes of the button
+ */
+ public static final int CREATE = Dialog.OK;
+
+ public static final int RESTORE_SELECTED_LINK = CREATE + 1;
+
+ public static final int CANCEL = RESTORE_SELECTED_LINK + 1;
+
+ /**
+ * title for the dialog
+ */
+ public static final String DIALOG_TITLE = Messages.CreateOrShowExistingLinkDialog_ShowOrCreate;
+
+ /**
+ * Message for the Buttons
+ */
+ private static final String CREATE_STRING = Messages.CreateOrShowExistingLinkDialog_Create;
+
+ private static final String RESTORE_SELECTION = Messages.CreateOrShowExistingLinkDialog_RestoreSelection;
+
+ private static final String CANCEL_STRING = "Cancel"; //$NON-NLS-1$
+
+
+ /**
+ * Titles for the columns
+ */
+ private static final String NAME = Messages.CreateOrShowExistingLinkDialog_Name;
+
+ private static final String ENDS = Messages.CreateOrShowExistingLinkDialog_Ends;
+
+ private static final String SOURCES = Messages.CreateOrShowExistingLinkDialog_Sources;
+
+ private static final String TARGETS = Messages.CreateOrShowExistingLinkDialog_Targets;
+
+ /**
+ * Size for the columns
+ */
+ private static final int COLUMN_NAME_SIZE = 150;
+
+ private static final int COLUMN_SIZE = 200;
+
+ /**
+ * the list of the elements to display in the Table
+ */
+ private final List<EdgeEndsMapper> existingLinks;
+
+ //FIXME : move the label provider!
+ final UMLLabelProvider labelProvider = new UMLLabelProvider();
+
+ /**
+ * the string displayed when there is no value to display
+ */
+ private static final String NOT_AVAILABLE = "N/A"; //$NON-NLS-1$
+
+ /**
+ * the image to display when the link is selected
+ */
+ private static final String CHECKED_ICON_PATH = "/icons/checkedRadioButton.gif"; //$NON-NLS-1$
+
+ /**
+ * the image to display when the link is not selected
+ */
+ private static final String UNCHECKED_ICON_PATH = "/icons/uncheckedRadioButton.gif"; //$NON-NLS-1$
+
+ /**
+ * the index of the selected element
+ */
+ private int selectedElementIndex = 0;
+
+ /**
+ * the selected element
+ */
+ private EObject result = null;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param dialogTitle
+ * the title for the dialog
+ * @param dialogMessage
+ * the message for the dialog
+ * @param elements
+ * the list of the possible elements
+ */
+ public CreateOrShowExistingLinkDialog(final String dialogTitle, final String dialogMessage, final List<EdgeEndsMapper> elements) {
+ super(Display.getDefault().getActiveShell(), dialogTitle, null, dialogMessage, MessageDialog.QUESTION, new String[]{ CREATE_STRING, RESTORE_SELECTION, CANCEL_STRING }, RESTORE_SELECTED_LINK);
+ this.existingLinks = elements;
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param title
+ * @param bound
+ * @param viewer
+ * @return
+ */
+ private TableViewerColumn createTableViewerColumn(String title, int bound, TableViewer viewer) {
+ final TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.NONE);
+ final TableColumn column = viewerColumn.getColumn();
+ column.setText(title);
+ column.setWidth(bound);
+ column.setResizable(false);
+ column.setMoveable(false);
+ return viewerColumn;
+ }
+
+ /**
+ *
+ * @see org.eclipse.jface.dialogs.MessageDialog#createCustomArea(org.eclipse.swt.widgets.Composite)
+ *
+ * @param parent
+ * @return
+ */
+ @Override
+ protected Control createCustomArea(final Composite parent) {
+ final Composite composite = parent;
+ final TableViewer viewer = new TableViewer(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
+ viewer.setContentProvider(new ArrayContentProvider());
+ final Table table = viewer.getTable();
+ table.setHeaderVisible(true);
+
+ ViewerColumn colCheckbox = createTableViewerColumn("", 20, viewer); //$NON-NLS-1$
+ colCheckbox.setLabelProvider(new ColumnLabelProvider() {
+
+ @Override
+ public String getText(Object element) {
+ return ""; //$NON-NLS-1$
+ }
+
+ @Override
+ public Image getImage(Object element) {
+ if(existingLinks.get(selectedElementIndex) == element) {
+ return Activator.getDefault().getImage(org.eclipse.papyrus.uml.diagram.common.Activator.ID, CHECKED_ICON_PATH);
+ }
+ return Activator.getDefault().getImage(org.eclipse.papyrus.uml.diagram.common.Activator.ID, UNCHECKED_ICON_PATH);
+ }
+
+ });
+ colCheckbox.setEditingSupport(new EditingSupport(viewer) {
+
+ private CheckboxCellEditor checkboxCellEditor;
+
+ @Override
+ protected void setValue(Object element, Object value) {
+ if(checkboxCellEditor.getValue() == Boolean.TRUE) {
+ selectedElementIndex = existingLinks.indexOf(element);
+ }
+ for(final EdgeEndsMapper current : existingLinks) {
+ viewer.update(current, null);
+ }
+ }
+
+ @Override
+ protected Object getValue(Object element) {
+ return existingLinks.get(selectedElementIndex) == element;
+ }
+
+ @Override
+ protected CellEditor getCellEditor(Object element) {
+ checkboxCellEditor = new CheckboxCellEditor(parent, SWT.CHECK | SWT.READ_ONLY);
+ return checkboxCellEditor;
+ }
+
+ @Override
+ protected boolean canEdit(Object element) {
+ return true;
+ }
+ });
+ TableViewerColumn columnName = createTableViewerColumn(NAME, COLUMN_NAME_SIZE, viewer);
+ configureColumn(columnName);
+ columnName.setLabelProvider(new ColumnLabelProvider() {
+
+ @Override
+ public String getText(Object element) {
+ if(element instanceof EdgeEndsMapper) {
+ return labelProvider.getText(((EdgeEndsMapper)element).getLink());
+ }
+ //not possible
+ return NOT_AVAILABLE;
+ }
+
+ @Override
+ public Image getImage(Object element) {
+ return null;
+ }
+
+
+ });
+
+ TableViewerColumn columnEnds = createTableViewerColumn(ENDS, COLUMN_SIZE, viewer);
+ configureColumn(columnEnds);
+ columnEnds.setLabelProvider(new ColumnLabelProvider() {
+
+ @Override
+ public String getText(Object element) {
+ if(element instanceof EdgeEndsMapper) {
+ return getLabel(((EdgeEndsMapper)element).getEnds());
+ }
+ return NOT_AVAILABLE;
+ }
+ });
+
+
+ TableViewerColumn columnSources = createTableViewerColumn(SOURCES, COLUMN_SIZE, viewer);
+ configureColumn(columnSources);
+ columnSources.setLabelProvider(new ColumnLabelProvider() {
+
+ @Override
+ public String getText(Object element) {
+ if(element instanceof EdgeEndsMapper) {
+ return getLabel(((EdgeEndsMapper)element).getSources());
+ }
+ return NOT_AVAILABLE;
+ }
+ });
+
+ TableViewerColumn columnTargets = createTableViewerColumn(TARGETS, COLUMN_SIZE, viewer);
+ configureColumn(columnTargets);
+ columnTargets.setLabelProvider(new ColumnLabelProvider() {
+
+ @Override
+ public String getText(Object element) {
+ if(element instanceof EdgeEndsMapper) {
+ return getLabel(((EdgeEndsMapper)element).getTargets());
+ }
+ return NOT_AVAILABLE;
+ }
+ });
+
+ GridData gridData = new GridData();
+ gridData.verticalAlignment = GridData.FILL;
+ gridData.horizontalSpan = 2;
+ gridData.grabExcessHorizontalSpace = true;
+ gridData.grabExcessVerticalSpace = true;
+ gridData.horizontalAlignment = GridData.FILL;
+ viewer.getControl().setLayoutData(gridData);
+ viewer.setInput(existingLinks);
+ parent.pack();
+ return parent;
+ }
+
+ @Override
+ protected void buttonPressed(int buttonId) {
+ if(buttonId == RESTORE_SELECTED_LINK && this.existingLinks.size() >= this.selectedElementIndex) {
+ this.result = this.existingLinks.get(this.selectedElementIndex).getLink();
+ }
+ super.buttonPressed(buttonId);
+ }
+
+ /**
+ *
+ * @param viewerColumn
+ * the viewerColumn to configure
+ */
+ protected void configureColumn(final TableViewerColumn viewerColumn) {
+ viewerColumn.getColumn().setMoveable(true);
+ viewerColumn.getColumn().setResizable(true);
+ }
+
+ /**
+ *
+ * @param list
+ * the list of the elements for which we want the label
+ * @return
+ * the string to display for this list
+ */
+ private String getLabel(final Collection<?> list) {
+ if(list != null) {
+ final StringBuilder builder = new StringBuilder();
+ final Iterator<?> iter = list.iterator();
+ while(iter.hasNext()) {
+ builder.append(labelProvider.getText(iter.next()));
+ if(iter.hasNext()) {
+ builder.append(","); //$NON-NLS-1$
+ }
+ }
+ return builder.toString();
+ }
+ return NOT_AVAILABLE;
+ }
+
+ /**
+ *
+ * @return
+ * the selected link
+ */
+ public EObject getResult() {
+ return this.result;
+ }
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/helper/CreateOrShowExistingElementHelper.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/helper/CreateOrShowExistingElementHelper.java
new file mode 100644
index 00000000000..8dc3740b269
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/helper/CreateOrShowExistingElementHelper.java
@@ -0,0 +1,262 @@
+/*****************************************************************************
+ * Copyright (c) 2013 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.common.helper;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
+import org.eclipse.jface.dialogs.MessageDialogWithToggle;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.papyrus.uml.diagram.common.dialogs.CreateOrShowExistingLinkDialog;
+import org.eclipse.papyrus.uml.diagram.common.messages.Messages;
+import org.eclipse.papyrus.uml.diagram.common.util.EdgeEndsMapper;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.UMLPackage;
+
+/**
+ *
+ * This class provides command to restore existing link instead of create new ones
+ *
+ *
+ *
+ * @author VL222926
+ *
+ */
+public class CreateOrShowExistingElementHelper {
+
+
+ /**
+ * the link helper to use. Will be used in the future
+ */
+ private ILinkMappingHelper linkMappingHelper;
+
+ /**
+ * preferences used to know if the dialog must be displayed or not
+ */
+ public static final String DISPLAY_DIALOG_FOR_CREATE_OR_RESTORE_ELEMENT = "Display Dialog For Create Or Restore Element"; //$NON-NLS-1$
+
+ /**
+ *
+ * Constructor.
+ *
+ */
+ public CreateOrShowExistingElementHelper() {
+ this(new ILinkMappingHelper() {
+
+ public Collection<?> getTarget(Element link) {
+ return LinkMappingHelper.getTarget(link);
+ }
+
+ public Collection<?> getSource(Element link) {
+ return LinkMappingHelper.getSource(link);
+ }
+ });
+ }
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param linkHelper
+ * the mapping helper to use to find sources and targets
+ */
+ public CreateOrShowExistingElementHelper(final ILinkMappingHelper linkHelper) {
+ this.linkMappingHelper = linkHelper;
+ }
+
+ /**
+ *
+ * @param req
+ * the create request
+ * @param defaultCommand
+ * the default command for this request
+ * @param existingElements
+ * the list of the link already existing between the source and the target for this kind of link
+ * @return
+ */
+ public Command getCreateOrRestoreElementCommand(final CreateRelationshipRequest req, final Command defaultCommand, final IElementType linkElementType) {
+ if(showDialogAccordingPreferences() && defaultCommand.canExecute()) {
+ final EObject container = req.getContainer();
+ if(container instanceof Element) {
+ final List<EdgeEndsMapper> existingElements = getExistingLinksBetweenSourceAndTarget((Element)req.getContainer(), req.getSource(), req.getTarget(), linkElementType);
+ if(existingElements.size() > 0) {
+ final String className = getIElementTypeNameToDisplay(linkElementType);
+ final String dialogTitle = NLS.bind(Messages.CreateOrShowExistingElementHelper_CreateOrRestoreX, className);
+ final String dialogMessage = NLS.bind(Messages.CreateOrShowExistingElementHelper_XBetweenTheseElementAlreadyExists, className);
+ CreateOrShowExistingLinkDialog dialog = new CreateOrShowExistingLinkDialog(dialogTitle, dialogMessage, existingElements);
+ return new ICommandProxy(getOpenLinkDialogCommand(req, defaultCommand, dialog, existingElements));
+ }
+ }
+ }
+ return defaultCommand;
+ }
+
+ /**
+ *
+ * @param element
+ * an element
+ * @param elementType
+ * an element type
+ * @return
+ * <code>true</code> if the element has the wanted type according to the element type
+ */
+ protected boolean hasWantedType(final EObject element, final IElementType elementType) {
+ return element.eClass() == elementType.getEClass();
+ }
+
+ /**
+ * Returns the preferences AND Create the preference if it doesn't yet exist
+ *
+ * @return
+ * the preference to know if a dialog must ask to the use if he wants create a new edge or restore an existing edge
+ */
+ protected boolean showDialogAccordingPreferences() {
+ final IPreferenceStore store = org.eclipse.papyrus.uml.diagram.common.Activator.getDefault().getPreferenceStore();
+ boolean contains = store.contains(DISPLAY_DIALOG_FOR_CREATE_OR_RESTORE_ELEMENT);
+ if(!contains) {
+ store.setValue(DISPLAY_DIALOG_FOR_CREATE_OR_RESTORE_ELEMENT, MessageDialogWithToggle.ALWAYS);
+ store.setDefault(DISPLAY_DIALOG_FOR_CREATE_OR_RESTORE_ELEMENT, MessageDialogWithToggle.NEVER);
+ }
+ return store.getString(DISPLAY_DIALOG_FOR_CREATE_OR_RESTORE_ELEMENT).equals(MessageDialogWithToggle.ALWAYS);
+ }
+
+ /**
+ *
+ * @param elementType
+ * an element type
+ * @return
+ * the element type to display in the dialog
+ */
+ protected String getIElementTypeNameToDisplay(final IElementType elementType) {
+ return elementType.getEClass().getName();
+ }
+
+ /**
+ *
+ * @param container
+ * the container
+ * @param source
+ * @param target
+ * @param wantedEClass
+ * @return
+ * a list of {@link EdgeEndsMapper} referencing the exising links between the source and the target
+ */
+ protected List<EdgeEndsMapper> getExistingLinksBetweenSourceAndTarget(final Element container, final EObject source, final EObject target, final IElementType wantedElementType) {
+ final List<EdgeEndsMapper> existingElement = new ArrayList<EdgeEndsMapper>();
+ for(final Element current : container.getOwnedElements()) {
+ if(hasWantedType(current, wantedElementType)) {
+ if(target != null) {
+ int i = 0;
+ i++;
+ }
+ final Collection<?> sources = this.linkMappingHelper.getSource(current);
+ final Collection<?> targets = this.linkMappingHelper.getTarget(current);
+ if(sources.contains(source) && targets.contains(target)) {
+ final EClass wantedEClass = wantedElementType.getEClass();
+ if((wantedEClass == UMLPackage.eINSTANCE.getConnector()) || (wantedEClass == UMLPackage.eINSTANCE.getAssociation())) {
+ existingElement.add(new EdgeEndsMapper(current, sources, null, null));
+ } else {
+ existingElement.add(new EdgeEndsMapper(current, null, sources, targets));
+ }
+ }
+ }
+ }
+ return existingElement;
+ }
+
+ /**
+ *
+ * @param request
+ * the request (can't be <code>null</code>)
+ * @param defaultCommand
+ * the default command to use to create the semantic element (can't be <code>null</code>)
+ * @param dialog
+ * the dialog to open (can't be <code>null</code>)
+ * @param existingEObject
+ * the list of the existing objects (can't be null, neither empty
+ * @return
+ * the command to open the dialog AND do the selected action
+ */
+ public static final ICommand getOpenLinkDialogCommand(final CreateRelationshipRequest request, final Command defaultCommand, final CreateOrShowExistingLinkDialog dialog, final List<EdgeEndsMapper> existingEObject) {
+ final AbstractTransactionalCommand compoundCommand = new AbstractTransactionalCommand(request.getEditingDomain(), "", null) { //$NON-NLS-1$
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor,
+ * org.eclipse.core.runtime.IAdaptable)
+ *
+ * @param monitor
+ * @param info
+ * @return
+ * @throws ExecutionException
+ */
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ int result = dialog.open();
+ switch(result) {
+ case CreateOrShowExistingLinkDialog.CREATE:
+ //we execute the default command
+ defaultCommand.execute();
+ return CommandResult.newOKCommandResult(request.getNewElement());
+ case CreateOrShowExistingLinkDialog.RESTORE_SELECTED_LINK:
+ final EObject selectedElement = dialog.getResult();
+ if(selectedElement != null) {//must always be true
+ request.setNewElement(selectedElement);
+ return CommandResult.newOKCommandResult(selectedElement);
+ } else {
+ return CommandResult.newErrorCommandResult("The selected element in the dialog is null"); //$NON-NLS-1$
+ }
+ default:
+ return CommandResult.newCancelledCommandResult();
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.core.commands.operations.AbstractOperation#canExecute()
+ *
+ * @return
+ */
+ @Override
+ public boolean canExecute() {
+ return defaultCommand.canExecute();
+ }
+ };
+ return compoundCommand;
+ }
+
+ /**
+ *
+ * @return
+ * the link mapping helper to use
+ */
+ public ILinkMappingHelper getLinkMappingHelper() {
+ return linkMappingHelper;
+ }
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/helper/LinkMappingHelper.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/helper/LinkMappingHelper.java
index d614cdd8e34..d6e307e04b7 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/helper/LinkMappingHelper.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/helper/LinkMappingHelper.java
@@ -17,8 +17,15 @@ package org.eclipse.papyrus.uml.diagram.common.helper;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.List;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.uml2.uml.ConnectableElement;
+import org.eclipse.uml2.uml.Connector;
+import org.eclipse.uml2.uml.ConnectorEnd;
+import org.eclipse.uml2.uml.Constraint;
import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.InterfaceRealization;
import org.eclipse.uml2.uml.util.UMLSwitch;
/**
@@ -133,6 +140,23 @@ public class LinkMappingHelper {
};
@Override
+ public Collection<?> caseConnector(final Connector object) {
+ final List<EObject> sources = new ArrayList<EObject>();
+ for(final ConnectorEnd current : object.getEnds()) {
+ final ConnectableElement role = current.getRole();
+ if(role != null) {
+ sources.add(role);
+ }
+ }
+ return sources;
+ }
+
+ @Override
+ public Collection<?> caseConstraint(Constraint object) {
+ return Collections.singletonList(object);
+ }
+
+ @Override
public Collection<?> defaultCase(org.eclipse.emf.ecore.EObject object) {
return Collections.EMPTY_LIST;
};
@@ -187,6 +211,31 @@ public class LinkMappingHelper {
};
@Override
+ public Collection<?> caseConnector(final Connector object) {
+ final List<EObject> targets = new ArrayList<EObject>();
+ for(final ConnectorEnd current : object.getEnds()) {
+ final ConnectableElement role = current.getRole();
+ if(role != null) {
+ targets.add(role);
+ }
+ }
+ return targets;
+ }
+
+ @Override
+ public Collection<?> caseConstraint(Constraint object) {
+ final List<EObject> targets = new ArrayList<EObject>();
+ targets.addAll(object.getConstrainedElements());
+ return targets;
+ }
+
+ @Override
+ public Collection<?> caseInterfaceRealization(InterfaceRealization object) {
+ final List<EObject> targets = new ArrayList<EObject>();
+ targets.addAll(object.getSuppliers());
+ return targets;
+ }
+ @Override
public Collection<?> defaultCase(org.eclipse.emf.ecore.EObject object) {
return Collections.EMPTY_LIST;
};
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/messages/Messages.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/messages/Messages.java
new file mode 100644
index 00000000000..aca16b0f18b
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/messages/Messages.java
@@ -0,0 +1,46 @@
+/*****************************************************************************
+ * Copyright (c) 2013 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.common.messages;
+
+import org.eclipse.osgi.util.NLS;
+
+public class Messages extends NLS {
+
+ private static final String BUNDLE_NAME = "org.eclipse.papyrus.uml.diagram.common.messages.messages"; //$NON-NLS-1$
+
+ public static String CreateOrShowExistingElementHelper_CreateOrRestoreX;
+
+ public static String CreateOrShowExistingElementHelper_XBetweenTheseElementAlreadyExists;
+
+ public static String CreateOrShowExistingLinkDialog_Create;
+
+ public static String CreateOrShowExistingLinkDialog_Ends;
+
+ public static String CreateOrShowExistingLinkDialog_Name;
+
+ public static String CreateOrShowExistingLinkDialog_RestoreSelection;
+
+ public static String CreateOrShowExistingLinkDialog_ShowOrCreate;
+
+ public static String CreateOrShowExistingLinkDialog_Sources;
+
+ public static String CreateOrShowExistingLinkDialog_Targets;
+ static {
+ // initialize resource bundle
+ NLS.initializeMessages(BUNDLE_NAME, Messages.class);
+ }
+
+ private Messages() {
+ }
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/messages/messages.properties b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/messages/messages.properties
new file mode 100644
index 00000000000..cd589f3dd21
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/messages/messages.properties
@@ -0,0 +1,9 @@
+CreateOrShowExistingElementHelper_CreateOrRestoreX=Create or Restore {0}
+CreateOrShowExistingElementHelper_XBetweenTheseElementAlreadyExists={0} between these elements already exists in the model.\nDo you want to restore it?
+CreateOrShowExistingLinkDialog_Create=Create
+CreateOrShowExistingLinkDialog_Ends=Ends
+CreateOrShowExistingLinkDialog_Name=Name
+CreateOrShowExistingLinkDialog_RestoreSelection=Restore Selection
+CreateOrShowExistingLinkDialog_ShowOrCreate=Show or Create
+CreateOrShowExistingLinkDialog_Sources=Sources
+CreateOrShowExistingLinkDialog_Targets=Targets
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/util/EdgeEndsMapper.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/util/EdgeEndsMapper.java
new file mode 100644
index 00000000000..8896b931b04
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/util/EdgeEndsMapper.java
@@ -0,0 +1,107 @@
+/*****************************************************************************
+ * Copyright (c) 2013 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.common.util;
+
+import java.util.Collection;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.uml2.uml.Connector;
+
+/**
+ *
+ * A utils class to map links, with their sources and targets OR with ends, when source/target have no sense for the link (example for
+ * {@link Connector})
+ *
+ */
+public class EdgeEndsMapper {
+
+ /**
+ * the link
+ */
+ private final EObject link;
+
+ /**
+ * the ends of the links
+ */
+ private final Collection<?> ends;
+
+ /**
+ * the targets of the links
+ */
+ private final Collection<?> targets;
+
+ /**
+ * the sources of the links
+ */
+ private final Collection<?> sources;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param link
+ * the represented link
+ * @param ends
+ * the ends for this link (could be <code>null</code>)
+ * @param sources
+ * the sources for this link (could be <code>null</code>)
+ * @param targets
+ * the targets for this link (could be <code>null</code>)
+ */
+ public EdgeEndsMapper(final EObject link, final Collection<?> ends, final Collection<?> sources, final Collection<?> targets) {
+ this.link = link;
+ this.ends = ends;
+ this.targets = targets;
+ this.sources = sources;
+ }
+
+ /**
+ *
+ * @return
+ * the link represented by the instance of this class
+ */
+ public EObject getLink() {
+ return link;
+ }
+
+ /**
+ *
+ * @return
+ * the ends for the links
+ */
+ public Collection<?> getEnds() {
+ return ends;
+ }
+
+ /**
+ *
+ * @return
+ * the targets for the links
+ */
+ public Collection<?> getTargets() {
+ return targets;
+ }
+
+ /**
+ *
+ * @return
+ * the sources for the link
+ */
+ public Collection<?> getSources() {
+ return sources;
+ }
+
+
+}
diff --git a/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/InterfaceRealizationEditHelper.java b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/InterfaceRealizationEditHelper.java
index 99301c68b74..a97a2957c89 100644
--- a/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/InterfaceRealizationEditHelper.java
+++ b/plugins/uml/org.eclipse.papyrus.uml.service.types/src/org/eclipse/papyrus/uml/service/types/helper/InterfaceRealizationEditHelper.java
@@ -17,6 +17,8 @@ package org.eclipse.papyrus.uml.service.types.helper;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest;
import org.eclipse.gmf.runtime.emf.type.core.requests.ReorientRelationshipRequest;
import org.eclipse.papyrus.uml.service.types.command.InterfaceRealizationReorientCommand;
import org.eclipse.uml2.uml.BehavioredClassifier;
@@ -50,21 +52,21 @@ public class InterfaceRealizationEditHelper extends DependencyEditHelper {
@Override
protected boolean canCreate(EObject source, EObject target) {
- if ((source != null) && !(source instanceof BehavioredClassifier)) {
+ if((source != null) && !(source instanceof BehavioredClassifier)) {
return false;
}
-
- if ((target != null) && !(target instanceof Interface)) {
+
+ if((target != null) && !(target instanceof Interface)) {
return false;
}
-
- if ((source != null) && (target != null) && (source == target)) {
+
+ if((source != null) && (target != null) && (source == target)) {
return false;
}
-
+
return true;
}
-
+
/**
* {@inheritDoc}
*/
@@ -72,4 +74,34 @@ public class InterfaceRealizationEditHelper extends DependencyEditHelper {
protected ICommand getReorientRelationshipCommand(ReorientRelationshipRequest req) {
return new InterfaceRealizationReorientCommand(req);
}
+
+ /**
+ *
+ * @see org.eclipse.papyrus.uml.service.types.helper.DirectedRelationshipEditHelper#getCreateRelationshipCommand(org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest)
+ *
+ * @param req
+ * @return
+ * the command to use to create the interface realization link
+ */
+ @Override
+ protected ICommand getCreateRelationshipCommand(CreateRelationshipRequest req) {
+ final ICommand cmd = super.getCreateRelationshipCommand(req);
+ req.setContainer(req.getSource());
+ return cmd;
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelper#configureRequest(org.eclipse.gmf.runtime.emf.type.core.requests.IEditCommandRequest)
+ *
+ * @param request
+ * the request
+ */
+ @Override
+ protected void configureRequest(final IEditCommandRequest request) {
+ super.configureRequest(request);
+ if(request instanceof CreateRelationshipRequest) {
+ ((CreateRelationshipRequest)request).setContainer(((CreateRelationshipRequest)request).getSource());
+ }
+ }
}

Back to the top