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,9 @@ public Object start(IApplicationContext appContext) throws Exception {
145157 Job .getJobManager ().suspend ();
146158
147159 Display display = createDisplay ();
160+
161+ initializeDefaultTheme (display );
162+
148163 // processor must be created before we start event loop
149164 DelayedEventsProcessor processor = new DelayedEventsProcessor (display );
150165
@@ -587,6 +602,14 @@ protected Shell getParentShell() {
587602 return null ;
588603 }
589604
605+ @ Override
606+ protected Control createContents (Composite parent ) {
607+ Control contents = super .createContents (parent );
608+ if (themeEngine != null ) {
609+ themeEngine .applyStyles (getShell (), true );
610+ }
611+ return contents ;
612+ }
590613 }.prompt (force );
591614 }
592615
@@ -852,6 +875,36 @@ protected static Version toMajorMinorVersion(Version version) {
852875 return new Version (version .getMajor (), version .getMinor (), 0 );
853876 }
854877
878+ protected void initializeDefaultTheme (Display display ) {
879+ IEclipsePreferences configurationScopeNode = ConfigurationScope .INSTANCE
880+ .getNode ("org.eclipse.e4.ui.css.swt.theme" ); //$NON-NLS-1$
881+ String defaultThemeId = configurationScopeNode .get ("themeid" , null ); //$NON-NLS-1$
882+ if (defaultThemeId != null ) {
883+ IEclipseContext tempContext = EclipseContextFactory .create ();
884+ tempContext .set (E4Application .THEME_ID , defaultThemeId );
885+ PartRenderingEngine .initializeStyling (display , tempContext );
886+
887+ Bundle bundle = FrameworkUtil .getBundle (IThemeManager .class );
888+ if (bundle != null ) {
889+ BundleContext bundleContext = bundle .getBundleContext ();
890+ ServiceReference <IThemeManager > ref = bundleContext .getServiceReference (IThemeManager .class );
891+ if (ref != null ) {
892+ IThemeManager mgr = bundleContext .getService (ref );
893+ if (mgr != null ) {
894+ themeEngine = mgr .getEngineForDisplay (display );
895+ if (themeEngine != null ) {
896+ display .addListener (SWT .Show , event -> {
897+ if (event .widget instanceof Shell shell ) {
898+ themeEngine .applyStyles (shell , true );
899+ }
900+ });
901+ }
902+ }
903+ }
904+ }
905+ }
906+ }
907+
855908 @ Override
856909 public void stop () {
857910 final IWorkbench workbench = PlatformUI .getWorkbench ();
0 commit comments