Using CreateChildCommand correctly? [message #638826] |
Fri, 12 November 2010 16:55 |
TSchwalb Messages: 9 Registered: September 2009 |
Junior Member |
|
|
Hi everyone,
I have looked through many webpages and examples, but I cannot figure out how to use the CreateChildCommand to create new model element of subclasses.
I have build a small example, which has three classes Main, Subclass and SubSubClass. Main has an Aggregation (0..*) to SubClass and SubClass has an Aggregation (0..*) to SubSubClass.
I have build a GMF editor to draw only SubClasses, which works perfect. I now want to build my own button, which creates a new SubSubClass below the selected subclass (to get the actual selected subclass is no problem). The SubSubClass does not need to be shown in the GMF editor.
I tried it using the following code (acutalSubClassEditPart is the EditPart of the subclass I want to add a subsubclass):
EditingDomain eddomain = acutalSubClassEditPart.getEditingDomain();
SubClassImpl dataElement = (SubClassImpl) ((NodeImpl) acutalSubClassEditPart.getModel()).getElement();
Object descriptor = dataElement.getSubSubClasses().iterator().next();
eddomain.getCommandStack().execute(CreateChildCommand.create (eddomain, descriptor, Diagramm1Factory.eINSTANCE.createSubSubClass(), null));
--> I am not sure according to the last parameter of the CreateChildCommand, but I read I can set it simple to null.
However I get the error:
java.lang.NullPointerException
at java.util.ArrayList.<init>(Unknown Source)
at org.eclipse.emf.edit.command.CreateChildCommand.create(Creat eChildCommand.java:68)
at diagramm1.diagram.aown.ButtonHandler.execute(ButtonHandler.j ava:48)
at org.eclipse.ui.internal.handlers.HandlerProxy.execute(Handle rProxy.java:293)
at org.eclipse.core.commands.Command.executeWithChecks(Command. java:476)
at org.eclipse.core.commands.ParameterizedCommand.executeWithCh ecks(ParameterizedCommand.java:508)
at org.eclipse.ui.internal.handlers.HandlerService.executeComma nd(HandlerService.java:169)
at org.eclipse.ui.internal.handlers.SlaveHandlerService.execute Command(SlaveHandlerService.java:241)
at org.eclipse.ui.menus.CommandContributionItem.handleWidgetSel ection(CommandContributionItem.java:820)
at org.eclipse.ui.menus.CommandContributionItem.access$19(Comma ndContributionItem.java:806)
at org.eclipse.ui.menus.CommandContributionItem$5.handleEvent(C ommandContributionItem.java:796)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.ja va:4066)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :3657)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:2629)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2593)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:24 27)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:670)
at org.eclipse.core.databinding.observable.Realm.runWithDefault (Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:663)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start (IDEApplication.java:115)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.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(EclipseS tarter.java:369)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 619)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:574)
at org.eclipse.equinox.launcher.Main.run(Main.java:1407)
at org.eclipse.equinox.launcher.Main.main(Main.java:1383)
Any help or suggestion are greatly appreciated
[Updated on: Fri, 12 November 2010 16:57] Report message to a moderator
|
|
|
|
|
Re: Using CreateChildCommand correctly? [message #639632 is a reply to message #638826] |
Wed, 17 November 2010 09:53 |
|
Hi,
it seems that
Diagramm1Factory.eINSTANCE.createSubSubClass(
is not the right parameter for the CreateCommand.
It seems that you should give an org.eclipse.emf.edit.command.CommandParameter
Regards,
Aurélien Pupier - Red Hat
Senior Software Engineer in Fuse Tooling team
|
|
|
|
Powered by
FUDForum. Page generated in 0.02620 seconds