Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMickael ADAM2017-06-22 07:05:23 +0000
committervincent lorenzo2017-07-04 09:02:54 +0000
commitc37be71eef998f263b92368aceb9041b4afbc427 (patch)
treec5b9b9077488f1207c53cb9e0c2367c03e1d29d6 /plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common
parent0628737af1be216d0baecc210622299e0887ebad (diff)
downloadorg.eclipse.papyrus-c37be71eef998f263b92368aceb9041b4afbc427.tar.gz
org.eclipse.papyrus-c37be71eef998f263b92368aceb9041b4afbc427.tar.xz
org.eclipse.papyrus-c37be71eef998f263b92368aceb9041b4afbc427.zip
Bug 517679 - [Diagram] Papyrus must provide a way to draw reference link
between elements https://bugs.eclipse.org/bugs/show_bug.cgi?id=517679 Change-Id: I8564c8c0b5e55cee0b3828f466f78c02dab449c9 Signed-off-by: Mickael ADAM <mickael.adam@all4tec.net> Signed-off-by: Vincent Lorenzo <vincent.lorenzo@cea.fr>
Diffstat (limited to 'plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common')
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF2
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/plugin.xml18
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/pom.xml2
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/StereotypePropertyReferenceEdgeEditPart.java51
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AbstractUMLShowHideRelatedLinkEditPolicy.java105
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/StereotypePropertyReferenceEdgeCleaningEditPolicy.java258
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/messages/Messages.java2
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/messages/messages.properties1
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/providers/StereotypePropertyReferenceEdgeEditPartFactory.java57
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/providers/StereotypePropertyReferenceEdgeEditPartProvider.java108
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/providers/StereotypePropertyReferenceEdgeViewFactory.java202
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/providers/StereotypePropertyReferenceEdgeViewProvider.java101
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/IStereotypePropertyReferenceEdgeAdvice.java56
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/ui/dialogs/ShowHideRelatedLinkSelectionDialog.java14
14 files changed, 964 insertions, 13 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF
index 90adedac71d..a3ee53d32eb 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF
@@ -90,7 +90,7 @@ Require-Bundle: org.eclipse.papyrus.extensionpoints.editors;bundle-version="[2.0
org.eclipse.papyrus.infra.internationalization.common;bundle-version="[1.0.0,2.0.0)";visibility:=reexport,
org.eclipse.papyrus.infra.gmfdiag.common;bundle-version="[3.0.0,4.0.0)"
Bundle-Vendor: %providerName
-Bundle-Version: 3.0.0.qualifier
+Bundle-Version: 3.1.0.qualifier
Eclipse-BuddyPolicy: dependent
Bundle-Activator: org.eclipse.papyrus.uml.diagram.common.Activator
Bundle-ManifestVersion: 2
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/plugin.xml b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/plugin.xml
index f8e452634cc..b8df48be71b 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/plugin.xml
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/plugin.xml
@@ -525,4 +525,22 @@
name="Automated Model Completion">
</page>
</extension>
+ <extension
+ point="org.eclipse.gmf.runtime.diagram.ui.editpartProviders">
+ <editpartProvider
+ class="org.eclipse.papyrus.uml.diagram.common.providers.StereotypePropertyReferenceEdgeEditPartProvider">
+ <Priority
+ name="Lowest">
+ </Priority>
+ </editpartProvider>
+ </extension>
+ <extension
+ point="org.eclipse.gmf.runtime.diagram.core.viewProviders">
+ <viewProvider
+ class="org.eclipse.papyrus.uml.diagram.common.providers.StereotypePropertyReferenceEdgeViewProvider">
+ <Priority
+ name="Lowest">
+ </Priority>
+ </viewProvider>
+ </extension>
</plugin>
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/pom.xml b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/pom.xml
index c6db74cc8dc..98b279c0b90 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/pom.xml
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/pom.xml
@@ -7,6 +7,6 @@
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>org.eclipse.papyrus.uml.diagram.common</artifactId>
- <version>3.0.0-SNAPSHOT</version>
+ <version>3.1.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project> \ No newline at end of file
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/StereotypePropertyReferenceEdgeEditPart.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/StereotypePropertyReferenceEdgeEditPart.java
new file mode 100644
index 00000000000..2e30f2199de
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editparts/StereotypePropertyReferenceEdgeEditPart.java
@@ -0,0 +1,51 @@
+/*****************************************************************************
+ * Copyright (c) 2017 CEA LIST, ALL4TEC and others.
+ *
+ * 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:
+ * Mickaël ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and implementation
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.common.editparts;
+
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.gmfdiag.common.editpart.ReferenceEdgeEditPart;
+import org.eclipse.papyrus.uml.diagram.common.editpolicies.StereotypePropertyReferenceEdgeCleaningEditPolicy;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.IStereotypePropertyReferenceEdgeAdvice;
+
+/**
+ * {@link ReferenceEdgeEditPart} for Stereotype property reference
+ *
+ * @author Mickaël ADAM
+ *
+ * @since 3.1
+ */
+public class StereotypePropertyReferenceEdgeEditPart extends ReferenceEdgeEditPart {
+
+ /**
+ * The visual Id.
+ */
+ public static final String VISUAL_ID = IStereotypePropertyReferenceEdgeAdvice.STEREOTYPE_PROPERTY_REFERENCE_EDGE_HINT;
+
+ /**
+ * Constructor.
+ */
+ public StereotypePropertyReferenceEdgeEditPart(final View view) {
+ super(view);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.editpart.ReferenceEdgeEditPart#createDefaultEditPolicies()
+ */
+ protected void createDefaultEditPolicies() {
+ super.createDefaultEditPolicies();
+ installEditPolicy(StereotypePropertyReferenceEdgeCleaningEditPolicy.EDIT_POLICY_KEY, new StereotypePropertyReferenceEdgeCleaningEditPolicy());
+ }
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AbstractUMLShowHideRelatedLinkEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AbstractUMLShowHideRelatedLinkEditPolicy.java
index a17cbe29ffb..7cc57aef977 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AbstractUMLShowHideRelatedLinkEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/AbstractUMLShowHideRelatedLinkEditPolicy.java
@@ -13,19 +13,25 @@
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.common.editpolicies;
+import static org.eclipse.papyrus.uml.diagram.common.stereotype.IStereotypePropertyReferenceEdgeAdvice.STEREOTYPE_PROPERTY_REFERENCE_EDGE_HINT;
+
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
import java.util.Map;
import java.util.Set;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.commands.Command;
@@ -35,10 +41,14 @@ import org.eclipse.gmf.runtime.common.core.command.ICommand;
import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.window.Window;
import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.AbstractShowHideRelatedLinkEditPolicy;
import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.EdgeWithNoSemanticElementRepresentationImpl;
+import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.StereotypePropertyReferenceEdgeRepresentation;
import org.eclipse.papyrus.infra.gmfdiag.common.updater.UpdaterLinkDescriptor;
import org.eclipse.papyrus.infra.gmfdiag.common.utils.Domain2Notation;
import org.eclipse.papyrus.uml.diagram.common.helper.LinkMappingHelper;
@@ -51,7 +61,10 @@ import org.eclipse.uml2.uml.Connector;
import org.eclipse.uml2.uml.Constraint;
import org.eclipse.uml2.uml.DirectedRelationship;
import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Extension;
import org.eclipse.uml2.uml.Relationship;
+import org.eclipse.uml2.uml.Stereotype;
+import org.eclipse.uml2.uml.util.UMLUtil;
/**
@@ -63,6 +76,11 @@ public abstract class AbstractUMLShowHideRelatedLinkEditPolicy extends AbstractS
/**
+ * The qualify name of the stereotype property reference edge element type.
+ */
+ private static final String STEREOTYPE_PROPERTY_REFERENCE_EDGE_ELEMENT_TYPE_QN = "org.eclipse.papyrus.umldi.StereotypePropertyReferenceEdge"; //$NON-NLS-1$
+
+ /**
*
* Constructor.
*
@@ -94,7 +112,7 @@ public abstract class AbstractUMLShowHideRelatedLinkEditPolicy extends AbstractS
* @param domain2NotationMap
* @param linksDescriptors
* @return
- * the command which open a dialog to ask for the user to select visible links, chained with the command to show/hide the links according
+ * the command which open a dialog to ask for the user to select visible links, chained with the command to show/hide the links according
* to the user selection
*/
@Override
@@ -110,7 +128,7 @@ public abstract class AbstractUMLShowHideRelatedLinkEditPolicy extends AbstractS
linkMapping.put(link, createLinkEndMapper((Element) link, current));
} else if (link instanceof EdgeWithNoSemanticElementRepresentationImpl) {
final EObject source = ((EdgeWithNoSemanticElementRepresentationImpl) link).getSource();
- if (source instanceof Comment || source instanceof Constraint) {
+ if (source instanceof Comment || source instanceof Constraint || STEREOTYPE_PROPERTY_REFERENCE_EDGE_HINT.equals(current.getVisualID())) {
linkMapping.put(link, createLinkEndMapper((Element) source, current));
}
}
@@ -133,7 +151,7 @@ public abstract class AbstractUMLShowHideRelatedLinkEditPolicy extends AbstractS
* @param descriptor
* the link descriptor
* @return
- * the collection of link descriptors without some invalid descriptor (we get this case when the link doesn't have source AND target, but
+ * the collection of link descriptors without some invalid descriptor (we get this case when the link doesn't have source AND target, but
* only ends)
*/
@Override
@@ -190,7 +208,7 @@ public abstract class AbstractUMLShowHideRelatedLinkEditPolicy extends AbstractS
/**
*
* @return
- * <code>true</code> if the link is oriented and <code>false</code> if not.
+ * <code>true</code> if the link is oriented and <code>false</code> if not.
* If not, that is to say than {@link LinkMappingHelper} should returns the same values for sources and targets
*/
public static final boolean isAnOrientedLink(final EObject link) {
@@ -202,6 +220,8 @@ public abstract class AbstractUMLShowHideRelatedLinkEditPolicy extends AbstractS
return false;
} else if (link instanceof Comment || link instanceof Constraint) {
return true;
+ } else if (link instanceof StereotypePropertyReferenceEdgeRepresentation) {
+ return true;
}
return false;
}
@@ -214,13 +234,13 @@ public abstract class AbstractUMLShowHideRelatedLinkEditPolicy extends AbstractS
* @param element
* an element
* @return
- * a linkEndsMapper according to this element
+ * a linkEndsMapper according to this element
*/
public static final LinkEndsMapper createLinkEndMapper(final Element element, final UpdaterLinkDescriptor descriptor) {
Collection<?> ends;
Collection<?> sources;
Collection<?> targets;
- if (element instanceof Comment || element instanceof Constraint) {
+ if (element instanceof Comment || element instanceof Constraint || STEREOTYPE_PROPERTY_REFERENCE_EDGE_HINT.equals(descriptor.getVisualID())) {
ends = Collections.emptyList();
sources = Collections.singletonList(descriptor.getSource());
targets = Collections.singletonList(descriptor.getDestination());
@@ -241,7 +261,7 @@ public abstract class AbstractUMLShowHideRelatedLinkEditPolicy extends AbstractS
* @param domain
* the editing domain
* @return
- * the command to open the dialog to choose the link to show
+ * the command to open the dialog to choose the link to show
*/
protected ICommand getOpenDialogCommand(final TransactionalEditingDomain domain, final Collection<EditPart> selectedEditPart, final Map<EditPart, Set<EObject>> availableLinks, final Collection<EObject> initialSelection,
final Map<EObject, LinkEndsMapper> linkMapping) {
@@ -278,4 +298,75 @@ public abstract class AbstractUMLShowHideRelatedLinkEditPolicy extends AbstractS
protected ILabelProvider getLabelProvider() {
return new UMLLabelProvider();
}
+
+ /**
+ * Collects all related links for view.
+ *
+ * @param view
+ * the view
+ * @param domain2NotationMap
+ * the domain2 notation map
+ * @return linkdescriptors
+ */
+ protected Collection<? extends UpdaterLinkDescriptor> collectPartRelatedLinks(final View view, final Domain2Notation domain2NotationMap) {
+ Collection<UpdaterLinkDescriptor> result = new LinkedList<UpdaterLinkDescriptor>();
+ result.addAll(super.collectPartRelatedLinks(view, domain2NotationMap));
+
+ // Get existing outgoing links
+ List<? extends UpdaterLinkDescriptor> outgoingDescriptors = getOutgoingStereotypePropertyReferenceLinks(view);
+ result.addAll(outgoingDescriptors);
+
+ return removeInvalidLinkDescriptor(result);
+ }
+
+ /**
+ * Get Outgoing Stereotype Property Reference Links for the given view.
+ *
+ * @since 3.1
+ */
+ protected List<UpdaterLinkDescriptor> getOutgoingStereotypePropertyReferenceLinks(final View view) {
+ Element element = (Element) view.getElement();
+ LinkedList<UpdaterLinkDescriptor> result = new LinkedList<UpdaterLinkDescriptor>();
+ if (null != element) {
+
+ IElementType type = ElementTypeRegistry.getInstance().getType(STEREOTYPE_PROPERTY_REFERENCE_EDGE_ELEMENT_TYPE_QN);
+
+ // gets all applied stereotype
+ EList<Stereotype> appliedStereotypes = element.getAppliedStereotypes();
+
+ for (Stereotype stereotype : appliedStereotypes) {
+ Stereotype actual = (stereotype == null) ? null : org.eclipse.papyrus.uml.tools.utils.UMLUtil.getAppliedSubstereotype(element, stereotype);
+ EObject stereotypeApplication = (actual == null) ? null : element.getStereotypeApplication(actual);
+
+ EList<EStructuralFeature> eAllStructuralFeatures = stereotypeApplication.eClass().getEAllStructuralFeatures();
+ // For each structural feature if set
+ for (EStructuralFeature eStructuralFeature : eAllStructuralFeatures) {
+ Object featureValue = stereotypeApplication.eGet(eStructuralFeature);
+
+ // If it's not the base feature
+ if (!eStructuralFeature.getName().startsWith(Extension.METACLASS_ROLE_PREFIX)) {
+
+ // gets The stereotype which contains the feature
+ Stereotype stereotypeFeatureContainer = (Stereotype) stereotype.getAllAttributes().stream().filter(p -> p.getName().equals(eStructuralFeature.getName())).findFirst().get().eContainer();
+
+ // Create edge representation
+ if (1 == eStructuralFeature.getUpperBound()) {
+ Element target = UMLUtil.getBaseElement((EObject) featureValue);
+ final StereotypePropertyReferenceEdgeRepresentation edgeRepresentation = new StereotypePropertyReferenceEdgeRepresentation(element, null == target ? (Element) featureValue : target, stereotypeFeatureContainer.getQualifiedName(),
+ eStructuralFeature.getName(), eStructuralFeature.getName());
+ result.add(new UpdaterLinkDescriptor(element, null == target ? (Element) featureValue : target, edgeRepresentation, type, STEREOTYPE_PROPERTY_REFERENCE_EDGE_HINT));
+ } else if (featureValue instanceof List) {
+ for (Object value : (List<?>) featureValue) {
+ Element target = UMLUtil.getBaseElement((EObject) value);
+ final StereotypePropertyReferenceEdgeRepresentation edgeRepresentation = new StereotypePropertyReferenceEdgeRepresentation(element, null == target ? (Element) value : target, stereotypeFeatureContainer.getQualifiedName(),
+ eStructuralFeature.getName(), eStructuralFeature.getName());
+ result.add(new UpdaterLinkDescriptor(element, null == target ? (Element) value : target, edgeRepresentation, type, STEREOTYPE_PROPERTY_REFERENCE_EDGE_HINT));
+ }
+ }
+ }
+ }
+ }
+ }
+ return result;
+ }
}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/StereotypePropertyReferenceEdgeCleaningEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/StereotypePropertyReferenceEdgeCleaningEditPolicy.java
new file mode 100644
index 00000000000..53aad558333
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/StereotypePropertyReferenceEdgeCleaningEditPolicy.java
@@ -0,0 +1,258 @@
+/*****************************************************************************
+ * Copyright (c) 2017 CEA LIST, ALL4TEC and others.
+ *
+ * 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:
+ * Mickaël ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and implementation
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.common.editpolicies;
+
+import static org.eclipse.papyrus.uml.diagram.common.Activator.log;
+import static org.eclipse.papyrus.uml.diagram.common.stereotype.IStereotypePropertyReferenceEdgeAdvice.FEATURE_TO_SET_ANNOTATION_KEY;
+import static org.eclipse.papyrus.uml.diagram.common.stereotype.IStereotypePropertyReferenceEdgeAdvice.STEREOTYPE_PROPERTY_REFERENCE_EDGE_HINT;
+import static org.eclipse.papyrus.uml.diagram.common.stereotype.IStereotypePropertyReferenceEdgeAdvice.STEREOTYPE_QUALIFIED_NAME_ANNOTATION_KEY;
+
+import java.util.Collections;
+import java.util.Map;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.ecore.EAnnotation;
+import org.eclipse.emf.transaction.Transaction;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.workspace.AbstractEMFOperation;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.EditPartViewer;
+import org.eclipse.gef.EditPolicy;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.editpolicies.AbstractEditPolicy;
+import org.eclipse.gmf.runtime.common.core.util.StringStatics;
+import org.eclipse.gmf.runtime.diagram.core.commands.DeleteCommand;
+import org.eclipse.gmf.runtime.diagram.core.listener.DiagramEventBroker;
+import org.eclipse.gmf.runtime.diagram.core.listener.NotificationListener;
+import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramGraphicalViewer;
+import org.eclipse.gmf.runtime.diagram.ui.util.EditPartUtil;
+import org.eclipse.gmf.runtime.notation.Edge;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.uml.tools.listeners.StereotypeElementListener.StereotypeExtensionNotification;
+import org.eclipse.papyrus.uml.tools.utils.ElementUtil;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.Stereotype;
+import org.eclipse.uml2.uml.Type;
+
+/**
+ * Edit policy for stereotype property reference edge which delete edge when related Profile or Stereotype are unapplyed.
+ *
+ * @author Mickael ADAM
+ * @since 3.1
+ */
+public class StereotypePropertyReferenceEdgeCleaningEditPolicy extends AbstractEditPolicy implements EditPolicy, NotificationListener {
+
+ /** The feature related to the edge. */
+ private String featureToSet;
+
+ /** The stereotype qualify name of the source which contains the feature */
+ private String stereotypeQualifyName;
+
+ /**
+ * The Key of this edit policy.
+ */
+ final public static String EDIT_POLICY_KEY = "REMOVE_INVALID_STEREOTYPE_REFERENCE_EDGE_EDIT_POLICY";//$NON-NLS-1$
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.gef.editpolicies.AbstractEditPolicy#activate()
+ */
+ @Override
+ public void activate() {
+ // listen source to know if stereotype
+ Edge edge = (Edge) getHost().getModel();
+
+ EAnnotation eAnnotation = ((View) edge).getEAnnotation(STEREOTYPE_PROPERTY_REFERENCE_EDGE_HINT);
+ if (null != eAnnotation) {
+ stereotypeQualifyName = eAnnotation.getDetails().get(STEREOTYPE_QUALIFIED_NAME_ANNOTATION_KEY);
+ featureToSet = eAnnotation.getDetails().get(FEATURE_TO_SET_ANNOTATION_KEY);
+ }
+
+ DiagramEventBroker diagramEventBroker = getDiagramEventBroker();
+ diagramEventBroker.addNotificationListener(getSourceElement(), this);
+ diagramEventBroker.addNotificationListener(getTargetElement(), this);
+
+ if (null == stereotypeQualifyName || null == featureToSet || !checkSourceStereotype() || !checkTargetStereotype()) {
+ destroyView();
+ }
+
+ }
+
+ /**
+ * Gets the diagram event broker from the editing domain.
+ *
+ * @return the diagram event broker
+ */
+ protected DiagramEventBroker getDiagramEventBroker() {
+ TransactionalEditingDomain theEditingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain();
+ if (theEditingDomain != null) {
+ return DiagramEventBroker.getInstance(theEditingDomain);
+ }
+ return null;
+ }
+
+ /**
+ * Get the target element.
+ */
+ protected Element getTargetElement() {
+ Edge edge = (Edge) getHost().getModel();
+ View target = edge.getTarget();
+ return null == target ? null : (Element) target.getElement();
+ }
+
+ /**
+ * Get the source element.
+ */
+ protected Element getSourceElement() {
+ Edge edge = (Edge) getHost().getModel();
+ View source = edge.getSource();
+ return null == source ? null : (Element) source.getElement();
+ }
+
+ /**
+ * Check the target stereotype.
+ */
+ private boolean checkTargetStereotype() {
+ boolean targetOk = false;
+
+ Stereotype sourceStereotype = getSourceElement().getApplicableStereotype(stereotypeQualifyName);
+ Property attribute = sourceStereotype.getAttribute(featureToSet, null);
+ if (null != attribute) {
+ Type targetType = attribute.getType();
+ if (targetType instanceof Stereotype) {
+ // feature as stereotype reference
+ targetOk = ElementUtil.hasStereotypeApplied(getTargetElement(), targetType.getQualifiedName());
+ } else {
+ targetOk = true;
+ }
+ }
+
+ return targetOk;
+ }
+
+ /**
+ * Check the source stereotype.
+ */
+ public boolean checkSourceStereotype() {
+ return null != getSourceElement() && ElementUtil.hasStereotypeApplied(getSourceElement(), stereotypeQualifyName);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.emf.common.notify.Adapter#notifyChanged(org.eclipse.emf.common.notify.Notification)
+ */
+ @Override
+ public void notifyChanged(final Notification notification) {
+
+ if (notification instanceof StereotypeExtensionNotification) {
+ if (getSourceElement() != null && getTargetElement() != null) {
+ if (null == stereotypeQualifyName || null == featureToSet || !checkSourceStereotype() || !checkTargetStereotype()) {
+ destroyView();
+ }
+ }
+ }
+ }
+
+ /**
+ * Returns a {@link Command} to delete the supplied {@link View}.
+ *
+ * @param view
+ * view to delete
+ * @return the command that destroys the specified view
+ */
+ protected Command getDeleteViewCommand(final View view) {
+ TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain();
+ return new ICommandProxy(new DeleteCommand(editingDomain, view));
+ }
+
+ /**
+ * Destroy obsolete view.
+ */
+ protected void destroyView() {
+ EditPart host = getHost();
+ View view = (View) host.getModel();
+ if (host instanceof IGraphicalEditPart) {
+ Command deleteViewCommand = getDeleteViewCommand(view);
+ if (deleteViewCommand != null && deleteViewCommand.canExecute()) {
+ executeCommand(deleteViewCommand);
+ }
+ }
+ }
+
+ /**
+ * Executes the supplied command inside an <code>unchecked action</code>
+ *
+ * @param cmd
+ * command that can be executed (i.e., cmd.canExecute() == true)
+ */
+ protected void executeCommand(final Command cmd) {
+ Map<String, Boolean> options = null;
+ EditPart ep = getHost();
+ boolean isActivating = true;
+ // use the viewer to determine if we are still initializing the diagram
+ // do not use the DiagramEditPart.isActivating since
+ // ConnectionEditPart's
+ // parent will not be a diagram edit part
+ EditPartViewer viewer = ep.getViewer();
+ if (viewer instanceof DiagramGraphicalViewer) {
+ isActivating = ((DiagramGraphicalViewer) viewer).isInitializing();
+ }
+
+ if (isActivating || !EditPartUtil.isWriteTransactionInProgress((IGraphicalEditPart) getHost(), false, false)) {
+ options = Collections.singletonMap(Transaction.OPTION_UNPROTECTED, Boolean.TRUE);
+ }
+
+ AbstractEMFOperation operation = new AbstractEMFOperation(((IGraphicalEditPart) getHost()).getEditingDomain(), StringStatics.BLANK, options) {
+
+ @Override
+ protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ cmd.execute();
+ return Status.OK_STATUS;
+ }
+
+ @Override
+ protected IStatus doUndo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ cmd.undo();
+ return Status.OK_STATUS;
+ }
+ };
+ try {
+ operation.execute(new NullProgressMonitor(), null);
+ } catch (ExecutionException e) {
+ log.error(e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.gef.editpolicies.AbstractEditPolicy#deactivate()
+ */
+ @Override
+ public void deactivate() {
+ getDiagramEventBroker().removeNotificationListener(getSourceElement(), this);
+ getDiagramEventBroker().removeNotificationListener(getTargetElement(), this);
+ }
+
+}
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
index 86579c5325b..dc570a910dc 100644
--- 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
@@ -34,6 +34,8 @@ public class Messages extends NLS {
public static String ShowHideRelatedLinkSelectionDialog_Sources;
+ public static String ShowHideRelatedLinkSelectionDialog_StereotypePropertyReferenceLabel;
+
public static String ShowHideRelatedLinkSelectionDialog_Ends;
public static String ShowHideRelatedLinkSelectionDialog_LinksToDisplay;
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
index 365038c99f7..7986221e649 100644
--- 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
@@ -15,6 +15,7 @@ ShowHideRelatedLinkSelectionDialog_CommentLink=Comment Link
ShowHideRelatedLinkSelectionDialog_ConstraintLink=Constraint Link
ShowHideRelatedLinkSelectionDialog_Targets=Targets
ShowHideRelatedLinkSelectionDialog_Sources=Sources
+ShowHideRelatedLinkSelectionDialog_StereotypePropertyReferenceLabel=Stereotype Property Reference
ShowHideRelatedLinkSelectionDialog_Ends=Ends
ShowHideRelatedLinkSelectionDialog_LinksToDisplay=Links To Display
ShowHideRelatedLinkSelectionDialog_LinkKind=Link Kind
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/providers/StereotypePropertyReferenceEdgeEditPartFactory.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/providers/StereotypePropertyReferenceEdgeEditPartFactory.java
new file mode 100644
index 00000000000..016c8f8646e
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/providers/StereotypePropertyReferenceEdgeEditPartFactory.java
@@ -0,0 +1,57 @@
+/*****************************************************************************
+ * Copyright (c) 2017 CEA LIST, ALL4TEC and others.
+ *
+ * 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:
+ * Mickaël ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and implementation
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.common.providers;
+
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.EditPartFactory;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.gmfdiag.common.editpart.ReferenceEdgeEditPart;
+import org.eclipse.papyrus.infra.gmfdiag.common.editpart.ReferenceEdgeNameEditPart;
+import org.eclipse.papyrus.uml.diagram.common.editparts.StereotypePropertyReferenceEdgeEditPart;
+
+/**
+ * {@link EditPartFactory} for Papyrus generic edit parts.
+ *
+ * @author Mickaël ADAM
+ *
+ * @since 3.1
+ */
+public class StereotypePropertyReferenceEdgeEditPartFactory implements EditPartFactory {
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.gef.EditPartFactory#createEditPart(org.eclipse.gef.EditPart, java.lang.Object)
+ */
+ @Override
+ public EditPart createEditPart(final EditPart context, final Object model) {
+ EditPart editPart = null;
+ if (model instanceof View) {
+ View view = (View) model;
+ switch (view.getType()) {
+
+ case ReferenceEdgeEditPart.VISUAL_ID:
+ editPart = new ReferenceEdgeEditPart(view);
+ break;
+ case StereotypePropertyReferenceEdgeEditPart.VISUAL_ID:
+ editPart = new StereotypePropertyReferenceEdgeEditPart(view);
+ break;
+ case ReferenceEdgeNameEditPart.VISUAL_ID:
+ editPart = new ReferenceEdgeNameEditPart(view);
+ break;
+ }
+ }
+ return editPart;
+ }
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/providers/StereotypePropertyReferenceEdgeEditPartProvider.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/providers/StereotypePropertyReferenceEdgeEditPartProvider.java
new file mode 100644
index 00000000000..fb44e1b737c
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/providers/StereotypePropertyReferenceEdgeEditPartProvider.java
@@ -0,0 +1,108 @@
+/*****************************************************************************
+ * Copyright (c) 2017 CEA LIST, ALL4TEC and others.
+ *
+ * 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:
+ * Mickaël ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and implementation
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.common.providers;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.gmfdiag.common.providers.DefaultEditPartProvider;
+import org.eclipse.papyrus.infra.gmfdiag.common.structure.DiagramStructure;
+
+/**
+ * EditPartProvider for papyrus generic edit part which are not associated to a diagram.
+ *
+ * @author Mickaël ADAM
+ *
+ * @since 3.1
+ */
+public class StereotypePropertyReferenceEdgeEditPartProvider extends DefaultEditPartProvider {
+
+ /**
+ * The expected model id for this DefaultEditPartProvider.
+ */
+ private static final String EXPECTED_MODEL_ID = "PapyrusEditPartProviderModelID";//$NON-NLS-1$
+
+ /**
+ * Constructor.
+ */
+ public StereotypePropertyReferenceEdgeEditPartProvider() {
+ super(new StereotypePropertyReferenceEdgeEditPartFactory(), new DiagramStructureExtension(), EXPECTED_MODEL_ID);
+ }
+
+ /**
+ * Empty {@link DiagramStructure} to permits to use {@link DefaultEditPartProvider} in all diagram.
+ *
+ * @author Mickael ADAM
+ */
+ private static final class DiagramStructureExtension extends DiagramStructure {
+ /**
+ * {@inheritDoc
+ *
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.structure.DiagramStructure#isSemanticLeafVisualID(java.lang.String)
+ */
+ @Override
+ public boolean isSemanticLeafVisualID(final String visualID) {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc
+ *
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.structure.DiagramStructure#isCompartmentVisualID(java.lang.String)
+ */
+ @Override
+ public boolean isCompartmentVisualID(final String visualID) {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc
+ *
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.structure.DiagramStructure#getVisualID(org.eclipse.gmf.runtime.notation.View)
+ */
+ @Override
+ public String getVisualID(final View view) {
+ return view.getType();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.structure.DiagramStructure#getNodeVisualID(org.eclipse.gmf.runtime.notation.View, org.eclipse.emf.ecore.EObject)
+ */
+ @Override
+ public String getNodeVisualID(final View containerView, final EObject domainElement) {
+ return null;
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.structure.DiagramStructure#getModelID(org.eclipse.gmf.runtime.notation.View)
+ */
+ @Override
+ public String getModelID(final View view) {
+ return EXPECTED_MODEL_ID;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.structure.DiagramStructure#checkNodeVisualID(org.eclipse.gmf.runtime.notation.View, org.eclipse.emf.ecore.EObject, java.lang.String)
+ */
+ @Override
+ public boolean checkNodeVisualID(final View containerView, final EObject domainElement, final String candidate) {
+ return false;
+ }
+ }
+
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/providers/StereotypePropertyReferenceEdgeViewFactory.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/providers/StereotypePropertyReferenceEdgeViewFactory.java
new file mode 100644
index 00000000000..912389efb2c
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/providers/StereotypePropertyReferenceEdgeViewFactory.java
@@ -0,0 +1,202 @@
+/*****************************************************************************
+ * Copyright (c) 2017 CEA LIST, ALL4TEC and others.
+ *
+ * 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:
+ * Mickaël ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and implementation
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.common.providers;
+
+import static org.eclipse.papyrus.uml.diagram.common.stereotype.IStereotypePropertyReferenceEdgeAdvice.EDGE_LABEL_ANNOTATION_KEY;
+import static org.eclipse.papyrus.uml.diagram.common.stereotype.IStereotypePropertyReferenceEdgeAdvice.FEATURE_TO_SET_ANNOTATION_KEY;
+import static org.eclipse.papyrus.uml.diagram.common.stereotype.IStereotypePropertyReferenceEdgeAdvice.STEREOTYPE_PROPERTY_REFERENCE_EDGE_HINT;
+import static org.eclipse.papyrus.uml.diagram.common.stereotype.IStereotypePropertyReferenceEdgeAdvice.STEREOTYPE_QUALIFIED_NAME_ANNOTATION_KEY;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.emf.ecore.EAnnotation;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EcoreFactory;
+import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
+import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
+import org.eclipse.gmf.runtime.diagram.core.view.factories.ViewFactory;
+import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelperAdvice;
+import org.eclipse.gmf.runtime.notation.Connector;
+import org.eclipse.gmf.runtime.notation.DecorationNode;
+import org.eclipse.gmf.runtime.notation.Edge;
+import org.eclipse.gmf.runtime.notation.Location;
+import org.eclipse.gmf.runtime.notation.Node;
+import org.eclipse.gmf.runtime.notation.NotationFactory;
+import org.eclipse.gmf.runtime.notation.RelativeBendpoints;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.gmf.runtime.notation.datatype.RelativeBendpoint;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.papyrus.infra.gmfdiag.common.editpart.ReferenceEdgeNameEditPart;
+import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.StereotypePropertyReferenceEdgeRepresentation;
+import org.eclipse.papyrus.infra.gmfdiag.common.updater.UpdaterLinkDescriptor;
+import org.eclipse.papyrus.uml.diagram.common.helper.PreferenceInitializerForElementHelper;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.IStereotypePropertyReferenceEdgeAdvice;
+
+/**
+ * {@link ViewFactory} for stereotype property reference edge.
+ *
+ * @author Mickael ADAM
+ *
+ * @since 3.1
+ */
+public class StereotypePropertyReferenceEdgeViewFactory implements ViewFactory {
+
+
+ /**
+ * Constructor.
+ */
+ public StereotypePropertyReferenceEdgeViewFactory() {
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.gmf.runtime.diagram.core.view.factories.ViewFactory#createView(org.eclipse.core.runtime.IAdaptable, org.eclipse.gmf.runtime.notation.View, java.lang.String, int, boolean, org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint)
+ */
+ @Override
+ public View createView(final IAdaptable semanticAdapter, final View containerView, final String semanticHint, final int index, final boolean persisted, final PreferencesHint preferencesHint) {
+ Edge view = null;
+ if (semanticHint.equals(STEREOTYPE_PROPERTY_REFERENCE_EDGE_HINT)) {
+ view = createStereotypePropertyReferenceEdge(semanticAdapter, containerView, index, persisted, preferencesHint);
+ }
+ return view;
+ }
+
+ /**
+ * Create the stereotype property reference edge.
+ */
+ @SuppressWarnings("unchecked")
+ public Edge createStereotypePropertyReferenceEdge(final IAdaptable semanticAdapter, final View containerView, final int index, final boolean persisted, final PreferencesHint preferencesHint) {
+ IEditHelperAdvice[] advices = ElementTypeRegistry.getInstance().getEditHelperAdvice(semanticAdapter.getAdapter(IElementType.class));
+ Connector edge = NotationFactory.eINSTANCE.createConnector();
+ edge.getStyles().add(NotationFactory.eINSTANCE.createFontStyle());
+ RelativeBendpoints bendpoints = NotationFactory.eINSTANCE.createRelativeBendpoints();
+ List<RelativeBendpoint> points = new ArrayList<RelativeBendpoint>(2);
+ points.add(new RelativeBendpoint());
+ points.add(new RelativeBendpoint());
+ bendpoints.setPoints(points);
+ edge.setBendpoints(bendpoints);
+ ViewUtil.insertChildView(containerView, edge, index, persisted);
+ edge.setType(STEREOTYPE_PROPERTY_REFERENCE_EDGE_HINT);
+
+ // Reference link is not attached to a semantic element
+ edge.setElement(null);
+
+ Node referenceLink_NameLabel = createLabel(edge, ReferenceEdgeNameEditPart.VISUAL_ID);
+ referenceLink_NameLabel.setLayoutConstraint(NotationFactory.eINSTANCE.createLocation());
+ Location referenceLink_NameLabel_Location = (Location) referenceLink_NameLabel.getLayoutConstraint();
+ referenceLink_NameLabel_Location.setX(0);
+ referenceLink_NameLabel_Location.setY(20);
+
+ StereotypePropertyReferenceEdgeRepresentation linkDescriptor = getStereotypePropertyReferenceEdgeRepresentation(advices, semanticAdapter);
+
+ // set annotation
+ EAnnotation eAnnotation = createAnnotation(linkDescriptor);
+ if (null != eAnnotation) {
+ edge.getEAnnotations().add(eAnnotation);
+ }
+
+ // initializePreferences
+ final IPreferenceStore prefStore = (IPreferenceStore) preferencesHint.getPreferenceStore();
+ PreferenceInitializerForElementHelper.initFontStyleFromPrefs(edge, prefStore, getStereotypePropertyReferenceEdgeId(linkDescriptor));
+ PreferenceInitializerForElementHelper.initLabelVisibilityFromPrefs(edge, prefStore, getStereotypePropertyReferenceEdgeId(linkDescriptor));
+
+ return edge;
+ }
+
+ /**
+ * Create the annotation for the edge.
+ *
+ * @param edgeDescriptor
+ * The edge descriptor
+ * @return the created annotation.
+ */
+ protected EAnnotation createAnnotation(final StereotypePropertyReferenceEdgeRepresentation edgeDescriptor) {
+ EAnnotation eAnnotation = null;
+ if (null != edgeDescriptor) {
+ eAnnotation = EcoreFactory.eINSTANCE.createEAnnotation();
+ eAnnotation.setSource(STEREOTYPE_PROPERTY_REFERENCE_EDGE_HINT);
+ eAnnotation.getDetails().put(FEATURE_TO_SET_ANNOTATION_KEY, edgeDescriptor.getFeatureToSet());
+ eAnnotation.getDetails().put(STEREOTYPE_QUALIFIED_NAME_ANNOTATION_KEY, edgeDescriptor.getStereotypeQualifiedName());
+ eAnnotation.getDetails().put(EDGE_LABEL_ANNOTATION_KEY, edgeDescriptor.getEdgeLabel());
+ }
+ return eAnnotation;
+ }
+
+ /**
+ * Get the stereotype property reference edge representation.
+ *
+ * @param advices
+ * The list of advices where to look
+ * @param semanticAdapter
+ * The semantic adapter to look at if not
+ */
+ protected StereotypePropertyReferenceEdgeRepresentation getStereotypePropertyReferenceEdgeRepresentation(final IEditHelperAdvice[] advices, final IAdaptable semanticAdapter) {
+ StereotypePropertyReferenceEdgeRepresentation linkDescriptor = getStereotypePropertyReferenceEdgeRepresentation(advices);
+
+ // If no advice to get information open dialog
+ if (null == linkDescriptor) {
+ UpdaterLinkDescriptor UpdaterLinkDescriptor = semanticAdapter.getAdapter(UpdaterLinkDescriptor.class);
+ EObject modelElement = UpdaterLinkDescriptor.getModelElement();
+ if (modelElement instanceof StereotypePropertyReferenceEdgeRepresentation) {
+ linkDescriptor = (StereotypePropertyReferenceEdgeRepresentation) modelElement;
+ }
+ }
+ return linkDescriptor;
+ }
+
+ /**
+ * Create A {@link DecorationNode} label.
+ *
+ * @param owner
+ * The owner of the label.
+ * @param hint
+ * The hint of the label.
+ * @return the created label.
+ */
+ protected Node createLabel(final View owner, final String hint) {
+ DecorationNode rv = NotationFactory.eINSTANCE.createDecorationNode();
+ rv.setType(hint);
+ ViewUtil.insertChildView(owner, rv, ViewUtil.APPEND, true);
+ return rv;
+ }
+
+ /**
+ * Get the {@link StereotypePropertyReferenceEdgeRepresentation} from an array of of {@link IEditHelperAdvice}.
+ */
+ protected StereotypePropertyReferenceEdgeRepresentation getStereotypePropertyReferenceEdgeRepresentation(final IEditHelperAdvice[] advices) {
+ StereotypePropertyReferenceEdgeRepresentation descriptor = null;
+ for (IEditHelperAdvice advice : advices) {
+ if (advice instanceof IStereotypePropertyReferenceEdgeAdvice) {
+ String stereotypeQualifyName = ((IStereotypePropertyReferenceEdgeAdvice) advice).getStereotypeQualifiedName();
+ String featureToSet = ((IStereotypePropertyReferenceEdgeAdvice) advice).getFeatureToSet();
+ String linkLabel = ((IStereotypePropertyReferenceEdgeAdvice) advice).getEdgeLabel();
+ if (null != stereotypeQualifyName && null != featureToSet) {
+ descriptor = new StereotypePropertyReferenceEdgeRepresentation(null, null, stereotypeQualifyName, featureToSet, linkLabel);
+ }
+ }
+ }
+ return descriptor;
+ }
+
+ /**
+ * Get stereotype property reference link Id from {@link StereotypePropertyReferenceEdgeRepresentation}.
+ */
+ protected String getStereotypePropertyReferenceEdgeId(final StereotypePropertyReferenceEdgeRepresentation linkDescriptor) {
+ return linkDescriptor.getStereotypeQualifiedName() + "::" + linkDescriptor.getFeatureToSet();//$NON-NLS-1$
+ }
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/providers/StereotypePropertyReferenceEdgeViewProvider.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/providers/StereotypePropertyReferenceEdgeViewProvider.java
new file mode 100644
index 00000000000..fabd9a8c6ae
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/providers/StereotypePropertyReferenceEdgeViewProvider.java
@@ -0,0 +1,101 @@
+/*****************************************************************************
+ * Copyright (c) 2017 CEA LIST, ALL4TEC and others.
+ *
+ * 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:
+ * Mickaël ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and implementation
+ *****************************************************************************/
+
+package org.eclipse.papyrus.uml.diagram.common.providers;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.architecture.representation.PapyrusRepresentationKind;
+import org.eclipse.papyrus.infra.gmfdiag.common.providers.CustomAbstractViewProvider;
+import org.eclipse.papyrus.infra.gmfdiag.common.providers.GraphicalTypeRegistry;
+import org.eclipse.papyrus.infra.gmfdiag.common.utils.DiagramUtils;
+import org.eclipse.papyrus.infra.gmfdiag.representation.PapyrusDiagram;
+import org.eclipse.papyrus.infra.viewpoints.policy.ViewPrototype;
+import org.eclipse.papyrus.uml.diagram.common.stereotype.IStereotypePropertyReferenceEdgeAdvice;
+
+/**
+ * View provider for papyrus view used in all diagram.
+ *
+ * @author Mickael ADAM
+ *
+ * @since 3.1
+ */
+public class StereotypePropertyReferenceEdgeViewProvider extends CustomAbstractViewProvider {
+
+ /** Map containing node view types supported by this provider. */
+ protected Map<String, Class<?>> nodeMap = new HashMap<String, Class<?>>();
+
+ /** Map containing edge view types supported by this provider. */
+ protected Map<String, Class<?>> edgeMap = new HashMap<String, Class<?>>();
+
+ /**
+ * Constructor.
+ */
+ public StereotypePropertyReferenceEdgeViewProvider() {
+ this.registry = new PapyrusGraphicalTypeRegistry();
+ edgeMap.put(IStereotypePropertyReferenceEdgeAdvice.STEREOTYPE_PROPERTY_REFERENCE_EDGE_HINT, StereotypePropertyReferenceEdgeViewFactory.class);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * We check that it's a Papyrus diagram.
+ *
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.providers.CustomAbstractViewProvider#isRelevantDiagram(org.eclipse.gmf.runtime.notation.Diagram)
+ */
+ @Override
+ protected boolean isRelevantDiagram(final Diagram diagram) {
+ ViewPrototype prototype = DiagramUtils.getPrototype(diagram);
+ PapyrusRepresentationKind representationKind = null;
+ if (prototype != null) {
+ representationKind = prototype.getRepresentationKind();
+ }
+ return representationKind instanceof PapyrusDiagram;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.providers.AbstractViewProvider#getNodeViewClass(org.eclipse.core.runtime.IAdaptable, org.eclipse.gmf.runtime.notation.View, java.lang.String)
+ */
+ @Override
+ protected Class<?> getNodeViewClass(final IAdaptable semanticAdapter, final View containerView, final String graphicalType) {
+ return nodeMap.get(graphicalType);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.providers.AbstractViewProvider#getEdgeViewClass(org.eclipse.core.runtime.IAdaptable, org.eclipse.gmf.runtime.notation.View, java.lang.String)
+ */
+ @Override
+ protected Class<?> getEdgeViewClass(final IAdaptable semanticAdapter, final View containerView, final String graphicalType) {
+ return edgeMap.get(graphicalType);
+ }
+
+ /**
+ * Graphical Type Registry specific to this view provider.
+ */
+ public class PapyrusGraphicalTypeRegistry extends GraphicalTypeRegistry {
+ /**
+ * Constructor.
+ */
+ public PapyrusGraphicalTypeRegistry() {
+ knownEdges.add(IStereotypePropertyReferenceEdgeAdvice.STEREOTYPE_PROPERTY_REFERENCE_EDGE_HINT);
+ }
+ }
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/IStereotypePropertyReferenceEdgeAdvice.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/IStereotypePropertyReferenceEdgeAdvice.java
new file mode 100644
index 00000000000..7115b65bf71
--- /dev/null
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/stereotype/IStereotypePropertyReferenceEdgeAdvice.java
@@ -0,0 +1,56 @@
+/*****************************************************************************
+ * Copyright (c) 2017 CEA LIST, ALL4TEC and others.
+ *
+ * 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:
+ * Mickaël ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.common.stereotype;
+
+/**
+ * Interface for stereotype property reference edge advice. It include used keywords.
+ *
+ * @author Mickaël ADAM
+ *
+ * @since 3.1
+ */
+public interface IStereotypePropertyReferenceEdgeAdvice {
+
+ /** The Constant STEREOTYPE_PROPERTY_REFERENCE_EDGE_HINT. */
+ public static final String STEREOTYPE_PROPERTY_REFERENCE_EDGE_HINT = "StereotypePropertyReferenceEdge";//$NON-NLS-1$
+
+ /** The Constant STEREOTYPE_QUALIFY_NAME_ANNOTATION_KEY. */
+ public static final String STEREOTYPE_QUALIFIED_NAME_ANNOTATION_KEY = "stereotypeQualifiedName";//$NON-NLS-1$
+
+ /** The Constant FEATURE_TO_SET_ANNOTATION_KEY. */
+ public static final String FEATURE_TO_SET_ANNOTATION_KEY = "featureToSet";//$NON-NLS-1$
+
+ /** The Constant EDGE_LABEL_ANNOTATION_KEY. */
+ public static final String EDGE_LABEL_ANNOTATION_KEY = "edgeLabel";//$NON-NLS-1$
+
+ /**
+ * Get the feature to set.
+ *
+ * @return the feature name to set as a {@link String}.
+ */
+ public String getFeatureToSet();
+
+ /**
+ * Get the stereotype qualify name.
+ *
+ * @return the stereotype qualify name of the source to set as a {@link String}.
+ */
+ public String getStereotypeQualifiedName();
+
+ /**
+ * Get the edge label.
+ *
+ * @return the edge label to display as a {@link String}.
+ */
+ public String getEdgeLabel();
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/ui/dialogs/ShowHideRelatedLinkSelectionDialog.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/ui/dialogs/ShowHideRelatedLinkSelectionDialog.java
index 8dbbc9eae41..d7835d0a881 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/ui/dialogs/ShowHideRelatedLinkSelectionDialog.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/ui/dialogs/ShowHideRelatedLinkSelectionDialog.java
@@ -1,5 +1,5 @@
/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
+ * Copyright (c) 2017 CEA LIST.
*
*
* All rights reserved. This program and the accompanying materials
@@ -9,6 +9,7 @@
*
* Contributors:
* Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ * Mickaël ADAM (ALL4TEC) - mickael.adam@all4tec.net - Bug 517679
*
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.common.ui.dialogs;
@@ -37,6 +38,7 @@ import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.EdgeWithNoSemanticElementRepresentationImpl;
+import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.StereotypePropertyReferenceEdgeRepresentation;
import org.eclipse.papyrus.uml.diagram.common.dialogs.AbstractCheckedTreeColumnViewerSelectionDialog;
import org.eclipse.papyrus.uml.diagram.common.messages.Messages;
import org.eclipse.papyrus.uml.diagram.common.util.LinkEndsMapper;
@@ -59,7 +61,7 @@ public class ShowHideRelatedLinkSelectionDialog extends AbstractCheckedTreeColum
/**
* the width for the first column
*/
- private final int FIRST_COLUMN_WIDTH = 180;
+ private final int FIRST_COLUMN_WIDTH = 200;
/**
* the width for the others columns
@@ -186,7 +188,7 @@ public class ShowHideRelatedLinkSelectionDialog extends AbstractCheckedTreeColum
/**
*
* @return
- * the checkedStateListener to use
+ * the checkedStateListener to use
*/
protected ICheckStateListener getOrCreateCheckStateListener() {
if (this.checkedStateListener == null) {
@@ -269,7 +271,7 @@ public class ShowHideRelatedLinkSelectionDialog extends AbstractCheckedTreeColum
/**
*
* @return
- * the checkedStateProvider to use for this dialog
+ * the checkedStateProvider to use for this dialog
*/
protected ICheckStateProvider getOrCreateCheckStateProvider() {
if (this.checkedStateProvider == null) {
@@ -367,6 +369,8 @@ public class ShowHideRelatedLinkSelectionDialog extends AbstractCheckedTreeColum
}
if (source instanceof Constraint) {
return Messages.ShowHideRelatedLinkSelectionDialog_ConstraintLink;
+ } else if (element instanceof StereotypePropertyReferenceEdgeRepresentation) {
+ return Messages.ShowHideRelatedLinkSelectionDialog_StereotypePropertyReferenceLabel;
}
}
if (element instanceof EObject) {
@@ -427,6 +431,8 @@ public class ShowHideRelatedLinkSelectionDialog extends AbstractCheckedTreeColum
return Messages.ShowHideRelatedLinkSelectionDialog_CommentLink;
} else if (source instanceof Constraint) {
return Messages.ShowHideRelatedLinkSelectionDialog_ConstraintLink;
+ } else if (element instanceof StereotypePropertyReferenceEdgeRepresentation) {
+ return ((StereotypePropertyReferenceEdgeRepresentation) element).getStereotypeQualifiedName() + "::" + ((StereotypePropertyReferenceEdgeRepresentation) element).getFeatureToSet();//$NON-NLS-1$
}
}
return labelProvider.getText(element);

Back to the top