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 .core .contexts .EclipseContextFactory ;
47+ import org .eclipse .e4 .core .contexts .IEclipseContext ;
48+ import org .eclipse .e4 .ui .css .swt .theme .IThemeEngine ;
49+ import org .eclipse .e4 .ui .css .swt .theme .IThemeManager ;
50+ import org .eclipse .e4 .ui .internal .workbench .swt .E4Application ;
51+ import org .eclipse .e4 .ui .internal .workbench .swt .PartRenderingEngine ;
4552import org .eclipse .equinox .app .IApplication ;
4653import org .eclipse .equinox .app .IApplicationContext ;
4754import org .eclipse .jface .dialogs .IDialogConstants ;
7178import org .eclipse .ui .internal .ide .StatusUtil ;
7279import org .eclipse .ui .preferences .ScopedPreferenceStore ;
7380import org .osgi .framework .Bundle ;
81+ import org .osgi .framework .BundleContext ;
82+ import org .osgi .framework .FrameworkUtil ;
83+ import org .osgi .framework .ServiceReference ;
7484import org .osgi .framework .Version ;
7585
7686/**
@@ -94,6 +104,8 @@ public class IDEApplication implements IApplication, IExecutableExtension {
94104
95105 private static final String USER_NAME = "user.name" ; //$NON-NLS-1$
96106
107+ private IThemeEngine themeEngine ;
108+
97109 // Use the branding plug-in of the platform feature since this is most likely
98110 // to change on an update of the IDE.
99111 private static final String WORKSPACE_CHECK_REFERENCE_BUNDLE_NAME = "org.eclipse.platform" ; //$NON-NLS-1$
@@ -145,6 +157,35 @@ public Object start(IApplicationContext appContext) throws Exception {
145157 Job .getJobManager ().suspend ();
146158
147159 Display display = createDisplay ();
160+
161+ IEclipsePreferences configurationScopeNode = ConfigurationScope .INSTANCE
162+ .getNode ("org.eclipse.e4.ui.css.swt.theme" ); //$NON-NLS-1$
163+ String defaultThemeId = configurationScopeNode .get ("themeid" , null ); //$NON-NLS-1$
164+ if (defaultThemeId != null ) {
165+ IEclipseContext tempContext = EclipseContextFactory .create ();
166+ tempContext .set (E4Application .THEME_ID , defaultThemeId );
167+ PartRenderingEngine .initializeStyling (display , tempContext );
168+
169+ Bundle bundle = FrameworkUtil .getBundle (IThemeManager .class );
170+ if (bundle != null ) {
171+ BundleContext bundleContext = bundle .getBundleContext ();
172+ ServiceReference <IThemeManager > ref = bundleContext .getServiceReference (IThemeManager .class );
173+ if (ref != null ) {
174+ IThemeManager mgr = bundleContext .getService (ref );
175+ if (mgr != null ) {
176+ themeEngine = mgr .getEngineForDisplay (display );
177+ if (themeEngine != null ) {
178+ display .addListener (SWT .Show , event -> {
179+ if (event .widget instanceof Shell shell ) {
180+ themeEngine .applyStyles (shell , true );
181+ }
182+ });
183+ }
184+ }
185+ }
186+ }
187+ }
188+
148189 // processor must be created before we start event loop
149190 DelayedEventsProcessor processor = new DelayedEventsProcessor (display );
150191
@@ -587,6 +628,14 @@ protected Shell getParentShell() {
587628 return null ;
588629 }
589630
631+ @ Override
632+ protected Control createContents (Composite parent ) {
633+ Control contents = super .createContents (parent );
634+ if (themeEngine != null ) {
635+ themeEngine .applyStyles (getShell (), true );
636+ }
637+ return contents ;
638+ }
590639 }.prompt (force );
591640 }
592641
0 commit comments