Creating an Action to Open the Xtext Project Wizard [message #697756] |
Mon, 18 July 2011 00:14 |
|
I'm working on a Google SoC project about Xtext and other DSL modeling tools. Now, I'm working on the creation of an Eclipse Cheat Sheet about Xtext.
To automate the things, I created an Action that opens the "New Xtext Project" wizard. After some research I ended with this code: https://gist.github.com/1088269
When I run the Action (through the Cheat Sheet) the wizard opens, but when I clicked the Finish button I got this error (http://cl.ly/2Q1X0r103E123T1z1E1I) and the following message in the log:
1 [Thread-1] ERROR org.eclipse.xtext.ui.wizard.XtextNewProjectWizard -
java.lang.reflect.InvocationTargetException
at org.eclipse.xtext.ui.wizard.XtextNewProjectWizard$1.run(XtextNewProjectWizard.java:57)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Caused by: java.lang.NullPointerException
at org.eclipse.xtext.xtext.ui.wizard.project.XtextProjectCreator.createProjectFactory(XtextProjectCreator.java:106)
at org.eclipse.xtext.xtext.ui.wizard.project.XtextProjectCreator.createDslProject(XtextProjectCreator.java:143)
at org.eclipse.xtext.xtext.ui.wizard.project.XtextProjectCreator.execute(XtextProjectCreator.java:90)
at org.eclipse.ui.actions.WorkspaceModifyOperation$1.run(WorkspaceModifyOperation.java:106)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1975)
at org.eclipse.ui.actions.WorkspaceModifyOperation.run(WorkspaceModifyOperation.java:118)
at org.eclipse.xtext.ui.wizard.XtextNewProjectWizard.doFinish(XtextNewProjectWizard.java:82)
at org.eclipse.xtext.ui.wizard.XtextNewProjectWizard$1.run(XtextNewProjectWizard.java:54)
... 1 more
!ENTRY org.apache.log4j 4 0 2011-07-17 21:12:00.691
!MESSAGE org.eclipse.xtext.ui.wizard.XtextNewProjectWizard -
Am I missing something? Is there any Action provided by the Xtext plugins?
Thank you
|
|
|
Re: Creating an Action to Open the Xtext Project Wizard [message #697760 is a reply to message #697756] |
Mon, 18 July 2011 00:46 |
Mirko Raner Messages: 125 Registered: July 2009 Location: New York City, NY |
Senior Member |
|
|
Welcome to the wonderful world of Guice dependency injection
As you may know, Xtext relies heavily on the Guice dependency injection framework. This means that most collaborators of a class will be procured via an @Inject annotation, which means that you cannot simply instantiate a class using a "new". In this case, you are missing the Provider for the PluginProjectFactory.
Now, in some cases you can try supplying the missing dependencies manually, but usually the dependencies themselves have other (Guice-injected) dependencies, and so you will end up with a large and unmanageable dependency tree.
A better strategy is to get the Guice Injector from your UI plug-in's activator and use getInstance(...) to create the object you need.
But the very best solution is to have the objects you need injected into your own code, for example, by providing the appropriate fields with an @Inject annotation. However, this will only work if your class itself is instantiated via Guice.
HTH,
Mirko
|
|
|
Re: Creating an Action to Open the Xtext Project Wizard [message #697929 is a reply to message #697760] |
Mon, 18 July 2011 11:41 |
|
Mirko Raner wrote on Sun, 17 July 2011 21:46A better strategy is to get the Guice Injector from your UI plug-in's activator and use getInstance(...) to create the object you need.
Have you any example or reference site I can look at?
I tried to replace (inside my current action's run() method)
NewXtextProjectWizard wizard = new NewXtextProjectWizard(new XtextProjectCreator()); with NewXtextProjectWizard wizard = Activator.getDefault().getInjector().getInstance(NewXtextProjectWizard.class);
But I got another error.
!STACK 0
com.google.inject.ConfigurationException: Guice configuration errors:
1) No implementation for org.eclipse.xtext.ui.wizard.IProjectCreator was bound.
while locating org.eclipse.xtext.ui.wizard.IProjectCreator
for parameter 0 at org.eclipse.xtext.xtext.ui.wizard.project.NewXtextProjectWizard.<init>(NewXtextProjectWizard.java:41)
while locating org.eclipse.xtext.xtext.ui.wizard.project.NewXtextProjectWizard
1 error
at com.google.inject.InjectorImpl.getProvider(InjectorImpl.java:784)
at com.google.inject.InjectorImpl.getProvider(InjectorImpl.java:743)
at com.google.inject.InjectorImpl.getInstance(InjectorImpl.java:793)
at org.eclipse.amalgam.tutorials.cheatsheets.xtext.actions.OpenXtextProjectWizard.run(OpenXtextProjectWizard.java:32)
at org.eclipse.ui.internal.cheatsheets.ActionRunner.runAction(ActionRunner.java:86)
at org.eclipse.ui.internal.cheatsheets.data.Action.execute(Action.java:100)
at org.eclipse.ui.internal.cheatsheets.views.CoreItem.runExecutable(CoreItem.java:506)
at org.eclipse.ui.internal.cheatsheets.views.CoreItem.runExecutable(CoreItem.java:501)
at org.eclipse.ui.internal.cheatsheets.views.CheatSheetViewer.runPerformExecutable(CheatSheetViewer.java:1046)
at org.eclipse.ui.internal.cheatsheets.views.CoreItem$1.linkActivated(CoreItem.java:89)
at org.eclipse.ui.forms.widgets.AbstractHyperlink.handleActivate(AbstractHyperlink.java:233)
at org.eclipse.ui.forms.widgets.ImageHyperlink.handleActivate(ImageHyperlink.java:199)
at org.eclipse.ui.forms.widgets.AbstractHyperlink.handleMouseUp(AbstractHyperlink.java:327)
at org.eclipse.ui.forms.widgets.AbstractHyperlink.access$2(AbstractHyperlink.java:311)
at org.eclipse.ui.forms.widgets.AbstractHyperlink$4.handleEvent(AbstractHyperlink.java:125)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:3783)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1375)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1398)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1383)
at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1195)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3629)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3284)
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)
I tried to use NewXtextProjectWizard wizard = Guice.createInjector(new XtextRuntimeModule()).getInstance(NewXtextProjectWizard.class); but i got the same error.
Quote:But the very best solution is to have the objects you need injected into your own code, for example, by providing the appropriate fields with an @Inject annotation. However, this will only work if your class itself is instantiated via Guice.
How could I make it? Should I create an ActionInvocation class and call
ActionInvocation actionInvocation = Activator.getDefault().getInjector().getInstance(ActionInvocation.class).invokeAction();
from my current action's run() method (and move it to the invokeAction() method)?
|
|
|
Powered by
FUDForum. Page generated in 0.03642 seconds