The themes can be switched at runtime by interacting with the IThemeEngine
, which can be acquired from the Eclipse 4 runtime service through injection. This provides a list of all installed themes, which can be used to populate the list viewer, and to allow the style to be changed.
Create a class called
ThemePart
in thecom.packtpub.e4.application.parts
package. Add an injected fieldIThemeEngine
, and acreate
method annotated with@PostConstruct
that takes aComposite
parameter:public class ThemePart { @Inject private IThemeEngine themeEngine; @PostConstruct public void create(Composite parent) { } }
In the
create
method, add aListViewer
that is associated with anArrayContentProvider
:ListViewer lv = new ListViewer(parent, SWT.NONE); lv.setContentProvider(new ArrayContentProvider());
Add a selection listener to the list viewer so that when an item is selected, the element is compared with the list of themes; if one is found, set it through...