Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 358818 - Copy business objects to clipboard creates exception in SWT / EcoreUtil.copy not handled by SWT clipboard
Summary: Copy business objects to clipboard creates exception in SWT / EcoreUtil.copy ...
Status: CLOSED FIXED
Alias: None
Product: Graphiti
Classification: Modeling
Component: Core (show other bugs)
Version: 0.8.0   Edit
Hardware: All All
: P3 minor (vote)
Target Milestone: 0.9.0   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard: Juno RC2 Theme_round_offs
Keywords:
Depends on:
Blocks:
 
Reported: 2011-09-25 08:58 EDT by Ivar Refsdal CLA
Modified: 2012-06-29 04:29 EDT (History)
2 users (show)

See Also:
michael.wenz: juno+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ivar Refsdal CLA 2011-09-25 08:58:05 EDT
Build Identifier: 

Full stacktrace:

!ENTRY org.eclipse.ui 4 0 2011-09-25 14:53:04.339
!MESSAGE Unhandled event loop exception
!STACK 0
java.lang.IllegalArgumentException: Argument not valid
	at org.eclipse.swt.SWT.error(SWT.java:4064)
	at org.eclipse.swt.SWT.error(SWT.java:3998)
	at org.eclipse.swt.SWT.error(SWT.java:3969)
	at org.eclipse.swt.dnd.DND.error(DND.java:281)
	at org.eclipse.swt.dnd.DND.error(DND.java:227)
	at org.eclipse.swt.dnd.Clipboard.setContents(Clipboard.java:448)
	at org.eclipse.swt.dnd.Clipboard.setContents(Clipboard.java:379)
	at org.eclipse.graphiti.ui.internal.util.clipboard.ModelClipboard.setNativeContentObjects(ModelClipboard.java:488)
	at org.eclipse.graphiti.ui.internal.util.clipboard.ModelClipboard.setContent(ModelClipboard.java:107)
	at org.eclipse.graphiti.ui.features.AbstractCopyFeature.putToClipboard(AbstractCopyFeature.java:84)
	at no.uio.ivarref.prediqt.copyandpaste.PrediqtCopyPNodeFeature.copy(PrediqtCopyPNodeFeature.java:53)
	at org.eclipse.graphiti.ui.internal.action.CopyAction.run(CopyAction.java:80)
	at org.eclipse.jface.action.Action.runWithEvent(Action.java:498)
	at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:584)
	at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:501)
	at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:411)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1258)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3540)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3161)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2640)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2604)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2438)
	at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:671)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:664)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:115)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:620)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:575)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1408)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1384)


Reproducible: Always

Steps to Reproduce:
1. Modify the copy feature to the following:
@Override
	public void copy(ICopyContext context) {
		// get the business-objects for all pictogram-elements

        PictogramElement[] pes = context.getPictogramElements();
        Collection<EObject> bos = new ArrayList<EObject>();
        for (int i = 0; i < pes.length; i++) {
            PictogramElement pe = pes[i];
            if (getBusinessObjectForPictogramElement(pe) instanceof EObject) {
				EObject eObject = (EObject) getBusinessObjectForPictogramElement(pe);
				bos.add(EcoreUtil.copy(eObject)); // EcoreUtil.copy causes the exception later on.
            }
        }

        // put all business objects to the clipboard
        putToClipboard(bos.toArray()); // exception thrown here.
	}

2. Run the application.
3. Copy a node.

Hackish-solution:
Remove the EcoreUtil.copy from the copy feature.
Let the paste feature use EcoreUtil.copy.
This works as one would expected.

It would also be good if this was mentioned in the documentation.
Comment 1 Michael Wenz CLA 2011-09-30 06:30:38 EDT
The stuff in Metamodel clipboard needs to be part of a resource, that's probably the reason for the exception with the coding above.
Right, should be mentioned in the docu.
Comment 2 Michael Wenz CLA 2012-05-29 03:42:12 EDT
The lacking information is now provided on the Copy&Paste page in the tutorial (was provided as part of the fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=375533)
Comment 3 Michael Wenz CLA 2012-06-29 04:29:45 EDT
Part of Graphiti 0.9.0 (Eclipse Juno)