1. Introduction
  2. Installation
  3. Using StyleSheets
    1. Diagram Stylesheets
    2. Model StyleSheet
    3. Project Stylesheets
  4. Deploying a CSS Theme
    1. With extension point
    2. In workspace preference
  5. Editing a StyleSheet
    1. Manually: The CSS Syntax
      1. Syntax elements
      2. Examples
    2. With the Papyrus tooling
  6. Supported properties
    1. Selector properties
    2. Style properties
      1. Value types
      2. Mask Label
  7. Manipulating styles
  8. Limitations and issues
    1. Selectors
      1. Selector inheritance
      2. Events support
    2. Known bugs

Introduction

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:

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

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.

Installation

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.

Eclipse implements the 2.1 version of the CSS syntax. The available selectors are:

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

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

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.

[appliedStereotypes~="Block"]{
    bold:true;
}

/* Equivalent: qualified name */
[appliedStereotypes~="SysML::Blocks::Block"]{
    bold:true;
}

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

[appliedStereotypes~=Block][isEncapsulated=true]{
    fontColor:red;
}

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:

Class[appliedStereotypes~=Block][appliedStereotypes~=MyCustomStereotype][isEncapsulated=true][myCustomProperty=SomeValue][isAbstract=false]{
	/* 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 */
	
	fillColor:red;
}

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:

Create style dialog

In the Stylesheet tab, select your stylesheet:

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

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:

[isAbstract=true]

Class[isAbstract=true]

The supported semantic element properties are:

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"] {
    visible:false;
}

Class > Compartment[kind="symbol"] {
    visible:true;
}

Compartment[kind="structure"]{
    collapsed:true;
}

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 nameValue typeInitial ValueApplies toComment
fillColorColorwhiteShapesIn 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)
transparencyinteger0ShapesValue 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]noneShapesExamples: "white blue horizontal" or "none"
fontColorColorblackShapes, floating labelsComments support HTML syntax. Most style-properties have no effect on comments
fontNameString"Segoe UI"Shapes, floating labelsMost fonts are platform-specific. The list of available Fonts can be found in the "Appearance" tab of the properties view
fontSizeinteger9Shapes, floating labels 
boldbooleanfalseShapes, floating labels 
italicbooleanfalseShapes, floating labelsIn UML, "italic" means "isAbstract=true". This property is disabled for all elements which can be abstract (e.g. Class)
underlinebooleanfalseShapes, floating labelsIn UML, "underline" means "isStatic=true". This property is disabled for all elements which can be static (e.g. Property)
strikeThroughbooleanfalseShapes, floating labels 
visiblebooleantrueAll elementsAlthough 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
collapsedbooleanfalseCompartments 
showTitlebooleanfalseCompartments 
lineColorColorblackShapes, Connectors 
lineWidthinteger-1Shapes, Connectors-1 means "default", and typically corresponds to 1px
routing[Manual | Rectilinear | Tree]ManualConnectorsThe value is case-sensitive: don't forget the initial Capital
roundedBendpointsRadiusinteger0ConnectorsApplies to connectors with routingStyle = Rectilinear or Tree
smoothness[None | Normal | Less | More]NoneConnectors 
avoidObstructionsbooleanfalseConnectors 
closestDistancebooleanfalseConnectors 
jumpLinkStatus[None | All | Below | Above]NoneConnectorsIt is not recommended to use jump links via CSS, as it gives strange results for overlapping connectors
jumpLinkType[Semicircle | Square | Chamfered]SemicircleConnectors 
jumpLinkReversebooleanfalseConnectors 

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

Property nameValue typeInitial ValueApplies toComment
displayBorderbooleantrueShapesIf set to false, the borders of the Shape will be hidden.
displayNamebooleantrueShapesIf set to false, the name of the Shape will be hidden
displayTagbooleantrueShapes, connectorsIf set to false, the tags (e.g. « component ») of the element will be hidden
maintainSymbolRatiobooleantrueShapesIf 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
elementIconbooleanfalseShapes, floating labelsWhether the icon should be displayed next to the label of the element. In the default "Papyrus Theme", the icon is displayed by default
shadowbooleanfalseShapesDisplay a shadow under the shape
qualifiedNameDepth[full | none | integer]noneShapes, floating labelsThe depth of the qualified name to display. Applies to UML::NamedElement
lineStyle[solid | dashed | dotted | hidden | double]N/AConnectorsIn 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.
lineDashLengthintegerN/AConnectorsWhen the lineStyle is set to "Dash", specifies the length of the dash
lineDashGapintegerN/AConnectorsWhen the lineStyle is set to "Dash", specifies the gap between the dashes
targetDecoration[none]N/AConnectorsIf "targetDecoration" is set to None, hides the target decoration of the Connector (e.g. the arrow)
sourceDecoration[none]N/AConnectorsIf "sourceDecoration" is set to None, hides the source decoration of the Connector (e.g. the arrow)
maskLabelstring[]N/ALabels, floating labelsThis property can be used to configure the display of complex labels (e.g. properties). See examples in the [#Mask_Label Mask Label] chapter below
svgFilepathN/AShapesThe 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
followSVGSymbolbooleanfalseShapesIf the SVG file has a path with the ID "papyrusPath", this path will be used to connect edges
svgCssFilepathN/AShapesThe 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, ...)
svgCssClassstringN/AShapesThe 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:

Port > Label {
	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. For example:

Association > Label:sourceMultiplicity {
	visible:false;
}

Association > Label:targetMultiplicity {
	visible:false;
}

Association > Label:sourceRole {
	maskLabel: name multiplicity;
}

Association > Label:targetRole {
	maskLabel: name multiplicity;
}

Association > Label:name {
	visible:false;
}

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

Result

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:

Selectors

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: