In an Eclipse 3.x application, the main window is typically accessed via a static accessor such as Display.getDisplay()
or workbench.getWorkbenchWindows()
. Both of these assume that there is a way of getting to this global list in the first place, often through tightly coupled code references. As well as OSGi services, E4 can also be used to inject references to GUI components. However, rather than accessing the GUI components directly, models are used instead. As a result, components in E4 tend to start with M (for Model)—such as MPart
, MWindow
, and MPerspective
.
To obtain the reference to the window, add a
private
fieldMWindow window
to theHello
class, along with an@Inject
annotation.Modify the
create
method so that the label of the text is taken from the window's title (label). The class will look like:import org.eclipse.e4.ui.model.application.ui.basic.MWindow; public class Hello { @Inject private MWindow window; @PostConstruct public void...