Papyrus Tutorial
Papyrus Tutorial
Papyrus Tutorial
27/09/2012
27/09/2012
Table of Contents
Historic of the document .............................................................................. 2
Introduction .................................................................................................. 3
Installation .................................................................................................... 4
Using StyleSheets ......................................................................................... 6
Editing a StyleSheet ..................................................................................... 7
Manually: The CSS Syntax ................................................................................. 7
Syntax elements ............................................................................................... 7
Examples .......................................................................................................... 8
With the Papyrus tooling. ................................................................................... 8
27/09/2012
Version #
Contributors
<Name>, <Affiliation>
0.9.1
Comments
This is the initial version of the document.
It is based on the Papyrus version 0.9.1.
27/09/2012
NTRODUCTION
While this allows defining a custom theme for our diagrams, this mechanism suffers
from a few limitations:
-
The release of Eclipse 4 Juno this summer gave us the opportunity to rely on their CSS
Engine to support Cascading StyleSheets in Papyrus diagrams. Just like in web pages,
the CSS format is used to separate the contents of our diagrams from their appearance.
It becomes possible to change the appearance of a whole diagram, or even a set of
diagrams, independently of the number of represented elements, in a single click.
27/09/2012
NSTALLATION
The CSS Stylesheet support is not shipped in the base installation of Papyrus.
However, it can be easily installed from the Papyrus discovery site. Select
Help, Install Papyrus Additional Components, and check Diagram
Stylesheets.
27/09/2012
Your diagrams should now look like the following:
Note: If you opened a diagram which has been created without the CSS Support, it may
still have a custom appearance, e.g. without Element icons. This might or might not be a
problem, as this may conflict with the CSS Theme. You can reset all custom appearances
by pressing the Default style button in the Style tab of the Diagrams properties view.
27/09/2012
SING
STYLESHEETS
Then, you need to associate this file with your diagram. Select a diagram, and then go to
the Style tab of the properties view, and add a new Diagram style sheet. There isnt
currently any style sheet available from the diagram, so you need to create a new
Stylesheet reference.
Browse your workspace to find your css file, and then validate. Your stylesheet is now
associated to your diagram.
27/09/2012
DITING A
STYLESHEET
Papyrus Stylesheets are stored in text files with the .css extension (e.g.
stylesheet.css).
The selector: describes the condition which has to be fulfilled for a rule to be
applied
The properties: describes the appearance of the elements matching the rule
Eclipse implements the 2.1 version of the CSS syntax. The available selectors are:
-
match
match
match
match
either
27/09/2012
Examples
* {
fillColor: red;
fontColor: #0000FF;
}
Meaning: all elements should be filled in red, and all texts should be blue (RGB Color
#0000FF)
Class {
gradient: white vertical;
elementIcon:true;
shadow:true;
qualifiedNameDepth:full;
}
Meaning: this style applies to all UML Classes. They will have a white and vertical
gradient. The Element icon and the shadow will be displayed, as well as their fully
qualified name.
ClassDiagram Class>Property {
fontColor: red;
}
Meaning: The properties directly contained in a Class, which is drawn on a
ClassDiagram (Either as a root element of the diagram, or in a Package) will be
displayed in red.
Conditions: The conditions under which the style will be applied (Corresponds to
the CSS Selectors)
Properties: The graphical properties to export to the style sheet
Stylesheet: The style sheet to edit
27/09/2012
If you have already associated the style sheet to your diagram, you can use the
Applies stylesheet button.
Otherwise, you need to select External stylesheet, and browse your workspace
to retrieve the file. Note that in this case, as the edited stylesheet might not be
applied to your diagram, you wont be able to see the changes in the current
diagram.
The kind of element to which the style applies (e.g. the style will be applied to
Class elements, or to any kind of elements). It can be restricted to a specific
diagram.
You can add restrictions on the current value(s) of the element (e.g. the style will
be applied to concrete classes). Only primitive type and enumerated attributes
are supported here.
The style name is used to apply a style manually.
The properties tab contains all the graphical properties that can be applied to the
selected object. It is used to choose the graphical properties to apply on the objects
matching the conditions.
27/09/2012
ANIPULATING STYLES
The computed styles will be applied automatically. For example, if
your stylesheet tells that all your abstract classes must be red, the
classes color will change automatically according to the value of their
isAbstract property.
In some other cases, however, you may want to specify manually the style that should be
applied to your objects. For this case, you can use the Applied styles property in the
Style tab of the properties view.
.myOwnStyle {
fillColor: #A6C198;
gradient:white horizontal;
}
Once a style is applied on an object, the object will be refreshed each time the style
definition changes. For example, changing the style myOwnStyle to the following
declaration:
.myOwnStyle {
fillColor: #E3A49C;
gradient: #FFFFFF horizontal;
}
All the green classes will become red.
10
27/09/2012
EPLOYING A
CSS THEME
Once you have defined your style sheet, you may want to export it to
create a new theme (Or to extend an existing theme). To do so, Papyrus
provides an extension point: org.eclipse.papyrus.infra.gmfdiag.css.theme.
This extension point needs two entries: a Theme Definition (ID, Label and icon of the
Theme), and Theme contributions (A set of style sheets which will compose the Theme).
More than one plug-in can contribute to the same Theme, which makes it possible to
extend a Theme.
The Theme can be modified from the Papyrus preferences page CSS Theme. Only one
theme can be activated at the same time. A Theme applies to all Papyrus Diagrams from
the workspace.
11
27/09/2012
IMITATIONS
& ISSUES
Selectors
Currently, it is not possible to handle complex selectors in the Papyrus stylesheets.
Selector inheritance
It is not possible to apply a style to all descendant of a given Metaclass. For example, a
Behavior will not inherit styles from a Class, although a Behavior actually is a Class.
Profile/Stereotype support
It is not possible to restrict a selector to an applied stereotype. There is currently no way
to specify that a style should only apply to classes on which the SysML::Blocks::Block
stereotype is applied.
Events support
Selectors based on user events are not yet implemented. For example, the CSS
specification defines the :hover pseudo-selector to represent an element hovered by the
mouse, which is not yet supported in Papyrus.
Stylesheets
Model stylesheets
Currently, stylesheets can only be applied to a Diagram. It is not yet possible to apply a
stylesheet on a Model.
Workspace stylesheets
The only way to define a workspace theme is through the use of a plug-in which defines
a new extension. It is not yet possible to create a new local theme from the preferences
page.
Bugs
The following bugs have been identified:
12
27/09/2012
372322: [Diagram - Refresh] The refresh action is not correctly binded to F5
https://bugs.eclipse.org/bugs/show_bug.cgi?id=372322
386574: [CSS - Refresh] Only the active diagram is refresh when the stylesheets change
https://bugs.eclipse.org/bugs/show_bug.cgi?id=386574
390534: [CSS - Appearance] Undoing graphical changes results in unexpected behavior
https://bugs.eclipse.org/bugs/show_bug.cgi?id=390534
13