javaeclipseeclipse-pluginpreferences

How do I get the value of Theme preference from Appearance preference page on Eclipse product?


On startup of eclipse product, I just want to get the eclipse UI preference value of Theme.

I tried with the below snippet, but it is returning an empty string value

Platform.getPreferencesService().getString("org.eclipse.ui.preferencePages.Views", "Theme", "",
                    null);

enter image description here

It would be great, If I am get this answer. Thanks in Advance


Solution

  • You get this from the IThemeEngine:

    IThemeEngine engine = PlatformUI.getWorkbench().getService(IThemeEngine.class);
    if (engine != null) {
        ITheme activeTheme = engine.getActiveTheme();
        if (activeTheme != null) {
            // The theme id
            String themeId = activeTheme.getId();
            // The display label
            String label = activeTheme.getLabel();
         
            ...
        }
    }
    

    IThemeEngine can also be injected in an e4 part or obtained from the IEclipseContext