In an Eclipse 3.x application, the main window is typically accessed via a static accessor like Display.getDisplay()
or workbench.getWorkbenchWindows()
. Both of these assume there is a way of getting to this global list in the first place, often through tightly coupled code references. In addition to 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 field
MWindow
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 create...