Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Injection into a custom view
Injection into a custom view [message #805870] Fri, 24 February 2012 03:37 Go to next message
Eclipse UserFriend
Forgive the dumb question, but I can't figure this out.
I am writing a custom view for my plugin. I want to use Xtext's image helper but the injection doesn't work as I hoped:

import org.eclipse.ui.part.ViewPart;
import org.eclipse.xtext.ui.IImageHelper;

public class MyView extends ViewPart {
  @Inject
  private IImageHelper images;
}

No matter what I try, images is always null.

This code works for me in other classes, so my guess is that I need to wire this view up to Guice correctly.
What do I need to do to get the injection to work in this way?
Thanks!
Re: Injection into a custom view [message #805885 is a reply to message #805870] Fri, 24 February 2012 04:00 Go to previous messageGo to next message
Eclipse UserFriend
DI only works if the class is instantiated by an Injector.
Use the ExecutableExtensionFactory of your language in the registration
of the view's class in the plugin.xml.

Am 24.02.12 09:37, schrieb John J. Camilleri:
> Forgive the dumb question, but I can't figure this out.
> I am writing a custom view for my plugin. I want to use Xtext's image
> helper but the injection doesn't work as I hoped:
>
> import org.eclipse.ui.part.ViewPart;
> import org.eclipse.xtext.ui.IImageHelper;
>
> public class MyView extends ViewPart {
> @Inject
> private IImageHelper images;
> }
> No matter what I try, images is always null.
>
> This code works for me in other classes, so my guess is that I need to
> wire this view up to Guice correctly.
> What do I need to do to get the injection to work in this way?
> Thanks!


--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com
Re: Injection into a custom view [message #805895 is a reply to message #805885] Fri, 24 February 2012 04:12 Go to previous messageGo to next message
Eclipse UserFriend
Amazing, thanks for the pointer! All I needed to change was this:
<view
  category="mydsl.ui.views"
  class="mydsl.ui.views.MyView"
  id="mydsl.ui.views.MyView"
  name="My View"
  >
</view>

into this:
<view
  category="mydsl.ui.views"
  class="mydsl.ui.MyDSLExecutableExtensionFactory:mydsl.ui.views.MyView"
  id="mydsl.ui.views.MyView"
  name="My View"
  >
</view>

This is actually in the docs, although I didn't understand it until now. Thanks again.

[Updated on: Fri, 24 February 2012 04:13] by Moderator

Re: Injection into a custom view [message #1008401 is a reply to message #805870] Tue, 12 February 2013 05:38 Go to previous message
Eclipse UserFriend
Hi John ,

I am a new user of xtext .
I have written a DSL and have the configured the IDE features .

I have addded a new view and have set the class to mydsl.ui.MyDSLExecutableExtensionFactory:mydsl.ui.views.ViewPartP

However I am not able to see this view in the others menu when I run my plugin .

I could not find any documentation on the site which helps understand adding custom views ..Could you please share the link of the documentation you are refering .

Thanks
Lalitha Iyer
Previous Topic:Global scope and resolving Maven/Plugin dependencies
Next Topic:Validate against model structure
Goto Forum:
  


Current Time: Thu Jul 03 14:10:57 EDT 2025

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

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

Back to the top