Bug 482689: [SysML][Parametric] when drop constraint property, the
compartment constraint cannot be displayed
https://bugs.eclipse.org/bugs/show_bug.cgi?id=482689

Change-Id: I86e83184cad0aa3c2e3eec4292d4146f815b202f
diff --git a/diagram/org.eclipse.papyrus.sysml14.diagram.parametric/plugin.xml b/diagram/org.eclipse.papyrus.sysml14.diagram.parametric/plugin.xml
index 607cb28..d5572c5 100644
--- a/diagram/org.eclipse.papyrus.sysml14.diagram.parametric/plugin.xml
+++ b/diagram/org.eclipse.papyrus.sysml14.diagram.parametric/plugin.xml
@@ -55,4 +55,10 @@
          strategy="org.eclipse.papyrus.sysml14.diagram.parametric.dnd.ConstraintDropStrategy">
    </strategy>
 </extension>
+<extension
+      point="org.eclipse.papyrus.infra.gmfdiag.dnd.dropStrategy">
+   <strategy
+         strategy="org.eclipse.papyrus.sysml14.diagram.parametric.dnd.ConstraintPropertyDropStrategy">
+   </strategy>
+</extension>
 </plugin>
diff --git a/diagram/org.eclipse.papyrus.sysml14.diagram.parametric/src/org/eclipse/papyrus/sysml14/diagram/parametric/dnd/ConstraintPropertyDropStrategy.java b/diagram/org.eclipse.papyrus.sysml14.diagram.parametric/src/org/eclipse/papyrus/sysml14/diagram/parametric/dnd/ConstraintPropertyDropStrategy.java
new file mode 100644
index 0000000..7a44549
--- /dev/null
+++ b/diagram/org.eclipse.papyrus.sysml14.diagram.parametric/src/org/eclipse/papyrus/sysml14/diagram/parametric/dnd/ConstraintPropertyDropStrategy.java
@@ -0,0 +1,108 @@
+/*****************************************************************************
+ * Copyright (c) 2015 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:
+ *  Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.sysml14.diagram.parametric.dnd;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
+import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry;
+import org.eclipse.gmf.runtime.emf.type.core.ISpecializationType;
+import org.eclipse.papyrus.infra.gmfdiag.dnd.policy.DropStrategyManager;
+import org.eclipse.papyrus.infra.gmfdiag.dnd.strategy.ExpansionElementDropStrategy;
+import org.eclipse.papyrus.sysml14.service.types.util.SysMLServiceTypeUtil;
+import org.eclipse.papyrus.uml.diagram.composite.edit.parts.ClassCompositeCompartmentEditPart;
+
+/**
+ * This strategy is a specialization in order to be able to drop Constraint inside constraint Property
+ *
+ */
+public class ConstraintPropertyDropStrategy extends ExpansionElementDropStrategy {
+
+
+	/**
+	 * ID tje internal Structure of a block
+	 */
+	private static final String INTERNAL_STRUCTURE_ID = "" + ClassCompositeCompartmentEditPart.VISUAL_ID;
+
+	@Override
+	public String getLabel() {
+		return "Constraint Property drag and drop inside parametric diagram";
+	}
+
+	@Override
+	public String getID() {
+		return "org.eclipse.papyrus.sysml14.diagram.parametric.dnd.ConstraintPropertyDropStrategy." + DropStrategyManager.DEFAULT_STRATEGY_KEY;
+	}
+
+	@Override
+	public String getDescription() {
+		return "This strategy is is a specialization in order to be able to drop a Constraint Property inside Parametric diagram.";
+	}
+
+
+
+	@Override
+	public Command doGetCommand(Request request, final EditPart targetEditPart) {
+
+		CompositeCommand cc = new CompositeCommand(getLabel());
+		if (targetEditPart instanceof GraphicalEditPart) {
+			IGraphicalEditPart graphicalEditPart = (IGraphicalEditPart) targetEditPart;
+			List<EObject> sourceElements = getSourceEObjects(request);
+			if (sourceElements.size() == 0) {
+				return null;
+			}
+
+			final List<EObject> valuesToAdd = new ArrayList<EObject>(sourceElements.size());
+			final ISpecializationType constraintPropertyElementType = (ISpecializationType) ElementTypeRegistry.getInstance().getType(SysMLServiceTypeUtil.ORG_ECLIPSE_PAPYRUS_SYSML14_CONSTRAINTPROPERTY);
+			// the target must me a constraint property
+			if (INTERNAL_STRUCTURE_ID.equals(graphicalEditPart.getNotationView().getType())) {
+
+				for (EObject sourceElement : sourceElements) {
+					if ((constraintPropertyElementType.getMatcher().matches(sourceElement))) {
+						addCommandDrop(targetEditPart, cc, valuesToAdd, sourceElement, (ISpecializationType) ElementTypeRegistry.getInstance().getType("org.eclipse.papyrus.SysML14.ConstraintPropertyComposite"));
+					}
+
+				}
+			}
+		}
+		return cc.canExecute() ? new ICommandProxy(cc.reduce()) : null;
+	}
+
+
+	/**
+	 * @see org.eclipse.papyrus.infra.gmfdiag.dnd.strategy.ExpansionElementDropStrategy#getPriority()
+	 *
+	 * @return
+	 */
+	@Override
+	public int getPriority() {
+		return -1000;
+	}
+
+	@Override
+	public String getCategoryID() {
+		return "org.eclipse.papyrus.sysml14.diagram.parametric";
+	}
+
+	@Override
+	public String getCategoryLabel() {
+		return "Constraint property drag and drop";
+	}
+}
\ No newline at end of file