diff options
Diffstat (limited to 'plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org')
15 files changed, 1777 insertions, 1777 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/Activator.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/Activator.java index 556dd538caa..218d30c55ea 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/Activator.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/Activator.java @@ -1,69 +1,69 @@ -/*****************************************************************************
- * Copyright (c) 2012 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.dnd;
-
-import org.eclipse.papyrus.infra.core.log.LogHelper;
-import org.eclipse.ui.plugin.AbstractUIPlugin;
-import org.osgi.framework.BundleContext;
-
-/**
- * The activator class controls the plug-in life cycle
- */
-public class Activator extends AbstractUIPlugin {
-
- // The plug-in ID
- public static final String PLUGIN_ID = "org.eclipse.papyrus.uml.diagram.dnd"; //$NON-NLS-1$
-
- // The shared instance
- private static Activator plugin;
-
- public static LogHelper log;
-
- /**
- * The constructor
- */
- public Activator() {
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
- */
- @Override
- public void start(BundleContext context) throws Exception {
- super.start(context);
- plugin = this;
- log = new LogHelper(this);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
- */
- @Override
- public void stop(BundleContext context) throws Exception {
- plugin = null;
- super.stop(context);
- }
-
- /**
- * Returns the shared instance
- *
- * @return the shared instance
- */
- public static Activator getDefault() {
- return plugin;
- }
-
-}
+/***************************************************************************** + * Copyright (c) 2012 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: + * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.dnd; + +import org.eclipse.papyrus.infra.core.log.LogHelper; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.eclipse.papyrus.uml.diagram.dnd"; //$NON-NLS-1$ + + // The shared instance + private static Activator plugin; + + public static LogHelper log; + + /** + * The constructor + */ + public Activator() { + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + @Override + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + log = new LogHelper(this); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + @Override + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/lifeline/ClassifierToInteractionDropStrategy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/lifeline/ClassifierToInteractionDropStrategy.java index b0130fd8052..3ac2dc0916b 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/lifeline/ClassifierToInteractionDropStrategy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/lifeline/ClassifierToInteractionDropStrategy.java @@ -1,112 +1,112 @@ -/*****************************************************************************
- * Copyright (c) 2014 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
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.dnd.lifeline;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.draw2d.geometry.Point;
-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.diagram.ui.requests.DropObjectsRequest;
-import org.eclipse.papyrus.infra.gmfdiag.dnd.strategy.TransactionalDropStrategy;
-import org.eclipse.papyrus.uml.diagram.dnd.Activator;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.uml2.uml.Interaction;
-import org.eclipse.uml2.uml.Lifeline;
-import org.eclipse.uml2.uml.Property;
-import org.eclipse.uml2.uml.Type;
-
-public class ClassifierToInteractionDropStrategy extends TransactionalDropStrategy {
-
- @Override
- public String getLabel() {
- return "Create a Lifeline";
- }
-
- @Override
- public String getDescription() {
- return "Drop a classifier on an interaction , create the lifeline and type it. This will create a new lifeline, a new Property in the interaction, typed by the dropped classifier. The Lifeline will represent this property."
- + "It is also possible to drop directly an already existing Property to the lifeline.";
- }
-
- @Override
- public Image getImage() {
- return null;
- }
-
- @Override
- public String getID() {
- return Activator.PLUGIN_ID + ".ClassifierToLifeline.represents";
- }
-
- @Deprecated
- public int getPriority() {
- return 0;
- }
-
- @Override
- protected Command doGetCommand(Request request, EditPart targetEditPart) {
- EObject targetElement = getTargetSemanticElement(targetEditPart);
- final Point location;
- if (!(targetElement instanceof Interaction)) {
- return null;
- }
- if (request instanceof DropObjectsRequest) {
- location = ((DropObjectsRequest) request).getLocation();
- }
- else {
- location = new Point(100, 100);
- }
- final EditPart interactionEditPart = targetEditPart;
- final Interaction targetInteraction = (Interaction) targetElement;
-
- List<EObject> sourceElements = getSourceEObjects(request);
-
- // The only supported case is "Drop a single classifier on an interaction"
- if (sourceElements.size() != 1) {
- return null;
- }
-
- EObject sourceElement = sourceElements.get(0);
- if (sourceElement instanceof Type) {
- final Type sourceType = (Type) sourceElement;
-
- Command resultCommand = new Command(getLabel()) {
-
- @Override
- public void execute() {
- Lifeline lifeline = targetInteraction.createLifeline("");
- Property property = targetInteraction.createOwnedAttribute("", sourceType);
- lifeline.setRepresents(property);
- ArrayList<Lifeline> droppedLifelines = new ArrayList<Lifeline>();
- droppedLifelines.add(lifeline);
- DropObjectsRequest dropRequest = new DropObjectsRequest();
- dropRequest.setObjects(droppedLifelines);
- dropRequest.setLocation(location);
- Command cmd = interactionEditPart.getCommand(dropRequest);
- cmd.execute();
-
-
- }
- };
-
- return resultCommand;
- }
-
- return null;
- }
-
-}
+/***************************************************************************** + * Copyright (c) 2014 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 + * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.dnd.lifeline; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.draw2d.geometry.Point; +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.diagram.ui.requests.DropObjectsRequest; +import org.eclipse.papyrus.infra.gmfdiag.dnd.strategy.TransactionalDropStrategy; +import org.eclipse.papyrus.uml.diagram.dnd.Activator; +import org.eclipse.swt.graphics.Image; +import org.eclipse.uml2.uml.Interaction; +import org.eclipse.uml2.uml.Lifeline; +import org.eclipse.uml2.uml.Property; +import org.eclipse.uml2.uml.Type; + +public class ClassifierToInteractionDropStrategy extends TransactionalDropStrategy { + + @Override + public String getLabel() { + return "Create a Lifeline"; + } + + @Override + public String getDescription() { + return "Drop a classifier on an interaction , create the lifeline and type it. This will create a new lifeline, a new Property in the interaction, typed by the dropped classifier. The Lifeline will represent this property." + + "It is also possible to drop directly an already existing Property to the lifeline."; + } + + @Override + public Image getImage() { + return null; + } + + @Override + public String getID() { + return Activator.PLUGIN_ID + ".ClassifierToLifeline.represents"; + } + + @Deprecated + public int getPriority() { + return 0; + } + + @Override + protected Command doGetCommand(Request request, EditPart targetEditPart) { + EObject targetElement = getTargetSemanticElement(targetEditPart); + final Point location; + if (!(targetElement instanceof Interaction)) { + return null; + } + if (request instanceof DropObjectsRequest) { + location = ((DropObjectsRequest) request).getLocation(); + } + else { + location = new Point(100, 100); + } + final EditPart interactionEditPart = targetEditPart; + final Interaction targetInteraction = (Interaction) targetElement; + + List<EObject> sourceElements = getSourceEObjects(request); + + // The only supported case is "Drop a single classifier on an interaction" + if (sourceElements.size() != 1) { + return null; + } + + EObject sourceElement = sourceElements.get(0); + if (sourceElement instanceof Type) { + final Type sourceType = (Type) sourceElement; + + Command resultCommand = new Command(getLabel()) { + + @Override + public void execute() { + Lifeline lifeline = targetInteraction.createLifeline(""); + Property property = targetInteraction.createOwnedAttribute("", sourceType); + lifeline.setRepresents(property); + ArrayList<Lifeline> droppedLifelines = new ArrayList<Lifeline>(); + droppedLifelines.add(lifeline); + DropObjectsRequest dropRequest = new DropObjectsRequest(); + dropRequest.setObjects(droppedLifelines); + dropRequest.setLocation(location); + Command cmd = interactionEditPart.getCommand(dropRequest); + cmd.execute(); + + + } + }; + + return resultCommand; + } + + return null; + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/lifeline/ClassifierToLifelineDropStrategy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/lifeline/ClassifierToLifelineDropStrategy.java index 1eedd765516..ce330807776 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/lifeline/ClassifierToLifelineDropStrategy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/lifeline/ClassifierToLifelineDropStrategy.java @@ -1,120 +1,120 @@ -/*****************************************************************************
- * 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.dnd.lifeline;
-
-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.papyrus.infra.gmfdiag.dnd.strategy.TransactionalDropStrategy;
-import org.eclipse.papyrus.uml.diagram.dnd.Activator;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.uml2.uml.Interaction;
-import org.eclipse.uml2.uml.Lifeline;
-import org.eclipse.uml2.uml.Property;
-import org.eclipse.uml2.uml.Type;
-
-/**
- * A DropStrategy to "Type" a Lifeline.
- * Drop a classifier on a Lifeline to type it.
- * This will create a new Property in the interaction, typed by the dropped classifier.
- * The Lifeline will represent this property.
- *
- * It is also possible to drop directly an already existing Property to the Lifeline.
- *
- * @author Camille Letavernier
- *
- */
-public class ClassifierToLifelineDropStrategy extends TransactionalDropStrategy {
-
- @Override
- public String getLabel() {
- return "Type a Lifeline";
- }
-
- @Override
- public String getDescription() {
- return "Drop a classifier on a Lifeline to type it. This will create a new Property in the interaction, typed by the dropped classifier. The Lifeline will represent this property."
- + "It is also possible to drop directly an already existing Property to the lifeline.";
- }
-
- @Override
- public Image getImage() {
- return null;
- }
-
- @Override
- public String getID() {
- return Activator.PLUGIN_ID + ".lifeline.represents";
- }
-
- @Deprecated
- public int getPriority() {
- return 0;
- }
-
- @Override
- protected Command doGetCommand(Request request, EditPart targetEditPart) {
- EObject targetElement = getTargetSemanticElement(targetEditPart);
-
- if (!(targetElement instanceof Lifeline)) {
- return null;
- }
-
-
- final Lifeline targetLifeline = (Lifeline) targetElement;
-
- final Interaction interaction = targetLifeline.getInteraction();
- if (interaction == null) {
- return null;
- }
-
- List<EObject> sourceElements = getSourceEObjects(request);
-
- // The only supported case is "Drop a single Type on a single Lifeline"
- if (sourceElements.size() != 1) {
- return null;
- }
-
- EObject sourceElement = sourceElements.get(0);
- if (sourceElement instanceof Type) {
- final Type sourceType = (Type) sourceElement;
-
- Command resultCommand = new Command(getLabel()) {
-
- @Override
- public void execute() {
- Property property = interaction.createOwnedAttribute("", sourceType);
- targetLifeline.setRepresents(property);
- }
- };
-
- return resultCommand;
- } else if (sourceElement instanceof Property) {
- final Property property = (Property) sourceElement;
- Command resultCommand = new Command(getLabel()) {
-
- @Override
- public void execute() {
- targetLifeline.setRepresents(property);
- }
- };
-
- return resultCommand;
- }
-
- return null;
- }
-
-}
+/***************************************************************************** + * 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: + * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.dnd.lifeline; + +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.papyrus.infra.gmfdiag.dnd.strategy.TransactionalDropStrategy; +import org.eclipse.papyrus.uml.diagram.dnd.Activator; +import org.eclipse.swt.graphics.Image; +import org.eclipse.uml2.uml.Interaction; +import org.eclipse.uml2.uml.Lifeline; +import org.eclipse.uml2.uml.Property; +import org.eclipse.uml2.uml.Type; + +/** + * A DropStrategy to "Type" a Lifeline. + * Drop a classifier on a Lifeline to type it. + * This will create a new Property in the interaction, typed by the dropped classifier. + * The Lifeline will represent this property. + * + * It is also possible to drop directly an already existing Property to the Lifeline. + * + * @author Camille Letavernier + * + */ +public class ClassifierToLifelineDropStrategy extends TransactionalDropStrategy { + + @Override + public String getLabel() { + return "Type a Lifeline"; + } + + @Override + public String getDescription() { + return "Drop a classifier on a Lifeline to type it. This will create a new Property in the interaction, typed by the dropped classifier. The Lifeline will represent this property." + + "It is also possible to drop directly an already existing Property to the lifeline."; + } + + @Override + public Image getImage() { + return null; + } + + @Override + public String getID() { + return Activator.PLUGIN_ID + ".lifeline.represents"; + } + + @Deprecated + public int getPriority() { + return 0; + } + + @Override + protected Command doGetCommand(Request request, EditPart targetEditPart) { + EObject targetElement = getTargetSemanticElement(targetEditPart); + + if (!(targetElement instanceof Lifeline)) { + return null; + } + + + final Lifeline targetLifeline = (Lifeline) targetElement; + + final Interaction interaction = targetLifeline.getInteraction(); + if (interaction == null) { + return null; + } + + List<EObject> sourceElements = getSourceEObjects(request); + + // The only supported case is "Drop a single Type on a single Lifeline" + if (sourceElements.size() != 1) { + return null; + } + + EObject sourceElement = sourceElements.get(0); + if (sourceElement instanceof Type) { + final Type sourceType = (Type) sourceElement; + + Command resultCommand = new Command(getLabel()) { + + @Override + public void execute() { + Property property = interaction.createOwnedAttribute("", sourceType); + targetLifeline.setRepresents(property); + } + }; + + return resultCommand; + } else if (sourceElement instanceof Property) { + final Property property = (Property) sourceElement; + Command resultCommand = new Command(getLabel()) { + + @Override + public void execute() { + targetLifeline.setRepresents(property); + } + }; + + return resultCommand; + } + + return null; + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/MoveInnerClassDropStrategy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/MoveInnerClassDropStrategy.java index d14504c54dd..45fbc310678 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/MoveInnerClassDropStrategy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/MoveInnerClassDropStrategy.java @@ -1,226 +1,226 @@ -/*****************************************************************************
- * Copyright (c) 2012 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.dnd.strategy;
-
-import java.util.LinkedList;
-import java.util.List;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.gef.EditPart;
-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.IGraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IPrimaryEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.requests.ArrangeRequest;
-import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest;
-import org.eclipse.gmf.runtime.diagram.ui.requests.DropObjectsRequest;
-import org.eclipse.gmf.runtime.diagram.ui.requests.RefreshConnectionsRequest;
-import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
-import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
-import org.eclipse.gmf.runtime.notation.Node;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.infra.gmfdiag.dnd.strategy.MoveDropStrategy;
-import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.ClassEditPart;
-import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.ClassEditPartCN;
-import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.ClassNestedClassifierCompartmentEditPart;
-import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.ClassNestedClassifierCompartmentEditPartCN;
-import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.ComponentEditPart;
-import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.ComponentEditPartCN;
-import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.ComponentNestedClassifierCompartmentEditPart;
-import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.ComponentNestedClassifierCompartmentEditPartCN;
-import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.InterfaceEditPart;
-import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.InterfaceEditPartCN;
-import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.InterfaceNestedClassifierCompartmentEditPart;
-import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.InterfaceNestedClassifierCompartmentEditPartCN;
-import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.NestedClassForClassEditPart;
-import org.eclipse.papyrus.uml.diagram.clazz.part.UMLVisualIDRegistry;
-import org.eclipse.papyrus.uml.diagram.common.commands.ShowHideElementsRequest;
-import org.eclipse.papyrus.uml.diagram.dnd.Activator;
-import org.eclipse.uml2.uml.Interface;
-import org.eclipse.uml2.uml.UMLPackage;
-
-/**
- * A DropStrategy to move a Classifier into a Class
- *
- * @author Camille Letavernier
- */
-// FIXME: The Class diagram already automatically displays inner classes
-// when they are added to the semantic model. There might be a conflict with this strategy.
-public class MoveInnerClassDropStrategy extends MoveDropStrategy {
-
- @Override
- public String getLabel() {
- return "Reparent";
- }
-
- @Override
- public String getID() {
- return Activator.PLUGIN_ID + ".move.innerClass";
- }
-
- @Override
- public String getDescription() {
- return "Move the selected class to the target class or package";
- }
-
- @Override
- protected EStructuralFeature getTargetFeature(Request request, EditPart targetEditPart) {
- EObject targetSemanticElement = getTargetSemanticElement(targetEditPart);
- if (targetSemanticElement instanceof org.eclipse.uml2.uml.Class) {
- // In this case, the service edit will create the GMF View for InnerClass
- return UMLPackage.eINSTANCE.getClass_NestedClassifier();
- }
- if (targetSemanticElement instanceof Interface) {
- return UMLPackage.eINSTANCE.getInterface_NestedClassifier();
- }
-
- return null;
- }
-
- @Override
- public int getPriority() {
- return 101;
- }
-
- /**
- *
- * @param request
- * @param targetEditPart
- * @return A command to edit the graphical view
- */
- @Override
- protected Command getGraphicalCommand(Request request, EditPart targetEditPart) {
- DropObjectsRequest dropRequest = getDropObjectsRequest(request);
- if (dropRequest == null) {
- return null;
- }
-
- // Create a view request from the drop request and then forward getting
- // the command for that.
-
- List<CreateViewRequest.ViewDescriptor> viewDescriptors = new LinkedList<CreateViewRequest.ViewDescriptor>();
-
- for (EObject eObject : getSourceEObjects(dropRequest)) {
- if (eObject instanceof org.eclipse.uml2.uml.Class) {
- viewDescriptors.add(new CreateViewRequest.ViewDescriptor(new EObjectAdapter(eObject), Node.class, NestedClassForClassEditPart.VISUAL_ID, ((IGraphicalEditPart) targetEditPart).getDiagramPreferencesHint()));
- }
- }
- if (viewDescriptors.isEmpty()) {
- return null;
- }
-
- CreateViewRequest createViewRequest = new CreateViewRequest(viewDescriptors);
- createViewRequest.setLocation(dropRequest.getLocation());
-
- targetEditPart = getTargetEditPart(targetEditPart);
-
- Command createCommand = targetEditPart.getCommand(createViewRequest);
-
- if (createCommand != null) {
- List<?> result = (List<?>) createViewRequest.getNewObject();
- dropRequest.setResult(result);
-
- RefreshConnectionsRequest refreshRequest = new RefreshConnectionsRequest(result);
- Command refreshCommand = targetEditPart.getCommand(refreshRequest);
-
- ArrangeRequest arrangeRequest = new ArrangeRequest(RequestConstants.REQ_ARRANGE_DEFERRED);
- arrangeRequest.setViewAdaptersToArrange(result);
- Command arrangeCommand = targetEditPart.getCommand(arrangeRequest);
-
- CompoundCommand cc = new CompoundCommand(createCommand.getLabel());
-
- cc.add(createCommand.chain(refreshCommand));
- cc.add(arrangeCommand);
-
- for (Object object : dropRequest.getObjects()) {
- if (object instanceof EditPart) {
- EditPart editPart = (EditPart) object;
- ShowHideElementsRequest destroyViewRequest = new ShowHideElementsRequest(editPart);
- Command destroyViewCommand = editPart.getCommand(destroyViewRequest);
- if (destroyViewCommand != null) {
- cc.add(destroyViewCommand);
- }
- }
- }
-
- return cc;
- }
-
- return null;
- }
-
- protected EditPart getTargetEditPart(final EditPart targetEditPart) {
- if (targetEditPart instanceof IGraphicalEditPart) {
- EditPart primaryEditPart = getPrimaryEditPart(targetEditPart);
- View primaryView = ((IGraphicalEditPart) targetEditPart).getPrimaryView();
-
- String nestedClassSemanticHint = null;
- switch (UMLVisualIDRegistry.getVisualID(primaryView)) {
- case ClassEditPart.VISUAL_ID:
- nestedClassSemanticHint = ClassNestedClassifierCompartmentEditPart.VISUAL_ID;
- break;
- case ClassEditPartCN.VISUAL_ID:
- nestedClassSemanticHint = ClassNestedClassifierCompartmentEditPartCN.VISUAL_ID;
- break;
- case InterfaceEditPart.VISUAL_ID:
- nestedClassSemanticHint = InterfaceNestedClassifierCompartmentEditPart.VISUAL_ID;
- break;
- case InterfaceEditPartCN.VISUAL_ID:
- nestedClassSemanticHint = InterfaceNestedClassifierCompartmentEditPartCN.VISUAL_ID;
- break;
- case ComponentEditPart.VISUAL_ID:
- nestedClassSemanticHint = ComponentNestedClassifierCompartmentEditPart.VISUAL_ID;
- break;
- case ComponentEditPartCN.VISUAL_ID:
- nestedClassSemanticHint = ComponentNestedClassifierCompartmentEditPartCN.VISUAL_ID;
- break;
- }
-
- if (nestedClassSemanticHint != null) {
- String type = UMLVisualIDRegistry.getType(nestedClassSemanticHint);
- EditPart target = ((IGraphicalEditPart) primaryEditPart).getChildBySemanticHint(type);
- if (target != null) {
- return target;
- }
- }
- }
-
- return targetEditPart;
- }
-
- protected EditPart getPrimaryEditPart(final EditPart targetEditPart) {
- EditPart currentPart = targetEditPart;
-
- while (currentPart != null) {
- if (currentPart instanceof IPrimaryEditPart) {
- return currentPart;
- }
- currentPart = currentPart.getParent();
- }
-
- return targetEditPart;
- }
-
- public String getCategoryID() {
- return "org.eclipse.papyrus.drop.classToClassifier";
- }
-
- public String getCategoryLabel() {
- return "Drop a Class on a Classifier";
- }
-
- public String getCategory() {
- return null;
- }
-}
+/***************************************************************************** + * Copyright (c) 2012 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: + * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.dnd.strategy; + +import java.util.LinkedList; +import java.util.List; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.gef.EditPart; +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.IGraphicalEditPart; +import org.eclipse.gmf.runtime.diagram.ui.editparts.IPrimaryEditPart; +import org.eclipse.gmf.runtime.diagram.ui.requests.ArrangeRequest; +import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest; +import org.eclipse.gmf.runtime.diagram.ui.requests.DropObjectsRequest; +import org.eclipse.gmf.runtime.diagram.ui.requests.RefreshConnectionsRequest; +import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants; +import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter; +import org.eclipse.gmf.runtime.notation.Node; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.infra.gmfdiag.dnd.strategy.MoveDropStrategy; +import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.ClassEditPart; +import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.ClassEditPartCN; +import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.ClassNestedClassifierCompartmentEditPart; +import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.ClassNestedClassifierCompartmentEditPartCN; +import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.ComponentEditPart; +import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.ComponentEditPartCN; +import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.ComponentNestedClassifierCompartmentEditPart; +import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.ComponentNestedClassifierCompartmentEditPartCN; +import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.InterfaceEditPart; +import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.InterfaceEditPartCN; +import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.InterfaceNestedClassifierCompartmentEditPart; +import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.InterfaceNestedClassifierCompartmentEditPartCN; +import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.NestedClassForClassEditPart; +import org.eclipse.papyrus.uml.diagram.clazz.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.common.commands.ShowHideElementsRequest; +import org.eclipse.papyrus.uml.diagram.dnd.Activator; +import org.eclipse.uml2.uml.Interface; +import org.eclipse.uml2.uml.UMLPackage; + +/** + * A DropStrategy to move a Classifier into a Class + * + * @author Camille Letavernier + */ +// FIXME: The Class diagram already automatically displays inner classes +// when they are added to the semantic model. There might be a conflict with this strategy. +public class MoveInnerClassDropStrategy extends MoveDropStrategy { + + @Override + public String getLabel() { + return "Reparent"; + } + + @Override + public String getID() { + return Activator.PLUGIN_ID + ".move.innerClass"; + } + + @Override + public String getDescription() { + return "Move the selected class to the target class or package"; + } + + @Override + protected EStructuralFeature getTargetFeature(Request request, EditPart targetEditPart) { + EObject targetSemanticElement = getTargetSemanticElement(targetEditPart); + if (targetSemanticElement instanceof org.eclipse.uml2.uml.Class) { + // In this case, the service edit will create the GMF View for InnerClass + return UMLPackage.eINSTANCE.getClass_NestedClassifier(); + } + if (targetSemanticElement instanceof Interface) { + return UMLPackage.eINSTANCE.getInterface_NestedClassifier(); + } + + return null; + } + + @Override + public int getPriority() { + return 101; + } + + /** + * + * @param request + * @param targetEditPart + * @return A command to edit the graphical view + */ + @Override + protected Command getGraphicalCommand(Request request, EditPart targetEditPart) { + DropObjectsRequest dropRequest = getDropObjectsRequest(request); + if (dropRequest == null) { + return null; + } + + // Create a view request from the drop request and then forward getting + // the command for that. + + List<CreateViewRequest.ViewDescriptor> viewDescriptors = new LinkedList<CreateViewRequest.ViewDescriptor>(); + + for (EObject eObject : getSourceEObjects(dropRequest)) { + if (eObject instanceof org.eclipse.uml2.uml.Class) { + viewDescriptors.add(new CreateViewRequest.ViewDescriptor(new EObjectAdapter(eObject), Node.class, NestedClassForClassEditPart.VISUAL_ID, ((IGraphicalEditPart) targetEditPart).getDiagramPreferencesHint())); + } + } + if (viewDescriptors.isEmpty()) { + return null; + } + + CreateViewRequest createViewRequest = new CreateViewRequest(viewDescriptors); + createViewRequest.setLocation(dropRequest.getLocation()); + + targetEditPart = getTargetEditPart(targetEditPart); + + Command createCommand = targetEditPart.getCommand(createViewRequest); + + if (createCommand != null) { + List<?> result = (List<?>) createViewRequest.getNewObject(); + dropRequest.setResult(result); + + RefreshConnectionsRequest refreshRequest = new RefreshConnectionsRequest(result); + Command refreshCommand = targetEditPart.getCommand(refreshRequest); + + ArrangeRequest arrangeRequest = new ArrangeRequest(RequestConstants.REQ_ARRANGE_DEFERRED); + arrangeRequest.setViewAdaptersToArrange(result); + Command arrangeCommand = targetEditPart.getCommand(arrangeRequest); + + CompoundCommand cc = new CompoundCommand(createCommand.getLabel()); + + cc.add(createCommand.chain(refreshCommand)); + cc.add(arrangeCommand); + + for (Object object : dropRequest.getObjects()) { + if (object instanceof EditPart) { + EditPart editPart = (EditPart) object; + ShowHideElementsRequest destroyViewRequest = new ShowHideElementsRequest(editPart); + Command destroyViewCommand = editPart.getCommand(destroyViewRequest); + if (destroyViewCommand != null) { + cc.add(destroyViewCommand); + } + } + } + + return cc; + } + + return null; + } + + protected EditPart getTargetEditPart(final EditPart targetEditPart) { + if (targetEditPart instanceof IGraphicalEditPart) { + EditPart primaryEditPart = getPrimaryEditPart(targetEditPart); + View primaryView = ((IGraphicalEditPart) targetEditPart).getPrimaryView(); + + String nestedClassSemanticHint = null; + switch (UMLVisualIDRegistry.getVisualID(primaryView)) { + case ClassEditPart.VISUAL_ID: + nestedClassSemanticHint = ClassNestedClassifierCompartmentEditPart.VISUAL_ID; + break; + case ClassEditPartCN.VISUAL_ID: + nestedClassSemanticHint = ClassNestedClassifierCompartmentEditPartCN.VISUAL_ID; + break; + case InterfaceEditPart.VISUAL_ID: + nestedClassSemanticHint = InterfaceNestedClassifierCompartmentEditPart.VISUAL_ID; + break; + case InterfaceEditPartCN.VISUAL_ID: + nestedClassSemanticHint = InterfaceNestedClassifierCompartmentEditPartCN.VISUAL_ID; + break; + case ComponentEditPart.VISUAL_ID: + nestedClassSemanticHint = ComponentNestedClassifierCompartmentEditPart.VISUAL_ID; + break; + case ComponentEditPartCN.VISUAL_ID: + nestedClassSemanticHint = ComponentNestedClassifierCompartmentEditPartCN.VISUAL_ID; + break; + } + + if (nestedClassSemanticHint != null) { + String type = UMLVisualIDRegistry.getType(nestedClassSemanticHint); + EditPart target = ((IGraphicalEditPart) primaryEditPart).getChildBySemanticHint(type); + if (target != null) { + return target; + } + } + } + + return targetEditPart; + } + + protected EditPart getPrimaryEditPart(final EditPart targetEditPart) { + EditPart currentPart = targetEditPart; + + while (currentPart != null) { + if (currentPart instanceof IPrimaryEditPart) { + return currentPart; + } + currentPart = currentPart.getParent(); + } + + return targetEditPart; + } + + public String getCategoryID() { + return "org.eclipse.papyrus.drop.classToClassifier"; + } + + public String getCategoryLabel() { + return "Drop a Class on a Classifier"; + } + + public String getCategory() { + return null; + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/classifier/ClassifierAsClassifierToStructureCompartmentDropStrategy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/classifier/ClassifierAsClassifierToStructureCompartmentDropStrategy.java index 835fc82ce3d..b949fb097c9 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/classifier/ClassifierAsClassifierToStructureCompartmentDropStrategy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/classifier/ClassifierAsClassifierToStructureCompartmentDropStrategy.java @@ -1,115 +1,115 @@ -/*****************************************************************************
- * Copyright (c) 2012 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.dnd.strategy.classifier;
-
-import java.util.Map;
-
-import org.eclipse.draw2d.geometry.Point;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.gef.EditPart;
-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.requests.DropObjectsRequest;
-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.dnd.Activator;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.uml2.uml.StructuredClassifier;
-import org.eclipse.uml2.uml.Type;
-
-/**
- * A strategy to drop a classifier into the structure compartment (composite structure diagram). There are two options to do this.
- * (1) Drop the classifier itself. It is more likely that the user wants to do this, if the classifier is also a behavior.
- * (2) Create an property typed with the classifier.
- *
- * @author Ansgar Radermacher
- *
- */
-public class ClassifierAsClassifierToStructureCompartmentDropStrategy extends TransactionalDropStrategy {
-
- @Override
- public String getLabel() {
- return "Classifier into structure compartment"; //$NON-NLS-1$
- }
-
- @Override
- public String getID() {
- return Activator.PLUGIN_ID + ".ClassifierToStructureCompDrop"; //$NON-NLS-1$
- }
-
- @Override
- public String getDescription() {
- return "Drops a classifier into the structure compartment of a class."; //$NON-NLS-1$
- }
-
- @Override
- public Image getImage() {
- return null;
- }
-
- @Override
- public int getPriority() {
- return 0;
- }
-
- public void setOptions(Map<String, Object> options) {
- // Nothing
- }
-
- @Override
- public Command doGetCommand(Request request, EditPart targetEditPart) {
-
- if (!(request instanceof DropObjectsRequest)) {
- return null;
- }
- DropObjectsRequest dropRequest = (DropObjectsRequest) request;
- EObject targetSemanticElement = getTargetSemanticElement(targetEditPart);
-
- if ((targetSemanticElement instanceof StructuredClassifier) &&
- (dropRequest.getLocation() != null) &&
- (targetEditPart instanceof GraphicalEditPart)) {
- GraphicalEditPart gtEditPart = (GraphicalEditPart) targetEditPart;
-
- TypeHelper helper = new TypeHelper((TransactionalEditingDomain) getEditingDomain(targetEditPart));
-
- Point location = dropRequest.getLocation().getCopy();
- gtEditPart.getContentPane().translateToRelative(location);
- gtEditPart.getContentPane().translateFromParent(location);
- location.translate(gtEditPart.getContentPane().getClientArea().getLocation().getNegated());
-
- CompoundCommand cc = new CompoundCommand();
-
- for (EObject dropElement : getSourceEObjects(request)) {
- if (dropElement instanceof Type) {
- Type type = (Type) dropElement;
- // check whether element is a nested classifier of the targetSemanticElement
- if (type.allNamespaces().contains(targetSemanticElement)) {
- cc.add(helper.dropTypeOnClassifier(gtEditPart, (Type) dropElement, location));
- }
- }
- }
- return cc.canExecute() ? cc : null;
- }
- return null;
- }
-
- public String getCategoryID() {
- return "org.eclipse.papyrus.dnd.ClassifierToStructureCompDrop"; //$NON-NLS-1$
- }
-
- public String getCategoryLabel() {
- return "Drop a classifier into the structure compartment of a class"; //$NON-NLS-1$
- }
-}
+/***************************************************************************** + * Copyright (c) 2012 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: + * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.dnd.strategy.classifier; + +import java.util.Map; + +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.EditPart; +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.requests.DropObjectsRequest; +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.dnd.Activator; +import org.eclipse.swt.graphics.Image; +import org.eclipse.uml2.uml.StructuredClassifier; +import org.eclipse.uml2.uml.Type; + +/** + * A strategy to drop a classifier into the structure compartment (composite structure diagram). There are two options to do this. + * (1) Drop the classifier itself. It is more likely that the user wants to do this, if the classifier is also a behavior. + * (2) Create an property typed with the classifier. + * + * @author Ansgar Radermacher + * + */ +public class ClassifierAsClassifierToStructureCompartmentDropStrategy extends TransactionalDropStrategy { + + @Override + public String getLabel() { + return "Classifier into structure compartment"; //$NON-NLS-1$ + } + + @Override + public String getID() { + return Activator.PLUGIN_ID + ".ClassifierToStructureCompDrop"; //$NON-NLS-1$ + } + + @Override + public String getDescription() { + return "Drops a classifier into the structure compartment of a class."; //$NON-NLS-1$ + } + + @Override + public Image getImage() { + return null; + } + + @Override + public int getPriority() { + return 0; + } + + public void setOptions(Map<String, Object> options) { + // Nothing + } + + @Override + public Command doGetCommand(Request request, EditPart targetEditPart) { + + if (!(request instanceof DropObjectsRequest)) { + return null; + } + DropObjectsRequest dropRequest = (DropObjectsRequest) request; + EObject targetSemanticElement = getTargetSemanticElement(targetEditPart); + + if ((targetSemanticElement instanceof StructuredClassifier) && + (dropRequest.getLocation() != null) && + (targetEditPart instanceof GraphicalEditPart)) { + GraphicalEditPart gtEditPart = (GraphicalEditPart) targetEditPart; + + TypeHelper helper = new TypeHelper((TransactionalEditingDomain) getEditingDomain(targetEditPart)); + + Point location = dropRequest.getLocation().getCopy(); + gtEditPart.getContentPane().translateToRelative(location); + gtEditPart.getContentPane().translateFromParent(location); + location.translate(gtEditPart.getContentPane().getClientArea().getLocation().getNegated()); + + CompoundCommand cc = new CompoundCommand(); + + for (EObject dropElement : getSourceEObjects(request)) { + if (dropElement instanceof Type) { + Type type = (Type) dropElement; + // check whether element is a nested classifier of the targetSemanticElement + if (type.allNamespaces().contains(targetSemanticElement)) { + cc.add(helper.dropTypeOnClassifier(gtEditPart, (Type) dropElement, location)); + } + } + } + return cc.canExecute() ? cc : null; + } + return null; + } + + public String getCategoryID() { + return "org.eclipse.papyrus.dnd.ClassifierToStructureCompDrop"; //$NON-NLS-1$ + } + + public String getCategoryLabel() { + return "Drop a classifier into the structure compartment of a class"; //$NON-NLS-1$ + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/constraint/NamespaceToConstraintDropStrategy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/constraint/NamespaceToConstraintDropStrategy.java index 4a10c1b110f..79f8bc11ab1 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/constraint/NamespaceToConstraintDropStrategy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/constraint/NamespaceToConstraintDropStrategy.java @@ -1,107 +1,107 @@ -/*****************************************************************************
- * Copyright (c) 2014 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:
- * Ansgar Radermacher (CEA LIST) - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.dnd.strategy.constraint;
-
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EStructuralFeature;
-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.emf.type.core.commands.SetValueCommand;
-import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
-import org.eclipse.papyrus.infra.gmfdiag.common.service.palette.AspectUnspecifiedTypeConnectionTool.CreateAspectUnspecifiedTypeConnectionRequest;
-import org.eclipse.papyrus.infra.gmfdiag.dnd.strategy.TransactionalDropStrategy;
-import org.eclipse.papyrus.uml.diagram.dnd.Activator;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.uml2.uml.Constraint;
-import org.eclipse.uml2.uml.Namespace;
-import org.eclipse.uml2.uml.UMLPackage;
-
-/**
- * A strategy to drop a name-space on a constraint. The constraint
- * context will be updated by the dropped name-space.
- */
-public class NamespaceToConstraintDropStrategy extends TransactionalDropStrategy {
-
- protected static final EStructuralFeature constraintContext_feature = UMLPackage.eINSTANCE.getConstraint_Context();
-
- @Override
- public String getLabel() {
- return "Set constraint context";
- }
-
- @Override
- public String getID() {
- return Activator.PLUGIN_ID + ".constraintContext"; //$NON-NLS-1$
- }
-
- public String getCategoryID() {
- return getID();
- }
-
- public String getCategoryLabel() {
- return "Sets the dropped namespace as context of the target constraint.";
- }
-
- @Override
- public String getDescription() {
- return getCategoryLabel();
- }
-
- @Override
- public Image getImage() {
- return null;
- }
-
- @Override
- public int getPriority() {
- return 0;
- }
-
- public void setOptions(Map<String, Object> options) {
- // Nothing
- }
-
- @Override
- public Command doGetCommand(Request request, EditPart targetEditPart) {
-
- if (request instanceof CreateAspectUnspecifiedTypeConnectionRequest) {
- return null;
- }
- CompositeCommand cc = new CompositeCommand(getLabel());
-
- EObject semanticElement = getTargetSemanticElement(targetEditPart);
-
- List<EObject> sourceElements = getSourceEObjects(request);
- if (sourceElements.size() != 1) {
- return null;
- }
- if (!(semanticElement instanceof Constraint)) {
- return null;
- }
-
- Object sourceElement = sourceElements.get(0);
- if (sourceElement instanceof Namespace) {
-
- SetRequest setContextRequest = new SetRequest(semanticElement, constraintContext_feature, sourceElement);
- SetValueCommand setContextCommand = new SetValueCommand(setContextRequest);
-
- cc.add(setContextCommand);
- }
- return cc.canExecute() ? new ICommandProxy(cc.reduce()) : null;
- }
-}
+/***************************************************************************** + * Copyright (c) 2014 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: + * Ansgar Radermacher (CEA LIST) - Initial API and implementation + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.dnd.strategy.constraint; + +import java.util.List; +import java.util.Map; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EStructuralFeature; +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.emf.type.core.commands.SetValueCommand; +import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest; +import org.eclipse.papyrus.infra.gmfdiag.common.service.palette.AspectUnspecifiedTypeConnectionTool.CreateAspectUnspecifiedTypeConnectionRequest; +import org.eclipse.papyrus.infra.gmfdiag.dnd.strategy.TransactionalDropStrategy; +import org.eclipse.papyrus.uml.diagram.dnd.Activator; +import org.eclipse.swt.graphics.Image; +import org.eclipse.uml2.uml.Constraint; +import org.eclipse.uml2.uml.Namespace; +import org.eclipse.uml2.uml.UMLPackage; + +/** + * A strategy to drop a name-space on a constraint. The constraint + * context will be updated by the dropped name-space. + */ +public class NamespaceToConstraintDropStrategy extends TransactionalDropStrategy { + + protected static final EStructuralFeature constraintContext_feature = UMLPackage.eINSTANCE.getConstraint_Context(); + + @Override + public String getLabel() { + return "Set constraint context"; + } + + @Override + public String getID() { + return Activator.PLUGIN_ID + ".constraintContext"; //$NON-NLS-1$ + } + + public String getCategoryID() { + return getID(); + } + + public String getCategoryLabel() { + return "Sets the dropped namespace as context of the target constraint."; + } + + @Override + public String getDescription() { + return getCategoryLabel(); + } + + @Override + public Image getImage() { + return null; + } + + @Override + public int getPriority() { + return 0; + } + + public void setOptions(Map<String, Object> options) { + // Nothing + } + + @Override + public Command doGetCommand(Request request, EditPart targetEditPart) { + + if (request instanceof CreateAspectUnspecifiedTypeConnectionRequest) { + return null; + } + CompositeCommand cc = new CompositeCommand(getLabel()); + + EObject semanticElement = getTargetSemanticElement(targetEditPart); + + List<EObject> sourceElements = getSourceEObjects(request); + if (sourceElements.size() != 1) { + return null; + } + if (!(semanticElement instanceof Constraint)) { + return null; + } + + Object sourceElement = sourceElements.get(0); + if (sourceElement instanceof Namespace) { + + SetRequest setContextRequest = new SetRequest(semanticElement, constraintContext_feature, sourceElement); + SetValueCommand setContextCommand = new SetValueCommand(setContextRequest); + + cc.add(setContextCommand); + } + return cc.canExecute() ? new ICommandProxy(cc.reduce()) : null; + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/instancespecification/ClassifierToSlotsDropStrategy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/instancespecification/ClassifierToSlotsDropStrategy.java index f4877e4b44f..d716fa731da 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/instancespecification/ClassifierToSlotsDropStrategy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/instancespecification/ClassifierToSlotsDropStrategy.java @@ -1,173 +1,173 @@ -/*****************************************************************************
- * Copyright (c) 2012 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.dnd.strategy.instancespecification;
-
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EStructuralFeature;
-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.common.core.command.ICommand;
-import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
-import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
-import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
-import org.eclipse.papyrus.infra.gmfdiag.common.service.palette.AspectUnspecifiedTypeConnectionTool.CreateAspectUnspecifiedTypeConnectionRequest;
-import org.eclipse.papyrus.infra.gmfdiag.common.utils.RequestUtils;
-import org.eclipse.papyrus.infra.gmfdiag.dnd.strategy.TransactionalDropStrategy;
-import org.eclipse.papyrus.uml.diagram.dnd.Activator;
-import org.eclipse.papyrus.uml.diagram.dnd.strategy.instancespecification.command.SelectAndCreateSlotsCommand;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.uml2.uml.Classifier;
-import org.eclipse.uml2.uml.InstanceSpecification;
-import org.eclipse.uml2.uml.UMLPackage;
-
-/**
- * A strategy to drop a Classifier on an InstanceSpecification. The instance
- * specification will be typed by the dropped classifiers, and a dialog will
- * be opened for the user to select the slots to create in the
- * InstanceSpecification.
- *
- * The slots will correspond to the classifier's property.
- *
- * @author Camille Letavernier
- *
- */
-public class ClassifierToSlotsDropStrategy extends TransactionalDropStrategy {
-
- private static final EStructuralFeature feature = UMLPackage.eINSTANCE.getInstanceSpecification_Classifier();
-
- @Override
- public String getLabel() {
- return "Type instance specification";
- }
-
- @Override
- public String getID() {
- return Activator.PLUGIN_ID + ".instanceSpecification"; //$NON-NLS-1$
- }
-
- @Override
- public String getDescription() {
- return "Sets the dropped classifiers as classifiers for the target InstanceSpecification. Slots corresponding to the classifiers' properties are also created.";
- }
-
- @Override
- public Image getImage() {
- return null;
- }
-
- @Override
- public int getPriority() {
- return 0;
- }
-
- public void setOptions(Map<String, Object> options) {
- // Nothing
- }
-
- @Override
- public Command doGetCommand(Request request, EditPart targetEditPart) {
-
- if (request instanceof CreateAspectUnspecifiedTypeConnectionRequest) {
- return null;
- }
- CompositeCommand cc = new CompositeCommand(getLabel());
-
- EObject semanticElement = getTargetSemanticElement(targetEditPart);
-
- List<EObject> sourceElements = getSourceEObjects(request);
- List<Classifier> valuesToAdd = new ArrayList<>(sourceElements.size());
- for (EObject sourceElement : sourceElements) {
- if (!(sourceElement instanceof Classifier)) {
- return null;
- }
- valuesToAdd.add((Classifier) sourceElement);
- }
-
- if (!(semanticElement instanceof InstanceSpecification)) {
- return null;
- }
-
- List<Classifier> currentValues = (List<Classifier>) semanticElement.eGet(feature);
-
- List<Classifier> values = new LinkedList<>();
- values.addAll(currentValues);
- values.addAll(valuesToAdd);
-
- SetRequest setClassifiersRequest = new SetRequest(semanticElement, feature, values);
- SetValueCommand setClassifiersCommand = new SetValueCommand(setClassifiersRequest);
-
- cc.add(setClassifiersCommand);
-
- // Add slots
- ICommand editSlotsCommand = getEditSlotsCommand(valuesToAdd, targetEditPart, request);
- if (editSlotsCommand != null) {
- cc.add(editSlotsCommand);
- }
-
- return cc.canExecute() ? new ICommandProxy(cc.reduce()) : null;
- }
-
- protected ICommand getEditSlotsCommand(List<Classifier> classifiers, EditPart targetEditPart, Request request) {
- for (Classifier classifier : classifiers) {
- if (!classifier.getAllAttributes().isEmpty()) {
- // FIXME: This is inconsistent with ClassifierPropertiesContentProvider,
- // which doesn't only relies on getAllAttributes()...
- // When a Class (without any property) implements an Interface (With at least one property),
- // this will return a null command, while the dialog would have displayed the interface's properties
-
- // There is at least one property
- boolean headless = !RequestUtils.useGUI(request);
- return new SelectAndCreateSlotsCommand(classifiers, targetEditPart, headless);
- }
- }
-
- return null;
- }
-
- /**
- * @deprecated Use {@link #getEditSlotsCommand(List, EditPart, Request)} instead
- * @param classifiers
- * @param targetEditPart
- * @return
- */
- @Deprecated
- protected ICommand getEditSlotsCommand(List<Classifier> classifiers, EditPart targetEditPart) {
- for (Classifier classifier : classifiers) {
- if (!classifier.getAllAttributes().isEmpty()) {
- // FIXME: This is inconsistent with ClassifierPropertiesContentProvider,
- // which doesn't only relies on getAllAttributes()...
- // When a Class (without any property) implements an Interface (With at least one property),
- // this will return a null command, while the dialog would have displayed the interface's properties
-
- // There is at least one property
- return new SelectAndCreateSlotsCommand(classifiers, targetEditPart);
- }
- }
-
- return null;
- }
-
- public String getCategoryID() {
- return "org.eclipse.papyrus.dnd.classifierToInstanceSpecification";
- }
-
- public String getCategoryLabel() {
- return "Drop a Classifier on an InstanceSpecification";
- }
-}
+/***************************************************************************** + * Copyright (c) 2012 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: + * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.dnd.strategy.instancespecification; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EStructuralFeature; +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.common.core.command.ICommand; +import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy; +import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand; +import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest; +import org.eclipse.papyrus.infra.gmfdiag.common.service.palette.AspectUnspecifiedTypeConnectionTool.CreateAspectUnspecifiedTypeConnectionRequest; +import org.eclipse.papyrus.infra.gmfdiag.common.utils.RequestUtils; +import org.eclipse.papyrus.infra.gmfdiag.dnd.strategy.TransactionalDropStrategy; +import org.eclipse.papyrus.uml.diagram.dnd.Activator; +import org.eclipse.papyrus.uml.diagram.dnd.strategy.instancespecification.command.SelectAndCreateSlotsCommand; +import org.eclipse.swt.graphics.Image; +import org.eclipse.uml2.uml.Classifier; +import org.eclipse.uml2.uml.InstanceSpecification; +import org.eclipse.uml2.uml.UMLPackage; + +/** + * A strategy to drop a Classifier on an InstanceSpecification. The instance + * specification will be typed by the dropped classifiers, and a dialog will + * be opened for the user to select the slots to create in the + * InstanceSpecification. + * + * The slots will correspond to the classifier's property. + * + * @author Camille Letavernier + * + */ +public class ClassifierToSlotsDropStrategy extends TransactionalDropStrategy { + + private static final EStructuralFeature feature = UMLPackage.eINSTANCE.getInstanceSpecification_Classifier(); + + @Override + public String getLabel() { + return "Type instance specification"; + } + + @Override + public String getID() { + return Activator.PLUGIN_ID + ".instanceSpecification"; //$NON-NLS-1$ + } + + @Override + public String getDescription() { + return "Sets the dropped classifiers as classifiers for the target InstanceSpecification. Slots corresponding to the classifiers' properties are also created."; + } + + @Override + public Image getImage() { + return null; + } + + @Override + public int getPriority() { + return 0; + } + + public void setOptions(Map<String, Object> options) { + // Nothing + } + + @Override + public Command doGetCommand(Request request, EditPart targetEditPart) { + + if (request instanceof CreateAspectUnspecifiedTypeConnectionRequest) { + return null; + } + CompositeCommand cc = new CompositeCommand(getLabel()); + + EObject semanticElement = getTargetSemanticElement(targetEditPart); + + List<EObject> sourceElements = getSourceEObjects(request); + List<Classifier> valuesToAdd = new ArrayList<>(sourceElements.size()); + for (EObject sourceElement : sourceElements) { + if (!(sourceElement instanceof Classifier)) { + return null; + } + valuesToAdd.add((Classifier) sourceElement); + } + + if (!(semanticElement instanceof InstanceSpecification)) { + return null; + } + + List<Classifier> currentValues = (List<Classifier>) semanticElement.eGet(feature); + + List<Classifier> values = new LinkedList<>(); + values.addAll(currentValues); + values.addAll(valuesToAdd); + + SetRequest setClassifiersRequest = new SetRequest(semanticElement, feature, values); + SetValueCommand setClassifiersCommand = new SetValueCommand(setClassifiersRequest); + + cc.add(setClassifiersCommand); + + // Add slots + ICommand editSlotsCommand = getEditSlotsCommand(valuesToAdd, targetEditPart, request); + if (editSlotsCommand != null) { + cc.add(editSlotsCommand); + } + + return cc.canExecute() ? new ICommandProxy(cc.reduce()) : null; + } + + protected ICommand getEditSlotsCommand(List<Classifier> classifiers, EditPart targetEditPart, Request request) { + for (Classifier classifier : classifiers) { + if (!classifier.getAllAttributes().isEmpty()) { + // FIXME: This is inconsistent with ClassifierPropertiesContentProvider, + // which doesn't only relies on getAllAttributes()... + // When a Class (without any property) implements an Interface (With at least one property), + // this will return a null command, while the dialog would have displayed the interface's properties + + // There is at least one property + boolean headless = !RequestUtils.useGUI(request); + return new SelectAndCreateSlotsCommand(classifiers, targetEditPart, headless); + } + } + + return null; + } + + /** + * @deprecated Use {@link #getEditSlotsCommand(List, EditPart, Request)} instead + * @param classifiers + * @param targetEditPart + * @return + */ + @Deprecated + protected ICommand getEditSlotsCommand(List<Classifier> classifiers, EditPart targetEditPart) { + for (Classifier classifier : classifiers) { + if (!classifier.getAllAttributes().isEmpty()) { + // FIXME: This is inconsistent with ClassifierPropertiesContentProvider, + // which doesn't only relies on getAllAttributes()... + // When a Class (without any property) implements an Interface (With at least one property), + // this will return a null command, while the dialog would have displayed the interface's properties + + // There is at least one property + return new SelectAndCreateSlotsCommand(classifiers, targetEditPart); + } + } + + return null; + } + + public String getCategoryID() { + return "org.eclipse.papyrus.dnd.classifierToInstanceSpecification"; + } + + public String getCategoryLabel() { + return "Drop a Classifier on an InstanceSpecification"; + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/instancespecification/command/SelectAndCreateSlotsCommand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/instancespecification/command/SelectAndCreateSlotsCommand.java index eaf3c9e0a8f..12b45b92326 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/instancespecification/command/SelectAndCreateSlotsCommand.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/instancespecification/command/SelectAndCreateSlotsCommand.java @@ -1,249 +1,249 @@ -/*****************************************************************************
- * Copyright (c) 2012 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.dnd.strategy.instancespecification.command;
-
-import java.util.HashSet;
-import java.util.List;
-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.core.runtime.NullProgressMonitor;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.Request;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gmf.runtime.common.core.command.AbstractCommand;
-import org.eclipse.gmf.runtime.common.core.command.CommandResult;
-import org.eclipse.gmf.runtime.common.core.command.ICommand;
-import org.eclipse.gmf.runtime.diagram.core.edithelpers.CreateElementRequestAdapter;
-import org.eclipse.gmf.runtime.diagram.ui.commands.CommandProxy;
-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.requests.CreateViewAndElementRequest;
-import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest.ViewAndElementDescriptor;
-import org.eclipse.gmf.runtime.emf.type.core.commands.CreateElementCommand;
-import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
-import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
-import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
-import org.eclipse.gmf.runtime.notation.Node;
-import org.eclipse.jface.window.Window;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
-import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.InstanceSpecificationSlotCompartmentEditPart;
-import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.InstanceSpecificationSlotCompartmentEditPartCN;
-import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.SlotEditPart;
-import org.eclipse.papyrus.uml.diagram.clazz.part.UMLVisualIDRegistry;
-import org.eclipse.papyrus.uml.diagram.clazz.providers.UMLElementTypes;
-import org.eclipse.papyrus.uml.diagram.dnd.strategy.instancespecification.ui.SlotSelectionDialog;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.uml2.uml.Classifier;
-import org.eclipse.uml2.uml.InstanceSpecification;
-import org.eclipse.uml2.uml.Property;
-import org.eclipse.uml2.uml.Slot;
-import org.eclipse.uml2.uml.UMLPackage;
-import org.eclipse.uml2.uml.ValueSpecification;
-
-/**
- * An interactive Command to create slots in an InstanceSpecification.
- * A dialog will be opened for the user to select the properties he wishes
- * to instantiate.
- *
- * @author Camille Letavernier
- *
- */
-public class SelectAndCreateSlotsCommand extends AbstractCommand {
-
- protected final List<Classifier> classifiers;
-
- protected final EditPart targetEditPart;
-
- protected final InstanceSpecification specification;
-
- protected final boolean headless;
-
- public SelectAndCreateSlotsCommand(List<Classifier> classifiers, EditPart targetEditPart) {
- this(classifiers, targetEditPart, false);
- }
-
- public SelectAndCreateSlotsCommand(List<Classifier> classifiers, EditPart targetEditPart, boolean headless) {
- super("Create slots");
- this.classifiers = classifiers;
- this.targetEditPart = targetEditPart;
- specification = (InstanceSpecification) EMFHelper.getEObject(targetEditPart);
- this.headless = headless;
- }
-
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
- Object[] propertiesToInstantiate = getProperties();
-
- if (propertiesToInstantiate == null) {
- return CommandResult.newCancelledCommandResult();
- }
-
- // For each selected property, create the corresponding slot
- for (Object propertyObject : propertiesToInstantiate) {
- Property property = (Property) propertyObject;
- // Creates the slot
- TransactionalEditingDomain domain = (TransactionalEditingDomain) EMFHelper.resolveEditingDomain(targetEditPart);
- CreateElementRequest createElementRequest = new CreateElementRequest(domain, specification, UMLElementTypes.Slot_SlotLabel);
-
- ICommand slotCreationCommand;
-
- // If the slot compartment is visible, create the slot graphically
- if (isSlotCompartmentAvailable(targetEditPart)) {
- CreateElementRequestAdapter adapter = new CreateElementRequestAdapter(createElementRequest);
- ViewAndElementDescriptor descriptor = new ViewAndElementDescriptor(adapter, Node.class, UMLVisualIDRegistry.getType(SlotEditPart.VISUAL_ID), ((IGraphicalEditPart) targetEditPart).getDiagramPreferencesHint());
- Request createRequest = new CreateViewAndElementRequest(descriptor);
- EditPart realTarget = targetEditPart.getTargetEditPart(createRequest);
-
- Command gefCommand = realTarget.getCommand(createRequest);
-
- if (gefCommand instanceof ICommandProxy) {
- slotCreationCommand = ((ICommandProxy) gefCommand).getICommand();
- slotCreationCommand = slotCreationCommand.reduce();
- } else {
- slotCreationCommand = new CommandProxy(gefCommand);
- }
- } else { // The compartment is not visible ; only create the semantic slot
- slotCreationCommand = new CreateElementCommand(createElementRequest);
- }
-
- slotCreationCommand.execute(new NullProgressMonitor(), null);
-
- CommandResult commandResult = slotCreationCommand.getCommandResult();
- if (commandResult != null) {
- if (!commandResult.getStatus().isOK()) {
- return commandResult;
- }
- }
-
- // Retrieve the created slot, and update its properties
- Slot newSlot = getNewSlot(commandResult);
- if (newSlot == null) {
- newSlot = getNewSlot(createElementRequest);
- }
-
- if (newSlot != null) {
- updateSlotProperties(newSlot, property);
- } else {
- return CommandResult.newErrorCommandResult("Could not create the slot for property " + property.getName());//$NON-NLS-1$
- }
-
- // Initialize properties: feature & name & default value
- }
-
- return CommandResult.newOKCommandResult();
- }
-
- protected Object[] getProperties() {
- // Headless
- if (headless) {
- return getAllProperties();
- }
-
- // UI
-
- // Open the dialog to select the slots
- SlotSelectionDialog dialog = new SlotSelectionDialog(Display.getCurrent().getActiveShell(), specification, classifiers);
- if (dialog.open() != Window.OK) {
- return null;
- }
-
- return dialog.getResult();
- }
-
- protected Property[] getAllProperties() {
- Set<Property> allProperties = new HashSet<>();
- for (Classifier classifier : classifiers) {
- allProperties.addAll(classifier.getAllAttributes());
- }
- return allProperties.toArray(new Property[allProperties.size()]);
- }
-
- protected Slot getNewSlot(CreateElementRequest request) {
- if (request.getNewElement() instanceof Slot) {
- return (Slot) request.getNewElement();
- }
- return null;
- }
-
- // Retrieves a slot from a CommandResult
- protected Slot getNewSlot(CommandResult commandResult) {
- Object objectResult = commandResult.getReturnValue();
- if (objectResult instanceof List) {
- // Result of the semantic + graphical creation command
- List<?> listResult = (List<?>) objectResult;
- for (Object elementResult : listResult) {
- if (elementResult instanceof CreateElementRequestAdapter) {
- CreateElementRequest request = (CreateElementRequest) ((CreateElementRequestAdapter) elementResult).getAdapter(CreateElementRequest.class);
- if (request != null) {
- EObject newElement = request.getNewElement();
- if (newElement instanceof Slot) {
- Slot slot = (Slot) newElement;
- return slot;
- }
- }
- }
- }
- } else if (commandResult.getReturnValue() instanceof Slot) {
- // Result of the semantic creation command
- return (Slot) commandResult.getReturnValue();
- }
-
- return null;
- }
-
- // Sets the slot's property (definingFeature) and initialize its value (property#defaultValue)
- protected void updateSlotProperties(Slot slot, Property property) throws ExecutionException {
- SetRequest setFeatureRequest = new SetRequest(slot, UMLPackage.eINSTANCE.getSlot_DefiningFeature(), property);
- SetValueCommand setFeatureCommand = new SetValueCommand(setFeatureRequest);
- setFeatureCommand.execute(new NullProgressMonitor(), null);
-
- if (property.getDefaultValue() != null) {
- ValueSpecification defaultValue = property.getDefaultValue();
- ValueSpecification currentValue = EcoreUtil.copy(defaultValue);
- currentValue.setName(property.getName());
-
- SetRequest setValueRequest = new SetRequest(slot, UMLPackage.eINSTANCE.getSlot_Value(), currentValue);
- SetValueCommand setValueCommand = new SetValueCommand(setValueRequest);
- setValueCommand.execute(new NullProgressMonitor(), null);
- }
- }
-
- // Tests whether the slot compartment edit part is available
- protected boolean isSlotCompartmentAvailable(EditPart targetEditPart) {
- if (targetEditPart instanceof InstanceSpecificationSlotCompartmentEditPart || targetEditPart instanceof InstanceSpecificationSlotCompartmentEditPartCN) {
- return true;
- }
- for (Object editPartObject : targetEditPart.getChildren()) {
- if (isSlotCompartmentAvailable((EditPart) editPartObject)) {
- return true;
- }
- }
- return false;
- }
-
- @Override
- protected CommandResult doRedoWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
- return null;
- }
-
- @Override
- protected CommandResult doUndoWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
- return null;
- }
-
-}
+/***************************************************************************** + * Copyright (c) 2012 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: + * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.dnd.strategy.instancespecification.command; + +import java.util.HashSet; +import java.util.List; +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.core.runtime.NullProgressMonitor; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.emf.transaction.TransactionalEditingDomain; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.Request; +import org.eclipse.gef.commands.Command; +import org.eclipse.gmf.runtime.common.core.command.AbstractCommand; +import org.eclipse.gmf.runtime.common.core.command.CommandResult; +import org.eclipse.gmf.runtime.common.core.command.ICommand; +import org.eclipse.gmf.runtime.diagram.core.edithelpers.CreateElementRequestAdapter; +import org.eclipse.gmf.runtime.diagram.ui.commands.CommandProxy; +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.requests.CreateViewAndElementRequest; +import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewAndElementRequest.ViewAndElementDescriptor; +import org.eclipse.gmf.runtime.emf.type.core.commands.CreateElementCommand; +import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand; +import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest; +import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest; +import org.eclipse.gmf.runtime.notation.Node; +import org.eclipse.jface.window.Window; +import org.eclipse.papyrus.infra.emf.utils.EMFHelper; +import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.InstanceSpecificationSlotCompartmentEditPart; +import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.InstanceSpecificationSlotCompartmentEditPartCN; +import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.SlotEditPart; +import org.eclipse.papyrus.uml.diagram.clazz.part.UMLVisualIDRegistry; +import org.eclipse.papyrus.uml.diagram.clazz.providers.UMLElementTypes; +import org.eclipse.papyrus.uml.diagram.dnd.strategy.instancespecification.ui.SlotSelectionDialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.uml2.uml.Classifier; +import org.eclipse.uml2.uml.InstanceSpecification; +import org.eclipse.uml2.uml.Property; +import org.eclipse.uml2.uml.Slot; +import org.eclipse.uml2.uml.UMLPackage; +import org.eclipse.uml2.uml.ValueSpecification; + +/** + * An interactive Command to create slots in an InstanceSpecification. + * A dialog will be opened for the user to select the properties he wishes + * to instantiate. + * + * @author Camille Letavernier + * + */ +public class SelectAndCreateSlotsCommand extends AbstractCommand { + + protected final List<Classifier> classifiers; + + protected final EditPart targetEditPart; + + protected final InstanceSpecification specification; + + protected final boolean headless; + + public SelectAndCreateSlotsCommand(List<Classifier> classifiers, EditPart targetEditPart) { + this(classifiers, targetEditPart, false); + } + + public SelectAndCreateSlotsCommand(List<Classifier> classifiers, EditPart targetEditPart, boolean headless) { + super("Create slots"); + this.classifiers = classifiers; + this.targetEditPart = targetEditPart; + specification = (InstanceSpecification) EMFHelper.getEObject(targetEditPart); + this.headless = headless; + } + + @Override + protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException { + Object[] propertiesToInstantiate = getProperties(); + + if (propertiesToInstantiate == null) { + return CommandResult.newCancelledCommandResult(); + } + + // For each selected property, create the corresponding slot + for (Object propertyObject : propertiesToInstantiate) { + Property property = (Property) propertyObject; + // Creates the slot + TransactionalEditingDomain domain = (TransactionalEditingDomain) EMFHelper.resolveEditingDomain(targetEditPart); + CreateElementRequest createElementRequest = new CreateElementRequest(domain, specification, UMLElementTypes.Slot_SlotLabel); + + ICommand slotCreationCommand; + + // If the slot compartment is visible, create the slot graphically + if (isSlotCompartmentAvailable(targetEditPart)) { + CreateElementRequestAdapter adapter = new CreateElementRequestAdapter(createElementRequest); + ViewAndElementDescriptor descriptor = new ViewAndElementDescriptor(adapter, Node.class, UMLVisualIDRegistry.getType(SlotEditPart.VISUAL_ID), ((IGraphicalEditPart) targetEditPart).getDiagramPreferencesHint()); + Request createRequest = new CreateViewAndElementRequest(descriptor); + EditPart realTarget = targetEditPart.getTargetEditPart(createRequest); + + Command gefCommand = realTarget.getCommand(createRequest); + + if (gefCommand instanceof ICommandProxy) { + slotCreationCommand = ((ICommandProxy) gefCommand).getICommand(); + slotCreationCommand = slotCreationCommand.reduce(); + } else { + slotCreationCommand = new CommandProxy(gefCommand); + } + } else { // The compartment is not visible ; only create the semantic slot + slotCreationCommand = new CreateElementCommand(createElementRequest); + } + + slotCreationCommand.execute(new NullProgressMonitor(), null); + + CommandResult commandResult = slotCreationCommand.getCommandResult(); + if (commandResult != null) { + if (!commandResult.getStatus().isOK()) { + return commandResult; + } + } + + // Retrieve the created slot, and update its properties + Slot newSlot = getNewSlot(commandResult); + if (newSlot == null) { + newSlot = getNewSlot(createElementRequest); + } + + if (newSlot != null) { + updateSlotProperties(newSlot, property); + } else { + return CommandResult.newErrorCommandResult("Could not create the slot for property " + property.getName());//$NON-NLS-1$ + } + + // Initialize properties: feature & name & default value + } + + return CommandResult.newOKCommandResult(); + } + + protected Object[] getProperties() { + // Headless + if (headless) { + return getAllProperties(); + } + + // UI + + // Open the dialog to select the slots + SlotSelectionDialog dialog = new SlotSelectionDialog(Display.getCurrent().getActiveShell(), specification, classifiers); + if (dialog.open() != Window.OK) { + return null; + } + + return dialog.getResult(); + } + + protected Property[] getAllProperties() { + Set<Property> allProperties = new HashSet<>(); + for (Classifier classifier : classifiers) { + allProperties.addAll(classifier.getAllAttributes()); + } + return allProperties.toArray(new Property[allProperties.size()]); + } + + protected Slot getNewSlot(CreateElementRequest request) { + if (request.getNewElement() instanceof Slot) { + return (Slot) request.getNewElement(); + } + return null; + } + + // Retrieves a slot from a CommandResult + protected Slot getNewSlot(CommandResult commandResult) { + Object objectResult = commandResult.getReturnValue(); + if (objectResult instanceof List) { + // Result of the semantic + graphical creation command + List<?> listResult = (List<?>) objectResult; + for (Object elementResult : listResult) { + if (elementResult instanceof CreateElementRequestAdapter) { + CreateElementRequest request = (CreateElementRequest) ((CreateElementRequestAdapter) elementResult).getAdapter(CreateElementRequest.class); + if (request != null) { + EObject newElement = request.getNewElement(); + if (newElement instanceof Slot) { + Slot slot = (Slot) newElement; + return slot; + } + } + } + } + } else if (commandResult.getReturnValue() instanceof Slot) { + // Result of the semantic creation command + return (Slot) commandResult.getReturnValue(); + } + + return null; + } + + // Sets the slot's property (definingFeature) and initialize its value (property#defaultValue) + protected void updateSlotProperties(Slot slot, Property property) throws ExecutionException { + SetRequest setFeatureRequest = new SetRequest(slot, UMLPackage.eINSTANCE.getSlot_DefiningFeature(), property); + SetValueCommand setFeatureCommand = new SetValueCommand(setFeatureRequest); + setFeatureCommand.execute(new NullProgressMonitor(), null); + + if (property.getDefaultValue() != null) { + ValueSpecification defaultValue = property.getDefaultValue(); + ValueSpecification currentValue = EcoreUtil.copy(defaultValue); + currentValue.setName(property.getName()); + + SetRequest setValueRequest = new SetRequest(slot, UMLPackage.eINSTANCE.getSlot_Value(), currentValue); + SetValueCommand setValueCommand = new SetValueCommand(setValueRequest); + setValueCommand.execute(new NullProgressMonitor(), null); + } + } + + // Tests whether the slot compartment edit part is available + protected boolean isSlotCompartmentAvailable(EditPart targetEditPart) { + if (targetEditPart instanceof InstanceSpecificationSlotCompartmentEditPart || targetEditPart instanceof InstanceSpecificationSlotCompartmentEditPartCN) { + return true; + } + for (Object editPartObject : targetEditPart.getChildren()) { + if (isSlotCompartmentAvailable((EditPart) editPartObject)) { + return true; + } + } + return false; + } + + @Override + protected CommandResult doRedoWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException { + return null; + } + + @Override + protected CommandResult doUndoWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException { + return null; + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/instancespecification/ui/ClassifierPropertiesContentProvider.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/instancespecification/ui/ClassifierPropertiesContentProvider.java index 4c219675ac7..275bdc7e278 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/instancespecification/ui/ClassifierPropertiesContentProvider.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/instancespecification/ui/ClassifierPropertiesContentProvider.java @@ -1,140 +1,140 @@ -/*****************************************************************************
- * Copyright (c) 2012 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.dnd.strategy.instancespecification.ui;
-
-import java.util.Collection;
-import java.util.LinkedHashSet;
-
-import org.eclipse.jface.viewers.ITreeContentProvider;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.uml2.uml.Classifier;
-import org.eclipse.uml2.uml.Property;
-
-/**
- * A TreeContentProvider which returns a collection of properties from a
- * collection of classifiers.
- *
- * The roots are the classifiers, the leafs are the properties.
- *
- * @author Camille Letavernier
- */
-public class ClassifierPropertiesContentProvider implements ITreeContentProvider {
-
- private Viewer viewer;
-
- private Collection<Classifier> input;
-
- @Override
- public void dispose() {
- viewer = null;
- input = null;
- }
-
- @Override
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- this.viewer = viewer;
- this.input = (Collection<Classifier>) newInput;
- }
-
- @Override
- public Object[] getElements(Object inputElement) {
- Collection<Classifier> result = new LinkedHashSet<Classifier>();
-
- for (Classifier classifier : input) {
- getAllGenerals(classifier, result);
- }
-
- return result.toArray();
- }
-
- @Override
- public Object[] getChildren(Object parentElement) {
- if (parentElement instanceof Classifier) {
- Classifier element = (Classifier) parentElement;
- // Set<Property> children = new LinkedHashSet<Property>();
-
- return element.getAttributes().toArray();
-
- // //Find all extended or implemented classifiers (Including self)
- // LinkedHashSet<Classifier> allGenerals = new LinkedHashSet<Classifier>();
- // getAllGenerals(element, allGenerals);
-
- // Find all properties
- // for(Classifier classifier : allGenerals) {
- // //Skip properties owned by another classifier,
- // //when this classifier is included in the input (To avoid duplication)
- // if(isCloserClassifier(element, classifier)) {
- // children.addAll(classifier.getAttributes());
- // }
- // }
- //
- // //Remove all redefined properties
- // LinkedHashSet<Property> childrenCopy = new LinkedHashSet<Property>(children);
- // for(Property property : children) {
- // childrenCopy.removeAll(property.getRedefinedProperties());
- // }
- //
- // return childrenCopy.toArray();
- }
-
- return new Object[0];
- }
-
- protected boolean isCloserClassifier(Classifier current, Classifier classifier) {
- if (current == classifier || input.size() == 1) {
- return true;
- }
-
- if (input.contains(classifier)) {
- return false;
- }
-
- return true;
- }
-
- protected void getAllGenerals(Classifier classifier, Collection<Classifier> result) {
- if (result.contains(classifier)) {
- return;
- }
-
- // Don't take the implemented interfaces into account. The semantic here is not clear enough.
- //
- // if(classifier instanceof BehavioredClassifier) {
- // for(Classifier general : ((BehavioredClassifier)classifier).getImplementedInterfaces()) {
- // getAllGenerals(general, result);
- // }
- // }
-
- for (Classifier general : classifier.getGenerals()) {
- getAllGenerals(general, result);
- }
-
- result.add(classifier);
- }
-
- @Override
- public Object getParent(Object element) {
- if (element instanceof Property) {
- return ((Property) element).getOwner();
- }
- return null;
- }
-
- @Override
- public boolean hasChildren(Object element) {
- if (element instanceof Classifier) {
- return !((Classifier) element).getAllAttributes().isEmpty();
- }
- return false;
- }
-
-}
+/***************************************************************************** + * Copyright (c) 2012 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: + * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.dnd.strategy.instancespecification.ui; + +import java.util.Collection; +import java.util.LinkedHashSet; + +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.uml2.uml.Classifier; +import org.eclipse.uml2.uml.Property; + +/** + * A TreeContentProvider which returns a collection of properties from a + * collection of classifiers. + * + * The roots are the classifiers, the leafs are the properties. + * + * @author Camille Letavernier + */ +public class ClassifierPropertiesContentProvider implements ITreeContentProvider { + + private Viewer viewer; + + private Collection<Classifier> input; + + @Override + public void dispose() { + viewer = null; + input = null; + } + + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + this.viewer = viewer; + this.input = (Collection<Classifier>) newInput; + } + + @Override + public Object[] getElements(Object inputElement) { + Collection<Classifier> result = new LinkedHashSet<Classifier>(); + + for (Classifier classifier : input) { + getAllGenerals(classifier, result); + } + + return result.toArray(); + } + + @Override + public Object[] getChildren(Object parentElement) { + if (parentElement instanceof Classifier) { + Classifier element = (Classifier) parentElement; + // Set<Property> children = new LinkedHashSet<Property>(); + + return element.getAttributes().toArray(); + + // //Find all extended or implemented classifiers (Including self) + // LinkedHashSet<Classifier> allGenerals = new LinkedHashSet<Classifier>(); + // getAllGenerals(element, allGenerals); + + // Find all properties + // for(Classifier classifier : allGenerals) { + // //Skip properties owned by another classifier, + // //when this classifier is included in the input (To avoid duplication) + // if(isCloserClassifier(element, classifier)) { + // children.addAll(classifier.getAttributes()); + // } + // } + // + // //Remove all redefined properties + // LinkedHashSet<Property> childrenCopy = new LinkedHashSet<Property>(children); + // for(Property property : children) { + // childrenCopy.removeAll(property.getRedefinedProperties()); + // } + // + // return childrenCopy.toArray(); + } + + return new Object[0]; + } + + protected boolean isCloserClassifier(Classifier current, Classifier classifier) { + if (current == classifier || input.size() == 1) { + return true; + } + + if (input.contains(classifier)) { + return false; + } + + return true; + } + + protected void getAllGenerals(Classifier classifier, Collection<Classifier> result) { + if (result.contains(classifier)) { + return; + } + + // Don't take the implemented interfaces into account. The semantic here is not clear enough. + // + // if(classifier instanceof BehavioredClassifier) { + // for(Classifier general : ((BehavioredClassifier)classifier).getImplementedInterfaces()) { + // getAllGenerals(general, result); + // } + // } + + for (Classifier general : classifier.getGenerals()) { + getAllGenerals(general, result); + } + + result.add(classifier); + } + + @Override + public Object getParent(Object element) { + if (element instanceof Property) { + return ((Property) element).getOwner(); + } + return null; + } + + @Override + public boolean hasChildren(Object element) { + if (element instanceof Classifier) { + return !((Classifier) element).getAllAttributes().isEmpty(); + } + return false; + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/instancespecification/ui/ClassifierPropertiesLabelProvider.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/instancespecification/ui/ClassifierPropertiesLabelProvider.java index ee4d4a13545..7e3f5c9878f 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/instancespecification/ui/ClassifierPropertiesLabelProvider.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/instancespecification/ui/ClassifierPropertiesLabelProvider.java @@ -1,90 +1,90 @@ -/*****************************************************************************
- * Copyright (c) 2012 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.dnd.strategy.instancespecification.ui;
-
-import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.jface.viewers.StyledCellLabelProvider;
-import org.eclipse.jface.viewers.StyledString;
-import org.eclipse.jface.viewers.ViewerCell;
-import org.eclipse.papyrus.uml.tools.providers.UMLLabelProvider;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.uml2.uml.Classifier;
-
-/**
- * A LabelProvider for the Classifiers' properties
- *
- * @author Camille Letavernier
- */
-public class ClassifierPropertiesLabelProvider extends StyledCellLabelProvider {
-
- private final ILabelProvider umlLabelProvider = new UMLLabelProvider();
-
- @Override
- public void update(ViewerCell cell) {
- Object element = cell.getElement();
- int columnIndex = cell.getColumnIndex();
-
- StyledString styledText = getStyledText(element, columnIndex);
-
- cell.setText(styledText.getString());
- cell.setStyleRanges(styledText.getStyleRanges());
- cell.setImage(getImage(element, columnIndex));
- }
-
- protected StyledString getStyledText(Object element, int columnIndex) {
- // if(columnIndex == 1 && element instanceof Property) {
- // Property property = (Property)element;
- // String classifierLabel = umlLabelProvider.getText(property.getOwner());
- // String qualifiedName = " (" + ((Classifier)property.getOwner()).getQualifiedName() + ")";
- //
- // StyledString styledString = new StyledString(classifierLabel);
- // styledString.append(qualifiedName, StyledString.QUALIFIER_STYLER);
- //
- // return styledString;
- // }
-
- if (columnIndex == 1 && element instanceof Classifier) {
- Classifier classifier = (Classifier) element;
-
- StyledString styledString = new StyledString(classifier.getQualifiedName(), StyledString.QUALIFIER_STYLER);
-
- return styledString;
- }
-
- return new StyledString(getText(element, columnIndex));
- }
-
- protected String getText(Object element, int columnIndex) {
- switch (columnIndex) {
- case 0:
- return umlLabelProvider.getText(element);
- default:
- return "";
- }
- }
-
- protected Image getImage(Object element, int columnIndex) {
- switch (columnIndex) {
- case 0:
- return umlLabelProvider.getImage(element);
- case 1:
- // if(element instanceof Property) {
- // return umlLabelProvider.getImage(((Property)element).getOwner());
- // }
- if (element instanceof Classifier) {
- return umlLabelProvider.getImage(element);
- }
- default:
- return null;
- }
- }
-}
+/***************************************************************************** + * Copyright (c) 2012 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: + * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.dnd.strategy.instancespecification.ui; + +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.StyledCellLabelProvider; +import org.eclipse.jface.viewers.StyledString; +import org.eclipse.jface.viewers.ViewerCell; +import org.eclipse.papyrus.uml.tools.providers.UMLLabelProvider; +import org.eclipse.swt.graphics.Image; +import org.eclipse.uml2.uml.Classifier; + +/** + * A LabelProvider for the Classifiers' properties + * + * @author Camille Letavernier + */ +public class ClassifierPropertiesLabelProvider extends StyledCellLabelProvider { + + private final ILabelProvider umlLabelProvider = new UMLLabelProvider(); + + @Override + public void update(ViewerCell cell) { + Object element = cell.getElement(); + int columnIndex = cell.getColumnIndex(); + + StyledString styledText = getStyledText(element, columnIndex); + + cell.setText(styledText.getString()); + cell.setStyleRanges(styledText.getStyleRanges()); + cell.setImage(getImage(element, columnIndex)); + } + + protected StyledString getStyledText(Object element, int columnIndex) { + // if(columnIndex == 1 && element instanceof Property) { + // Property property = (Property)element; + // String classifierLabel = umlLabelProvider.getText(property.getOwner()); + // String qualifiedName = " (" + ((Classifier)property.getOwner()).getQualifiedName() + ")"; + // + // StyledString styledString = new StyledString(classifierLabel); + // styledString.append(qualifiedName, StyledString.QUALIFIER_STYLER); + // + // return styledString; + // } + + if (columnIndex == 1 && element instanceof Classifier) { + Classifier classifier = (Classifier) element; + + StyledString styledString = new StyledString(classifier.getQualifiedName(), StyledString.QUALIFIER_STYLER); + + return styledString; + } + + return new StyledString(getText(element, columnIndex)); + } + + protected String getText(Object element, int columnIndex) { + switch (columnIndex) { + case 0: + return umlLabelProvider.getText(element); + default: + return ""; + } + } + + protected Image getImage(Object element, int columnIndex) { + switch (columnIndex) { + case 0: + return umlLabelProvider.getImage(element); + case 1: + // if(element instanceof Property) { + // return umlLabelProvider.getImage(((Property)element).getOwner()); + // } + if (element instanceof Classifier) { + return umlLabelProvider.getImage(element); + } + default: + return null; + } + } +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/instancespecification/ui/SlotSelectionDialog.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/instancespecification/ui/SlotSelectionDialog.java index c2b36d71bb6..5ea8a90ff85 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/instancespecification/ui/SlotSelectionDialog.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/instancespecification/ui/SlotSelectionDialog.java @@ -1,172 +1,172 @@ -/*****************************************************************************
- * Copyright (c) 2012 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.dnd.strategy.instancespecification.ui;
-
-import java.util.LinkedHashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.jface.viewers.ColumnWeightData;
-import org.eclipse.jface.viewers.TableLayout;
-import org.eclipse.jface.viewers.TreeViewer;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.TreeEditor;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Tree;
-import org.eclipse.swt.widgets.TreeColumn;
-import org.eclipse.swt.widgets.TreeItem;
-import org.eclipse.ui.dialogs.SelectionDialog;
-import org.eclipse.uml2.uml.Classifier;
-import org.eclipse.uml2.uml.InstanceSpecification;
-import org.eclipse.uml2.uml.Property;
-import org.eclipse.uml2.uml.Slot;
-
-/**
- * A dialog which lets the user choose the properties he wishes to instantiate,
- * from a list of classifiers.
- *
- * The dialog returns the list of selected properties.
- *
- * @author Camille Letavernier
- */
-public class SlotSelectionDialog extends SelectionDialog {
-
- private final InstanceSpecification specification;
-
- private final List<Classifier> classifiers;
-
- private final Map<Property, Boolean> properties;
-
- public SlotSelectionDialog(Shell parentShell, InstanceSpecification specification, List<Classifier> classifiers) {
- super(parentShell);
- this.specification = specification;
- this.classifiers = classifiers;
- properties = new LinkedHashMap<Property, Boolean>();
- }
-
- @Override
- public void create() {
- setTitle("Select the slots to create");
- super.create();
-
- getShell().setImage(org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImage("icons/papyrus.png"));
-
- Composite parent = getDialogArea();
-
- Label label = new Label(parent, SWT.NONE);
- label.setText("Select the slots you wish to create. Existing slots cannot be removed here");
-
- TreeViewer viewer = new TreeViewer(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
-
- viewer.getTree().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
- Tree tree = viewer.getTree();
-
- TableLayout layout = new TableLayout();
-
- TreeColumn propertyColumn = new TreeColumn(tree, SWT.CENTER);
- propertyColumn.setText("Property");
- layout.addColumnData(new ColumnWeightData(30, 150, true));
-
- TreeColumn ownerColumn = new TreeColumn(tree, SWT.CENTER);
- ownerColumn.setText("Qualified name");
- layout.addColumnData(new ColumnWeightData(60, 300, true));
-
- TreeColumn checkColumn = new TreeColumn(tree, SWT.CENTER);
- checkColumn.setText("Create slot");
- layout.addColumnData(new ColumnWeightData(10, 70, true));
-
- tree.setLayout(layout);
- tree.setHeaderVisible(true);
-
- viewer.setContentProvider(new ClassifierPropertiesContentProvider());
- viewer.setLabelProvider(new ClassifierPropertiesLabelProvider());
-
- viewer.setInput(classifiers);
- viewer.expandAll();
-
- for (TreeItem classifierItem : tree.getItems()) {
- for (TreeItem propertyItem : classifierItem.getItems()) {
- final Property property = (Property) propertyItem.getData();
- properties.put(property, select(property));
-
- final Button checkbox = new Button(tree, SWT.CHECK);
-
- checkbox.setSelection(true);
- checkbox.setEnabled(select(property));
-
- checkbox.addSelectionListener(new SelectionListener() {
-
- @Override
- public void widgetSelected(SelectionEvent e) {
- properties.put(property, checkbox.getSelection());
- }
-
- @Override
- public void widgetDefaultSelected(SelectionEvent e) {
- // Nothing
- }
-
- });
-
- TreeEditor editor = new TreeEditor(tree);
- editor.horizontalAlignment = SWT.CENTER;
- editor.grabHorizontal = true;
-
- editor.setEditor(checkbox, propertyItem, 2);
- }
- }
-
- parent.layout();
-
- getShell().pack();
- }
-
- protected boolean select(Property property) {
- // Checks whether a slot already represents the given property
- for (Slot slot : specification.getSlots()) {
- if (slot.getDefiningFeature() == property) {
- return false;
- }
- }
- return true;
- }
-
- @Override
- protected void okPressed() {
- List<Property> result = new LinkedList<>();
- for (Map.Entry<Property, Boolean> entry : properties.entrySet()) {
- if (entry.getValue()) {
- result.add(entry.getKey());
- }
- }
- setResult(result);
- super.okPressed();
- }
-
- @Override
- public Composite getDialogArea() {
- return (Composite) super.getDialogArea();
- }
-
- @Override
- public boolean isResizable() {
- return true;
- }
-
-}
+/***************************************************************************** + * Copyright (c) 2012 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: + * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.dnd.strategy.instancespecification.ui; + +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import org.eclipse.jface.viewers.ColumnWeightData; +import org.eclipse.jface.viewers.TableLayout; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.TreeEditor; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeColumn; +import org.eclipse.swt.widgets.TreeItem; +import org.eclipse.ui.dialogs.SelectionDialog; +import org.eclipse.uml2.uml.Classifier; +import org.eclipse.uml2.uml.InstanceSpecification; +import org.eclipse.uml2.uml.Property; +import org.eclipse.uml2.uml.Slot; + +/** + * A dialog which lets the user choose the properties he wishes to instantiate, + * from a list of classifiers. + * + * The dialog returns the list of selected properties. + * + * @author Camille Letavernier + */ +public class SlotSelectionDialog extends SelectionDialog { + + private final InstanceSpecification specification; + + private final List<Classifier> classifiers; + + private final Map<Property, Boolean> properties; + + public SlotSelectionDialog(Shell parentShell, InstanceSpecification specification, List<Classifier> classifiers) { + super(parentShell); + this.specification = specification; + this.classifiers = classifiers; + properties = new LinkedHashMap<Property, Boolean>(); + } + + @Override + public void create() { + setTitle("Select the slots to create"); + super.create(); + + getShell().setImage(org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImage("icons/papyrus.png")); + + Composite parent = getDialogArea(); + + Label label = new Label(parent, SWT.NONE); + label.setText("Select the slots you wish to create. Existing slots cannot be removed here"); + + TreeViewer viewer = new TreeViewer(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); + + viewer.getTree().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + Tree tree = viewer.getTree(); + + TableLayout layout = new TableLayout(); + + TreeColumn propertyColumn = new TreeColumn(tree, SWT.CENTER); + propertyColumn.setText("Property"); + layout.addColumnData(new ColumnWeightData(30, 150, true)); + + TreeColumn ownerColumn = new TreeColumn(tree, SWT.CENTER); + ownerColumn.setText("Qualified name"); + layout.addColumnData(new ColumnWeightData(60, 300, true)); + + TreeColumn checkColumn = new TreeColumn(tree, SWT.CENTER); + checkColumn.setText("Create slot"); + layout.addColumnData(new ColumnWeightData(10, 70, true)); + + tree.setLayout(layout); + tree.setHeaderVisible(true); + + viewer.setContentProvider(new ClassifierPropertiesContentProvider()); + viewer.setLabelProvider(new ClassifierPropertiesLabelProvider()); + + viewer.setInput(classifiers); + viewer.expandAll(); + + for (TreeItem classifierItem : tree.getItems()) { + for (TreeItem propertyItem : classifierItem.getItems()) { + final Property property = (Property) propertyItem.getData(); + properties.put(property, select(property)); + + final Button checkbox = new Button(tree, SWT.CHECK); + + checkbox.setSelection(true); + checkbox.setEnabled(select(property)); + + checkbox.addSelectionListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + properties.put(property, checkbox.getSelection()); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + // Nothing + } + + }); + + TreeEditor editor = new TreeEditor(tree); + editor.horizontalAlignment = SWT.CENTER; + editor.grabHorizontal = true; + + editor.setEditor(checkbox, propertyItem, 2); + } + } + + parent.layout(); + + getShell().pack(); + } + + protected boolean select(Property property) { + // Checks whether a slot already represents the given property + for (Slot slot : specification.getSlots()) { + if (slot.getDefiningFeature() == property) { + return false; + } + } + return true; + } + + @Override + protected void okPressed() { + List<Property> result = new LinkedList<>(); + for (Map.Entry<Property, Boolean> entry : properties.entrySet()) { + if (entry.getValue()) { + result.add(entry.getKey()); + } + } + setResult(result); + super.okPressed(); + } + + @Override + public Composite getDialogArea() { + return (Composite) super.getDialogArea(); + } + + @Override + public boolean isResizable() { + return true; + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/state/AbstractBehaviorToStateDropStrategy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/state/AbstractBehaviorToStateDropStrategy.java index 8e4273f5796..54877d4768b 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/state/AbstractBehaviorToStateDropStrategy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/state/AbstractBehaviorToStateDropStrategy.java @@ -1,111 +1,111 @@ -/*****************************************************************************
- * Copyright (c) 2012 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.dnd.strategy.state;
-
-import java.util.List;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.Request;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.papyrus.infra.gmfdiag.dnd.strategy.TransactionalDropStrategy;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.uml2.uml.Behavior;
-import org.eclipse.uml2.uml.State;
-
-/**
- * Abstract implementation for a Behavior being dropped on a State. One of the State's
- * features will be set to the dropped behavior (doActivity, Entry, Exit)
- *
- * @author Camille Letavernier
- *
- */
-// FIXME: This is a sample implementation. The edited features are composite, which means
-// the dropped behavior is actually moved to the target state.
-// We should either add a warning to avoid confusing the user, or offer a refactoring option
-// (e.g. Move the behavior to an operation, create a new FunctionBehavior in the state,
-// and link the FunctionBehavior#specification to the operation)
-public abstract class AbstractBehaviorToStateDropStrategy extends TransactionalDropStrategy {
-
- @Override
- public String getLabel() {
- String featureName = getFeatureToEdit().getName();
- return "Behavior -> State : sets the \"" + featureName + "\" property";
- }
-
- @Override
- public String getDescription() {
- String featureName = getFeatureToEdit().getName();
- return "When a Behavior is dropped on a State, sets the behavior as the state's \"" + featureName + "\" property";
- }
-
- @Override
- public Image getImage() {
- return null;
- }
-
- @Override
- public String getID() {
- String featureName = getFeatureToEdit().getName();
- return "org.eclipse.papyrus.behaviorToState." + featureName;
- }
-
- @Override
- public int getPriority() {
- return 50;
- }
-
- public String getCategory() {
- return "org.eclipse.papyrus.behaviorToState";
- }
-
- @Override
- public Command doGetCommand(Request request, EditPart targetEditPart) {
- if (!(getTargetSemanticElement(targetEditPart) instanceof State)) {
- return null;
- }
-
- List<EObject> sourceEObjects = getSourceEObjects(request);
-
- if (sourceEObjects.size() != 1) {
- return null;
- }
-
- if (!(sourceEObjects.get(0) instanceof Behavior)) {
- return null;
- }
-
- final Behavior behavior = (Behavior) sourceEObjects.get(0);
- final State targetState = (State) getTargetSemanticElement(targetEditPart);
-
- EObject ancestor = targetState.eContainer();
- while (ancestor != null) {
- if (ancestor == behavior) {
- return null; // Avoid containment cycle
- }
-
- ancestor = ancestor.eContainer();
- }
-
- return new Command() {
-
- @Override
- public void execute() {
- targetState.eSet(getFeatureToEdit(), behavior);
- }
- };
- }
-
- protected abstract EStructuralFeature getFeatureToEdit();
-
-}
+/***************************************************************************** + * Copyright (c) 2012 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: + * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.dnd.strategy.state; + +import java.util.List; + +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.gef.EditPart; +import org.eclipse.gef.Request; +import org.eclipse.gef.commands.Command; +import org.eclipse.papyrus.infra.gmfdiag.dnd.strategy.TransactionalDropStrategy; +import org.eclipse.swt.graphics.Image; +import org.eclipse.uml2.uml.Behavior; +import org.eclipse.uml2.uml.State; + +/** + * Abstract implementation for a Behavior being dropped on a State. One of the State's + * features will be set to the dropped behavior (doActivity, Entry, Exit) + * + * @author Camille Letavernier + * + */ +// FIXME: This is a sample implementation. The edited features are composite, which means +// the dropped behavior is actually moved to the target state. +// We should either add a warning to avoid confusing the user, or offer a refactoring option +// (e.g. Move the behavior to an operation, create a new FunctionBehavior in the state, +// and link the FunctionBehavior#specification to the operation) +public abstract class AbstractBehaviorToStateDropStrategy extends TransactionalDropStrategy { + + @Override + public String getLabel() { + String featureName = getFeatureToEdit().getName(); + return "Behavior -> State : sets the \"" + featureName + "\" property"; + } + + @Override + public String getDescription() { + String featureName = getFeatureToEdit().getName(); + return "When a Behavior is dropped on a State, sets the behavior as the state's \"" + featureName + "\" property"; + } + + @Override + public Image getImage() { + return null; + } + + @Override + public String getID() { + String featureName = getFeatureToEdit().getName(); + return "org.eclipse.papyrus.behaviorToState." + featureName; + } + + @Override + public int getPriority() { + return 50; + } + + public String getCategory() { + return "org.eclipse.papyrus.behaviorToState"; + } + + @Override + public Command doGetCommand(Request request, EditPart targetEditPart) { + if (!(getTargetSemanticElement(targetEditPart) instanceof State)) { + return null; + } + + List<EObject> sourceEObjects = getSourceEObjects(request); + + if (sourceEObjects.size() != 1) { + return null; + } + + if (!(sourceEObjects.get(0) instanceof Behavior)) { + return null; + } + + final Behavior behavior = (Behavior) sourceEObjects.get(0); + final State targetState = (State) getTargetSemanticElement(targetEditPart); + + EObject ancestor = targetState.eContainer(); + while (ancestor != null) { + if (ancestor == behavior) { + return null; // Avoid containment cycle + } + + ancestor = ancestor.eContainer(); + } + + return new Command() { + + @Override + public void execute() { + targetState.eSet(getFeatureToEdit(), behavior); + } + }; + } + + protected abstract EStructuralFeature getFeatureToEdit(); + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/state/BehaviorToDoActivityDropStrategy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/state/BehaviorToDoActivityDropStrategy.java index 79baefb1d08..4738312ab7e 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/state/BehaviorToDoActivityDropStrategy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/state/BehaviorToDoActivityDropStrategy.java @@ -1,31 +1,31 @@ -/*****************************************************************************
- * Copyright (c) 2012 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.dnd.strategy.state;
-
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.uml2.uml.UMLPackage;
-
-/**
- * Concrete implementation to edit a State's doActivity feature
- *
- * @see {@link AbstractBehaviorToStateDropStrategy}
- *
- * @author Camille Letavernier
- */
-public class BehaviorToDoActivityDropStrategy extends AbstractBehaviorToStateDropStrategy {
-
- @Override
- protected EStructuralFeature getFeatureToEdit() {
- return UMLPackage.eINSTANCE.getState_DoActivity();
- }
-
-}
+/***************************************************************************** + * Copyright (c) 2012 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: + * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.dnd.strategy.state; + +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.uml2.uml.UMLPackage; + +/** + * Concrete implementation to edit a State's doActivity feature + * + * @see {@link AbstractBehaviorToStateDropStrategy} + * + * @author Camille Letavernier + */ +public class BehaviorToDoActivityDropStrategy extends AbstractBehaviorToStateDropStrategy { + + @Override + protected EStructuralFeature getFeatureToEdit() { + return UMLPackage.eINSTANCE.getState_DoActivity(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/state/BehaviorToEntryDropStrategy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/state/BehaviorToEntryDropStrategy.java index a193ece27dd..4df2f34f430 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/state/BehaviorToEntryDropStrategy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/state/BehaviorToEntryDropStrategy.java @@ -1,31 +1,31 @@ -/*****************************************************************************
- * Copyright (c) 2012 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.dnd.strategy.state;
-
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.uml2.uml.UMLPackage;
-
-/**
- * Concrete implementation to edit a State's entry feature
- *
- * @see {@link AbstractBehaviorToStateDropStrategy}
- *
- * @author Camille Letavernier
- */
-public class BehaviorToEntryDropStrategy extends AbstractBehaviorToStateDropStrategy {
-
- @Override
- protected EStructuralFeature getFeatureToEdit() {
- return UMLPackage.eINSTANCE.getState_Entry();
- }
-
-}
+/***************************************************************************** + * Copyright (c) 2012 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: + * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.dnd.strategy.state; + +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.uml2.uml.UMLPackage; + +/** + * Concrete implementation to edit a State's entry feature + * + * @see {@link AbstractBehaviorToStateDropStrategy} + * + * @author Camille Letavernier + */ +public class BehaviorToEntryDropStrategy extends AbstractBehaviorToStateDropStrategy { + + @Override + protected EStructuralFeature getFeatureToEdit() { + return UMLPackage.eINSTANCE.getState_Entry(); + } + +} diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/state/BehaviorToExitDropStrategy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/state/BehaviorToExitDropStrategy.java index 71095691d4c..f762604476d 100644 --- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/state/BehaviorToExitDropStrategy.java +++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.dnd/src/org/eclipse/papyrus/uml/diagram/dnd/strategy/state/BehaviorToExitDropStrategy.java @@ -1,31 +1,31 @@ -/*****************************************************************************
- * Copyright (c) 2012 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.dnd.strategy.state;
-
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.uml2.uml.UMLPackage;
-
-/**
- * Concrete implementation to edit a State's exit feature
- *
- * @see {@link AbstractBehaviorToStateDropStrategy}
- *
- * @author Camille Letavernier
- */
-public class BehaviorToExitDropStrategy extends AbstractBehaviorToStateDropStrategy {
-
- @Override
- protected EStructuralFeature getFeatureToEdit() {
- return UMLPackage.eINSTANCE.getState_Exit();
- }
-
-}
+/***************************************************************************** + * Copyright (c) 2012 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: + * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation + *****************************************************************************/ +package org.eclipse.papyrus.uml.diagram.dnd.strategy.state; + +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.uml2.uml.UMLPackage; + +/** + * Concrete implementation to edit a State's exit feature + * + * @see {@link AbstractBehaviorToStateDropStrategy} + * + * @author Camille Letavernier + */ +public class BehaviorToExitDropStrategy extends AbstractBehaviorToStateDropStrategy { + + @Override + protected EStructuralFeature getFeatureToEdit() { + return UMLPackage.eINSTANCE.getState_Exit(); + } + +} |