Skip to content

Retrieving the theme via org.eclipse.e4.ui.css.swt.theme does not always work #4168

Description

@jomillerOpen

If the workspace's theme is inherrited from the default value (say it's been set to dark mode).
If I try to get the current workspace's theme via:
(Code samples simplified)
Preferences preferences1 = InstanceScope.INSTANCE.getNode("org.eclipse.e4.ui.css.swt.theme");
String themeCssUri2 = preferences1.get("themeid", "");
Preferences preferences2 = ConfigurationScope.INSTANCE.getNode("org.eclipse.e4.ui.css.swt.theme");
String themeCssUri3 = preferences2.get("themeid", "");
Preferences preferences3 = DefaultScope.INSTANCE.getNode("org.eclipse.e4.ui.css.swt.theme");
String themeCssUri4 = preferences3.get("themeid", "");

or via

IPreferencesService service = Platform.getPreferencesService();
String themeId = service.getString("org.eclipse.e4.ui.css.swt.theme", "currentThemeId", null, null);
String themeId2 = service.getString("org.eclipse.e4.ui.css.swt.theme", "currentThemeId", null, new IScopeContext[] { InstanceScope.INSTANCE });
String themeId3 = service.getString("org.eclipse.e4.ui.css.swt.theme", "currentThemeId", null, new IScopeContext[] { ConfigurationScope.INSTANCE });
String themeId4 = service.getString("org.eclipse.e4.ui.css.swt.theme", "currentThemeId", null, new IScopeContext[] {DefaultScope.INSTANCE });

The themeID is always blank. If the preference was set on the workspace level (so that there's a preference file located at .metadata.plugins\org.eclipse.core.runtime\org.eclipse.e4.ui.css.swt.theme.prefs, then the themeID can be retrieved.

The only way I can currently reliably retrieve the themeID with and without the workspace preference file present, is to use:
IThemeEngine engine = PlatformUI.getWorkbench().getService(IThemeEngine.class);
ITheme activeTheme = engine.getActiveTheme();
String themeCssUri = activeTheme.getId();

When I was using copilot to help troubleshoot, it seemed to think that the e4 theme service injected the theme on load time, so it was bypassing the regular settings mechanisms.

Steps to reproduce

Have the default theme set to dark mode. Open a workspace where the file .metadata.plugins\org.eclipse.core.runtime\org.eclipse.e4.ui.css.swt.theme.prefs is not present. Try the above methods to retrieve the current theme's string (should be "org.eclipse.e4.ui.css.theme.e4_dark").

I expected: That the themeID, like other preference settings, would be retrievable at one of the scopes available at the very least. I can understand that without the preference file in the workspace that it wouldn't be available at the workspace scope, but one of the higher scopes should still have the value available.

Tested under this environment:

  • OS & version: Windows 11
  • Eclipse IDE/Platform version (as shown in Help > About): Eclipse 2026-06, org.eclipse.e4.ui.css.swt.theme=0.15.100v20260507-0340

Community

  • [ Y] I understand reporting an issue to this OSS project does not mandate anyone to fix it. Other contributors may consider the issue, or not, at their own convenience. The most efficient way to get it fixed is that I fix it myself and contribute it back as a good quality patch to the project.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions