Skip to main content
Jump to: navigation, search


< MDT‎ | Papyrus
Revision as of 09:25, 23 September 2014 by (Talk | contribs) (Style properties)


The standard UML specification provides a few hints to represent graphical elements. However, it only focuses on the general representation of these elements (e.g. A Class is a rectangle, with optional compartments for its attributes and operations, and its name should be displayed in italic if the Class is abstract).

Nevertheless, for a better readability (and even esthetic), the user has a certain freedom for changing some graphical properties, such as an Element's color. Until now, in Papyrus, this customization could be done by two complement means:

  • Appearance tab (Properties view): change the appearance of the selected element(s)
  • Preferences page: change the initial appearance of all newly created element(s)

While this allows defining a custom theme for our diagrams, this mechanism suffers from a few limitations:

  • It is not possible to create different categories of appearance for the same semantic Element (e.g. "Blue Class" and "Green class"). We'd have to create "Blue classes" and change some of them to "Green"manually.
  • If we wanted to change the current theme, we'd have either to change each object's appearance one by one, or to write an automatic transformation, which could be really complicated.
  • It is not easy to export a Theme, as they are stored in the Eclipse preferences. It is almost impossible to ship a ready-to-use distribution of Papyrus with a custom theme.

The Cascading StyleSheets (CSS) component adds the capacity to define some Stylesheets for your 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.


The CSS Stylesheet support is now shipped in the base installation of Papyrus. It doesn't require any specific installation step anymore.

Without the CSS component, or with the "Black & White" CSS Theme, your diagrams look like:

Papyrus diagram without CSS Theme

With the default "Papyrus" CSS Theme, your diagrams look like:

Papyrus Diagram with CSS Theme

Note: If you opened a diagram which has been created without the CSS Support, it may still have a user-defined 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 Diagram's properties view.

Using StyleSheets

To define a custom style, the first step is to create a Stylesheet. The creation is really straightforward: a Stylesheet is a text file with the .css extension. You can create such a file using the "New > File" wizard.
There are several options for using stylesheets.

Diagram Stylesheets

You can define a particular style for a diagram.

  1. Select a diagram
  2. Go to the Style tab of the properties view
  3. Add a new "Diagram style sheet". There isn't currently any style sheet available from the diagram, so you need to create a new "Stylesheet reference".
    Import stylesheet in Papyrus
  4. Browse your workspace to find your css file, and press OK. Your stylesheet is now associated to your diagram.

Model StyleSheet

Similarily to "Diagram Stylesheet" you can define a particular style for a Model.

  1. Select a model
  2. Go to the Style tab of the properties view
  3. Add a new "Model style sheet"
  4. Browse your workspace to find your css file, and press OK. Your stylesheet is now associated to your Model.

Project Stylesheets

You can associate to a project specific stylesheets.

  1. Select a project in "Project Explorer" view
  2. Open project preference properties: "Right click > properties"
  3. Go to CSS stylesheets page: "Papyrus > Style sheets"
  4. Add a new "Project style sheet". There isn't currently any style sheet available from project, so you need to create a new "Stylesheet reference".
    Style sheets project properties in Papyrus
  5. Browse your workspace to find your css file, and press OK. Now, your stylesheet is associated with the project.

Deploying a CSS Theme

Once you have defined your style sheets, you may want to export it to create a new theme (Or to extend an existing theme). To do so, Papyrus provides two ways to define a theme.

With extension point

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.

In workspace preference

You can define theme in workspace preferences. A theme is defined by style sheets.

  1. Go to the Papyrus preference: "Window > Preferences > Papyrus > CSS Theme"
  2. Add a new theme. There are currently two existing themes: "Papyrus Theme" and "Black & White".
    Creation of theme in Papyrus
  3. Write a name for this new theme
  4. (optional) Choose an icon
  5. Associate one or more style sheets with this theme
  6. Press OK to finish creation

You can edit or create a theme with a selection of CSS files in Project Explorer view. For this, select the CSS files, right click and select "CSS Theme"

Editing a StyleSheet

Papyrus Stylesheets are stored in text files with the ".css" extension (e.g. stylesheet.css).

Manually: The CSS Syntax

Syntax elements

The CSS syntax is a list of rules, which associates selectors and properties.

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

  • *: Matches all elements
  • ElementType: Matches the elements of type "ElementType"
  • .myStyle: Matches the elements on which the style "myStyle" is applied
  • #myID: Matches the element with the CSS ID "myID". The CSS ID must be unique among a diagram. To avoid confusing the users, and because this selector doesn't make much sense on diagrams, this selector has been disabled in Papyrus.
  • [property=value]: Matches the elements which have a property "property" with the value "value". It can also match the properties of Stereotypes
  • [appliedStereotypes~="MyStereotype"]: Matches the elements on which the Stereotype "MyStereotype" is applied. You can use either the Stereotype's name or qualified name (MyProfile::MyPackage::MyStereotype). Note: always use the "~=" operator (Which means "contains"), because UML elements can have more than one applied stereotype.
  • :pseudo: Matches the element on which the pseudo-selector "pseudo" is applied. Pseudo-selectors are typically used for dynamic events, and for filtering some non-semantic properties. In Papyrus, they are used for identifying more precisely the floating labels (When an element has more than one label: see the [#Mask_Label Mask Label] chapter below), and they are also used by the animation framework to specify events (See the Moka documentation)

These selectors can be combined using one of the following combinators:

  • Selector1 Selector2: Descendant selector. Matches the elements which match Selector2 and are contained in an element matching Selector1
  • Selector1 > Selector2: Child selector. Matches the elements which match Selector2 and are directly contained in an element matching Selector2
  • Selector1 + Selector2: Sibling selector. Matches the elements which match Selector2 and are immediately preceded by a Sibling element which match Selector1.
  • Selector1, Selector2: Alternative selector. Matches elements matching either Selector1 or Selector2

A rule also contains a list of properties, in the form property:value;

In Papyrus, the selectors apply to semantic elements and properties (i.e. UML Elements), and the properties apply to the appearance properties (i.e. GMF Appearance properties). A few custom properties (Independent from the GMF Appearance model) are also available (See "Supported properties" below).


* {
    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;

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.

/* Equivalent: qualified name */

Meaning: The elements with the "Block" stereotype must be displayed in bold.


Meaning: The elements with the "Block" stereotype, and the stereotype property "isEncapsulated" set to true, must be displayed in red.

All these rules can be combined:

	/* A class on which the stereotypes "Block" and "MyCustomStereotype" are applied, 
	*  and on which the stereotype property "isEncapsulated" is set to true, 
	*  the stereotype property "myCustomProperty" is set to "SomeValue", and 
	*  the UML Property "isAbstract" is set to false */

With the Papyrus tooling

Papyrus also provides a tool to generate a CSS Rule from an element displayed in the diagram. You need to create a stylesheet before you can edit it with the Create style tool, and it is recommended (Although not required) to associate this style sheet with your current diagram.

To use it, create an element and change its appearance via the "Appearance" tab of the properties view. Then, right click on the element, and select "Format", "Create a new style". The dialog box contains three tabs:

  • 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

Create style dialog

In the Stylesheet tab, select your stylesheet:

  • 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 won't be able to see the changes in the current diagram.

In the conditions tab, there are three groups of options:

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

Supported properties

Selector properties

Selector properties are semantic element properties. They can be used with one of the following syntaxes:



The supported semantic element properties are:

  • Strings: [name=MyName], [name="My name"] (Quotes are required for complex Strings)
  • Integers: [size="12"] (Quotes are required)
  • Booleans: [isAbstract=true] (Quotes are optional)
  • Enumerations: [visibility=visible] (Quotes are optional)
  • References to named elements (UML NamedElement or Ecore ENamedElement): [type=String]

The supported properties are the semantic properties of the UML element (e.g. isAbstract, name, type, ...), as well as the semantic properties of the stereotypes applied to the UML element (e.g. isEncapsulated for a SysML Block)

Some selectors can also be used to represent some specific parts of an element. For example, it is possible to hide a specific compartment:

Class > Compartment[kind="attribute"] {
Class > Compartment[kind="symbol"] {
Port > Label {
    visible: false;

Style properties

Style properties are graphical properties supported by the display. Note that some graphical elements may not support some specific properties (Either because they shouldn't support them, or because they are not yet implemented). For example, a UML::Class will not support the italic property, because in UML, italic means abstract.

The CSS Supports all GMF Notation properties, as well as a few Papyrus-specific properties. This chapter will only list all the Papyrus-specific properties.

The simplest way to discover new style properties is to use the Appearance tab of the Properties view in Papyrus. When hovering one of the appearance properties, the tooltip indicates the name of the corresponding CSS property

CSS Property in tooltip

This table lists the most common properties:

Property name Value type Initial Value Applies to Comment
fillColor Color white Shapes In the default "Papyrus Theme", the fill color depends on the type of element. The used colors are #C3D1D5 (Light blue, Default), #C3D7DD (Lighter blue, Class), #FFFFCC (Yellow, Comment), #C8FFE6 (Teal, Constraints)
transparency integer 0 Shapes Value is a percentage: values in the range (0, 100) are supported. Transparency works only if the gradient is activated: Bug 419320
gradient [Color Color [ horizontal | vertical ] | none] none Shapes Examples: "white blue horizontal" or "none"
fontColor Color black Shapes, floating labels Comments support HTML syntax. Most style-properties have no effect on comments
fontName String "Segoe UI" Shapes, floating labels Most fonts are platform-specific. The list of available Fonts can be found in the "Appearance" tab of the properties view
fontSize integer 9 Shapes, floating labels
bold boolean false Shapes, floating labels
italic boolean false Shapes, floating labels In UML, "italic" means "isAbstract=true". This property is disabled for all elements which can be abstract (e.g. Class)
underline boolean false Shapes, floating labels In UML, "underline" means "isStatic=true". This property is disabled for all elements which can be static (e.g. Property)
strikeThrough boolean false Shapes, floating labels
visible boolean true All elements Although this property will work for any diagram elements, it is probably a bad idea to use it with anything else than a Compartment or a Label
collapsed boolean false Compartments
showTitle boolean false Compartments
lineColor Color black Shapes, Connectors
lineWidth integer -1 Shapes, Connectors -1 means "default", and typically corresponds to 1px
routing [Manual | Rectilinear | Tree] Manual Connectors The value is case-sensitive: don't forget the initial Capital
roundedBendpointsRadius integer 0 Connectors Applies to connectors with routingStyle = Rectilinear or Tree
smoothness [None | Normal | Less | More] None Connectors
avoidObstructions boolean false Connectors
closestDistance boolean false Connectors
jumpLinkStatus [None | All | Below | Above] None Connectors It is not recommended to use jump links via CSS, as it gives strange results for overlapping connectors
jumpLinkType [Semicircle | Square | Chamfered] Semicircle Connectors
jumpLinkReverse boolean false Connectors
xMarginLabel int 0 Labels Define the vertical margin of the label in pixel. This is the space between the text box and his container.
yMarginLabel int 0 Labels Define the horizontal margin of the label in pixel. This is the space between the text box and his container.

The following properties can be used to bypass the standard UML notation. They can typically be used for pure DSML notations:

Property name Value type Initial Value Applies to Comment
displayBorder boolean true Shapes If set to false, the borders of the Shape will be hidden.
displayName boolean true Shapes If set to false, the name of the Shape will be hidden
displayTag boolean true Shapes, connectors If set to false, the tags (e.g. « component ») of the element will be hidden
maintainSymbolRatio boolean true Shapes If the shape is represented with a Symbol, specifies whether the ratio should be maintained or not. If the Symbol is displayed in a compartment, it is usually a good idea to maintain the ratio. If the symbol is the only representation (e.g. when the name, border and compartments are hidden), it is recommended to not maintain the ratio
elementIcon boolean false Shapes, floating labels Whether the icon should be displayed next to the label of the element. In the default "Papyrus Theme", the icon is displayed by default
shadow boolean false Shapes Display a shadow under the shape
qualifiedNameDepth [full | none | integer] none Shapes, floating labels The depth of the qualified name to display. Applies to UML::NamedElement
lineStyle [solid | dashed | dotted | hidden | double] N/A Connectors In UML, the line type depends on the semantic element (e.g. solid line for associations, dashed line for dependencies...). In most cases, you should avoid using this property, as this would change the well-known UML notation. However, it can be useful for creating pure DSML, where the UML notation should be hidden.
lineDashLength integer N/A Connectors When the lineStyle is set to "Dash", specifies the length of the dash
lineDashGap integer N/A Connectors When the lineStyle is set to "Dash", specifies the gap between the dashes
targetDecoration [none] N/A Connectors If "targetDecoration" is set to None, hides the target decoration of the Connector (e.g. the arrow)
sourceDecoration [none] N/A Connectors If "sourceDecoration" is set to None, hides the source decoration of the Connector (e.g. the arrow)
maskLabel string[] N/A Labels, floating labels This property can be used to configure the display of complex labels (e.g. properties). See examples in the [#Mask_Label Mask Label] chapter below
svgFile path N/A Shapes The path to an SVG file, which should be used as a symbol for the element. It will be displayed in the "symbol" compartment of the shape
followSVGSymbol boolean false Shapes If the SVG file has a path with the ID "papyrusPath", this path will be used to connect edges
svgCssFile path N/A Shapes The path to a CSS file which will be applied to the SVG symbol (If an SVG symbol is used). Can be used to dynamically change the appearance of the SVG image (e.g. change color, ...)
svgCssClass string N/A Shapes The CSS Class to be applied at the root of the SVG document (If an SVG symbol is used). Can be used to dynamically change the appearance of the SVG image

Value types

String: Simple (Ascii) strings can be written without quotes: property:value. Complex strings must be written with quotes: property: "my value"; path: "platform:/plugin/my.example.plugin/resources/myFile.ext";
Integer: Quotes are optional: size: 18
Boolean: Quotes are optional: bold: true
Color: There are three ways for using colors. The simplest one is to use the list of predefined CSS Color names: fillColor: teal. It is also possible to use the Hexadecimal RGB notation: fillColor: #008080. The last option is to use the rgb() function: fillColor: rgb(0, 128, 128)

Mask Label

Some labels can be configured with a "Mask": in the appearance tab of the properties view, some elements have a list of checkboxes which are used to select which parts of the label should be displayed (e.g. visibility, type, name, multiplicity...)

The CSS property "maskLabel" has the same purpose. The value of this property is the list of labels to display. For example, if you want to display only the name of the Ports, write:

/* Broken in Papyrus 1.0.0 (See Erratum below) */
Port > Label { 
	maskLabel: name;
/* Works in Papyrus 1.0.0 (See Erratum below) */
Port { 
	maskLabel: name;

If you want to display the name, type and multiplicity of a Property, write:

Property {
	maskLabel: name type multiplicity;

Note that the order of the values doesn't matter. It is also important to understand the difference between the port and the property: the rule to match the port's label is different than the one for the property, because the Port is represented with two graphical elements: a square for the Port, and a floating text for its label. The Property is represented with a single text element. It is especially important for Associations, as Association have six different labels: one label for the Association itself, two labels for each association end (Source and target), and one label for the Association's stereotypes. The rules for configuring associations thus needs to be more precise.

Erratum: Due to Bug 437186, in Papyrus 1.0.0 / Luna, the rule Port > Label doesn't work for maskLabel. You need to use Port. In Papyrus 1.0.1, both rules should be valid. The syntax Association > Label is still valid for Associations, because we still need to distinguish the different labels (Whereas the Port has a single Label and doesn't require the distinction)

For example:

Association > Label:sourceMultiplicity {
Association > Label:targetMultiplicity {
Association > Label:sourceRole {
	maskLabel: name multiplicity;
Association > Label:targetRole {
	maskLabel: name multiplicity;
Association > Label:name {

These rules result in:

Association labels result

The list of accepted values depends on the element. To find the list of values, select an element in a Diagram (e.g. a Property), go to the Appearance tab of the properties view, and find the list of checkboxes named "Label customization". Hover the checkboxes, and look at the tooltip to find the value:

Mask label

To obtain the result shown in this screenshot, write:

Property {
	maskLabel: name type defaultValue;

Which results in:

Mask label result

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

Limitations and issues

There are currently a few identified limitations to the Stylesheet framework, as well as a few minor bugs:


Currently, some complex selectors are not supported in the Papyrus stylesheets. Especially, the following are not supported yet:

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.

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.

Known bugs

The following bugs have been identified:

  • Bug 372322: [Diagram - Refresh] The refresh action is not correctly binded to F5
  • Bug 386574: [CSS - Refresh] Only the active diagram is refresh when the stylesheets change
  • Bug 436665: [CSS] Refresh issue when an element is moved to a different owner

Back to the top