use of org.eclipse.e4.ui.css.swt.engine.CSSSWTEngineImpl in project eclipse.platform.ui by eclipse-platform.
the class ThemeEngineManager method getCSSSWTEngine.
private CSSEngine getCSSSWTEngine(Display display) {
CSSEngine cssEngine = WidgetElement.getEngine(display);
if (cssEngine != null) {
return cssEngine;
}
cssEngine = new CSSSWTEngineImpl(display, true);
cssEngine.setErrorHandler(e -> logError(e.getMessage(), e));
WidgetElement.setEngine(display, cssEngine);
return cssEngine;
}
use of org.eclipse.e4.ui.css.swt.engine.CSSSWTEngineImpl in project eclipse.platform.ui by eclipse-platform.
the class ParserTestUtil method createEngine.
public static CSSEngine createEngine() {
Display display = Display.getDefault();
CSSEngine engine = new CSSSWTEngineImpl(display);
engine.setErrorHandler(ERROR_HANDLER);
return engine;
}
use of org.eclipse.e4.ui.css.swt.engine.CSSSWTEngineImpl in project eclipse.platform.ui by eclipse-platform.
the class CascadeTest method setUp.
@BeforeEach
public void setUp() throws Exception {
display = Display.getDefault();
engine = new CSSSWTEngineImpl(display);
}
use of org.eclipse.e4.ui.css.swt.engine.CSSSWTEngineImpl in project eclipse.platform.ui by eclipse-platform.
the class PartRenderingEngine method initializeStyling.
public static void initializeStyling(Display display, IEclipseContext appContext) {
String cssTheme = (String) appContext.get(E4Application.THEME_ID);
String cssURI = (String) appContext.get(IWorkbench.CSS_URI_ARG);
IScopeContext[] contexts = new IScopeContext[] { DefaultScope.INSTANCE, InstanceScope.INSTANCE };
boolean enableThemePreference = Platform.getPreferencesService().getBoolean("org.eclipse.e4.ui.workbench.renderers.swt", ENABLED_THEME_KEY, true, contexts);
if ("none".equals(cssTheme) || (!enableThemePreference)) {
appContext.set(IStylingEngine.class, new IStylingEngine() {
@Override
public void setClassname(Object widget, String classname) {
}
@Override
public void setId(Object widget, String id) {
}
@Override
public void style(Object widget) {
}
@Override
public CSSStyleDeclaration getStyle(Object widget) {
return null;
}
@Override
public void setClassnameAndId(Object widget, String classname, String id) {
}
});
} else if (cssTheme != null) {
final IThemeEngine themeEngine = createThemeEngine(display, appContext);
String cssResourcesURI = (String) appContext.get(IWorkbench.CSS_RESOURCE_URI_ARG);
// Create the OSGi resource locator
if (cssResourcesURI != null) {
// TODO: Should this be set through an extension as well?
themeEngine.registerResourceLocator(new OSGiResourceLocator(cssResourcesURI));
}
appContext.set(IStylingEngine.class, new IStylingEngine() {
@Override
public void setClassname(Object widget, String classname) {
WidgetElement.setCSSClass((Widget) widget, classname);
themeEngine.applyStyles(widget, true);
}
@Override
public void setId(Object widget, String id) {
WidgetElement.setID((Widget) widget, id);
themeEngine.applyStyles(widget, true);
}
@Override
public void style(Object widget) {
themeEngine.applyStyles(widget, true);
}
@Override
public CSSStyleDeclaration getStyle(Object widget) {
return themeEngine.getStyle(widget);
}
@Override
public void setClassnameAndId(Object widget, String classname, String id) {
WidgetElement.setCSSClass((Widget) widget, classname);
WidgetElement.setID((Widget) widget, id);
themeEngine.applyStyles(widget, true);
}
});
setCSSTheme(display, themeEngine, cssTheme);
} else if (cssURI != null) {
String cssResourcesURI = (String) appContext.get(IWorkbench.CSS_RESOURCE_URI_ARG);
final CSSSWTEngineImpl cssEngine = new CSSSWTEngineImpl(display, true);
WidgetElement.setEngine(display, cssEngine);
if (cssResourcesURI != null) {
cssEngine.getResourcesLocatorManager().registerResourceLocator(new OSGiResourceLocator(cssResourcesURI));
}
// FIXME: is this needed?
// $NON-NLS-1$
display.setData("org.eclipse.e4.ui.css.context", appContext);
appContext.set(IStylingEngine.class, new IStylingEngine() {
@Override
public void setClassname(Object widget, String classname) {
WidgetElement.setCSSClass((Widget) widget, classname);
cssEngine.applyStyles(widget, true);
}
@Override
public void setId(Object widget, String id) {
WidgetElement.setID((Widget) widget, id);
cssEngine.applyStyles(widget, true);
}
@Override
public void style(Object widget) {
cssEngine.applyStyles(widget, true);
}
@Override
public CSSStyleDeclaration getStyle(Object widget) {
Element e = cssEngine.getCSSElementContext(widget).getElement();
if (e == null) {
return null;
}
return cssEngine.getViewCSS().getComputedStyle(e, null);
}
@Override
public void setClassnameAndId(Object widget, String classname, String id) {
WidgetElement.setCSSClass((Widget) widget, classname);
WidgetElement.setID((Widget) widget, id);
cssEngine.applyStyles(widget, true);
}
});
URL url;
try {
url = FileLocator.resolve(new URL(cssURI));
try (InputStream stream = url.openStream()) {
cssEngine.parseStyleSheet(stream);
}
} catch (IOException e) {
Activator.log(LogService.LOG_ERROR, e.getMessage(), e);
}
Shell[] shells = display.getShells();
for (Shell s : shells) {
try {
s.setRedraw(false);
s.reskin(SWT.ALL);
cssEngine.applyStyles(s, true);
} catch (Exception e) {
Activator.log(LogService.LOG_ERROR, e.getMessage(), e);
} finally {
s.setRedraw(true);
}
}
}
CSSRenderingUtils cssUtils = ContextInjectionFactory.make(CSSRenderingUtils.class, appContext);
appContext.set(CSSRenderingUtils.class, cssUtils);
}
use of org.eclipse.e4.ui.css.swt.engine.CSSSWTEngineImpl in project eclipse.platform.ui by eclipse-platform.
the class CSSSWTTestCase method createEngine.
public CSSEngine createEngine(String styleSheet, Display display) {
engine = new CSSSWTEngineImpl(display);
engine.setErrorHandler(e -> fail(e.getMessage()));
try {
engine.parseStyleSheet(new StringReader(styleSheet));
} catch (IOException e) {
fail(e.getMessage());
}
return engine;
}
Aggregations