Search in sources :

Example 1 with WidgetElement

use of org.eclipse.e4.ui.css.swt.dom.WidgetElement in project eclipse.platform.ui by eclipse-platform.

the class CSSPropertyBackgroundSWTHandler method applyCSSPropertyBackgroundColor.

@Override
public void applyCSSPropertyBackgroundColor(Object element, CSSValue value, String pseudo, CSSEngine engine) throws Exception {
    Widget widget = (Widget) ((WidgetElement) element).getNativeWidget();
    if (value.getCssValueType() == CSSValue.CSS_PRIMITIVE_VALUE) {
        Color newColor = (Color) engine.convert(value, Color.class, widget.getDisplay());
        if (widget instanceof CTabItem) {
            CTabFolder folder = ((CTabItem) widget).getParent();
            if ("selected".equals(pseudo)) {
                // tab folder selection manages gradients
                CSSSWTColorHelper.setSelectionBackground(folder, newColor);
            } else {
                CSSSWTColorHelper.setBackground(folder, newColor);
            }
        } else if (widget instanceof Control) {
            GradientBackgroundListener.remove((Control) widget);
            CSSSWTColorHelper.setBackground((Control) widget, newColor);
            CompositeElement.setBackgroundOverriddenByCSSMarker(widget);
        }
    } else if (value.getCssValueType() == CSSValue.CSS_VALUE_LIST) {
        Gradient grad = (Gradient) engine.convert(value, Gradient.class, widget.getDisplay());
        if (grad == null) {
            // warn?
            return;
        }
        if (widget instanceof CTabItem) {
            CTabFolder folder = ((CTabItem) widget).getParent();
            Color[] colors = CSSSWTColorHelper.getSWTColors(grad, folder.getDisplay(), engine);
            int[] percents = CSSSWTColorHelper.getPercents(grad);
            if ("selected".equals(pseudo)) {
                folder.setSelectionBackground(colors, percents, true);
            } else {
                folder.setBackground(colors, percents, true);
            }
        } else if (widget instanceof Control) {
            GradientBackgroundListener.handle((Control) widget, grad);
            CompositeElement.setBackgroundOverriddenByCSSMarker(widget);
        }
    }
}
Also used : Control(org.eclipse.swt.widgets.Control) Gradient(org.eclipse.e4.ui.css.core.dom.properties.Gradient) CTabFolder(org.eclipse.swt.custom.CTabFolder) Color(org.eclipse.swt.graphics.Color) Widget(org.eclipse.swt.widgets.Widget) CTabItem(org.eclipse.swt.custom.CTabItem)

Example 2 with WidgetElement

use of org.eclipse.e4.ui.css.swt.dom.WidgetElement in project eclipse.platform.ui by eclipse-platform.

the class AbstractCSSSWTEngineImpl method reset.

@Override
public void reset() {
    for (CSSElementContext elementContext : getElementsContext().values()) {
        Element element = elementContext.getElement();
        if (element instanceof WidgetElement && isApplicableToReset((WidgetElement) element)) {
            ((WidgetElement) element).reset();
        }
    }
    getResourcesRegistry().dispose();
    super.reset();
}
Also used : WidgetElement(org.eclipse.e4.ui.css.swt.dom.WidgetElement) CSSElementContext(org.eclipse.e4.ui.css.core.engine.CSSElementContext) CSSStylableElement(org.eclipse.e4.ui.css.core.dom.CSSStylableElement) WidgetElement(org.eclipse.e4.ui.css.swt.dom.WidgetElement) Element(org.w3c.dom.Element)

Aggregations

CSSStylableElement (org.eclipse.e4.ui.css.core.dom.CSSStylableElement)1 Gradient (org.eclipse.e4.ui.css.core.dom.properties.Gradient)1 CSSElementContext (org.eclipse.e4.ui.css.core.engine.CSSElementContext)1 WidgetElement (org.eclipse.e4.ui.css.swt.dom.WidgetElement)1 CTabFolder (org.eclipse.swt.custom.CTabFolder)1 CTabItem (org.eclipse.swt.custom.CTabItem)1 Color (org.eclipse.swt.graphics.Color)1 Control (org.eclipse.swt.widgets.Control)1 Widget (org.eclipse.swt.widgets.Widget)1 Element (org.w3c.dom.Element)1