Differences
This shows you the differences between two versions of the page.
e4_rcp_theming [2017/12/11 16:18] |
e4_rcp_theming [2021/04/05 11:23] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Eclipse e4 RCP Theming ====== | ||
+ | Giving an Eclipse e4 application a new theme is rather easy with the e4 css theme support. There are many tutorials and articles about it. | ||
+ | |||
+ | 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 '' | ||
+ | |||
+ | <note warning> | ||
+ | |||
+ | There is a bundle with the symbolic name '' | ||
+ | |||
+ | I found the package in the bundle '' | ||
+ | |||
+ | So no '' | ||
+ | |||
+ | But if we can't switch themes dynamically perhaps we can load the correct theme on application start ... and yes, that is possible. Long live the '' | ||
+ | |||
+ | <sxh java> | ||
+ | import org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine; | ||
+ | import org.eclipse.e4.core.contexts.IEclipseContext; | ||
+ | import org.eclipse.e4.ui.workbench.lifecycle.PostContextCreate; | ||
+ | |||
+ | public class LifeCycleManager { | ||
+ | |||
+ | @PostContextCreate | ||
+ | void postContextCreate(IEclipseContext context) { | ||
+ | String cssURI = " | ||
+ | this.context.set(E4Workbench.CSS_URI_ARG, | ||
+ | PartRenderingEngine.initializeStyling(Display.getCurrent(), | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ====== Update ====== | ||
+ | |||
+ | This also works for setting/ | ||
+ | |||
+ | The necessary classes can be found in the plugin '' | ||
+ | |||
+ | <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, | ||
+ | break; | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | {{tag> |