4242import org .eclipse .core .runtime .Status ;
4343import org .eclipse .core .runtime .jobs .Job ;
4444import org .eclipse .core .runtime .preferences .ConfigurationScope ;
45+ import org .eclipse .core .runtime .preferences .IEclipsePreferences ;
46+ import org .eclipse .e4 .ui .css .swt .theme .IThemeEngine ;
47+ import org .eclipse .e4 .ui .css .swt .theme .IThemeManager ;
4548import org .eclipse .equinox .app .IApplication ;
4649import org .eclipse .equinox .app .IApplicationContext ;
4750import org .eclipse .jface .dialogs .IDialogConstants ;
7174import org .eclipse .ui .internal .ide .StatusUtil ;
7275import org .eclipse .ui .preferences .ScopedPreferenceStore ;
7376import org .osgi .framework .Bundle ;
77+ import org .osgi .framework .BundleContext ;
78+ import org .osgi .framework .FrameworkUtil ;
79+ import org .osgi .framework .ServiceReference ;
7480import org .osgi .framework .Version ;
7581
7682/**
@@ -94,6 +100,8 @@ public class IDEApplication implements IApplication, IExecutableExtension {
94100
95101 private static final String USER_NAME = "user.name" ; //$NON-NLS-1$
96102
103+ private IThemeEngine themeEngine ;
104+
97105 // Use the branding plug-in of the platform feature since this is most likely
98106 // to change on an update of the IDE.
99107 private static final String WORKSPACE_CHECK_REFERENCE_BUNDLE_NAME = "org.eclipse.platform" ; //$NON-NLS-1$
@@ -145,6 +153,32 @@ public Object start(IApplicationContext appContext) throws Exception {
145153 Job .getJobManager ().suspend ();
146154
147155 Display display = createDisplay ();
156+
157+ IEclipsePreferences configurationScopeNode = ConfigurationScope .INSTANCE
158+ .getNode ("org.eclipse.e4.ui.css.swt.theme" ); //$NON-NLS-1$
159+ String defaultThemeId = configurationScopeNode .get ("themeid" , null ); //$NON-NLS-1$
160+ if (defaultThemeId != null ) {
161+ Bundle bundle = FrameworkUtil .getBundle (IThemeManager .class );
162+ if (bundle != null ) {
163+ BundleContext bundleContext = bundle .getBundleContext ();
164+ ServiceReference <IThemeManager > ref = bundleContext .getServiceReference (IThemeManager .class );
165+ if (ref != null ) {
166+ IThemeManager mgr = bundleContext .getService (ref );
167+ if (mgr != null ) {
168+ themeEngine = mgr .getEngineForDisplay (display );
169+ if (themeEngine != null ) {
170+ themeEngine .setTheme (defaultThemeId , false );
171+ display .addListener (SWT .Show , event -> {
172+ if (event .widget instanceof Shell shell ) {
173+ themeEngine .applyStyles (shell , true );
174+ }
175+ });
176+ }
177+ }
178+ }
179+ }
180+ }
181+
148182 // processor must be created before we start event loop
149183 DelayedEventsProcessor processor = new DelayedEventsProcessor (display );
150184
@@ -587,6 +621,14 @@ protected Shell getParentShell() {
587621 return null ;
588622 }
589623
624+ @ Override
625+ protected Control createContents (Composite parent ) {
626+ Control contents = super .createContents (parent );
627+ if (themeEngine != null ) {
628+ themeEngine .applyStyles (getShell (), true );
629+ }
630+ return contents ;
631+ }
590632 }.prompt (force );
591633 }
592634
0 commit comments