Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/PasteShapeOrElementAction.java')
-rw-r--r--plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/PasteShapeOrElementAction.java62
1 files changed, 62 insertions, 0 deletions
diff --git a/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/PasteShapeOrElementAction.java b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/PasteShapeOrElementAction.java
new file mode 100644
index 00000000000..20137e686cc
--- /dev/null
+++ b/plugins/views/modelexplorer/org.eclipse.papyrus.views.modelexplorer/src/org/eclipse/papyrus/modelexplorer/actions/PasteShapeOrElementAction.java
@@ -0,0 +1,62 @@
+/*****************************************************************************
+ * Copyright (c) 2009 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) ansgar.radermacher@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.modelexplorer.actions;
+
+import java.util.Collection;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.edit.command.AddCommand;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.emf.edit.ui.action.PasteAction;
+import org.eclipse.gmf.runtime.notation.View;
+
+/**
+ * Action used for pasting either a model element or a shape (i.e. the model element reprented
+ * by the shape). Delegates to PasteShapeOrElementCommand
+ *
+ * @author Ansgar Radermacher (CEA LIST)
+ */
+public class PasteShapeOrElementAction extends PasteAction
+{
+ public PasteShapeOrElementAction (EditingDomain domain) {
+ super (domain);
+ }
+
+ @Override
+ public Command createCommand(Collection<?> selection)
+ {
+ if ((selection.size () == 1) && (domain != null)) {
+ Object owner = selection.iterator().next ();
+
+ boolean onlyViewsInClipboard = true;
+ boolean foundView = false;
+ if (domain.getClipboard () != null) {
+ for (Object clipObject : domain.getClipboard ()) {
+ if (clipObject instanceof View) {
+ foundView = true;
+ }
+ else {
+ onlyViewsInClipboard = false;
+ }
+ }
+ }
+ // TODO: currently only works for a single element to be copied.
+ if (onlyViewsInClipboard && foundView) {
+ View shape = (View) domain.getClipboard ().iterator ().next ();
+ return AddCommand.create (domain, owner, null, shape.getElement ());
+ }
+ }
+ return super.createCommand (selection);
+ }
+}

Back to the top