Time for action – switching between themes

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.

  1. Create a class called ThemePart in the com.packtpub.e4.application.parts package. Add an injected field IThemeEngine, and a create method annotated with @PostConstruct that takes a Composite parameter:
    public class ThemePart {
      @Inject
      private IThemeEngine themeEngine;
      @PostConstruct
      public void create(Composite parent) {
      }
     }
  2. In the create method, add a ListViewer that is associated with an ArrayContentProvider:
    ListViewer lv = ...

Get Eclipse Plug-in Development Beginner's Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.