User Tools

Site Tools


e4_rcp_theming

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
e4_rcp_theming [2017/12/11 15:18]
mihael
e4_rcp_theming [2018/05/25 14:56] (current)
mihael
Line 5: Line 5:
 And you can give your e4 RCP application a distinct theme. No problem there. But when you want to give your user the ability to switch themes that is a completely other story. Switching themes includes accessing the ''​IThemeManager''​ which is in the package ''​org.eclipse.ui.themes''​. Still sounds easy enough. Importing the package as a dependency and add the bundle ''​org.eclipse.ui.themes''​ to the application build and we are all done. And you can give your e4 RCP application a distinct theme. No problem there. But when you want to give your user the ability to switch themes that is a completely other story. Switching themes includes accessing the ''​IThemeManager''​ which is in the package ''​org.eclipse.ui.themes''​. Still sounds easy enough. Importing the package as a dependency and add the bundle ''​org.eclipse.ui.themes''​ to the application build and we are all done.
  
-<note warning>**WRONG!**</​note>​+<note warning>Problem with this is that ''​org.eclipse.ui.themes''​ seems to depend on parts of the Eclipse IDE which you normally don't have in an Eclipse e4 RCP application. So this approach does not work.</​note>​
  
 There is a bundle with the symbolic name ''​org.eclipse.ui.themes''​ but it doesn'​t export the java package ''​org.eclipse.ui.themes''​. The bundles contains the CSS and image files but no java package. There is a bundle with the symbolic name ''​org.eclipse.ui.themes''​ but it doesn'​t export the java package ''​org.eclipse.ui.themes''​. The bundles contains the CSS and image files but no java package.
Line 28: Line 28:
  PartRenderingEngine.initializeStyling(Display.getCurrent(),​ this.context);​  PartRenderingEngine.initializeStyling(Display.getCurrent(),​ this.context);​
  }  }
 +}
 +</​sxh>​
 +
 +====== Update ======
 +
 +This also works for setting/​switching a theme.
 +
 +The necessary classes can be found in the plugin ''​org.eclipse.e4.ui.css.swt.theme''​.
 +
 +<sxh java>
 +@Inject
 +private IThemeManager themeManager;​
 +
 +IThemeEngine engine = themeManager.getEngineForDisplay(Display.getCurrent());​
 +for (ITheme theme : engine.getThemes()) {
 +    if (theme.getId().equals(currentThemeId)) {
 + engine.setTheme(theme,​ true);
 + break;
 +    }
 } }
 </​sxh>​ </​sxh>​
  
 {{tag>​devel java e4}} {{tag>​devel java e4}}
e4_rcp_theming.txt ยท Last modified: 2018/05/25 14:56 by mihael