Skip to content

Commit a6ae91c

Browse files
committed
Merge AbstractCSSSWTEngineImpl into CSSSWTEngineImpl
Same housekeeping pattern as the previous core-engine merge: AbstractCSSSWTEngineImpl was an abstract layer with two abstract hooks (initializeCSSPropertyHandlers, initializeCSSElementProvider) whose only concrete subclass was CSSSWTEngineImpl. Inline the abstract layer into the concrete leaf, drop the two now-redundant template methods, and register the SWT element provider and the registry-driven property handler provider directly in the constructor. Bundle internal (x-friends only); no API surface changed. All 194 css.swt tests still pass. Contributes to #3980
1 parent ff1f1b7 commit a6ae91c

2 files changed

Lines changed: 90 additions & 158 deletions

File tree

bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/engine/AbstractCSSSWTEngineImpl.java

Lines changed: 0 additions & 141 deletions
This file was deleted.

bundles/org.eclipse.e4.ui.css.swt/src/org/eclipse/e4/ui/css/swt/engine/CSSSWTEngineImpl.java

Lines changed: 90 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2008, 2019 Angelo Zerr and others.
2+
* Copyright (c) 2008, 2026 Angelo Zerr and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -16,34 +16,63 @@
1616

1717
import org.eclipse.core.runtime.ILog;
1818
import org.eclipse.core.runtime.RegistryFactory;
19+
import org.eclipse.e4.ui.css.core.dom.CSSStylableElement;
20+
import org.eclipse.e4.ui.css.core.engine.CSSElementContext;
21+
import org.eclipse.e4.ui.css.core.impl.engine.CSSEngineImpl;
1922
import org.eclipse.e4.ui.css.core.impl.engine.RegistryCSSElementProvider;
2023
import org.eclipse.e4.ui.css.core.impl.engine.RegistryCSSPropertyHandlerProvider;
24+
import org.eclipse.e4.ui.css.core.resources.IResourcesRegistry;
25+
import org.eclipse.e4.ui.css.swt.dom.WidgetElement;
26+
import org.eclipse.e4.ui.css.swt.properties.converters.CSSValueSWTColorConverterImpl;
27+
import org.eclipse.e4.ui.css.swt.properties.converters.CSSValueSWTCursorConverterImpl;
28+
import org.eclipse.e4.ui.css.swt.properties.converters.CSSValueSWTFontConverterImpl;
29+
import org.eclipse.e4.ui.css.swt.properties.converters.CSSValueSWTFontDataConverterImpl;
30+
import org.eclipse.e4.ui.css.swt.properties.converters.CSSValueSWTGradientConverterImpl;
31+
import org.eclipse.e4.ui.css.swt.properties.converters.CSSValueSWTImageConverterImpl;
32+
import org.eclipse.e4.ui.css.swt.properties.converters.CSSValueSWTRGBConverterImpl;
33+
import org.eclipse.e4.ui.css.swt.resources.SWTResourceRegistryKeyFactory;
34+
import org.eclipse.e4.ui.css.swt.resources.SWTResourcesRegistry;
2135
import org.eclipse.swt.SWT;
2236
import org.eclipse.swt.events.DisposeListener;
2337
import org.eclipse.swt.widgets.Display;
2438
import org.eclipse.swt.widgets.Shell;
2539
import org.eclipse.swt.widgets.Widget;
40+
import org.w3c.dom.Element;
2641

2742
/**
28-
* CSS SWT Engine implementation which configure CSSEngineImpl to apply styles
29-
* to SWT widgets with static handler strategy.
43+
* CSS SWT Engine. Configures {@link CSSEngineImpl} with the SWT-specific
44+
* value converters and the registry-driven element + property handler
45+
* providers, and applies styles to SWT widgets.
3046
*/
31-
public class CSSSWTEngineImpl extends AbstractCSSSWTEngineImpl {
47+
public class CSSSWTEngineImpl extends CSSEngineImpl {
3248

33-
private DisposeListener disposeListener;
49+
protected Display display;
50+
51+
private final DisposeListener disposeListener = e -> handleWidgetDisposed(e.widget);
3452

3553
public CSSSWTEngineImpl(Display display) {
36-
super(display);
37-
init();
54+
this(display, false);
3855
}
3956

4057
public CSSSWTEngineImpl(Display display, boolean lazyApplyingStyles) {
41-
super(display, lazyApplyingStyles);
42-
init();
43-
}
58+
this.display = display;
4459

45-
private void init() {
46-
disposeListener = e -> handleWidgetDisposed(e.widget);
60+
registerCSSValueConverter(CSSValueSWTRGBConverterImpl.INSTANCE);
61+
registerCSSValueConverter(CSSValueSWTColorConverterImpl.INSTANCE);
62+
registerCSSValueConverter(CSSValueSWTGradientConverterImpl.INSTANCE);
63+
registerCSSValueConverter(CSSValueSWTCursorConverterImpl.INSTANCE);
64+
registerCSSValueConverter(CSSValueSWTFontConverterImpl.INSTANCE);
65+
registerCSSValueConverter(CSSValueSWTFontDataConverterImpl.INSTANCE);
66+
registerCSSValueConverter(CSSValueSWTImageConverterImpl.INSTANCE);
67+
68+
if (lazyApplyingStyles) {
69+
new CSSSWTApplyStylesListener(display, this);
70+
}
71+
72+
setElementProvider(new RegistryCSSElementProvider(RegistryFactory.getRegistry()));
73+
propertyHandlerProviders.add(new RegistryCSSPropertyHandlerProvider(RegistryFactory.getRegistry()));
74+
75+
setResourceRegistryKeyFactory(new SWTResourceRegistryKeyFactory());
4776
}
4877

4978
@Override
@@ -54,13 +83,58 @@ protected void hookNativeWidget(Object widget) {
5483
}
5584

5685
@Override
57-
protected void initializeCSSPropertyHandlers() {
58-
propertyHandlerProviders.add(new RegistryCSSPropertyHandlerProvider(RegistryFactory.getRegistry()));
86+
public IResourcesRegistry getResourcesRegistry() {
87+
IResourcesRegistry resourcesRegistry = super.getResourcesRegistry();
88+
if (resourcesRegistry == null) {
89+
super.setResourcesRegistry(new SWTResourcesRegistry(display));
90+
}
91+
return super.getResourcesRegistry();
5992
}
6093

6194
@Override
62-
protected void initializeCSSElementProvider() {
63-
setElementProvider(new RegistryCSSElementProvider(RegistryFactory.getRegistry()));
95+
public Element getElement(Object element) {
96+
if (element instanceof CSSStylableElement
97+
&& ((CSSStylableElement) element).getNativeWidget() instanceof Widget) {
98+
return (CSSStylableElement) element;
99+
} else if (element instanceof Widget) {
100+
if (isStylable((Widget) element)) {
101+
return super.getElement(element);
102+
}
103+
} else {
104+
// FIXME: we need to pass through the ThemeElementDefinitions;
105+
// perhaps they should be handled by a separate engine
106+
return super.getElement(element);
107+
}
108+
return null;
109+
}
110+
111+
/**
112+
* Return true if the given widget can be styled.
113+
*/
114+
protected boolean isStylable(Widget widget) {
115+
return !widget.isDisposed()
116+
&& !Boolean.TRUE.equals(widget.getData("org.eclipse.e4.ui.css.disabled")); //$NON-NLS-1$
117+
}
118+
119+
@Override
120+
public void reset() {
121+
for (CSSElementContext elementContext : getElementsContext().values()) {
122+
Element element = elementContext.getElement();
123+
if (element instanceof WidgetElement
124+
&& isApplicableToReset((WidgetElement) element)) {
125+
((WidgetElement) element).reset();
126+
}
127+
}
128+
129+
getResourcesRegistry().dispose();
130+
super.reset();
131+
}
132+
133+
private boolean isApplicableToReset(WidgetElement element) {
134+
if (element.getNativeWidget() instanceof Widget) {
135+
return !((Widget) element.getNativeWidget()).isDisposed();
136+
}
137+
return false;
64138
}
65139

66140
@Override
@@ -78,5 +152,4 @@ public void reapply() {
78152
}
79153
}
80154
}
81-
82155
}

0 commit comments

Comments
 (0)