Search in sources :

Example 1 with IThemeEngine

use of org.eclipse.e4.ui.css.swt.theme.IThemeEngine in project dbeaver by serge-rider.

the class TextEditorUtils method isDarkThemeEnabled.

public static boolean isDarkThemeEnabled() {
    boolean isDark = false;
    IThemeEngine engine = PlatformUI.getWorkbench().getService(IThemeEngine.class);
    if (engine != null) {
        ITheme activeTheme = engine.getActiveTheme();
        if (activeTheme != null) {
            isDark = activeTheme.getId().contains("dark");
        }
    }
    return isDark;
}
Also used : ITheme(org.eclipse.e4.ui.css.swt.theme.ITheme) IThemeEngine(org.eclipse.e4.ui.css.swt.theme.IThemeEngine)

Example 2 with IThemeEngine

use of org.eclipse.e4.ui.css.swt.theme.IThemeEngine in project dbeaver by dbeaver.

the class TextEditorUtils method isDarkThemeEnabled.

public static boolean isDarkThemeEnabled() {
    boolean isDark = false;
    IThemeEngine engine = PlatformUI.getWorkbench().getService(IThemeEngine.class);
    if (engine != null) {
        ITheme activeTheme = engine.getActiveTheme();
        if (activeTheme != null) {
            isDark = activeTheme.getId().contains("dark");
        }
    }
    return isDark;
}
Also used : ITheme(org.eclipse.e4.ui.css.swt.theme.ITheme) IThemeEngine(org.eclipse.e4.ui.css.swt.theme.IThemeEngine)

Example 3 with IThemeEngine

use of org.eclipse.e4.ui.css.swt.theme.IThemeEngine in project dbeaver by serge-rider.

the class E4ThemeColor method getCssValueFromTheme.

public static String getCssValueFromTheme(Display display, String value) {
    // use reflection so that this can build against Eclipse 3.x
    BundleContext context = FrameworkUtil.getBundle(E4ThemeColor.class).getBundleContext();
    ServiceReference<IThemeManager> reference = context.getServiceReference(IThemeManager.class);
    if (reference != null) {
        IThemeManager iThemeManager = context.getService(reference);
        if (iThemeManager != null) {
            IThemeEngine themeEngine = iThemeManager.getEngineForDisplay(display);
            if (themeEngine != null) {
                CSSStyleDeclaration shellStyle = getStyleDeclaration(themeEngine, display);
                if (shellStyle != null) {
                    CSSValue cssValue = shellStyle.getPropertyCSSValue(value);
                    if (cssValue != null) {
                        return cssValue.getCssText();
                    }
                }
            }
        }
    }
    return null;
}
Also used : CSSValue(org.w3c.dom.css.CSSValue) IThemeEngine(org.eclipse.e4.ui.css.swt.theme.IThemeEngine) IThemeManager(org.eclipse.e4.ui.css.swt.theme.IThemeManager) CSSStyleDeclaration(org.w3c.dom.css.CSSStyleDeclaration) BundleContext(org.osgi.framework.BundleContext)

Example 4 with IThemeEngine

use of org.eclipse.e4.ui.css.swt.theme.IThemeEngine in project xtext-xtend by eclipse.

the class XtendThemeManager method handleEvent.

@Override
public void handleEvent(Event event) {
    if (!IThemeEngine.Events.THEME_CHANGED.equals(event.getTopic())) {
        return;
    }
    IThemeEngine themeEngine = PlatformUI.getWorkbench().getService(IThemeEngine.class);
    ITheme theme = themeEngine.getActiveTheme();
    IEclipsePreferences preferences = InstanceScope.INSTANCE.getNode(ORG_ECLIPSE_XTEND_CORE_XTEND);
    if (!theme.getId().contains("dark")) {
        // resetting from dark theme does not work the same way
        // as a workaround reset the preferences by evaluating the XtendHighlightingConfiguration
        IHighlightingConfiguration highlightingConfiguration = new XtendHighlightingConfiguration();
        highlightingConfiguration.configure((id, name, style) -> {
            setColorPreference(preferences, getSyntaxHightlightingPreferenceKey(id, COLOR_SUFFIX), style.getColor());
            setColorPreference(preferences, getSyntaxHightlightingPreferenceKey(id, BACKGROUNDCOLOR_SUFFIX), style.getBackgroundColor());
            String styleKey = getSyntaxHightlightingPreferenceKey(id, STYLE_SUFFIX);
            int styleMask = style.getStyle();
            if (preferences.getInt(styleKey, -1) != -1) {
                preferences.remove(styleKey);
            }
            if (styleMask > 0) {
                preferences.putInt(styleKey, styleMask);
            }
        });
    }
    themeEngine.applyStyles(preferences, false);
}
Also used : ITheme(org.eclipse.e4.ui.css.swt.theme.ITheme) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) IThemeEngine(org.eclipse.e4.ui.css.swt.theme.IThemeEngine) IHighlightingConfiguration(org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightingConfiguration)

Example 5 with IThemeEngine

use of org.eclipse.e4.ui.css.swt.theme.IThemeEngine in project dbeaver by dbeaver.

the class E4ThemeColor method getCssValueFromTheme.

public static String getCssValueFromTheme(Display display, String value) {
    // use reflection so that this can build against Eclipse 3.x
    BundleContext context = FrameworkUtil.getBundle(E4ThemeColor.class).getBundleContext();
    ServiceReference<IThemeManager> reference = context.getServiceReference(IThemeManager.class);
    if (reference != null) {
        IThemeManager iThemeManager = context.getService(reference);
        if (iThemeManager != null) {
            IThemeEngine themeEngine = iThemeManager.getEngineForDisplay(display);
            if (themeEngine != null) {
                CSSStyleDeclaration shellStyle = getStyleDeclaration(themeEngine, display);
                if (shellStyle != null) {
                    CSSValue cssValue = shellStyle.getPropertyCSSValue(value);
                    if (cssValue != null) {
                        return cssValue.getCssText();
                    }
                }
            }
        }
    }
    return null;
}
Also used : CSSValue(org.w3c.dom.css.CSSValue) IThemeEngine(org.eclipse.e4.ui.css.swt.theme.IThemeEngine) IThemeManager(org.eclipse.e4.ui.css.swt.theme.IThemeManager) CSSStyleDeclaration(org.w3c.dom.css.CSSStyleDeclaration) BundleContext(org.osgi.framework.BundleContext)

Aggregations

IThemeEngine (org.eclipse.e4.ui.css.swt.theme.IThemeEngine)6 ITheme (org.eclipse.e4.ui.css.swt.theme.ITheme)3 IThemeManager (org.eclipse.e4.ui.css.swt.theme.IThemeManager)2 BundleContext (org.osgi.framework.BundleContext)2 CSSStyleDeclaration (org.w3c.dom.css.CSSStyleDeclaration)2 CSSValue (org.w3c.dom.css.CSSValue)2 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)1 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)1 MApplication (org.eclipse.e4.ui.model.application.MApplication)1 IHighlightingConfiguration (org.eclipse.xtext.ui.editor.syntaxcoloring.IHighlightingConfiguration)1