From 50bfe9d57677163871b3e9b14c8a529e29114b9a Mon Sep 17 00:00:00 2001
From: Florian Hoelzl <hoelzl@fortiss.org>
Date: Mon, 2 Jul 2012 09:21:22 +0000
Subject: [PATCH] bugfix: using copier without references refs 877

---
 .../kernel/ui/util/CopyPasteUtils.java        | 48 +++++++++----------
 1 file changed, 22 insertions(+), 26 deletions(-)

diff --git a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/util/CopyPasteUtils.java b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/util/CopyPasteUtils.java
index 2707f68be..d0e3aee71 100644
--- a/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/util/CopyPasteUtils.java
+++ b/org.fortiss.tooling.kernel.ui/trunk/src/org/fortiss/tooling/kernel/ui/util/CopyPasteUtils.java
@@ -32,15 +32,15 @@ import org.fortiss.tooling.kernel.service.IElementCompositorService;
 import org.fortiss.tooling.kernel.ui.dnd.CompositionServiceLocalCopyPasteTransfer;
 
 /**
- * Methods for copy/paste transfer. EMF serialization and {@link TextTransfer}
- * is used to transfer an {@link EObject} to and from the clipboard.
+ * Methods for copy/paste transfer. EMF serialization and {@link TextTransfer} is used to transfer
+ * an {@link EObject} to and from the clipboard.
  * 
  * @author hoelzl
  * @author hummel
  * 
  * @author $Author$
  * @version $Rev$
- * @ConQAT.Rating GREEN Hash: 66DCD29F29D3D1958A16436665674F4F
+ * @ConQAT.Rating YELLOW Hash: 3E2EE9FEF37D885B6678B56882284F9A
  */
 public class CopyPasteUtils {
 
@@ -55,18 +55,17 @@ public class CopyPasteUtils {
 		try {
 			EObject[] content = new EObject[selection.size()];
 			int i = 0;
-			for (EObject sel : selection) {
-				content[i] = EcoreUtil.copy(sel);
+			EcoreUtil.Copier copier = new EcoreUtil.Copier(true, false);
+			for(EObject sel : selection) {
+				content[i] = copier.copy(sel);
 			}
 			Clipboard clipboard = new Clipboard(Display.getDefault());
-			clipboard.setContents(new Object[] { content },
-					new Transfer[] { CompositionServiceLocalCopyPasteTransfer
-							.getInstance() }, DND.CLIPBOARD
-							| DND.SELECTION_CLIPBOARD);
+			clipboard.setContents(new Object[] {content},
+					new Transfer[] {CompositionServiceLocalCopyPasteTransfer.getInstance()},
+					DND.CLIPBOARD | DND.SELECTION_CLIPBOARD);
 			clipboard.dispose();
-		} catch (Exception e) {
-			MessageDialog.openError(Display.getDefault().getActiveShell(),
-					"Copy",
+		} catch(Exception e) {
+			MessageDialog.openError(Display.getDefault().getActiveShell(), "Copy",
 					"Clipboard contents not writeable: " + e.getMessage());
 			return;
 		}
@@ -76,8 +75,8 @@ public class CopyPasteUtils {
 	private static EObject[] getClipBoardContent() {
 		Clipboard clipboard = new Clipboard(Display.getDefault());
 
-		EObject[] content = (EObject[]) clipboard
-				.getContents(CompositionServiceLocalCopyPasteTransfer
+		EObject[] content =
+				(EObject[])clipboard.getContents(CompositionServiceLocalCopyPasteTransfer
 						.getInstance());
 		clipboard.dispose();
 		return content;
@@ -93,14 +92,13 @@ public class CopyPasteUtils {
 	 * @param context
 	 *            the composition context to be passed to the compositor
 	 */
-	public static void pasteFromClipboard(EObject target,
-			IElementCompositionContext context) {
-		if (!canPasteInto(target, context)) {
+	public static void pasteFromClipboard(EObject target, IElementCompositionContext context) {
+		if(!canPasteInto(target, context)) {
 			return;
 		}
-		for (EObject insertObj : getClipBoardContent()) {
-			IElementCompositorService.INSTANCE.compose(target,
-					EcoreUtil.copy(insertObj), context);
+		for(EObject insertObj : getClipBoardContent()) {
+			EcoreUtil.Copier copier = new EcoreUtil.Copier();
+			IElementCompositorService.INSTANCE.compose(target, copier.copy(insertObj), context);
 		}
 	}
 
@@ -115,15 +113,13 @@ public class CopyPasteUtils {
 	 * @return true if the clipboard element can be composed with the given
 	 *         target
 	 */
-	public static boolean canPasteInto(EObject target,
-			IElementCompositionContext context) {
+	public static boolean canPasteInto(EObject target, IElementCompositionContext context) {
 		EObject[] contents = getClipBoardContent();
-		if (contents == null) {
+		if(contents == null) {
 			return false;
 		}
-		for (EObject insertObj : contents) {
-			if (IElementCompositorService.INSTANCE.canCompose(target,
-					insertObj, context)) {
+		for(EObject insertObj : contents) {
+			if(IElementCompositorService.INSTANCE.canCompose(target, insertObj, context)) {
 				return true;
 			}
 		}
-- 
GitLab