-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[1316] Support a new parametric SVG node style
bug: #1316 Signed-off-by: Laurent Fasani <laurent.fasani@obeo.fr>
- Loading branch information
Showing
41 changed files
with
1,466 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
= ADR-070 - Contribute a diagram node style | ||
|
||
== Context | ||
|
||
Currently, the diagram styles are hardcoded and known by the sirius-component core in the backend and in the frontend. | ||
|
||
The aim of this adr is to explain how to contribute a new diagram style from an additional project and what changes are needed in the sirius-component projects to support the contributed style. | ||
|
||
=== Current state | ||
On the backend, style are managed specifically for | ||
* the rendering in `sirius-components-diagrams` | ||
* the layout in `sirius-components-diagrams-layout` | ||
** ELK layout | ||
** Incremental layout | ||
* the service called by the front end | ||
|
||
On the frontend, styles are managed with a dedicated sprotty inherited view. | ||
|
||
== Enhancement == | ||
|
||
For the rest of this adr, let's consider that the contributed style is a parametric svg style node. | ||
|
||
=== Use cases | ||
|
||
*Specifier* | ||
|
||
When defining the diagram description with the web view modeler, the specifier should be able to select the contributed style as well as hardcoded existing style (such as node, node list and image styles) | ||
|
||
*Developper* | ||
|
||
On the backend, the developper will provide spring bean to allow | ||
* defining the new nodestyle | ||
* adding the node style as part of the view modeler | ||
* the style rendering when rendering the diagram | ||
* Optional (customizing the layout) | ||
|
||
On the front end, the developper needs to provide a specific sprotty view to render the style on the frontend | ||
|
||
=== Code changes | ||
|
||
The code needs to evolve so that it is able to manage the contributed style without having any direct dependency of its definition. | ||
Everywhere, the specific node styles are used, the code should adapt to get bean contribution that implement the right API: | ||
|
||
* Diagram rendering: A new API `INodeStyleProvider` has been created to provide a node type and to instanciate the nodeStyle inheriting from `INodeStyle` | ||
* Incremental and ELK layout: A new API `ICustomNodeLabelPositionProvider` has been defined to customize the position of the node Label. This API is used for both ELK and incremental layout | ||
|
||
|
||
* Front end: the code must be able to render the new node style by adding a new sprotty view. In our example `node:parametric-svg` node type and `ParametricSVGView` have been added. | ||
Currently, delegating the creation of the sprotty pojo is not yet supported. So the digram convertion from the data returned by the server to data managed by sprotty is hardcoded. | ||
The link between the node type and the sprotty view capable of rendering the node is done `dependencyInjection` | ||
``` | ||
configureModelElement(context, 'node:parametric-svg', Node, ParametricSVGView); | ||
``` | ||
|
||
== Developper guide | ||
|
||
=== backend | ||
|
||
* View model: contribute an extension of the `view.ecore` and add a subtype of `NodeStyleDescription` | ||
* Diagram rendering : Create a diagram node style | ||
** Add a new POJO class representing the node style. It must implements `INodeStyle` | ||
** Add a `INodeStyleProvider` to provide a node type and to instanciate the nodeStyle inheriting from `INodeStyle` | ||
|
||
* ELK layout: If the default configuration from `LayoutConfiguratorRegistry` is not sufficient, it is possible to provide a bean implementing `IDiagramLayoutConfiguratorProvider` to customize the ELK configuration. | ||
* Incremental and ELK layout: | ||
** (Optional) Provide a bean implementing `ICustomNodeLabelPositionProvider` to customize the position of the node Label. | ||
|
||
* Service: Add a graphqls file that contains `extend union INodeStyle = `<new Node Style>`` and the declaration of the new node type itself For example: | ||
``` | ||
extend union INodeStyle = SVGNodeStyle | ||
|
||
type SVGNodeStyle { | ||
svgURL: String! | ||
backgroundColor: String! | ||
borderColor: String! | ||
borderRadius: Int! | ||
borderSize: Int! | ||
borderStyle: LineStyle! | ||
} | ||
``` | ||
|
||
=== frontend | ||
* Add a new diagram node style type that implements `INodeStyle` | ||
* Add a new diagram node style type that extends `GQLINodeStyle` | ||
* update the diagramEventSubscription | ||
* Add a specific sprotty view that is able to render the style and configure the node style for sprotty | ||
|
||
== Status | ||
|
||
Work in progress |
46 changes: 46 additions & 0 deletions
46
...core/src/main/java/org/eclipse/sirius/components/core/api/IParametricSVGImageFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 CEA. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.sirius.components.core.api; | ||
|
||
import java.util.EnumMap; | ||
|
||
/** | ||
* Service used to compute dynamically the svg image of node. | ||
* | ||
* @author lfasani | ||
*/ | ||
public interface IParametricSVGImageFactory { | ||
|
||
enum SVGAttribute { | ||
WIDTH("width"), //$NON-NLS-1$ | ||
HEIGHT("height"), //$NON-NLS-1$ | ||
LABELWIDTH("labelWidth"), //$NON-NLS-1$ | ||
LABELHEIGHT("labelHeight"), //$NON-NLS-1$ | ||
COLOR("color"), //$NON-NLS-1$ | ||
BORDERCOLOR("borderColor"), //$NON-NLS-1$ | ||
BORDERSTYLE("borderStyle"), //$NON-NLS-1$ | ||
BORDERSIZE("borderSize"); //$NON-NLS-1$ | ||
|
||
private String label; | ||
|
||
SVGAttribute(String label) { | ||
this.label = label; | ||
} | ||
|
||
public String getLabel() { | ||
return this.label; | ||
} | ||
} | ||
|
||
byte[] createSvg(String svgType, EnumMap<SVGAttribute, String> attributesValues); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...org/eclipse/sirius/components/collaborative/diagrams/api/IParametricSVGImageRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 CEA. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.sirius.components.collaborative.diagrams.api; | ||
|
||
import java.util.List; | ||
|
||
import org.eclipse.sirius.components.annotations.PublicApi; | ||
|
||
/** | ||
* Interface of the service used to get the path of the parametric svg images accessible from the jars used in the | ||
* application.</br> | ||
* The specifier must provide an implementation of this API as a {@link @Service} to provide available images. | ||
* | ||
* @author lfasani | ||
*/ | ||
@PublicApi | ||
public interface IParametricSVGImageRegistry { | ||
/** | ||
* Get the paths of the svg images than can be parameterized.</br> | ||
* The images are those in the jar. | ||
* <p> | ||
* Warning: <b>The path must be unique</b>. Indeed, the images are contained in a jar but the system does not know | ||
* about the jars. Then if an image is contained in the same folder structure in many jars, then the result to read | ||
* the image will be unpredictable. | ||
* </p> | ||
* | ||
* The folder must be of the form: | ||
* | ||
* <pre> | ||
* (/ADDITIONAL_FOLDER1/.../ADDITIONAL_FOLDERn)/IMAGE | ||
* </pre> | ||
* | ||
* <p> | ||
* Path examples:</br> | ||
* "/myparametricsvgfolder/myImage.svg", "/myParametricImage.svg" | ||
* </p> | ||
* | ||
* @return a list a paths. | ||
*/ | ||
List<ParametricSVGImage> getImages(); | ||
} |
54 changes: 54 additions & 0 deletions
54
...ain/java/org/eclipse/sirius/components/collaborative/diagrams/api/ParametricSVGImage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 CEA. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Obeo - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.sirius.components.collaborative.diagrams.api; | ||
|
||
import java.text.MessageFormat; | ||
import java.util.Objects; | ||
import java.util.UUID; | ||
|
||
/** | ||
* POJO representing a parametric svg image. | ||
* | ||
* @author lfasani | ||
*/ | ||
public class ParametricSVGImage { | ||
private UUID id; | ||
|
||
private String label; | ||
|
||
private String path; | ||
|
||
public ParametricSVGImage(UUID id, String label, String path) { | ||
this.id = Objects.requireNonNull(id); | ||
this.label = Objects.requireNonNull(label); | ||
this.path = Objects.requireNonNull(path); | ||
} | ||
|
||
public UUID getId() { | ||
return this.id; | ||
} | ||
|
||
public String getLabel() { | ||
return this.label; | ||
} | ||
|
||
public String getPath() { | ||
return this.path; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
String pattern = "{0} '{' id: {1}, label: {2}, path: {3} '}'"; //$NON-NLS-1$ | ||
return MessageFormat.format(pattern, this.getClass().getSimpleName(), this.id, this.label, this.path); | ||
} | ||
} |
Oops, something went wrong.