Copyright 2012 Manumitting Technologies CSS & Eclipse 4 Application Platform Brian de Alwis Manumitting Technologies [email protected] 1 Tuesday, 27 March, 12
Copyright 2012 Manumitting Technologies
CSS & Eclipse 4 Application PlatformBrian de AlwisManumitting [email protected]
1
Tuesday, 27 March, 12
2
Tuesday, 27 March, 12
Copyright 2012 Manumitting Technologies
Eclipse 4 goal:make writing plugins easy
3
Tuesday, 27 March, 12
Copyright 2012 Manumitting Technologies
Eclipse 4 goal:make writing plugins easy
Allow better control over the look of Eclipse-based products
3
Tuesday, 27 March, 12
Copyright 2012 Manumitting Technologies
Eclipse 4 goal:make writing plugins easy
Allow better control over the look of Eclipse-based products
Let those who can, do
3
Tuesday, 27 March, 12
4
Tuesday, 27 March, 12
5
Tuesday, 27 March, 12
5
Tuesday, 27 March, 12
5
CSSTuesday, 27 March, 12
6
html
body
h1
div
p p
div
em
imgp
HTMLTuesday, 27 March, 12
6
html
body
h1
div
p p
div
em
imgp
HTML
Shell
Composite
Group
Composite
Text Combo
Composite
Table
TreeLabel
SWTTuesday, 27 March, 12
7
Tuesday, 27 March, 12
8
Tuesday, 27 March, 12
Jon Dearden’s winning entry for the EclipseCon e4 Rover Competition (2010)
9
Tuesday, 27 March, 12
CSS on SWT
10
Tuesday, 27 March, 12
CSS Rules
11
h1 { color: red; }
selector property value
Tuesday, 27 March, 12
CSS Rules
11
h1
Selectors
Tuesday, 27 March, 12
CSS Rules
11
h1
h1.class
Selectors
Tuesday, 27 March, 12
CSS Rules
11
h1
h1.class
h1#id
Selectors
Tuesday, 27 March, 12
CSS Rules
11
h1
h1.class
h1#id
instanceof
==
getClass() == h1
Selectors
Tuesday, 27 March, 12
CSS Selectors for SWT
12
Shell.MTrimmedWindow
CTabFolder.EditorStack
Group
CTabItem.Editor
Text Combo
CTabItem.Editor
Table#serverList
TableText
Composite#f1 Composite#f2
Composite.MArea
Tuesday, 27 March, 12
CSS Selectors for SWT
13
CompositeShell.MTrimmedWindow
CTabFolder.EditorStack
Group
CTabItem.Editor
Text Combo
CTabItem.Editor
Table#serverList
TableText
Composite#f1 Composite#f2
Composite.MArea
Tuesday, 27 March, 12
CSS Selectors for SWT
14
Composite
Composite.MArea
Shell.MTrimmedWindow
CTabFolder.EditorStack
Group
CTabItem.Editor
Text Combo
CTabItem.Editor
Table#serverList
TableText
Composite#f1 Composite#f2
Composite.MArea
Tuesday, 27 March, 12
CSS Selectors for SWT
15
Composite
Composite#f2
Shell.MTrimmedWindow
CTabFolder.EditorStack
Group
CTabItem.Editor
Text Combo
CTabItem.Editor
Table#serverList
TableText
Composite#f1 Composite#f2
Composite.MArea
Composite.MArea
Tuesday, 27 March, 12
Compound Selectors
16
Shell.MTrimmedWindow
CTabFolder.EditorStack
Group
CTabItem
Text Combo
CTabItem
Text
TreeLabel
Text
Tuesday, 27 March, 12
Child Selectors
17
Shell.MTrimmedWindow
CTabFolder.EditorStack
Group
CTabItem
Text Combo
CTabItem
Text
TreeLabel
.MTrimmedWindow > Text
Text
Tuesday, 27 March, 12
Descendant Selectors
18
.MTrimmedWindow Text
Shell.MTrimmedWindow
CTabFolder.EditorStack
Group
CTabItem
Text Combo
CTabItem
Text
TreeLabel
Text
Tuesday, 27 March, 12
Descendant Selectors
18
.MTrimmedWindow Text
Shell.MTrimmedWindow
CTabFolder.EditorStack
Group
CTabItem
Text Combo
CTabItem
Text
TreeLabel
Text
Shell
Text
Tuesday, 27 March, 12
Attribute Selectors
19
Button[style~=‘SWT.CHECK’]
Widget.class Widget[class~=‘class’]~
=
~=
Exact value
Partial value
Tuesday, 27 March, 12
Pseudo-elements and -classes
20
Text:focus { background: parchment; }
Shell:parented { background: red; }
What are these properties?
Tuesday, 27 March, 12
Demo: CSS Spy& CSS Scratchpad
21
Tuesday, 27 March, 12
Exposing InformationLeveraging the CSS for your own widgets
22
Tuesday, 27 March, 12
Copyright 2012 Manumitting Technologies
Extend in 3 easy steps
Identify your widgets
Define matching DOM elements where necessary
Add custom properties
23
Tuesday, 27 March, 12
Copyright 2012 Manumitting Technologies
Identifying Widgets
E4 exposes SWT widgets too: type#id.class
type corresponds to the widget class
#id matches an object's elementId 'id' (with '.' translated to '-')
.class matches against the modelled element type, any tags on the modelled element, style bits, and widget data key-value items
24
Tuesday, 27 March, 12
Aside: Assigning Class & Id
25
import org.eclipse.e4.ui.css.swt.dom.WidgetElement;
WidgetElement.setCSSClass( widget, “class string”);
WidgetElement.setID(widget, “id”);
WidgetElement.getEngine(widget) .applyStyles(widget, true);
.error { border: 1px red; }
#cssSource { font: Courier; }
Tuesday, 27 March, 12
Widgets ⇔ DOM Elements
26
ElementAdapter
ControlElement
ItemElement CompositeElement
CTabItemElement ShellElement
Defines:
Local + package name
Provides:
Attributes
Pseudo elements
Tuesday, 27 March, 12
27
<extension point="org.eclipse.e4.ui.css.core.elementProvider"> <provider class="org.eclipse.e4.ui.css.swt.dom.SWTElementProvider"> <widget class="org.eclipse.swt.widgets.Control" /> <widget class="org.eclipse.swt.widgets.Composite" /> <widget class="org.eclipse.swt.widgets.Button" /> </provider></extension>
Tuesday, 27 March, 12
28
Add custom properties handlers<extension point="org.eclipse.e4.ui.css.property.handler"> <handler adapter="org.eclipse.e4.ui.css.swt.dom.CTabFolderElement" composite="false" handler="o.e.e4.ui.css.swt.properties.custom. CSSPropertyCornerRadiusSWTHandler"> <property-name name="swt-corner-radius"/> <property-name name="corner-radius" deprecated="renamed as swt-corner-radius"/> </handler></extension>
Tuesday, 27 March, 12
29
public class XXXPropertyHandler implements ICSSPropertyHandler { public boolean applyCSSProperty(Object element, String property, CSSValue value, String pseudo, CSSEngine engine) throws Exception { ... }
public String retrieveCSSProperty(Object widget, String pseudo, CSSEngine engine) throws Exception { return ...; } }
Tuesday, 27 March, 12
Pitfalls
30
Tuesday, 27 March, 12
31SWT.INHERIT_NONE
Composite.getBackgroundMode()
Tuesday, 27 March, 12
32
Composite.getBackgroundMode()
SWT.INHERIT_DEFAULTTuesday, 27 March, 12
33
Using parent’s background
Tuesday, 27 March, 12
34
Text { color: grey; background-color: black; }Composite > Text { color: silver; }Text.error { color: red; }Text.warning { color: orange; }
Which rule wins?
Tuesday, 27 March, 12
34
Text { color: grey; background-color: black; }Composite > Text { color: silver; }Text.error { color: red; }Text.warning { color: orange; }
Which rule wins?
Specificity Cascades
Tuesday, 27 March, 12
Copyright 2012 Manumitting Technologies
CSS Differences: HTML vs SWT
SWT.BORDER vs “border” property
“border” is emulated
Gradients
Background mode vs gradients & images
35
Tuesday, 27 March, 12
Copyright 2012 Manumitting Technologies
CSS & JFace
How to use CSS for setting fonts and colours for label providers?
36
Tuesday, 27 March, 12
Building Your Own Engine
37
Tuesday, 27 March, 12
Best Practices
38
Tuesday, 27 March, 12
Copyright 2012 Manumitting Technologies
Best practices
Identify rules for labeling/identifying structure
Scoping
SWT Quirks
background mode
background image & background colour
(Lack of) support for non-px dimensions
39
Tuesday, 27 March, 12
Scoping
40
Text { color: ‘white’; background-color: ‘black’; }
Tuesday, 27 March, 12
Scoping
40
Text { color: ‘white’; background-color: ‘black’; }
Affects Text instances everywhere.Including startup dialogs.
Tuesday, 27 March, 12
Scoping
40
Text { color: ‘white’; background-color: ‘black’; }
.MTrimmedWindow Text,
.MWindow Text { color: ‘white’; background-color: ‘black’;}
Tuesday, 27 March, 12
Use classes, not types
41
Tuesday, 27 March, 12
Copyright 2012 Manumitting Technologies
Use CSS Tools
SCSS/SASS (sass-lang.net)
CSS precompiler
CSS Lint (csslint.net)
Web Designers (e.g., OOCSS)
Learn from lessons of what to do and not to do
42
Tuesday, 27 March, 12
Copyright 2012 Manumitting Technologies
Be careful out there, kids
Many articles generated by non-developers promulgating unsound techniques (e.g., “classitis”, avoiding semantically-meaningful names!!!)
But these are the people who will be doing the styling
43
Tuesday, 27 March, 12
Copyright 2012 Manumitting Technologies
Future work (M7 and beyond)
44
CSS Box model + floats — stop embedding layouts?
Text transforms
Inheritance on type field?
Tuesday, 27 March, 12
Copyright 2012 Manumitting Technologies
Resources
E4 docs: http://wiki.eclipse.org/Eclipse4/RCP
e4 forum and mailing list
45
Tuesday, 27 March, 12
Copyright 2012 Manumitting Technologies
Thank you!
Angelo Zerr — original implementation
Bogdan Georghe
46
Tuesday, 27 March, 12
Pre-emptive Questions
47
Tuesday, 27 March, 12
How does this work with the SWT Browser widget?
48
?Tuesday, 27 March, 12