Skip to main content



      Home
Home » Eclipse Projects » XWT » Using e4 DI in a XWT EventHandler
Using e4 DI in a XWT EventHandler [message #1058134] Sun, 12 May 2013 06:59 Go to next message
Eclipse UserFriend
Hi,

we're using XWT in our E4 application which works pretty good. The only problem is to get DI work in the EventHandler class we are using.

Setup looks like the following:
SomeGuiPart -> uses @PostConstruct to load XWT file and setup some fields in it
SomeGuiEventHandler -> is referenced from the XWT file using x:Class="...SomeGuiEventHandler"


The problem now is, that SomeGuiEventHandler is not part of the application model and of that no DI is available. Sadly I also don't see a way to
a) access the Eclipse context from the event handler, or
b) access the SomeGuiPart instance from the event handler, or
c) create the event handler instance in the SomeGuiPart and pass it to the XWT instance

So, the only solution I see is to handle the XWT events in the part class which is a part of the application model.

Are there better options to handle events in a separate class?

Greetings
Tobias
Re: Using e4 DI in a XWT EventHandler [message #1058137 is a reply to message #1058134] Sun, 12 May 2013 07:37 Go to previous message
Eclipse UserFriend
Hi Tobias,
That is currently not directly supported by XWT, but you can achieve that this way:

Composite parent = ...;
URL url = ...;

// this is your event handler instance which you can prepare via org.eclipse.e4.core.contexts.ContextInjectionFactory.inject(Object, IEclipseContext)
// you should also put the SomeGUIPart instance into the provided IEclipseContext, so it can be injected into the events handler
Object eventsHandler = ...;

Map<String, Object> options = new HashMap<String, Object>();
options.put(IXWTLoader.CONTAINER_PROPERTY, parent);
options.put(IXWTLoader.CLASS_PROPERTY, eventsHandler);
// other options
XWT.loadWithOptions(url, options);


You should wrap the code in a util method to make it reusable (if you need that often).

Tobias P. wrote on Sun, 12 May 2013 12:59
Hi,

we're using XWT in our E4 application which works pretty good. The only problem is to get DI work in the EventHandler class we are using.

Setup looks like the following:
SomeGuiPart -> uses @PostConstruct to load XWT file and setup some fields in it
SomeGuiEventHandler -> is referenced from the XWT file using x:Class="...SomeGuiEventHandler"


The problem now is, that SomeGuiEventHandler is not part of the application model and of that no DI is available. Sadly I also don't see a way to
a) access the Eclipse context from the event handler, or
b) access the SomeGuiPart instance from the event handler, or
c) create the event handler instance in the SomeGuiPart and pass it to the XWT instance

So, the only solution I see is to handle the XWT events in the part class which is a part of the application model.

Are there better options to handle events in a separate class?

Greetings
Tobias

Previous Topic:xwt with Sash and FormLayout
Next Topic:Is XWT dead?
Goto Forum:
  


Current Time: Sat May 17 12:47:56 EDT 2025

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

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

Back to the top