Download as pdf or txt
Download as pdf or txt
You are on page 1of 61

CSS & Eclipse 4 Application

Platform
Brian de Alwis
Manumitting Technologies
bsd@mt.ca

Copyright 2012 Manumitting Technologies


Tuesday, 27 March, 12

2
Tuesday, 27 March, 12

Eclipse 4 goal:
make writing plugins easy

Copyright 2012 Manumitting Technologies


Tuesday, 27 March, 12

Eclipse 4 goal:
make writing plugins easy
Allow better control over the look of
Eclipse-based products

Copyright 2012 Manumitting Technologies


Tuesday, 27 March, 12

Eclipse 4 goal:
make writing plugins easy
Allow better control over the look of
Eclipse-based products
Let those who can, do

Copyright 2012 Manumitting Technologies


Tuesday, 27 March, 12

4
Tuesday, 27 March, 12

5
Tuesday, 27 March, 12

5
Tuesday, 27 March, 12

CSS
5
Tuesday, 27 March, 12

html
body
div

div

h1 p p img p
em

HTML
6
Tuesday, 27 March, 12

html

Shell

body

Composite

div

div

Composite

Composite

h1 p p img p

Group Text Label Tree Combo

em

Table

HTML

SWT
6

Tuesday, 27 March, 12

7
Tuesday, 27 March, 12

8
Tuesday, 27 March, 12

Jon Deardens winning entry for the


EclipseCon e4 Rover Competition (2010)
9
Tuesday, 27 March, 12

CSS on SWT
10
Tuesday, 27 March, 12

CSS Rules
h1

{ color: red; }

selector property value

11
Tuesday, 27 March, 12

CSS Rules Selectors


h1

11
Tuesday, 27 March, 12

CSS Rules Selectors


h1
h1.class

11
Tuesday, 27 March, 12

CSS Rules Selectors


h1
h1.class
h1#id

11
Tuesday, 27 March, 12

CSS Rules Selectors


h1
h1.class
h1#id

getClass() == h1
instanceof
==

11
Tuesday, 27 March, 12

CSS Selectors for SWT


Shell.MTrimmedWindow
Composite.MArea
CTabFolder.EditorStack
CTabItem.Editor CTabItem.Editor
Composite#f1
Group Text
Table#serverList
Tuesday, 27 March, 12

Composite#f2
Text Table Combo
12

CSS Selectors for SWT


Shell.MTrimmedWindow

Composite

Composite.MArea
CTabFolder.EditorStack
CTabItem.Editor CTabItem.Editor
Composite#f1
Group Text
Table#serverList

Tuesday, 27 March, 12

Composite#f2
Text Table Combo
13

CSS Selectors for SWT


Shell.MTrimmedWindow

Composite

Composite.MArea

Composite.MArea

CTabFolder.EditorStack

CTabItem.Editor CTabItem.Editor
Composite#f1
Group Text
Table#serverList
Tuesday, 27 March, 12

Composite#f2
Text Table Combo
14

CSS Selectors for SWT


Shell.MTrimmedWindow

Composite

Composite.MArea

Composite.MArea

CTabFolder.EditorStack

CTabItem.Editor CTabItem.Editor

Composite#f2

Composite#f1
Group Text
Table#serverList

Tuesday, 27 March, 12

Composite#f2
Text Table Combo
15

Compound Selectors

Shell.MTrimmedWindow
Text

CTabFolder.EditorStack
CTabItem

CTabItem

Group Text Label Tree Combo


Text
16
Tuesday, 27 March, 12

Child Selectors
.MTrimmedWindow > Text
Shell.MTrimmedWindow
Text

CTabFolder.EditorStack
CTabItem

CTabItem

Group Text Label Tree Combo


Text
17
Tuesday, 27 March, 12

Descendant Selectors
.MTrimmedWindow Text
Shell.MTrimmedWindow
Text

CTabFolder.EditorStack
CTabItem

CTabItem

Group Text Label Tree Combo


Text
18
Tuesday, 27 March, 12

Descendant Selectors
.MTrimmedWindow Text
Shell

Shell.MTrimmedWindow

Text

Text

CTabFolder.EditorStack
CTabItem

CTabItem

Group Text Label Tree Combo


Text
18
Tuesday, 27 March, 12

Attribute Selectors
Button[style~=SWT.CHECK]
Widget.class

Exact value

~=

Partial value

Widget[class~=class]

19
Tuesday, 27 March, 12

Pseudo-elements and classes


Text:focus { background: parchment; }
Shell:parented { background: red; }

What are these properties?


20
Tuesday, 27 March, 12

Demo: CSS Spy


& CSS Scratchpad

21
Tuesday, 27 March, 12

Exposing Information
Leveraging the CSS for your own widgets
22
Tuesday, 27 March, 12

Extend in 3 easy steps

Identify your widgets


Define matching DOM elements where necessary
Add custom properties

Copyright 2012 Manumitting Technologies


Tuesday, 27 March, 12

23

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

Copyright 2012 Manumitting Technologies


Tuesday, 27 March, 12

24

Aside: Assigning Class & Id


import org.eclipse.e4.ui.css.swt.dom.WidgetElement;

WidgetElement.setCSSClass(
widget, class string);

.error { border: 1px red; }


WidgetElement.setID(widget, id);

#cssSource { font: Courier; }


WidgetElement.getEngine(widget)
.applyStyles(widget, true);
25
Tuesday, 27 March, 12

Widgets
Defines:
Local + package
name
Provides:
Attributes

DOM Elements
ElementAdapter

ControlElement
ItemElement

CTabItemElement

CompositeElement

ShellElement

Pseudo elements

26
Tuesday, 27 March, 12

<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>

27
Tuesday, 27 March, 12

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>

28
Tuesday, 27 March, 12

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 ...;

}
}

29
Tuesday, 27 March, 12

Pitfalls
30
Tuesday, 27 March, 12

Composite.getBackgroundMode()

SWT.INHERIT_NONE
Tuesday, 27 March, 12

31

Composite.getBackgroundMode()

SWT.INHERIT_DEFAULT
Tuesday, 27 March, 12

32

Using parents background

33
Tuesday, 27 March, 12

Text { color: grey; background-color: black; }


Composite > Text { color: silver; }
Text.error { color: red; }
Text.warning { color: orange; }

Which rule wins?

34
Tuesday, 27 March, 12

Text { color: grey; background-color: black; }


Composite > Text { color: silver; }
Text.error { color: red; }
Text.warning { color: orange; }

Which rule wins?

Specificity

Cascades

34
Tuesday, 27 March, 12

CSS Differences: HTML vs


SWT
SWT.BORDER vs border property
border is emulated
Gradients
Background mode vs gradients & images

Copyright 2012 Manumitting Technologies


Tuesday, 27 March, 12

35

CSS & JFace

How to use CSS for setting fonts and colours for label
providers?

Copyright 2012 Manumitting Technologies


Tuesday, 27 March, 12

36

Building Your Own Engine


37
Tuesday, 27 March, 12

Best Practices

38
Tuesday, 27 March, 12

Best practices
Identify rules for labeling/identifying structure
Scoping
SWT Quirks
background mode
background image & background colour
(Lack of) support for non-px dimensions

Copyright 2012 Manumitting Technologies


Tuesday, 27 March, 12

39

Scoping
Text {
color: white;
background-color: black;
}

40
Tuesday, 27 March, 12

Scoping
Text {
color: white;
background-color: black;
}
Affects Text instances everywhere.
Including startup dialogs.

40
Tuesday, 27 March, 12

Scoping
.MTrimmedWindow Text,
.MWindow
Text { Text {
color:
color: white;
white;
background-color:
background-color: black;
black;
}}

40
Tuesday, 27 March, 12

Use classes, not types

41
Tuesday, 27 March, 12

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

Copyright 2012 Manumitting Technologies


Tuesday, 27 March, 12

42

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

Copyright 2012 Manumitting Technologies


Tuesday, 27 March, 12

43

Future work (M7 and beyond)

CSS Box model + floats stop embedding layouts?


Text transforms
Inheritance on type field?

Copyright 2012 Manumitting Technologies


Tuesday, 27 March, 12

44

Resources

E4 docs: http://wiki.eclipse.org/Eclipse4/RCP
e4 forum and mailing list

Copyright 2012 Manumitting Technologies


Tuesday, 27 March, 12

45

Thank you!

Angelo Zerr original implementation


Bogdan Georghe

Copyright 2012 Manumitting Technologies


Tuesday, 27 March, 12

46

Pre-emptive Questions

47
Tuesday, 27 March, 12

How does this work with the


SWT Browser widget?

?
48
Tuesday, 27 March, 12

You might also like