Skip to main content


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 08:37 Go to next message
John J. Camilleri is currently offline John J. CamilleriFriend
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 09:00 Go to previous messageGo to next message
Jan Koehnlein is currently offline Jan KoehnleinFriend
Messages: 760
Registered: July 2009
Location: Hamburg
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


---
Get professional support from the Xtext committers at www.typefox.io
Re: Injection into a custom view [message #805895 is a reply to message #805885] Fri, 24 February 2012 09:12 Go to previous messageGo to next message
John J. Camilleri is currently offline John J. CamilleriFriend
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 09:13]

Report message to a moderator

Re: Injection into a custom view [message #1008401 is a reply to message #805870] Tue, 12 February 2013 10:38 Go to previous message
Lalitha Iyer is currently offline Lalitha IyerFriend
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 25 19:04:36 GMT 2024

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

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

Back to the top