From 493c486be6044c250fda32ec782103cf3a9e7bdc Mon Sep 17 00:00:00 2001 From: Camille Letavernier Date: Mon, 22 Feb 2016 13:52:00 +0100 Subject: 475569: [Composite Diagram] DnD strategy mechanism should be used to create PropertyPart https://bugs.eclipse.org/bugs/show_bug.cgi?id=475569 Change-Id: I9e8ca9f0ae9f97d445939fcc6eda52f7d12d6512 Signed-off-by: Camille Letavernier --- ...ropertyToStructuredCompartmentDropStrategy.java | 39 +++++++++++++++------- 1 file changed, 27 insertions(+), 12 deletions(-) (limited to 'plugins/uml') diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/classifier/ClassifierAsPropertyToStructuredCompartmentDropStrategy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/classifier/ClassifierAsPropertyToStructuredCompartmentDropStrategy.java index 6542c52eb2a..664faf92418 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/classifier/ClassifierAsPropertyToStructuredCompartmentDropStrategy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/classifier/ClassifierAsPropertyToStructuredCompartmentDropStrategy.java @@ -1,6 +1,6 @@ /***************************************************************************** * Copyright (c) 2015 CEA LIST 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 @@ -8,7 +8,7 @@ * * Contributors: * CEA LIST - Initial API and implementation - * + * *****************************************************************************/ package org.eclipse.papyrus.uml.diagram.dnd.strategy.classifier; @@ -23,9 +23,12 @@ import org.eclipse.gef.Request; import org.eclipse.gef.commands.Command; import org.eclipse.gef.commands.CompoundCommand; import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart; import org.eclipse.gmf.runtime.diagram.ui.requests.DropObjectsRequest; +import org.eclipse.gmf.runtime.notation.View; import org.eclipse.papyrus.infra.gmfdiag.dnd.strategy.TransactionalDropStrategy; import org.eclipse.papyrus.uml.diagram.composite.custom.helper.TypeHelper; +import org.eclipse.papyrus.uml.diagram.composite.edit.parts.CompositeStructureDiagramEditPart; import org.eclipse.papyrus.uml.diagram.dnd.Activator; import org.eclipse.swt.graphics.Image; import org.eclipse.uml2.uml.Association; @@ -35,10 +38,10 @@ import org.eclipse.uml2.uml.Property; import org.eclipse.uml2.uml.StructuredClassifier; /** - * + * * Class provide ability of drop a {@link Classifier} on a {@link Classifier} as a {@link Property} - * - * In a parent {@link Classifier} will be created a {@link Property} and shown in it + * + * In a parent {@link Classifier} will be created a {@link Property} and shown in it * when user drop a child {@link Classifier} on the parent {@link Classifier}. * The child {@link Classifier} not will be shown in the parent container in this case. */ @@ -71,28 +74,35 @@ public class ClassifierAsPropertyToStructuredCompartmentDropStrategy extends Tra if (false == targetSemantic instanceof StructuredClassifier) { return false; } - return true; + + // Bug 475569: This strategy is specific to the composite diagram (Relying on TypeHelper and Composite-specific VisualIDs). + // Return false if the current diagram is not a Composite. This behavior might be improved by making this implementation more generic (ViewService?) + View notationView = ((IGraphicalEditPart) ep).getNotationView(); + if (notationView == null || notationView.getDiagram() == null) { + return false; + } + return CompositeStructureDiagramEditPart.MODEL_ID.equals(notationView.getDiagram().getType()); } @Override public Command doGetCommand(Request request, EditPart targetEditPart) { if (understandRequest(request) && isStructuredClassifierEP(targetEditPart)) { - + GraphicalEditPart gtEditPart = (GraphicalEditPart) targetEditPart; TypeHelper helper = new TypeHelper((TransactionalEditingDomain) getEditingDomain(targetEditPart)); Point location = getLocation((DropObjectsRequest) request, gtEditPart); - + CompoundCommand cc = new CompoundCommand(); - + for (EObject dropElement : getSourceEObjects(request)) { if (dropElement instanceof Collaboration) { continue; } if (dropElement instanceof Classifier && (false == dropElement instanceof Association)) { Classifier classifier = (Classifier) dropElement; - - cc.add(helper.dropTypeAsTypedProperty((GraphicalEditPart)gtEditPart, classifier, location)); - + + cc.add(helper.dropTypeAsTypedProperty(gtEditPart, classifier, location)); + } } return cc.canExecute() ? cc : null; @@ -100,14 +110,17 @@ public class ClassifierAsPropertyToStructuredCompartmentDropStrategy extends Tra return null; } + @Override public String getLabel() { return "Drop type as typed property"; //$NON-NLS-1$ } + @Override public String getID() { return Activator.PLUGIN_ID + ".ClassifierToStructureCompAsPropertyDrop"; //$NON-NLS-1$ } + @Override public String getDescription() { return "Drops a classifier into the structure compartment of a structured classifier as a property."; //$NON-NLS-1$ } @@ -120,10 +133,12 @@ public class ClassifierAsPropertyToStructuredCompartmentDropStrategy extends Tra return "Drop a classifier into the structure compartment of a structured classifier as property"; //$NON-NLS-1$ } + @Override public Image getImage() { return null; } + @Override public int getPriority() { return 0; } -- cgit v1.2.3