Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Noyrit2016-08-09 10:25:50 +0000
committerGerrit Code Review @ Eclipse.org2016-08-28 15:46:41 +0000
commit7310db0b3b2e8ee805fedf4bfd16baf438c89332 (patch)
tree3dadff6a067e8d8bcbf837d8277dfac7749aef27 /plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common
parent7851474fe5f33de156c797942945a3e9c97cb0a8 (diff)
downloadorg.eclipse.papyrus-7310db0b3b2e8ee805fedf4bfd16baf438c89332.tar.gz
org.eclipse.papyrus-7310db0b3b2e8ee805fedf4bfd16baf438c89332.tar.xz
org.eclipse.papyrus-7310db0b3b2e8ee805fedf4bfd16baf438c89332.zip
Bug 443799 - Fix potential bugs identified by FindBugs in oep.infra.*
Bug 499554 - Oxygen release version number moved to 3.0.0. Change-Id: I8e112db7175a5b89eb9b37973639627a6c29e007
Diffstat (limited to 'plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common')
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF26
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/pom.xml20
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/commands/AbstractCommonTransactionalCommmand.java142
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/commands/ModelCreationCommandBase.java2
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/CommentShapeForAppliedStereotypeEditPolicy.java2
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/ListenerEventEditPolicy.java488
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/handlers/PasteWithModelHandler.java2
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/listeners/AbstractPapyrusModifcationTriggerListener.java270
-rw-r--r--plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/providers/PapyrusDiagramGlobalActionHandler.java621
9 files changed, 786 insertions, 787 deletions
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF
index 25d71a48a6d..1e6c3452778 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/META-INF/MANIFEST.MF
@@ -51,39 +51,39 @@ Bundle-ClassPath: .
Bundle-Name: %pluginName
Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
-Require-Bundle: org.eclipse.papyrus.extensionpoints.editors;bundle-version="[1.2.0,2.0.0)";visibility:=reexport,
- org.eclipse.papyrus.uml.tools.utils;bundle-version="[2.0.0,3.0.0)";visibility:=reexport,
+Require-Bundle: org.eclipse.papyrus.extensionpoints.editors;bundle-version="[2.0.0,3.0.0)";visibility:=reexport,
+ org.eclipse.papyrus.uml.tools.utils;bundle-version="[3.0.0,4.0.0)";visibility:=reexport,
org.eclipse.gmf.runtime.diagram.ui.properties;bundle-version="[1.7.0,2.0.0)";visibility:=reexport,
- org.eclipse.papyrus.uml.diagram.wizards;bundle-version="[2.0.0,3.0.0)",
- org.eclipse.papyrus.editor;bundle-version="[1.2.0,2.0.0)",
+ org.eclipse.papyrus.uml.diagram.wizards;bundle-version="[3.0.0,4.0.0)",
+ org.eclipse.papyrus.editor;bundle-version="[2.0.0,3.0.0)",
org.eclipse.gmf.runtime.diagram.ui.render;bundle-version="[1.7.0,2.0.0)",
- org.eclipse.papyrus.infra.gmfdiag.preferences;bundle-version="[2.0.0,3.0.0)",
+ org.eclipse.papyrus.infra.gmfdiag.preferences;bundle-version="[3.0.0,4.0.0)",
org.eclipse.gmf.runtime.diagram.ui.actions;bundle-version="[1.7.0,2.0.0)",
org.eclipse.papyrus.infra.gmfdiag.dnd;bundle-version="[1.2.0,2.0.0)",
- org.eclipse.papyrus.uml.diagram.navigation;bundle-version="[1.2.0,2.0.0)",
+ org.eclipse.papyrus.uml.diagram.navigation;bundle-version="[2.0.0,3.0.0)",
org.eclipse.gmf.runtime.diagram.ui.printing;bundle-version="[1.7.0,2.0.0)",
org.eclipse.gmf.runtime.diagram.ui.providers.ide;bundle-version="[1.7.0,2.0.0)",
org.eclipse.papyrus.infra.services.resourceloading;bundle-version="[2.0.0,3.0.0)",
- org.eclipse.papyrus.uml.profile;bundle-version="[2.0.0,3.0.0)",
+ org.eclipse.papyrus.uml.profile;bundle-version="[3.0.0,4.0.0)",
org.eclipse.papyrus.infra.emf.appearance;bundle-version="[1.2.0,2.0.0)";visibility:=reexport,
org.eclipse.papyrus.infra.widgets.toolbox;bundle-version="[1.2.0,2.0.0)",
- org.eclipse.papyrus.infra.emf.readonly;bundle-version="[2.0.0,3.0.0)",
+ org.eclipse.papyrus.infra.emf.readonly;bundle-version="[3.0.0,4.0.0)",
org.eclipse.papyrus.infra.services.localizer;bundle-version="[1.2.0,2.0.0)",
org.apache.batik.dom.svg;bundle-version="[1.6.0,1.7.0)",
org.apache.batik.css;bundle-version="[1.6.0,1.7.0)",
org.apache.batik.util;bundle-version="[1.6.0,1.7.0)",
org.apache.batik.dom;bundle-version="[1.6.0,1.7.0)",
org.eclipse.papyrus.infra.core.pluginexplorer;bundle-version="[1.2.0,2.0.0)",
- org.eclipse.papyrus.uml.diagram.paletteconfiguration;bundle-version="[1.2.0,2.0.0)";visibility:=reexport,
- org.eclipse.papyrus.uml.modelrepair;bundle-version="[1.2.0,2.0.0)",
+ org.eclipse.papyrus.uml.diagram.paletteconfiguration;bundle-version="[2.0.0,3.0.0)";visibility:=reexport,
+ org.eclipse.papyrus.uml.modelrepair;bundle-version="[2.0.0,3.0.0)",
org.eclipse.papyrus.infra.gmfdiag.menu;bundle-version="[1.2.0,2.0.0)";visibility:=reexport,
org.eclipse.e4.ui.css.core;bundle-version="[0.11.0,1.0.0)",
- org.eclipse.papyrus.infra.gmfdiag.canonical;bundle-version="[1.2.0,2.0.0)";visibility:=reexport,
+ org.eclipse.papyrus.infra.gmfdiag.canonical;bundle-version="[2.0.0,3.0.0)";visibility:=reexport,
org.eclipse.papyrus.uml.appearance;bundle-version="[1.2.0,2.0.0)",
- org.eclipse.papyrus.infra.hyperlink;bundle-version="[2.0.0,3.0.0)",
+ org.eclipse.papyrus.infra.hyperlink;bundle-version="[3.0.0,4.0.0)",
org.eclipse.nebula.widgets.richtext;bundle-version="[1.0.0,2.0.0)"
Bundle-Vendor: %providerName
-Bundle-Version: 2.0.0.qualifier
+Bundle-Version: 3.0.0.qualifier
Eclipse-BuddyPolicy: dependent
Bundle-Activator: org.eclipse.papyrus.uml.diagram.common.Activator
Bundle-ManifestVersion: 2
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/pom.xml b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/pom.xml
index c14b9fc6bd6..c6db74cc8dc 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/pom.xml
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/pom.xml
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
-<project>
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.eclipse.papyrus</groupId>
- <artifactId>org.eclipse.papyrus.uml-diagrams</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- </parent>
- <artifactId>org.eclipse.papyrus.uml.diagram.common</artifactId>
- <version>2.0.0-SNAPSHOT</version>
- <packaging>eclipse-plugin</packaging>
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.eclipse.papyrus</groupId>
+ <artifactId>org.eclipse.papyrus.uml-diagrams</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+ </parent>
+ <artifactId>org.eclipse.papyrus.uml.diagram.common</artifactId>
+ <version>3.0.0-SNAPSHOT</version>
+ <packaging>eclipse-plugin</packaging>
</project> \ No newline at end of file
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/commands/AbstractCommonTransactionalCommmand.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/commands/AbstractCommonTransactionalCommmand.java
index 7331da7e234..4ca81edd57a 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/commands/AbstractCommonTransactionalCommmand.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/commands/AbstractCommonTransactionalCommmand.java
@@ -1,71 +1,71 @@
-/*******************************************************************************
- * Copyright (c) 2008 Conselleria de Infraestructuras y Transporte,
- * Generalitat de la Comunitat Valenciana .
- * 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: Francisco Javier Cano Muñoz (Prodevelop) - initial API implementation
- *
- ******************************************************************************/
-package org.eclipse.papyrus.uml.diagram.common.commands;
-
-import java.util.List;
-
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
-import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
-import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
-
-/**
- * An <AbstractTransactionalCommand> that can give proxies for EMF and GEF.
- *
- * @author <a href="mailto:fjcano@prodevelop.es">Francisco Javier Cano Muñoz</a>
- *
- */
-public abstract class AbstractCommonTransactionalCommmand extends AbstractTransactionalCommand {
-
- /**
- * Default constructor.
- *
- * @param domain
- * @param label
- * @param affectedFiles
- */
- public AbstractCommonTransactionalCommmand(TransactionalEditingDomain domain, String label, List affectedFiles) {
- super(domain, label, affectedFiles);
- }
-
- /**
- * To EMF proxy.
- *
- * @return
- */
- public Command toEMFCommand() {
- return new GMFtoEMFCommandWrapper(this);
- }
-
- /**
- * To GEF proxy.
- *
- * @return
- */
- // @unused
- public org.eclipse.gef.commands.Command toGEFCommand() {
- return new ICommandProxy(this);
- }
-
- /**
- * Execute this command in the <EditingDomain>'s <CommandStack> as a
- * transaction.
- */
- // @unused
- public void executeInTransaction() {
- if (getEditingDomain() != null) {
- getEditingDomain().getCommandStack().execute(toEMFCommand());
- }
- }
-
-}
+/*******************************************************************************
+ * Copyright (c) 2008 Conselleria de Infraestructuras y Transporte,
+ * Generalitat de la Comunitat Valenciana .
+ * 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: Francisco Javier Cano Muñoz (Prodevelop) - initial API implementation
+ *
+ ******************************************************************************/
+package org.eclipse.papyrus.uml.diagram.common.commands;
+
+import java.util.List;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.papyrus.infra.emf.gmf.command.GMFtoEMFCommandWrapper;
+
+/**
+ * An <AbstractTransactionalCommand> that can give proxies for EMF and GEF.
+ *
+ * @author <a href="mailto:fjcano@prodevelop.es">Francisco Javier Cano Muñoz</a>
+ *
+ */
+public abstract class AbstractCommonTransactionalCommmand extends AbstractTransactionalCommand {
+
+ /**
+ * Default constructor.
+ *
+ * @param domain
+ * @param label
+ * @param affectedFiles
+ */
+ public AbstractCommonTransactionalCommmand(TransactionalEditingDomain domain, String label, List affectedFiles) {
+ super(domain, label, affectedFiles);
+ }
+
+ /**
+ * To EMF proxy.
+ *
+ * @return
+ */
+ public Command toEMFCommand() {
+ return new GMFtoEMFCommandWrapper(this);
+ }
+
+ /**
+ * To GEF proxy.
+ *
+ * @return
+ */
+ // @unused
+ public org.eclipse.gef.commands.Command toGEFCommand() {
+ return new ICommandProxy(this);
+ }
+
+ /**
+ * Execute this command in the <EditingDomain>'s <CommandStack> as a
+ * transaction.
+ */
+ // @unused
+ public void executeInTransaction() {
+ if (getEditingDomain() != null) {
+ getEditingDomain().getCommandStack().execute(toEMFCommand());
+ }
+ }
+
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/commands/ModelCreationCommandBase.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/commands/ModelCreationCommandBase.java
index 5ae540b4a27..e723d778fd2 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/commands/ModelCreationCommandBase.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/commands/ModelCreationCommandBase.java
@@ -23,8 +23,8 @@ import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gmf.runtime.common.core.command.CommandResult;
import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
-import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
import org.eclipse.papyrus.infra.core.resource.ModelSet;
+import org.eclipse.papyrus.infra.emf.gmf.command.GMFtoEMFCommandWrapper;
import org.eclipse.papyrus.infra.ui.extension.commands.IModelCreationCommand;
import org.eclipse.papyrus.uml.tools.model.UmlUtils;
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/CommentShapeForAppliedStereotypeEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/CommentShapeForAppliedStereotypeEditPolicy.java
index 0e742df6772..3a2a4b1003e 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/CommentShapeForAppliedStereotypeEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/CommentShapeForAppliedStereotypeEditPolicy.java
@@ -29,9 +29,9 @@ import org.eclipse.gmf.runtime.diagram.ui.requests.EditCommandRequestWrapper;
import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.infra.core.listenerservice.IPapyrusListener;
+import org.eclipse.papyrus.infra.emf.gmf.util.GMFUnsafe;
import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IPapyrusEditPart;
import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationUtils;
-import org.eclipse.papyrus.infra.gmfdiag.common.utils.GMFUnsafe;
import org.eclipse.papyrus.uml.diagram.common.Activator;
import org.eclipse.papyrus.uml.diagram.common.figure.node.IPapyrusNodeUMLElementFigure;
import org.eclipse.papyrus.uml.diagram.common.stereotype.display.helper.StereotypeDisplayConstant;
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/ListenerEventEditPolicy.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/ListenerEventEditPolicy.java
index 758e1119629..80dd70e2bbc 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/ListenerEventEditPolicy.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/editpolicies/ListenerEventEditPolicy.java
@@ -1,244 +1,244 @@
-/*****************************************************************************
- * Copyright (c) 2011 Atos.
- *
- *
- * 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:
- * Atos - Initial API and implementation
- * Arthur Daussy (Atos) arthur.daussy@atos.net - Bug 249786: [General] drag'n'drop does not work for elements stored in nested classifier compartment
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.common.editpolicies;
-
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.editpolicies.AbstractEditPolicy;
-import org.eclipse.gmf.runtime.common.core.command.ICommand;
-import org.eclipse.gmf.runtime.diagram.core.listener.DiagramEventBroker;
-import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CanonicalEditPolicy;
-import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest;
-import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
-
-import com.google.common.collect.ImmutableSet;
-
-public abstract class ListenerEventEditPolicy extends AbstractEditPolicy implements IStructuralFeatureListener {
-
- /** Adds <code>String.class</tt> adaptablity to return a factory hint. Copied from {@link CanonicalEditPolicy} */
- protected static final class ElementListenerAdapter extends EObjectAdapter {
-
- private String _hint;
-
- /**
- * constructor
- *
- * @param element
- * @param hint
- */
- public ElementListenerAdapter(EObject element, String hint) {
- super(element);
- _hint = hint;
- }
-
- /** Adds <code>String.class</tt> adaptablity. */
- @Override
- public Object getAdapter(Class adapter) {
- if (adapter.equals(String.class)) {
- return _hint;
- }
- return super.getAdapter(adapter);
- }
- }
-
- public ListenerEventEditPolicy() {
- super();
- }
-
- /**
- * This method tries to locate the position that the view will be
- * inserted into it's parent. The position is determined by the position
- * of the semantic element. If the semantic element is not found the view
- * will be appended to it's parent.
- *
- * @param semanticChild
- * @return position where the view should be inserted
- */
- protected int getViewIndexFor(EObject semanticChild) {
- // The default implementation returns APPEND
- return ViewUtil.APPEND;
- }
-
- /**
- * Returns the default factory hint.
- *
- * @return <code>host().getView().getSemanticType()</code>
- */
- protected String getDefaultFactoryHint() {
- return ((View) host().getModel()).getType();
- }
-
-
- /**
- * Return a view descriptor.
- *
- * @param elementAdapter
- * semantic element
- * @param viewKind
- * type of view to create
- * @param hint
- * factory hint
- * @param index
- * index
- * @return a create <i>non-persisted</i> view descriptor
- */
- protected CreateViewRequest.ViewDescriptor getViewDescriptor(IAdaptable elementAdapter, Class viewKind, String hint, int index) {
- return new CreateViewRequest.ViewDescriptor(elementAdapter, viewKind, hint, index, false, host().getDiagramPreferencesHint());
- }
-
-
-
- /**
- * Gets the diagram event broker from the editing domain.
- *
- * @return the diagram event broker
- */
- private DiagramEventBroker getDiagramEventBroker() {
- TransactionalEditingDomain theEditingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain();
- if (theEditingDomain != null) {
- return DiagramEventBroker.getInstance(theEditingDomain);
- }
- throw new IllegalStateException("EditPolicy unable to retrive the DiagramEventBroker");//
- }
-
- /**
- * Return the {@link IGraphicalEditPart} host (never null)
- *
- * @return
- */
- protected IGraphicalEditPart host() {
- EditPart host = getHost();
- if (host instanceof IGraphicalEditPart) {
- return ((IGraphicalEditPart) host);
- }
- throw new IllegalStateException("The host of this EditPolicy is not an instance of IGraphicalEditPart");//
- }
-
- /**
- *
- * @return {@link EObject} of the host of this edit Policy or null if error
- */
- protected EObject getSemanticHost() {
- IGraphicalEditPart host = host();
- if (host != null) {
- return host.resolveSemanticElement();
- }
- return null;
- }
-
- /**
- * Add the listeners corresponding to to the structural feature
- *
- * @see org.eclipse.gef.editpolicies.AbstractEditPolicy#activate()
- */
- @Override
- public void activate() {
- for (EStructuralFeature feature : getEStructuralFeaturesToListen()) {
- getDiagramEventBroker().addNotificationListener(getSemanticHost(), feature, this);
- }
- super.activate();
- }
-
- /**
- * Add the listeners corresponding to to the structural feature
- *
- * @see org.eclipse.gef.editpolicies.AbstractEditPolicy#activate()
- */
- @Override
- public void deactivate() {
- for (EStructuralFeature feature : getEStructuralFeaturesToListen()) {
- getDiagramEventBroker().removeNotificationListener(getSemanticHost(), feature, this);
- }
- super.deactivate();
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.diagram.core.listener.NotificationPreCommitListener#transactionAboutToCommit(org.eclipse.emf.common.notify.Notification)
- *
- * @param notification
- * @return
- */
- @Override
- public org.eclipse.emf.common.command.Command transactionAboutToCommit(Notification notification) {
- ICommand result = null;
- if (getEStructuralFeaturesToListen().contains(notification.getFeature()) && handleNotificationType(notification.getEventType())) {
- Object newObject = notification.getNewValue();
- Object oldObject = notification.getOldValue();
- Object feature = notification.getFeature();
- int eventType = notification.getEventType();
- Object notifier = notification.getNotifier();
- if (isInstaceofOrNull(newObject, EObject.class) && isInstaceofOrNull(oldObject, EObject.class) && feature instanceof EStructuralFeature && isInstaceofOrNull(notifier, EObject.class)) {
- result = getCommand((EObject) newObject, (EObject) oldObject, (EStructuralFeature) feature, eventType, (EObject) notifier);
- } else {
- result = getSpecialCommandCommand(notification);
- }
- }
- return (result != null) ? new GMFtoEMFCommandWrapper(result) : null;
- }
-
- /**
- * Similar to instance but return true if the objet is null
- *
- * @param o
- * @param clazz
- * @return
- */
- private boolean isInstaceofOrNull(Object o, Class clazz) {
- return o == null || clazz.isInstance(o);
- }
-
- /**
- * This method could be override by extended class to handle specific notification
- *
- * @param notification
- * @return
- */
- protected ICommand getSpecialCommandCommand(Notification notification) {
- return null;
- }
-
- protected abstract ICommand getCommand(EObject newObject, EObject oldObject, EStructuralFeature feature, int eventType, EObject notifier);
-
- /**
- * {@inheritDoc IStructuralFeatureListener}
- *
- * @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IStructuralFeatureListener#handleNotificationType(int)
- *
- * @param type
- * @return
- */
- @Override
- public abstract boolean handleNotificationType(int type);
-
- /**
- * {@inheritDoc IStructuralFeatureListener}
- *
- * @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IStructuralFeatureListener#getEStructuralFeaturesToListen()
- *
- * @param type
- * @return
- */
- @Override
- public abstract ImmutableSet<EStructuralFeature> getEStructuralFeaturesToListen();
-}
+/*****************************************************************************
+ * Copyright (c) 2011 Atos.
+ *
+ *
+ * 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:
+ * Atos - Initial API and implementation
+ * Arthur Daussy (Atos) arthur.daussy@atos.net - Bug 249786: [General] drag'n'drop does not work for elements stored in nested classifier compartment
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.common.editpolicies;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.editpolicies.AbstractEditPolicy;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.diagram.core.listener.DiagramEventBroker;
+import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editpolicies.CanonicalEditPolicy;
+import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest;
+import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.emf.gmf.command.GMFtoEMFCommandWrapper;
+
+import com.google.common.collect.ImmutableSet;
+
+public abstract class ListenerEventEditPolicy extends AbstractEditPolicy implements IStructuralFeatureListener {
+
+ /** Adds <code>String.class</tt> adaptablity to return a factory hint. Copied from {@link CanonicalEditPolicy} */
+ protected static final class ElementListenerAdapter extends EObjectAdapter {
+
+ private String _hint;
+
+ /**
+ * constructor
+ *
+ * @param element
+ * @param hint
+ */
+ public ElementListenerAdapter(EObject element, String hint) {
+ super(element);
+ _hint = hint;
+ }
+
+ /** Adds <code>String.class</tt> adaptablity. */
+ @Override
+ public Object getAdapter(Class adapter) {
+ if (adapter.equals(String.class)) {
+ return _hint;
+ }
+ return super.getAdapter(adapter);
+ }
+ }
+
+ public ListenerEventEditPolicy() {
+ super();
+ }
+
+ /**
+ * This method tries to locate the position that the view will be
+ * inserted into it's parent. The position is determined by the position
+ * of the semantic element. If the semantic element is not found the view
+ * will be appended to it's parent.
+ *
+ * @param semanticChild
+ * @return position where the view should be inserted
+ */
+ protected int getViewIndexFor(EObject semanticChild) {
+ // The default implementation returns APPEND
+ return ViewUtil.APPEND;
+ }
+
+ /**
+ * Returns the default factory hint.
+ *
+ * @return <code>host().getView().getSemanticType()</code>
+ */
+ protected String getDefaultFactoryHint() {
+ return ((View) host().getModel()).getType();
+ }
+
+
+ /**
+ * Return a view descriptor.
+ *
+ * @param elementAdapter
+ * semantic element
+ * @param viewKind
+ * type of view to create
+ * @param hint
+ * factory hint
+ * @param index
+ * index
+ * @return a create <i>non-persisted</i> view descriptor
+ */
+ protected CreateViewRequest.ViewDescriptor getViewDescriptor(IAdaptable elementAdapter, Class viewKind, String hint, int index) {
+ return new CreateViewRequest.ViewDescriptor(elementAdapter, viewKind, hint, index, false, host().getDiagramPreferencesHint());
+ }
+
+
+
+ /**
+ * Gets the diagram event broker from the editing domain.
+ *
+ * @return the diagram event broker
+ */
+ private DiagramEventBroker getDiagramEventBroker() {
+ TransactionalEditingDomain theEditingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain();
+ if (theEditingDomain != null) {
+ return DiagramEventBroker.getInstance(theEditingDomain);
+ }
+ throw new IllegalStateException("EditPolicy unable to retrive the DiagramEventBroker");//
+ }
+
+ /**
+ * Return the {@link IGraphicalEditPart} host (never null)
+ *
+ * @return
+ */
+ protected IGraphicalEditPart host() {
+ EditPart host = getHost();
+ if (host instanceof IGraphicalEditPart) {
+ return ((IGraphicalEditPart) host);
+ }
+ throw new IllegalStateException("The host of this EditPolicy is not an instance of IGraphicalEditPart");//
+ }
+
+ /**
+ *
+ * @return {@link EObject} of the host of this edit Policy or null if error
+ */
+ protected EObject getSemanticHost() {
+ IGraphicalEditPart host = host();
+ if (host != null) {
+ return host.resolveSemanticElement();
+ }
+ return null;
+ }
+
+ /**
+ * Add the listeners corresponding to to the structural feature
+ *
+ * @see org.eclipse.gef.editpolicies.AbstractEditPolicy#activate()
+ */
+ @Override
+ public void activate() {
+ for (EStructuralFeature feature : getEStructuralFeaturesToListen()) {
+ getDiagramEventBroker().addNotificationListener(getSemanticHost(), feature, this);
+ }
+ super.activate();
+ }
+
+ /**
+ * Add the listeners corresponding to to the structural feature
+ *
+ * @see org.eclipse.gef.editpolicies.AbstractEditPolicy#activate()
+ */
+ @Override
+ public void deactivate() {
+ for (EStructuralFeature feature : getEStructuralFeaturesToListen()) {
+ getDiagramEventBroker().removeNotificationListener(getSemanticHost(), feature, this);
+ }
+ super.deactivate();
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.diagram.core.listener.NotificationPreCommitListener#transactionAboutToCommit(org.eclipse.emf.common.notify.Notification)
+ *
+ * @param notification
+ * @return
+ */
+ @Override
+ public org.eclipse.emf.common.command.Command transactionAboutToCommit(Notification notification) {
+ ICommand result = null;
+ if (getEStructuralFeaturesToListen().contains(notification.getFeature()) && handleNotificationType(notification.getEventType())) {
+ Object newObject = notification.getNewValue();
+ Object oldObject = notification.getOldValue();
+ Object feature = notification.getFeature();
+ int eventType = notification.getEventType();
+ Object notifier = notification.getNotifier();
+ if (isInstaceofOrNull(newObject, EObject.class) && isInstaceofOrNull(oldObject, EObject.class) && feature instanceof EStructuralFeature && isInstaceofOrNull(notifier, EObject.class)) {
+ result = getCommand((EObject) newObject, (EObject) oldObject, (EStructuralFeature) feature, eventType, (EObject) notifier);
+ } else {
+ result = getSpecialCommandCommand(notification);
+ }
+ }
+ return (result != null) ? new GMFtoEMFCommandWrapper(result) : null;
+ }
+
+ /**
+ * Similar to instance but return true if the objet is null
+ *
+ * @param o
+ * @param clazz
+ * @return
+ */
+ private boolean isInstaceofOrNull(Object o, Class clazz) {
+ return o == null || clazz.isInstance(o);
+ }
+
+ /**
+ * This method could be override by extended class to handle specific notification
+ *
+ * @param notification
+ * @return
+ */
+ protected ICommand getSpecialCommandCommand(Notification notification) {
+ return null;
+ }
+
+ protected abstract ICommand getCommand(EObject newObject, EObject oldObject, EStructuralFeature feature, int eventType, EObject notifier);
+
+ /**
+ * {@inheritDoc IStructuralFeatureListener}
+ *
+ * @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IStructuralFeatureListener#handleNotificationType(int)
+ *
+ * @param type
+ * @return
+ */
+ @Override
+ public abstract boolean handleNotificationType(int type);
+
+ /**
+ * {@inheritDoc IStructuralFeatureListener}
+ *
+ * @see org.eclipse.papyrus.uml.diagram.common.editpolicies.IStructuralFeatureListener#getEStructuralFeaturesToListen()
+ *
+ * @param type
+ * @return
+ */
+ @Override
+ public abstract ImmutableSet<EStructuralFeature> getEStructuralFeaturesToListen();
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/handlers/PasteWithModelHandler.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/handlers/PasteWithModelHandler.java
index 15049362040..8d2a6045fa5 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/handlers/PasteWithModelHandler.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/handlers/PasteWithModelHandler.java
@@ -24,7 +24,7 @@ import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
+import org.eclipse.papyrus.infra.emf.gmf.command.GMFtoEMFCommandWrapper;
import org.eclipse.papyrus.uml.diagram.common.helper.CleanDiagramHelper;
import org.eclipse.papyrus.uml.diagram.common.service.PasteCommandService;
import org.eclipse.ui.IEditorPart;
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/listeners/AbstractPapyrusModifcationTriggerListener.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/listeners/AbstractPapyrusModifcationTriggerListener.java
index 885af81d11c..987373465e5 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/listeners/AbstractPapyrusModifcationTriggerListener.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/listeners/AbstractPapyrusModifcationTriggerListener.java
@@ -1,135 +1,135 @@
-/*****************************************************************************
- * Copyright (c) 2011 Atos.
- *
- *
- * 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:
- * Atos - Initial API and implementation
- * Arthur Daussy Bug 366026 - [ActivityDiagram] Refactoring in order to try respect Generation Gap Pattern
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.common.listeners;
-
-import java.util.Collection;
-
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EStructuralFeature.Setting;
-import org.eclipse.emf.ecore.util.ECrossReferenceAdapter;
-import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
-import org.eclipse.emf.edit.domain.EditingDomain;
-import org.eclipse.emf.transaction.NotificationFilter;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.emf.transaction.TriggerListener;
-import org.eclipse.gmf.runtime.common.core.command.ICommand;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
-import org.eclipse.gmf.runtime.notation.NotationPackage;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
-import org.eclipse.papyrus.uml.diagram.common.util.DiagramEditPartsUtil;
-
-import com.google.common.base.Function;
-import com.google.common.base.Predicate;
-import com.google.common.base.Predicates;
-import com.google.common.collect.Iterables;
-
-/**
- * Abstract method used to trigger model modification by listenning the ressource set
- *
- * @author adaussy
- *
- */
-public abstract class AbstractPapyrusModifcationTriggerListener extends TriggerListener {
- @Override
- protected Command trigger(TransactionalEditingDomain domain, Notification notification) {
- if (notification != null) {
- ICommand cc = getModificationCommand(notification);
- if (cc != null) {
- return new GMFtoEMFCommandWrapper(cc);
- }
- }
- return null;
- }
-
- @Override
- public abstract NotificationFilter getFilter();
-
- /**
- * Command which will react to the trigger
- *
- * @param notif
- * @return
- */
- protected abstract ICommand getModificationCommand(Notification notif);
-
- /**
- * Return the main edipart which correspond to the {@link EObject} passed in argument
- *
- * @param eObject
- * @param rootEditPart
- * {@link IGraphicalEditPart} root from which the search will start
- * @return
- */
- protected IGraphicalEditPart getChildByEObject(final EObject eObject, IGraphicalEditPart rootEditPart, boolean isEdge) {
- return DiagramEditPartsUtil.getChildByEObject(eObject, rootEditPart, isEdge);
- }
-
-
- /**
- * Get the referencing views
- *
- * @param oldEObject
- * @param predicates
- * Additionnal predecate use to speciy search
- * @return
- */
- protected Iterable<View> getReferencingView(EObject oldEObject, Predicate<? super View>... predicates) {
- ECrossReferenceAdapter eCrossReferencer = ECrossReferenceAdapter.getCrossReferenceAdapter(oldEObject);
- Collection<Setting> settings = eCrossReferencer.getInverseReferences(oldEObject, false);
- Predicate<Setting> predicate = new Predicate<Setting>() {
-
- @Override
- public boolean apply(Setting input) {
- EObject from = input.getEObject();
- /*
- * Is a view
- */
- if (from instanceof View && NotationPackage.Literals.VIEW__ELEMENT.equals(input.getEStructuralFeature())) {
- return true;
- }
- return false;
- }
- };
-
- Iterable<Setting> referencingView = Iterables.filter(settings, predicate);
- Iterable<View> views = Iterables.transform(referencingView, new Function<Setting, View>() {
-
- @Override
- public View apply(Setting from) {
- return (View) from.getEObject();
- }
- });
-
- return Iterables.filter(views, Predicates.and(predicates));
- }
-
- /**
- * Get the transactionnal editing domain from EObject
- *
- * @param o
- * @return
- */
- protected TransactionalEditingDomain getEditingDomain(Object o) {
- EditingDomain editingDomain = AdapterFactoryEditingDomain.getEditingDomainFor(o);
- if (editingDomain instanceof TransactionalEditingDomain) {
- TransactionalEditingDomain transEditingDomain = (TransactionalEditingDomain) editingDomain;
- return transEditingDomain;
- }
- throw new RuntimeException("Enable to retreive editing domin from object");
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2011 Atos.
+ *
+ *
+ * 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:
+ * Atos - Initial API and implementation
+ * Arthur Daussy Bug 366026 - [ActivityDiagram] Refactoring in order to try respect Generation Gap Pattern
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.common.listeners;
+
+import java.util.Collection;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature.Setting;
+import org.eclipse.emf.ecore.util.ECrossReferenceAdapter;
+import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.transaction.NotificationFilter;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.transaction.TriggerListener;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.emf.gmf.command.GMFtoEMFCommandWrapper;
+import org.eclipse.papyrus.uml.diagram.common.util.DiagramEditPartsUtil;
+
+import com.google.common.base.Function;
+import com.google.common.base.Predicate;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Iterables;
+
+/**
+ * Abstract method used to trigger model modification by listenning the ressource set
+ *
+ * @author adaussy
+ *
+ */
+public abstract class AbstractPapyrusModifcationTriggerListener extends TriggerListener {
+ @Override
+ protected Command trigger(TransactionalEditingDomain domain, Notification notification) {
+ if (notification != null) {
+ ICommand cc = getModificationCommand(notification);
+ if (cc != null) {
+ return new GMFtoEMFCommandWrapper(cc);
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public abstract NotificationFilter getFilter();
+
+ /**
+ * Command which will react to the trigger
+ *
+ * @param notif
+ * @return
+ */
+ protected abstract ICommand getModificationCommand(Notification notif);
+
+ /**
+ * Return the main edipart which correspond to the {@link EObject} passed in argument
+ *
+ * @param eObject
+ * @param rootEditPart
+ * {@link IGraphicalEditPart} root from which the search will start
+ * @return
+ */
+ protected IGraphicalEditPart getChildByEObject(final EObject eObject, IGraphicalEditPart rootEditPart, boolean isEdge) {
+ return DiagramEditPartsUtil.getChildByEObject(eObject, rootEditPart, isEdge);
+ }
+
+
+ /**
+ * Get the referencing views
+ *
+ * @param oldEObject
+ * @param predicates
+ * Additionnal predecate use to speciy search
+ * @return
+ */
+ protected Iterable<View> getReferencingView(EObject oldEObject, Predicate<? super View>... predicates) {
+ ECrossReferenceAdapter eCrossReferencer = ECrossReferenceAdapter.getCrossReferenceAdapter(oldEObject);
+ Collection<Setting> settings = eCrossReferencer.getInverseReferences(oldEObject, false);
+ Predicate<Setting> predicate = new Predicate<Setting>() {
+
+ @Override
+ public boolean apply(Setting input) {
+ EObject from = input.getEObject();
+ /*
+ * Is a view
+ */
+ if (from instanceof View && NotationPackage.Literals.VIEW__ELEMENT.equals(input.getEStructuralFeature())) {
+ return true;
+ }
+ return false;
+ }
+ };
+
+ Iterable<Setting> referencingView = Iterables.filter(settings, predicate);
+ Iterable<View> views = Iterables.transform(referencingView, new Function<Setting, View>() {
+
+ @Override
+ public View apply(Setting from) {
+ return (View) from.getEObject();
+ }
+ });
+
+ return Iterables.filter(views, Predicates.and(predicates));
+ }
+
+ /**
+ * Get the transactionnal editing domain from EObject
+ *
+ * @param o
+ * @return
+ */
+ protected TransactionalEditingDomain getEditingDomain(Object o) {
+ EditingDomain editingDomain = AdapterFactoryEditingDomain.getEditingDomainFor(o);
+ if (editingDomain instanceof TransactionalEditingDomain) {
+ TransactionalEditingDomain transEditingDomain = (TransactionalEditingDomain) editingDomain;
+ return transEditingDomain;
+ }
+ throw new RuntimeException("Enable to retreive editing domin from object");
+ }
+}
diff --git a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/providers/PapyrusDiagramGlobalActionHandler.java b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/providers/PapyrusDiagramGlobalActionHandler.java
index aa7bec1e2b5..259090b55e5 100644
--- a/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/providers/PapyrusDiagramGlobalActionHandler.java
+++ b/plugins/uml/diagram/org.eclipse.papyrus.uml.diagram.common/src/org/eclipse/papyrus/uml/diagram/common/providers/PapyrusDiagramGlobalActionHandler.java
@@ -1,311 +1,310 @@
-/*****************************************************************************
- * Copyright (c) 2008 CEA LIST.
- *
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Patrick Tessier (CEA LIST) Patrick.Tessier@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.uml.diagram.common.providers;
-
-import java.awt.Toolkit;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.emf.edit.command.CopyToClipboardCommand;
-import org.eclipse.emf.edit.domain.EditingDomain;
-import org.eclipse.emf.edit.domain.IEditingDomainProvider;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.RequestConstants;
-import org.eclipse.gef.RootEditPart;
-import org.eclipse.gef.commands.CompoundCommand;
-import org.eclipse.gef.requests.GroupRequest;
-import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
-import org.eclipse.gmf.runtime.common.core.command.ICommand;
-import org.eclipse.gmf.runtime.common.ui.action.global.GlobalActionId;
-import org.eclipse.gmf.runtime.common.ui.services.action.global.IGlobalActionContext;
-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.ConnectionEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart;
-import org.eclipse.gmf.runtime.diagram.ui.render.clipboard.AWTClipboardHelper;
-import org.eclipse.gmf.runtime.diagram.ui.render.internal.providers.ImageSupportGlobalActionHandler;
-import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand;
-import org.eclipse.gmf.runtime.emf.ui.properties.actions.PropertyPageViewAction;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.papyrus.commands.wrappers.EMFtoGMFCommandWrapper;
-import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
-import org.eclipse.papyrus.uml.diagram.common.helper.CleanDiagramHelper;
-import org.eclipse.papyrus.uml.diagram.common.service.PasteCommandService;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IWorkbenchPart;
-
-/**
- * this class has in charge to launch command for cut copy paste (graphically)
- * it is also used to launch the copy into bmp like as writer software
- *
- */
-@SuppressWarnings("restriction")
-public class PapyrusDiagramGlobalActionHandler extends ImageSupportGlobalActionHandler {
-
- @Override
- public boolean canHandle(IGlobalActionContext cntxt) {
- /* Check if the active part is a IDiagramWorkbenchPart */
- IWorkbenchPart part = cntxt.getActivePart();
- part = (IWorkbenchPart) part.getAdapter(IDiagramWorkbenchPart.class);
- if (!(part instanceof IDiagramWorkbenchPart)) {
- return false;
- }
-
- /* Check if the selection is a structured selection */
- if (!(cntxt.getSelection() instanceof IStructuredSelection)) {
- return false;
- }
-
- /* Check the action id */
- String actionId = cntxt.getActionId();
- if (actionId.equals(GlobalActionId.COPY)) {
- return canCopy(cntxt);
- } else if (actionId.equals(GlobalActionId.CUT)) {
- return canCut(cntxt);
- } else if (actionId.equals(GlobalActionId.PASTE)) {
- return canPaste(cntxt);
- }
- return false;
- }
-
- @Override
- protected boolean canPaste(IGlobalActionContext cntxt) {
- /* Get the selected edit parts */
- Object[] objectsArray = ((IStructuredSelection) cntxt.getSelection()).toArray();
-
- if (objectsArray.length > 0 && objectsArray[0] instanceof GraphicalEditPart) {
- ICommand pastecommand = PasteCommandService.getInstance().getPasteViewCommand(((GraphicalEditPart) objectsArray[0]), Toolkit.getDefaultToolkit().getSystemClipboard(), ((GraphicalEditPart) objectsArray[0]).getEditingDomain().getClipboard());
- return pastecommand.canExecute();
- }
-
- if (!AWTClipboardHelper.getInstance().isImageCopySupported()) {
- return super.canPaste(cntxt);
- }
-
- /* Check if the clipboard has data for the drawing surface */
- return AWTClipboardHelper.getInstance().hasCustomData();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.gmf.runtime.common.ui.services.action.global.IGlobalActionHandler
- * #getCommand(org.eclipse.gmf.runtime.common.ui.services.action.
- * global.IGlobalActionContext)
- */
- @Override
- public ICommand getCommand(IGlobalActionContext cntxt) {
- /* Check if the active part is a IDiagramWorkbenchPart */
- IWorkbenchPart part = cntxt.getActivePart();
- part = (IWorkbenchPart) part.getAdapter(IDiagramWorkbenchPart.class);
- if (!(part instanceof IDiagramWorkbenchPart)) {
- return null;
- }
-
- /* Get the model operation context */
- IDiagramWorkbenchPart diagramPart = (IDiagramWorkbenchPart) part;
-
- /* Create a command */
- ICommand command = null;
-
- /* Check the action id */
- String actionId = cntxt.getActionId();
- if (actionId.equals(GlobalActionId.DELETE)) {
- CompoundCommand deleteCC = getDeleteCommand(diagramPart, cntxt);
- /* Set the command */
- if (deleteCC != null && deleteCC.canExecute()) {
- command = new CommandProxy(deleteCC);
- }
- } else if (actionId.equals(GlobalActionId.COPY)) {
- command = getCopyCommand(cntxt, diagramPart, false);
- } else if (actionId.equals(GlobalActionId.CUT)) {
- command = getCutCommand(cntxt, diagramPart);
- } else if (actionId.equals(GlobalActionId.PASTE)) {
-
- /* Get the selected edit parts */
- Object[] objectsArray = ((IStructuredSelection) cntxt.getSelection()).toArray();
-
- if (objectsArray.length > 0 && objectsArray[0] instanceof GraphicalEditPart) {
-
- ICommand pastecommand = PasteCommandService.getInstance().getPasteViewCommand(((GraphicalEditPart) objectsArray[0]), Toolkit.getDefaultToolkit().getSystemClipboard(), ((GraphicalEditPart) objectsArray[0]).getEditingDomain().getClipboard());
-
- if (pastecommand.canExecute()) {
- ((GraphicalEditPart) objectsArray[0]).getEditingDomain().getCommandStack().execute(new GMFtoEMFCommandWrapper(pastecommand));
- RootEditPart topEditPart = ((GraphicalEditPart) objectsArray[0]).getRoot();
- if (topEditPart.getChildren().get(0) instanceof DiagramEditPart) {
- CleanDiagramHelper.getInstance().run((DiagramEditPart) topEditPart.getChildren().get(0));
- }
-
- }
- return null;
- }
-
- } else if (actionId.equals(GlobalActionId.SAVE)) {
- part.getSite().getPage().saveEditor((IEditorPart) diagramPart, false);
- } else if (actionId.equals(GlobalActionId.PROPERTIES)) {
- new PropertyPageViewAction().run();
- }
-
- return command;
- }
-
- /**
- * @see org.eclipse.gmf.runtime.diagram.ui.providers.DiagramGlobalActionHandler#getCopyCommand(org.eclipse.gmf.runtime.common.ui.services.action.global.IGlobalActionContext, org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart, boolean) this
- * class also copy in the clipboard of the editing domain
- * selected elements
- *
- */
-
- @Override
- protected ICommand getCopyCommand(IGlobalActionContext cntxt, IDiagramWorkbenchPart diagramPart, boolean isUndoable) {
- /* Get the selected edit parts */
- Object[] objectsArray = ((IStructuredSelection) cntxt.getSelection()).toArray();
- CompositeCommand compositeCommand = new CompositeCommand(GlobalActionId.COPY);
- if (objectsArray.length > 0 && objectsArray[0] instanceof GraphicalEditPart) {
- // ((GraphicalEditPart)objectsArray[0]).getEditingDomain().setClipboard(((IStructuredSelection)
- // cntxt.getSelection()).toList());
- compositeCommand.add(new EMFtoGMFCommandWrapper(CopyToClipboardCommand.create(((GraphicalEditPart) objectsArray[0]).getEditingDomain(), getNotation(((IStructuredSelection) cntxt.getSelection()).toList()))));
- }
- if (objectsArray.length > 0 && objectsArray[0] instanceof ConnectionEditPart) {
- // ((GraphicalEditPart)objectsArray[0]).getEditingDomain().setClipboard(((IStructuredSelection)
- // cntxt.getSelection()).toList());
- compositeCommand.add(new EMFtoGMFCommandWrapper(CopyToClipboardCommand.create(((ConnectionEditPart) objectsArray[0]).getEditingDomain(), getNotation(((IStructuredSelection) cntxt.getSelection()).toList()))));
- }
- compositeCommand.add(super.getCopyCommand(cntxt, diagramPart, isUndoable));
- return compositeCommand;
- }
-
- /**
- * @see org.eclipse.gmf.runtime.diagram.ui.providers.DiagramGlobalActionHandler#getCutCommand(org.eclipse.gmf.runtime.common.ui.services.action.global.IGlobalActionContext, org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart)
- *
- * @param cntxt
- * @param diagramPart
- * @return
- */
-
- @Override
- protected ICommand getCutCommand(IGlobalActionContext cntxt, IDiagramWorkbenchPart diagramPart) {
- Object[] objectsArray = ((IStructuredSelection) cntxt.getSelection()).toArray();
- CompositeCommand compositeCommand = new CompositeCommand(GlobalActionId.CUT);
- if (objectsArray.length > 0 && objectsArray[0] instanceof GraphicalEditPart) {
- // ((GraphicalEditPart)objectsArray[0]).getEditingDomain().setClipboard(((IStructuredSelection)
- // cntxt.getSelection()).toList());
- compositeCommand.add(new EMFtoGMFCommandWrapper(CopyToClipboardCommand.create(((GraphicalEditPart) objectsArray[0]).getEditingDomain(), getNotation(((IStructuredSelection) cntxt.getSelection()).toList()))));
-
- }
- if (objectsArray.length > 0 && objectsArray[0] instanceof ConnectionEditPart) {
- // ((GraphicalEditPart)objectsArray[0]).getEditingDomain().setClipboard(((IStructuredSelection)
- // cntxt.getSelection()).toList());
- compositeCommand.add(new EMFtoGMFCommandWrapper(CopyToClipboardCommand.create(((ConnectionEditPart) objectsArray[0]).getEditingDomain(), getNotation(((IStructuredSelection) cntxt.getSelection()).toList()))));
- }
- ICommand cutCommand = super.getCutCommand(cntxt, diagramPart);
- if (cutCommand != null) {
- compositeCommand.add(cutCommand);
- }
- return compositeCommand;
- }
-
- /**
- * Returns appropriate delete command for this context.
- *
- * @param part
- * the workbench part
- * @param cntxt
- * the <code>IGlobalActionContext</code> holding the necessary
- * information needed by this action handler
- * @return CompoundCommand command
- */
- private CompoundCommand getDeleteCommand(IDiagramWorkbenchPart part, IGlobalActionContext cntxt) {
- /* Create the delete request */
- GroupRequest deleteReq = new GroupRequest(RequestConstants.REQ_DELETE);
-
- CompoundCommand deleteCC = new CompoundCommand(cntxt.getLabel());
-
- TransactionalEditingDomain editingDomain = getEditingDomain(part);
-
- if (editingDomain == null) {
- return deleteCC;
- }
-
- CompositeTransactionalCommand compositeCommand = new CompositeTransactionalCommand(editingDomain, cntxt.getLabel());
- /* Get the selected edit parts */
- Object[] objects = ((IStructuredSelection) cntxt.getSelection()).toArray();
- for (int i = 0; i < objects.length; i++) {
- /* Get the next part */
- EditPart editPart = (EditPart) objects[i];
-
- /* Send the request to the edit part */
- org.eclipse.gef.commands.Command command = editPart.getCommand(deleteReq);
- if (command != null)
- {
- compositeCommand.compose(new CommandProxy(command));
- // deleteCC.add(editPart.getCommand(deleteReq));
- }
- }
- if (!compositeCommand.isEmpty()) {
- deleteCC.add(new ICommandProxy(compositeCommand));
- }
-
- return deleteCC;
- }
-
- /**
- * Gets the transactional editing domain associated with the workbench <code>part</code>.
- *
- * @param part
- * the diagram workbench part
- * @return the editing domain, or <code>null</code> if there is none.
- */
- private TransactionalEditingDomain getEditingDomain(IDiagramWorkbenchPart part) {
-
- TransactionalEditingDomain result = null;
-
- IEditingDomainProvider provider = (IEditingDomainProvider) part.getAdapter(IEditingDomainProvider.class);
-
- if (provider != null) {
- EditingDomain domain = provider.getEditingDomain();
-
- if (domain != null && domain instanceof TransactionalEditingDomain) {
- result = (TransactionalEditingDomain) domain;
- }
- }
-
- return result;
- }
-
- /**
- * get the list of notation element from the a list of editpart
- *
- * @param editPartList
- * the list of editpart
- * @return the list of notation element
- */
- @SuppressWarnings({ "rawtypes", "unchecked" })
- protected List getNotation(List editPartList) {
- ArrayList notationList = new ArrayList();
- Iterator iterator = editPartList.iterator();
- while (iterator.hasNext()) {
- Object object = iterator.next();
- if (object instanceof EditPart) {
- notationList.add(((EditPart) object).getModel());
- }
- }
- return notationList;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2008 CEA LIST.
+ *
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Patrick Tessier (CEA LIST) Patrick.Tessier@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.uml.diagram.common.providers;
+
+import java.awt.Toolkit;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.emf.edit.command.CopyToClipboardCommand;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.edit.domain.IEditingDomainProvider;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.RequestConstants;
+import org.eclipse.gef.RootEditPart;
+import org.eclipse.gef.commands.CompoundCommand;
+import org.eclipse.gef.requests.GroupRequest;
+import org.eclipse.gmf.runtime.common.core.command.CompositeCommand;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.common.ui.action.global.GlobalActionId;
+import org.eclipse.gmf.runtime.common.ui.services.action.global.IGlobalActionContext;
+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.ConnectionEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart;
+import org.eclipse.gmf.runtime.diagram.ui.render.clipboard.AWTClipboardHelper;
+import org.eclipse.gmf.runtime.diagram.ui.render.internal.providers.ImageSupportGlobalActionHandler;
+import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand;
+import org.eclipse.gmf.runtime.emf.ui.properties.actions.PropertyPageViewAction;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.infra.emf.gmf.command.EMFtoGMFCommandWrapper;
+import org.eclipse.papyrus.infra.emf.gmf.command.GMFtoEMFCommandWrapper;
+import org.eclipse.papyrus.uml.diagram.common.helper.CleanDiagramHelper;
+import org.eclipse.papyrus.uml.diagram.common.service.PasteCommandService;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPart;
+
+/**
+ * this class has in charge to launch command for cut copy paste (graphically)
+ * it is also used to launch the copy into bmp like as writer software
+ *
+ */
+@SuppressWarnings("restriction")
+public class PapyrusDiagramGlobalActionHandler extends ImageSupportGlobalActionHandler {
+
+ @Override
+ public boolean canHandle(IGlobalActionContext cntxt) {
+ /* Check if the active part is a IDiagramWorkbenchPart */
+ IWorkbenchPart part = cntxt.getActivePart();
+ part = (IWorkbenchPart) part.getAdapter(IDiagramWorkbenchPart.class);
+ if (!(part instanceof IDiagramWorkbenchPart)) {
+ return false;
+ }
+
+ /* Check if the selection is a structured selection */
+ if (!(cntxt.getSelection() instanceof IStructuredSelection)) {
+ return false;
+ }
+
+ /* Check the action id */
+ String actionId = cntxt.getActionId();
+ if (actionId.equals(GlobalActionId.COPY)) {
+ return canCopy(cntxt);
+ } else if (actionId.equals(GlobalActionId.CUT)) {
+ return canCut(cntxt);
+ } else if (actionId.equals(GlobalActionId.PASTE)) {
+ return canPaste(cntxt);
+ }
+ return false;
+ }
+
+ @Override
+ protected boolean canPaste(IGlobalActionContext cntxt) {
+ /* Get the selected edit parts */
+ Object[] objectsArray = ((IStructuredSelection) cntxt.getSelection()).toArray();
+
+ if (objectsArray.length > 0 && objectsArray[0] instanceof GraphicalEditPart) {
+ ICommand pastecommand = PasteCommandService.getInstance().getPasteViewCommand(((GraphicalEditPart) objectsArray[0]), Toolkit.getDefaultToolkit().getSystemClipboard(), ((GraphicalEditPart) objectsArray[0]).getEditingDomain().getClipboard());
+ return pastecommand.canExecute();
+ }
+
+ if (!AWTClipboardHelper.getInstance().isImageCopySupported()) {
+ return super.canPaste(cntxt);
+ }
+
+ /* Check if the clipboard has data for the drawing surface */
+ return AWTClipboardHelper.getInstance().hasCustomData();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.gmf.runtime.common.ui.services.action.global.IGlobalActionHandler
+ * #getCommand(org.eclipse.gmf.runtime.common.ui.services.action.
+ * global.IGlobalActionContext)
+ */
+ @Override
+ public ICommand getCommand(IGlobalActionContext cntxt) {
+ /* Check if the active part is a IDiagramWorkbenchPart */
+ IWorkbenchPart part = cntxt.getActivePart();
+ part = (IWorkbenchPart) part.getAdapter(IDiagramWorkbenchPart.class);
+ if (!(part instanceof IDiagramWorkbenchPart)) {
+ return null;
+ }
+
+ /* Get the model operation context */
+ IDiagramWorkbenchPart diagramPart = (IDiagramWorkbenchPart) part;
+
+ /* Create a command */
+ ICommand command = null;
+
+ /* Check the action id */
+ String actionId = cntxt.getActionId();
+ if (actionId.equals(GlobalActionId.DELETE)) {
+ CompoundCommand deleteCC = getDeleteCommand(diagramPart, cntxt);
+ /* Set the command */
+ if (deleteCC != null && deleteCC.canExecute()) {
+ command = new CommandProxy(deleteCC);
+ }
+ } else if (actionId.equals(GlobalActionId.COPY)) {
+ command = getCopyCommand(cntxt, diagramPart, false);
+ } else if (actionId.equals(GlobalActionId.CUT)) {
+ command = getCutCommand(cntxt, diagramPart);
+ } else if (actionId.equals(GlobalActionId.PASTE)) {
+
+ /* Get the selected edit parts */
+ Object[] objectsArray = ((IStructuredSelection) cntxt.getSelection()).toArray();
+
+ if (objectsArray.length > 0 && objectsArray[0] instanceof GraphicalEditPart) {
+
+ ICommand pastecommand = PasteCommandService.getInstance().getPasteViewCommand(((GraphicalEditPart) objectsArray[0]), Toolkit.getDefaultToolkit().getSystemClipboard(), ((GraphicalEditPart) objectsArray[0]).getEditingDomain().getClipboard());
+
+ if (pastecommand.canExecute()) {
+ ((GraphicalEditPart) objectsArray[0]).getEditingDomain().getCommandStack().execute(new GMFtoEMFCommandWrapper(pastecommand));
+ RootEditPart topEditPart = ((GraphicalEditPart) objectsArray[0]).getRoot();
+ if (topEditPart.getChildren().get(0) instanceof DiagramEditPart) {
+ CleanDiagramHelper.getInstance().run((DiagramEditPart) topEditPart.getChildren().get(0));
+ }
+
+ }
+ return null;
+ }
+
+ } else if (actionId.equals(GlobalActionId.SAVE)) {
+ part.getSite().getPage().saveEditor((IEditorPart) diagramPart, false);
+ } else if (actionId.equals(GlobalActionId.PROPERTIES)) {
+ new PropertyPageViewAction().run();
+ }
+
+ return command;
+ }
+
+ /**
+ * @see org.eclipse.gmf.runtime.diagram.ui.providers.DiagramGlobalActionHandler#getCopyCommand(org.eclipse.gmf.runtime.common.ui.services.action.global.IGlobalActionContext, org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart, boolean) this
+ * class also copy in the clipboard of the editing domain
+ * selected elements
+ *
+ */
+
+ @Override
+ protected ICommand getCopyCommand(IGlobalActionContext cntxt, IDiagramWorkbenchPart diagramPart, boolean isUndoable) {
+ /* Get the selected edit parts */
+ Object[] objectsArray = ((IStructuredSelection) cntxt.getSelection()).toArray();
+ CompositeCommand compositeCommand = new CompositeCommand(GlobalActionId.COPY);
+ if (objectsArray.length > 0 && objectsArray[0] instanceof GraphicalEditPart) {
+ // ((GraphicalEditPart)objectsArray[0]).getEditingDomain().setClipboard(((IStructuredSelection)
+ // cntxt.getSelection()).toList());
+ compositeCommand.add(new EMFtoGMFCommandWrapper(CopyToClipboardCommand.create(((GraphicalEditPart) objectsArray[0]).getEditingDomain(), getNotation(((IStructuredSelection) cntxt.getSelection()).toList()))));
+ }
+ if (objectsArray.length > 0 && objectsArray[0] instanceof ConnectionEditPart) {
+ // ((GraphicalEditPart)objectsArray[0]).getEditingDomain().setClipboard(((IStructuredSelection)
+ // cntxt.getSelection()).toList());
+ compositeCommand.add(new EMFtoGMFCommandWrapper(CopyToClipboardCommand.create(((ConnectionEditPart) objectsArray[0]).getEditingDomain(), getNotation(((IStructuredSelection) cntxt.getSelection()).toList()))));
+ }
+ compositeCommand.add(super.getCopyCommand(cntxt, diagramPart, isUndoable));
+ return compositeCommand;
+ }
+
+ /**
+ * @see org.eclipse.gmf.runtime.diagram.ui.providers.DiagramGlobalActionHandler#getCutCommand(org.eclipse.gmf.runtime.common.ui.services.action.global.IGlobalActionContext, org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart)
+ *
+ * @param cntxt
+ * @param diagramPart
+ * @return
+ */
+
+ @Override
+ protected ICommand getCutCommand(IGlobalActionContext cntxt, IDiagramWorkbenchPart diagramPart) {
+ Object[] objectsArray = ((IStructuredSelection) cntxt.getSelection()).toArray();
+ CompositeCommand compositeCommand = new CompositeCommand(GlobalActionId.CUT);
+ if (objectsArray.length > 0 && objectsArray[0] instanceof GraphicalEditPart) {
+ // ((GraphicalEditPart)objectsArray[0]).getEditingDomain().setClipboard(((IStructuredSelection)
+ // cntxt.getSelection()).toList());
+ compositeCommand.add(new EMFtoGMFCommandWrapper(CopyToClipboardCommand.create(((GraphicalEditPart) objectsArray[0]).getEditingDomain(), getNotation(((IStructuredSelection) cntxt.getSelection()).toList()))));
+
+ }
+ if (objectsArray.length > 0 && objectsArray[0] instanceof ConnectionEditPart) {
+ // ((GraphicalEditPart)objectsArray[0]).getEditingDomain().setClipboard(((IStructuredSelection)
+ // cntxt.getSelection()).toList());
+ compositeCommand.add(new EMFtoGMFCommandWrapper(CopyToClipboardCommand.create(((ConnectionEditPart) objectsArray[0]).getEditingDomain(), getNotation(((IStructuredSelection) cntxt.getSelection()).toList()))));
+ }
+ ICommand cutCommand = super.getCutCommand(cntxt, diagramPart);
+ if (cutCommand != null) {
+ compositeCommand.add(cutCommand);
+ }
+ return compositeCommand;
+ }
+
+ /**
+ * Returns appropriate delete command for this context.
+ *
+ * @param part
+ * the workbench part
+ * @param cntxt
+ * the <code>IGlobalActionContext</code> holding the necessary
+ * information needed by this action handler
+ * @return CompoundCommand command
+ */
+ private CompoundCommand getDeleteCommand(IDiagramWorkbenchPart part, IGlobalActionContext cntxt) {
+ /* Create the delete request */
+ GroupRequest deleteReq = new GroupRequest(RequestConstants.REQ_DELETE);
+
+ CompoundCommand deleteCC = new CompoundCommand(cntxt.getLabel());
+
+ TransactionalEditingDomain editingDomain = getEditingDomain(part);
+
+ if (editingDomain == null) {
+ return deleteCC;
+ }
+
+ CompositeTransactionalCommand compositeCommand = new CompositeTransactionalCommand(editingDomain, cntxt.getLabel());
+ /* Get the selected edit parts */
+ Object[] objects = ((IStructuredSelection) cntxt.getSelection()).toArray();
+ for (int i = 0; i < objects.length; i++) {
+ /* Get the next part */
+ EditPart editPart = (EditPart) objects[i];
+
+ /* Send the request to the edit part */
+ org.eclipse.gef.commands.Command command = editPart.getCommand(deleteReq);
+ if (command != null) {
+ compositeCommand.compose(new CommandProxy(command));
+ // deleteCC.add(editPart.getCommand(deleteReq));
+ }
+ }
+ if (!compositeCommand.isEmpty()) {
+ deleteCC.add(new ICommandProxy(compositeCommand));
+ }
+
+ return deleteCC;
+ }
+
+ /**
+ * Gets the transactional editing domain associated with the workbench <code>part</code>.
+ *
+ * @param part
+ * the diagram workbench part
+ * @return the editing domain, or <code>null</code> if there is none.
+ */
+ private TransactionalEditingDomain getEditingDomain(IDiagramWorkbenchPart part) {
+
+ TransactionalEditingDomain result = null;
+
+ IEditingDomainProvider provider = (IEditingDomainProvider) part.getAdapter(IEditingDomainProvider.class);
+
+ if (provider != null) {
+ EditingDomain domain = provider.getEditingDomain();
+
+ if (domain != null && domain instanceof TransactionalEditingDomain) {
+ result = (TransactionalEditingDomain) domain;
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * get the list of notation element from the a list of editpart
+ *
+ * @param editPartList
+ * the list of editpart
+ * @return the list of notation element
+ */
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ protected List getNotation(List editPartList) {
+ ArrayList notationList = new ArrayList();
+ Iterator iterator = editPartList.iterator();
+ while (iterator.hasNext()) {
+ Object object = iterator.next();
+ if (object instanceof EditPart) {
+ notationList.add(((EditPart) object).getModel());
+ }
+ }
+ return notationList;
+ }
+}

Back to the top