Diagram Services

1. Palette

The palette computed in a diagram can be customized by using a service implementing either of those interfaces:

  • o.e.s.c.collaborative.diagrams.palette.api.IDiagramPaletteCustomizer

  • o.e.s.c.collaborative.diagrams.palette.api.IDiagramConnectorPaletteCustomizer

The IDiagramPaletteCustomizer is used to perform any change in a palette computed for the diagram itself, any diagram element or any set of diagram elements selected. On the other hand, the IDiagramConnectorPaletteCustomizer can be used to change the palette computed while using the connector tool which is mostly used to create edges between diagram elements.

A service implementing any of those interfaces can add, transform or even remove any tools, tool sections or quick access tools from the computed palette.

The tool of a diagram palette can be overridden using the paletteToolOverrideExtensionPoint. Some configuration is required to make an overridden tool work with the last tool used & the search feature of the palette. Some props are available to make it easier.

For a diagram, using the canHandle: (representationKind: string, tool: GQLTool) method, the value of representationKind will be DIAGRAM_REPRESENTATION_KIND (exported from the diagram package).

1.1. Last tool used

The last tool used is displayed on top the tool section. You need to call the prop onInvoked() after the execution of a tool to set it as the last tool used.

1.2. Search feature

The current searched value is available from the prop searchedValue. Palette package export the function fuzzyMatch = (candidate: string, searchTerm: string): MatchResult. If there is a searchedValue you need to test your label with fuzzyMatch it in order to know if the tool is candidate. If there is a searchedValue but the attributed matches of MatchResult is false then the contributed component should not render.

2. Layout configurations

Diagram layout configurations are contributed by the backend through org.eclipse.sirius.components.collaborative.diagrams.api.ILayoutConfigurationsProvider. Register a Spring service implementing this interface to contribute configurations for a diagram:

  • canHandle(IEditingContext, DiagramContext, DiagramDescription) selects the diagrams handled by the provider.

  • getLayoutConfigurations(IEditingContext, DiagramContext, DiagramDescription) returns the ordered list of LayoutConfiguration records for those diagrams.

There is no identifier deduplication, so use distinct configuration identifiers across providers. The first configuration is used for automatic layout and as the initial choice of the Arrange All button.

Each configuration contains:

Property Description

id

A stable identifier for the configuration.

label

The label displayed in the Arrange All menu, translated by the backend.

iconURL

The list of icon URLs displayed by the frontend.

layoutOptions

A list of LayoutOptionEntry records containing string key and value properties. The frontend converts this list into the options dictionary passed to ELK.

The sirius-components-collaborative-diagrams module registers DefaultLayoutConfigurationsProvider, which contributes Flow Layout (elk-layered), Compact Layout (elk-rect-packing) and Orthogonal Layout (elk-spore-overlap), in that order. The Flow Layout configuration uses the diagram description’s arrange layout direction.

3. Style customization

3.1. Node style customization

Node style customizations are contributed by the backend through org.eclipse.sirius.components.diagrams.renderer.api.INodeStyleCustomizer. Register a Spring service implementing this interface to contribute style customization for a node:

  • customize(VariableManager, DiagramDescription, NodeDescription, INodeStyle) returns the customized INodeStyle.

Each contributed service is executed at all diagram refreshes between the computation of the node style by the diagram description and user customization made through the appearance menu.

Sirius Web applies node style customizers in sequence. Each customizer receives the style returned by the previous one, starting with the style computed from the node description. The application order is unspecified. If multiple customizers change the same property, the last one to change it takes precedence.

For example, org.eclipse.sirius.components.flow.starter.services.PowerStatusNodeStyleCustomizer customizes the border color of flow elements depending on their power status.

The returned style must be compatible with the node type and supported by both the backend and the frontend. See Contribute custom diagram nodes.