And this XWTAbstractPart has a method refresh to indicate the
even handler class to use. See the option XWTLoader.CLASS_PROPERTY
below:
protected void refresh(URL
url, Object dataContext, ClassLoader loader) {
if (parent == null ||
isConstructing()) {
return;
}
parent.setVisible(false);
for (Control
child : parent.getChildren()) {
child.dispose();
}
ClassLoader classLoader =
Thread.currentThread()
.getContextClassLoader();
try {
XWT.setLoadingContext(new
DefaultLoadingContext(loader));
HashMap<String,
Object> newOptions = new HashMap<String, Object>();
newOptions.put(XWTLoader.CONTAINER_PROPERTY, parent);
newOptions.put(XWTLoader.DATACONTEXT_PROPERTY,
dataContext);
newOptions.put(XWTLoader.CLASS_PROPERTY, this);
XWT.loadWithOptions(url,
newOptions);
GridLayoutFactory.fillDefaults().generateLayout(parent);
parent.layout(true, true);
} catch (Exception e) {
LoggerManager.log(e);
} finally {
Thread.currentThread().setContextClassLoader(classLoader);
parent.setVisible(true);
}
}
This option is the default even handler if there is no x:Class
found in XWT file.
Best regards
Yves YANG
From: Yves (Yingmin) YANG
[mailto:yves.yang@xxxxxxxxxxx]
Sent: Monday, May 13, 2013 1:25 AM
To: 'ml@xxxxxxxxxx'; 'E4 Project developer mailing list'
Subject: RE: [e4-dev] Using DI in a XWT EventHandler
Hi,
Have you look at the class XWT AbstractPart in the o.xx
ui.workbench plugin ? This class handle the event handle of UI and has the
reference to IEclipseContext and data context.
You can create a subclass of this class to delegate event message
to other classes.
Best regards
Yves YANG
From:
e4-dev-bounces@xxxxxxxxxxx [mailto:e4-dev-bounces@xxxxxxxxxxx] On Behalf Of Ben
Sent: Sunday, May 12, 2013 12:14 PM
To: E4 Project developer mailing list
Subject: [e4-dev] Using DI in a XWT EventHandler
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?