Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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
John J. Camilleri is currently offline John J. Camilleri
Messages: 33
Registered: November 2011
Location: Göteborg
Member
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
Jan Koehnlein is currently offline Jan Koehnlein
Messages: 655
Registered: July 2009
Senior Member
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
John J. Camilleri is currently offline John J. Camilleri
Messages: 33
Registered: November 2011
Location: Göteborg
Member
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]

Report message to a 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
Lalitha Iyer is currently offline Lalitha Iyer
Messages: 1
Registered: February 2013
Junior Member
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 Apr 17 23:41:44 EDT 2014

Powered by FUDForum. Page generated in 0.13082 seconds