svn commit: r13206 - branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/UMLUtil.java

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: b00__1
Date: 2007-08-02 04:23:05-0700
New Revision: 13206

Modified:
   branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/UMLUtil.java

Log:
Enhance UMLUtil with a copy method for any UML element and destination.

Modified: branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/UMLUtil.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/UMLUtil.java?view=diff&rev=13206&p1=branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/UMLUtil.java&p2=branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/UMLUtil.java&r1=13205&r2=13206
==============================================================================
--- branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/UMLUtil.java	(original)
+++ branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/UMLUtil.java	2007-08-02 04:23:05-0700
@@ -26,9 +26,15 @@
 
 package org.argouml.model.euml;
 
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.command.StrictCompoundCommand;
 import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.edit.command.CopyToClipboardCommand;
+import org.eclipse.emf.edit.command.PasteFromClipboardCommand;
+import org.eclipse.emf.edit.domain.EditingDomain;
 import org.eclipse.uml2.uml.Association;
 import org.eclipse.uml2.uml.AssociationClass;
+import org.eclipse.uml2.uml.Element;
 import org.eclipse.uml2.uml.Operation;
 import org.eclipse.uml2.uml.Property;
 import org.eclipse.uml2.uml.Type;
@@ -36,6 +42,7 @@
 /**
  * This class exposes protected methods from
  * {@link org.eclipse.uml2.uml.UMLUtil}
+ * and adds additional util methods
  * 
  * @author Bogdan Pistol
  */
@@ -54,5 +61,23 @@
     public static EList<Operation> getOwnedOperations(Type type) {
         return org.eclipse.uml2.uml.util.UMLUtil.getOwnedOperations(type);
     }
+    
+    public static boolean copy(EditingDomain editingDomain, Element source, Element destination) {
+        Command copyToClipboard = CopyToClipboardCommand.create(editingDomain, source);
+        Command pasteFromClipboard = PasteFromClipboardCommand.create(editingDomain, destination, null);
+        StrictCompoundCommand copyCommand = new StrictCompoundCommand() {
+            {
+                isPessimistic = true;
+            }
+        };
+        copyCommand.append(copyToClipboard);
+        copyCommand.append(pasteFromClipboard);
+        if (!copyCommand.canExecute()) {
+            return false;
+        } else {
+            editingDomain.getCommandStack().execute(copyCommand);
+            return true;
+        }
+    }
 
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.