Skip to content
Snippets Groups Projects
Commit 50bfe9d5 authored by Florian Hölzl's avatar Florian Hölzl
Browse files

bugfix: using copier without references

refs 877
parent 1c553d72
No related branches found
No related tags found
No related merge requests found
...@@ -32,15 +32,15 @@ import org.fortiss.tooling.kernel.service.IElementCompositorService; ...@@ -32,15 +32,15 @@ import org.fortiss.tooling.kernel.service.IElementCompositorService;
import org.fortiss.tooling.kernel.ui.dnd.CompositionServiceLocalCopyPasteTransfer; import org.fortiss.tooling.kernel.ui.dnd.CompositionServiceLocalCopyPasteTransfer;
/** /**
* Methods for copy/paste transfer. EMF serialization and {@link TextTransfer} * Methods for copy/paste transfer. EMF serialization and {@link TextTransfer} is used to transfer
* is used to transfer an {@link EObject} to and from the clipboard. * an {@link EObject} to and from the clipboard.
* *
* @author hoelzl * @author hoelzl
* @author hummel * @author hummel
* *
* @author $Author$ * @author $Author$
* @version $Rev$ * @version $Rev$
* @ConQAT.Rating GREEN Hash: 66DCD29F29D3D1958A16436665674F4F * @ConQAT.Rating YELLOW Hash: 3E2EE9FEF37D885B6678B56882284F9A
*/ */
public class CopyPasteUtils { public class CopyPasteUtils {
...@@ -55,18 +55,17 @@ public class CopyPasteUtils { ...@@ -55,18 +55,17 @@ public class CopyPasteUtils {
try { try {
EObject[] content = new EObject[selection.size()]; EObject[] content = new EObject[selection.size()];
int i = 0; int i = 0;
for (EObject sel : selection) { EcoreUtil.Copier copier = new EcoreUtil.Copier(true, false);
content[i] = EcoreUtil.copy(sel); for(EObject sel : selection) {
content[i] = copier.copy(sel);
} }
Clipboard clipboard = new Clipboard(Display.getDefault()); Clipboard clipboard = new Clipboard(Display.getDefault());
clipboard.setContents(new Object[] { content }, clipboard.setContents(new Object[] {content},
new Transfer[] { CompositionServiceLocalCopyPasteTransfer new Transfer[] {CompositionServiceLocalCopyPasteTransfer.getInstance()},
.getInstance() }, DND.CLIPBOARD DND.CLIPBOARD | DND.SELECTION_CLIPBOARD);
| DND.SELECTION_CLIPBOARD);
clipboard.dispose(); clipboard.dispose();
} catch (Exception e) { } catch(Exception e) {
MessageDialog.openError(Display.getDefault().getActiveShell(), MessageDialog.openError(Display.getDefault().getActiveShell(), "Copy",
"Copy",
"Clipboard contents not writeable: " + e.getMessage()); "Clipboard contents not writeable: " + e.getMessage());
return; return;
} }
...@@ -76,8 +75,8 @@ public class CopyPasteUtils { ...@@ -76,8 +75,8 @@ public class CopyPasteUtils {
private static EObject[] getClipBoardContent() { private static EObject[] getClipBoardContent() {
Clipboard clipboard = new Clipboard(Display.getDefault()); Clipboard clipboard = new Clipboard(Display.getDefault());
EObject[] content = (EObject[]) clipboard EObject[] content =
.getContents(CompositionServiceLocalCopyPasteTransfer (EObject[])clipboard.getContents(CompositionServiceLocalCopyPasteTransfer
.getInstance()); .getInstance());
clipboard.dispose(); clipboard.dispose();
return content; return content;
...@@ -93,14 +92,13 @@ public class CopyPasteUtils { ...@@ -93,14 +92,13 @@ public class CopyPasteUtils {
* @param context * @param context
* the composition context to be passed to the compositor * the composition context to be passed to the compositor
*/ */
public static void pasteFromClipboard(EObject target, public static void pasteFromClipboard(EObject target, IElementCompositionContext context) {
IElementCompositionContext context) { if(!canPasteInto(target, context)) {
if (!canPasteInto(target, context)) {
return; return;
} }
for (EObject insertObj : getClipBoardContent()) { for(EObject insertObj : getClipBoardContent()) {
IElementCompositorService.INSTANCE.compose(target, EcoreUtil.Copier copier = new EcoreUtil.Copier();
EcoreUtil.copy(insertObj), context); IElementCompositorService.INSTANCE.compose(target, copier.copy(insertObj), context);
} }
} }
...@@ -115,15 +113,13 @@ public class CopyPasteUtils { ...@@ -115,15 +113,13 @@ public class CopyPasteUtils {
* @return true if the clipboard element can be composed with the given * @return true if the clipboard element can be composed with the given
* target * target
*/ */
public static boolean canPasteInto(EObject target, public static boolean canPasteInto(EObject target, IElementCompositionContext context) {
IElementCompositionContext context) {
EObject[] contents = getClipBoardContent(); EObject[] contents = getClipBoardContent();
if (contents == null) { if(contents == null) {
return false; return false;
} }
for (EObject insertObj : contents) { for(EObject insertObj : contents) {
if (IElementCompositorService.INSTANCE.canCompose(target, if(IElementCompositorService.INSTANCE.canCompose(target, insertObj, context)) {
insertObj, context)) {
return true; return true;
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment