Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[e4-dev] Dynamic CSS Theme Switcher

All,

 

@Paul, tanks for fixing bug 278369 so quickly, the Theme Switcher is working again

 

The contacts demo now contains a dynamic css theme switcher. You can switch at runtime from

 

 

to

 

 

using the Themes menu. The code is in org.eclipse.e4.demo.contacts.handlers.ThemeUtil.java. Suggestions for improvements are very welcome. Currently it is using the IWorkbench injected in the corresponding Handler’s execute method. Then getting the shell and the display. Currently the css engine is a property in the display, I did not find a better way of getting it…

 

Here is the snippet:

 

                public static void switchTheme(IWorkbench workbench, final String css) {

                               if (workbench instanceof Workbench) {

                                               Workbench wb = (Workbench) workbench;

                                               final Shell shell = (Shell) wb.getWindow();

                                               Display display = shell.getDisplay();

                                               final CSSEngine engine = (CSSEngine) display

                                                                              .getData("org.eclipse.e4.ui.css.core.engine");

 

                                               display.syncExec(new Runnable() {

                                                               public void run() {

                                                                              try {

                                                                                              URL url = "">resolve(new URL(

                                                                                                                             "platform:/plugin/org.eclipse.e4.demo.contacts/css/"

                                                                                                                                                             + css));

 

                                                                                              InputStreamReader streamReader = new InputStreamReader(

                                                                                                                             url.openStream());

                                                                                              engine.reset();

                                                                                              engine.parseStyleSheet(streamReader);

                                                                                              engine.applyStyles(shell, true, false);

                                                                              } catch (MalformedURLException e) {

                                                                                              // TODO Auto-generated catch block

                                                                                              e.printStackTrace();

                                                                              } catch (IOException e) {

                                                                                              // TODO Auto-generated catch block

                                                                                              e.printStackTrace();

                                                                              }

                                                               }

                                               });

                               }

 

Currently the defaults for UI elements not using css are NOT resetted to SWT defaults. So, all the css files must have exactly the same elements with different values. I tried

 

engine.applyStyles(shell, true, true); // The red true is supposed to reset to SWT defaults

 

but this gives strange results, I have filed bug 278381 for that…

 

But besides that, it’s great to see the dynamic css theme change working in an e4 RCP app, perhaps that would be a nice feature for the bootstrap workbench.

 

Best regards,

 

Kai

 

Kai Tödter

 

Siemens AG

Corporate Technology

Architecture

CT SE 2

Otto-Hahn-Ring 6

81739 Munich, Germany

Phone: +49 89 636-41064

Fax: +49 89 636-45450

mailto: kai.toedter@xxxxxxxxxxx

Internet: www.siemens.com/corporate-technology

 

Siemens Aktiengesellschaft: Chairman of the Supervisory Board: Gerhard Cromme; Managing Board: Peter Loescher, Chairman, President and Chief Executive Officer; Heinrich Hiesinger, Joe Kaeser, Rudi Lamprecht, Eduardo Montes, Juergen Radomski, Erich R. Reinhardt, Hermann Requardt, Uriel J. Sharef, Peter Y. Solmssen, Klaus Wucherer; Registered offices: Berlin and Munich; Commercial registries: Berlin Charlottenburg, HRB 12300, Munich, HRB 6684; WEEE-Reg.-No. DE 23691322

 

 


Back to the top