Skip to content

Commit d59348a

Browse files
authored
Merge branch 'eclipse-platform:master' into master
2 parents 0c2eeb8 + ca934b3 commit d59348a

31 files changed

+906
-716
lines changed

docs/CSS.md

Lines changed: 50 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Eclipse
1+
Eclipse
22
======
33

44

@@ -21,6 +21,7 @@ Sample
2121

2222
The sample code below creates a simple Label within a Shell but the Label's foreground colour is styled to a blue colour by the CSS engine.
2323

24+
```java
2425
Display display = new Display();
2526
Shell shell = new Shell();
2627
shell.setLayout(new GridLayout());
@@ -50,15 +51,16 @@ The sample code below creates a simple Label within a Shell but the Label's fore
5051
}
5152
}
5253
display.dispose();
54+
```
5355

5456
SWT Mapping
5557
-----------
5658

57-
CSS style sheets can be used to modify SWT widget properties.
59+
CSS style sheets can be used to modify SWT widget properties.
5860

5961

60-
Many SWT property setting methods can be accessed via CSS.
61-
These tables show the equivalent mapping from SWT method to CSS property.
62+
Many SWT property setting methods can be accessed via CSS.
63+
These tables show the equivalent mapping from SWT method to CSS property.
6264
They also show pseudo selectors which can be used to choose styling based on widget state.
6365

6466

@@ -78,23 +80,23 @@ They also show pseudo selectors which can be used to choose styling based on wid
7880
| | font-style font-size font-weight font-family | Label { font-style: italic;           font-size: 12;           font-weight: bold;           font-family: "Terminal"; } |
7981
| setForeground(Color) | color | Button { color: #FF0000 } |
8082

81-
83+
8284

8385
### Widget: Button
8486

8587
| SWT Method | CSS Property Name | CSS Example |
8688
| --- | --- | --- |
8789
| setAlignment(int) | swt-alignment | Label { swt-alignment: up; } /* if pushbutton mode */ |
8890

89-
91+
9092

9193
### Widget: Label
9294

9395
| SWT Method | CSS Property Name | CSS Example |
9496
| --- | --- | --- |
9597
| setAlignment(int) | swt-alignment | Label { swt-alignment: center; } |
9698

97-
99+
98100

99101
### Widget: CTabFolder
100102

@@ -115,15 +117,15 @@ They also show pseudo selectors which can be used to choose styling based on wid
115117
| setBackground(Color\[\],int\[\]) | swt-unselected-tabs-color | CTabFolder { swt-unselected-tabs-color: #FF0000 #FFFFFF 100%; } |
116118
| setTabHeight(int) | swt-tab-height | CTabFolder { swt-tab-height: 10px; } |
117119

118-
120+
119121

120122
### Widget: CTabItem
121123

122124
| SWT Method | CSS Property Name | CSS Example |
123125
| --- | --- | --- |
124126
| setShowClose(boolean) | swt-show-close | CTabItem { swt-show-close: true } |
125127

126-
128+
127129

128130
### Widget: CTabFolder with e4Renderer
129131

@@ -138,7 +140,7 @@ Note: The following examples assume that you have first set the tab-renderer to
138140
| setSelectedTabFill(Color) | swt-selected-tab-fill | CTabFolder { swt-selected-tab-fill: #F79402; } |
139141
| setTabOutline(Color) | swt-tab-outline | CTabFolder { swt-tab-outline: #F79402; } |
140142

141-
143+
142144

143145
### Pseudo classes which can be used in CSS to style SWT widgets
144146

@@ -153,7 +155,7 @@ Note: The following examples assume that you have first set the tab-renderer to
153155
| CTabFolder | :selected | CTabFolder:selected { background-color: #FF0000; } |
154156
| CTabItem | :selected | CTabItem:selected { font-weight: bold; } |
155157

156-
158+
157159
† As of yet styles are only applied when SWT UI is initially loaded, if widget state is changed afterwards, changes will not take effect
158160

159161

@@ -164,89 +166,74 @@ E4/CSS/Add Selector
164166

165167
This is a "how-to" that will explain the steps needed to add a CSS Selector in E4.
166168

167-
168-
\- Create a class in org.eclipse.e4.ui.css.swt.selectors, and name it "DynamicPseudoClassesSWTxxxxHandler" where "xxxx" is the name of the selector
169169

170-
171-
\- Make this new class extend "AbstractDynamicPseudoClassesControlHandler"
170+
\- Create a class in org.eclipse.e4.ui.css.swt.selectors, and name it "DynamicPseudoClassesSWTxxxxHandler" where "xxxx" is the name of the selector
172171

173172

173+
\- Make this new class extend "AbstractDynamicPseudoClassesControlHandler"
174+
```java
174175
public class DynamicPseudoClassesSWTActiveHandler extends AbstractDynamicPseudoClassesControlHandler
175-
176-
177-
176+
```
178177

179-
180178
\- Within the class, create a IDynamicPseudoClassesHandler and set it equal to an instance of DynamicPseudoClassesSWTxxxxHandler
181-
179+
```java
182180
public static final IDynamicPseudoClassesHandler INSTANCE = new DynamicPseudoClassesSWTxxxxHandler();
183-
181+
```
182+
184183

185-
186184

187-
188-
\- Add the following two methods:
189185

186+
\- Add the following two methods:
187+
```java
190188
protected void intialize(final Control control, final CSSEngine engine) {}
191189
protected void dispose(Control control, CSSEngine engine) {}
192-
190+
```
191+
192+
* Note: method name is intilize is not initialize
193+
193194

194195

195-
Note: method name is intilize is not initialize
196-
197196

198-
199197

200-
201198
\- In the intialize method, add the code needed (most likely listeners to look for change of state). For an example, see org.eclipse.e4.ui.css.swt.selectors.DynamicPseudoClassesSWTActiveHandler
202199

203-
204-
\- Make use of the setData() method on the widget (to get information about the widget in another class), as well as applying the styles to the engine. For example, in a listener's method, you can do the following:
205200

201+
\- Make use of the setData() method on the widget (to get information about the widget in another class), as well as applying the styles to the engine. For example, in a listener's method, you can do the following:
202+
```java
206203
try {
207204
control.setData("Some Qualified String", Boolean.TRUE);
208205
engine.applyStyles(control, false, true);
209206
} catch (Exception ex) {
210207
engine.handleExceptions(ex);
211208
}
212-
213-
214-
215-
216-
209+
```
217210

218211
\- It is preferable to use a qualified string, and to keep it in org.eclipse.e4.ui.css.swt.CSSSWTConstants
219212

220-
213+
221214
\- In the dispose method, get rid of all listeners that were created in the above intialize method
222215

223-
216+
224217
\- In org.eclipse.e4.ui.css.swt.dom.SWTElement#isPseudoInstanceOf add the new selector with the use of an "if" statement
218+
```java
225219
if ("xxxx".equals(s)) {}
226-
227-
228-
220+
```
229221

230-
231222
\- Within the if statement, return the appropriate boolean value based on the setData() you used in your listener, and add any other conditional statements that may be necessary
232-
223+
```java
233224
if ("xxxx".equals(s)) {
234225
Widget widget = getNativeWidget();
235226
if (widget != null) {
236227
return widget.getData("Some Qualified String") == null;
237228
}
238229
}
239-
230+
```
240231

241-
242232

243-
244233
\- Now, we must go in org.eclipse.e4.ui.css.swt.engine.AbstractCSSSWTEngineImpl , and register the name of the selector and the instance of the above class just created:
245-
234+
```java
246235
super.registerDynamicPseudoClassHandler("xxxx", DynamicPseudoClassesSWTxxxxHandler.INSTANCE);
247-
248-
249-
236+
```
250237

251238
E4/CSS/Add Styleable Property
252239
=============================
@@ -262,55 +249,47 @@ Create the Property Handler Class
262249

263250
Create a class in org.eclipse.e4.ui.css.swt.properties.custom and name it "CSSPropertyXXXXSWTHandler", where XXXX is the name of the property
264251

265-
266-
\- Make this new class extend "AbstractCSSPropertySWTHandler"
267252

253+
\- Make this new class extend "AbstractCSSPropertySWTHandler"
254+
```java
268255
public class CSSPropertyXXXXSWTHandler extends AbstractCSSPropertySWTHandler
269-
270-
271-
256+
```
272257

273-
274258
\- Add the following two methods:
275-
259+
```java
276260
public void applyCSSProperty(Control control, String property, CSSValue value, String pseudo, CSSEngine engine) throws Exception {}
277-
278261

279-
public String retrieveCSSProperty(Control control, String property, String pseudo, CSSEngine engine) throws Exception {}
280-
281262

282-
263+
public String retrieveCSSProperty(Control control, String property, String pseudo, CSSEngine engine) throws Exception {}
264+
```
283265

284266
Implement Property Setting
285267
--------------------------
286268

287-
Within the applyCSSProperty method, write the code needed to apply the wanted styles. For example, for the border-visible property (CTabFolder) we write the following:
288-
269+
Within the applyCSSProperty method, write the code needed to apply the wanted styles. For example, for the border-visible property (CTabFolder) we write the following:
270+
```java
289271
public void applyCSSProperty(Control control, String property, CSSValue value, String pseudo, CSSEngine engine) throws Exception {
290272
boolean isBorderVisible = (Boolean)engine.convert(value, Boolean.class, null);
291273
if (control instanceof CTabFolder) {
292274
CTabFolder folder = (CTabFolder) control;
293275
folder.setBorderVisible(isBorderVisible);
294276
}
295277
}
296-
297-
298-
278+
```
299279

300280
Implement Property Retrieval
301281
----------------------------
302282

303283
Within the retrieveCSSProperty method, write the code needed to retrieve the value of the applied property. Again, for border-visible, we write the following:
304284

285+
```java
305286
public String retrieveCSSProperty(Control control, String property, String pseudo, CSSEngine engine) throws Exception {
306287
if (control instanceof CTabFolder) {
307288
CTabFolder folder = (CTabFolder) control;
308289
return Boolean.toString( folder.getBorderVisible() );
309290
}
310291
}
311-
312-
313-
292+
```
314293

315294
Expose the Property
316295
-------------------
@@ -320,9 +299,10 @@ Finally we must wire in the property handler to the CSS Engine. There are two ap
320299
* Configure the property using the org.eclipse.e4.ui.css.core.propertyHandler extension point.
321300
* Explicitly configure the CSS engine instance in the initializeCSSPropertyHandlers() method. In this case, we must first register the name of the property and the above class just created. We must also register the CSSPropertyHandler created in the class:
322301

302+
```java
323303
super.registerCSSProperty("xxxx", CSSPropertyXXXXSWTHandler.class);
324304
super.registerCSSPropertyHandler(CSSPropertyXXXXSWTHandler.class, new CSSPropertyXXXXSWTHandler());
325-
305+
```
326306

327307
Using CSS in Eclipse 3.6
328308
------------------------

0 commit comments

Comments
 (0)