Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Using CreateChildCommand correctly?
Using CreateChildCommand correctly? [message #638826] Fri, 12 November 2010 16:55 Go to next message
TSchwalb  is currently offline TSchwalb Friend
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 #638828 is a reply to message #638826] Fri, 12 November 2010 16:59 Go to previous messageGo to next message
Aurélien Pupier is currently offline Aurélien PupierFriend
Messages: 637
Registered: July 2009
Location: Grenoble, FRANCE
Senior Member

Hi,

and if you try to put an empty arralist instead of null?

Regards,


Aurélien Pupier - Red Hat
Senior Software Engineer in Fuse Tooling team
Re: Using CreateChildCommand correctly? [message #638830 is a reply to message #638826] Fri, 12 November 2010 17:04 Go to previous messageGo to next message
TSchwalb  is currently offline TSchwalb Friend
Messages: 9
Registered: September 2009
Junior Member
Hi,
thanks for your fast reply.

You mean the following code:
eddomain.getCommandStack().execute(CreateChildCommand.create (eddomain, descriptor, Diagramm1Factory.eINSTANCE.createSubSubClass(), new ArrayList()));

I get the following error:
java.lang.ClassCastException: diagramm1.impl.SubSubClassImpl cannot be cast to org.eclipse.emf.edit.command.CommandParameter
at org.eclipse.emf.edit.provider.ItemProviderAdapter.createComm and(ItemProviderAdapter.java:997)
at org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain.crea teCommand(AdapterFactoryEditingDomain.java:464)
at org.eclipse.emf.edit.command.CreateChildCommand.create(Creat eChildCommand.java:66)
at diagramm1.diagram.aown.ButtonHandler.execute(ButtonHandler.j ava:49)
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)

Re: Using CreateChildCommand correctly? [message #639632 is a reply to message #638826] Wed, 17 November 2010 09:53 Go to previous messageGo to next message
Aurélien Pupier is currently offline Aurélien PupierFriend
Messages: 637
Registered: July 2009
Location: Grenoble, FRANCE
Senior Member

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
Re: Using CreateChildCommand correctly? [message #640218 is a reply to message #638826] Fri, 19 November 2010 15:40 Go to previous message
TSchwalb  is currently offline TSchwalb Friend
Messages: 9
Registered: September 2009
Junior Member
Hi,
I now solved the problem. I use an AddCommand instead of a CreateChildCommand, and now it works fine for the desired purpose.

Here is an example:
SubSubClass newSubSubClass = Diagramm1Factory.eINSTANCE.createSubSubClass();
eddomain.getCommandStack().execute(AddCommand.create(eddomai n, dataElement, Diagramm1Package.eINSTANCE.getSubClass_SubSubClasses(), newSubSubClass));

Regards,
Previous Topic:GMF Tooling Committers: Michael Golubev starts 100% as of 1.12.2010
Next Topic:Creating a parent element for a child node
Goto Forum:
  


Current Time: Thu Apr 25 02:31:57 GMT 2024

Powered by FUDForum. Page generated in 0.02620 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top