Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3647] Add support for diagram style with background customization #3648

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ As a result, the following maven modules have been deleted: `sirius-web-sample-a

* The `String` attribute `org.eclipse.sirius.components.collaborative.diagrams.dto.InvokeSingleClickOnDiagramElementToolInput#selectedObjectId` has been replaced by the attribute `variables` of type `List<ToolVariable>`
- https://github.com/eclipse-sirius/sirius-web/issues/3437[#3437] [core] Migrate frontend to MUI 5, if you contributed React componenent that use MUI, you should upgrade them to use MUI 5.
- https://github.com/eclipse-sirius/sirius-web/issues/2204[#2204] [core] Added `getStyledLabel` in `IDefaultLabelService` and `IObjectService`, you must implement this method if you have custom implementation of these interface.
- https://github.com/eclipse-sirius/sirius-web/issues/2204[#2204] [core] Add `getStyledLabel` in `IDefaultLabelService` and `IObjectService`, you must implement this method if you have custom implementation of these interface.
- https://github.com/eclipse-sirius/sirius-web/issues/3815[#3815] [core] Make child creation descriptions locale independent

=== Dependency update
Expand Down Expand Up @@ -88,9 +88,11 @@ As a result, the following maven modules have been deleted: `sirius-web-sample-a
- https://github.com/eclipse-sirius/sirius-web/issues/3821[#3821] [sirius-web] Allow to filter resources in `RewriteProxiesEventHandler`.
Introduce new `IRewriteProxiesResourceFilter` interface, to register resource filter for `RewriteProxiesEventHandler`.
- https://github.com/eclipse-sirius/sirius-web/issues/3570[#3570] [diagram] Add max width expression in the View DSL for labels
- https://github.com/eclipse-sirius/sirius-web/issues/2204[#2204] [core] Added `getStyledLabel` in `IDefaultLabelService` and `IObjectService` that can be used to display styled string in the explorer for example.
- https://github.com/eclipse-sirius/sirius-web/issues/2204[#2204] [core] Add `getStyledLabel` in `IDefaultLabelService` and `IObjectService` that can be used to display styled string in the explorer for example.
+
image:doc/screenshots/treeItemLabelStyled.jpg[StyledString, 70%]
- https://github.com/eclipse-sirius/sirius-web/issues/3647[#3647] [diagram] Add support for diagram style with background customization


=== Improvements

Expand Down Expand Up @@ -191,8 +193,7 @@ More existing APIs will be migrated to this new common pattern.
- https://github.com/eclipse-sirius/sirius-web/issues/3616[#3616] [diagram] Fix potential exceptions due to duplicate keys in diagram event processing
- https://github.com/eclipse-sirius/sirius-web/issues/3624[#3624] [diagram] Fix an issue where the header separator does not fill the entire width of the node
- https://github.com/eclipse-sirius/sirius-web/issues/3531[#3531] [diagram] Fix unnecessary edges label re render
- https://github.com/eclipse-sirius/sirius-web/issues/3650[#3650] [diagram] Fix potential NPE in DiagramNavigator and Node toString method
- https://github.com/eclipse-sirius/sirius-web/issues/3649[#3649] [sirius-web] Restore support for Related elements view icons
- https://github.com/eclipse-sirius/sirius-web/issues/3650[#3650] [diagram] Fix potential NPE in DiagramNavigator and Node toString method- https://github.com/eclipse-sirius/sirius-web/issues/3649[#3649] [sirius-web] Restore support for Related elements view icons
- https://github.com/eclipse-sirius/sirius-web/issues/3630[#3630] [sirius-web] Restore support for the deletion of dangling representations
- https://github.com/eclipse-sirius/sirius-web/issues/3666[#3666] [core] Enable EMF's intrinsicIDToEObjectMap for JSON resources to support languages which use modeled identifiers (e.g. SysMLv2).
- https://github.com/eclipse-sirius/sirius-web/issues/3664[#3664] [core] The Default.svg image is no longer displayed with the new architecture.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.eclipse.sirius.components.diagrams.ArrowStyle;
import org.eclipse.sirius.components.diagrams.CollapsingState;
import org.eclipse.sirius.components.diagrams.Diagram;
import org.eclipse.sirius.components.diagrams.DiagramStyle;
import org.eclipse.sirius.components.diagrams.Edge;
import org.eclipse.sirius.components.diagrams.EdgeStyle;
import org.eclipse.sirius.components.diagrams.FreeFormLayoutStrategy;
Expand Down Expand Up @@ -59,6 +60,7 @@ public Diagram getDiagram(String id) {
.size(Size.UNDEFINED)
.nodes(List.of())
.edges(List.of())
.style(DiagramStyle.newDiagramStyle().build())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.eclipse.sirius.components.compatibility.emf.modeloperations.CreateViewOperationHandler;
import org.eclipse.sirius.components.core.api.IEditingContext;
import org.eclipse.sirius.components.diagrams.Diagram;
import org.eclipse.sirius.components.diagrams.DiagramStyle;
import org.eclipse.sirius.components.diagrams.FreeFormLayoutStrategy;
import org.eclipse.sirius.components.diagrams.INodeStyle;
import org.eclipse.sirius.components.diagrams.InsideLabelLocation;
Expand Down Expand Up @@ -88,6 +89,7 @@ public void initialize() {
.nodeDescriptions(List.of(this.getNodeDescription(UUID.randomUUID().toString())))
.edgeDescriptions(List.of())
.dropHandler(variableManager -> new Failure(""))
.styleProvider(variableManager -> DiagramStyle.newDiagramStyle().build())
.build();

Diagram diagram = Diagram.newDiagram(UUID.randomUUID().toString())
Expand All @@ -98,6 +100,7 @@ public void initialize() {
.size(Size.of(100, 100))
.nodes(new ArrayList<>())
.edges(List.of())
.style(DiagramStyle.newDiagramStyle().build())
.build();

IDiagramContext diagramContext = new IDiagramContext.NoOp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.eclipse.sirius.components.core.api.IEditingContext;
import org.eclipse.sirius.components.diagrams.CollapsingState;
import org.eclipse.sirius.components.diagrams.Diagram;
import org.eclipse.sirius.components.diagrams.DiagramStyle;
import org.eclipse.sirius.components.diagrams.FreeFormLayoutStrategy;
import org.eclipse.sirius.components.diagrams.INodeStyle;
import org.eclipse.sirius.components.diagrams.ImageNodeStyle;
Expand Down Expand Up @@ -91,6 +92,7 @@ public void initialize() {
.nodeDescriptions(List.of(this.getNodeDescription(UUID.randomUUID().toString())))
.edgeDescriptions(List.of())
.dropHandler(variableManager -> new Failure(""))
.styleProvider(variableManager -> DiagramStyle.newDiagramStyle().build())
.build();

Node node = Node.newNode(UUID.randomUUID().toString())
Expand Down Expand Up @@ -135,6 +137,7 @@ public void initialize() {
.size(Size.of(100, 100))
.nodes(List.of(node))
.edges(List.of())
.style(DiagramStyle.newDiagramStyle().build())
.build();

IDiagramContext diagramContext = new IDiagramContext.NoOp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.eclipse.sirius.components.compatibility.diagrams.DiagramLabelProvider;
import org.eclipse.sirius.components.compatibility.services.diagrams.api.IDiagramDescriptionConverter;
import org.eclipse.sirius.components.diagrams.ArrangeLayoutDirection;
import org.eclipse.sirius.components.diagrams.DiagramStyle;
import org.eclipse.sirius.components.diagrams.description.DiagramDescription;
import org.eclipse.sirius.components.diagrams.description.DiagramDescription.Builder;
import org.eclipse.sirius.components.interpreter.AQLInterpreter;
Expand All @@ -41,6 +42,8 @@ public class DiagramDescriptionConverter implements IDiagramDescriptionConverter

private static final String FORCE_AUTO_LAYOUT = "FORCE_AUTO_LAYOUT";

private static final String DEFAULT_BACKGROUND_COLOR = "transparent";

private final List<IDiagramDescriptionPopulator> diagramDescriptionPopulators;

private final IAQLInterpreterFactory interpreterFactory;
Expand All @@ -67,7 +70,8 @@ public DiagramDescription convert(org.eclipse.sirius.diagram.description.Diagram
.canCreatePredicate(canCreatePredicate)
.labelProvider(labelProvider)
.autoLayout(this.isAutoLayoutMode(siriusDiagramDescription))
.arrangeLayoutDirection(ArrangeLayoutDirection.UNDEFINED);
.arrangeLayoutDirection(ArrangeLayoutDirection.UNDEFINED)
.styleProvider(variableManager -> DiagramStyle.newDiagramStyle().background(DEFAULT_BACKGROUND_COLOR).build());

for (IDiagramDescriptionPopulator diagramDescriptionPopulator : this.diagramDescriptionPopulators) {
diagramDescriptionPopulator.populate(builder, siriusDiagramDescription, interpreter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,13 @@ public boolean isFaded(IDiagramElement diagramElement) {
}
return isFaded;
}

@Override
public boolean isDiagramEmpty(IDiagramService diagramService) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This must be new since the last time I reviewed this PR because this cannot work. I could accept that in the services of Papaya diagrams because it would work in this case but imagine that I have 1 node in my diagram which has 10 child nodes and the view deletion request is for one of its child node then this code does not work.

Imagine now that I have 3 nodes in my diagram and a tool triggers the creation of 3 view deletion request then this code would not work either. Finding out that a diagram is empty in all use case is more complex than what you algorithm suggest. Please move both the implementation of this service and its definition out of IDiagramServices for now and into something in the Java services of Papaya (since I suspect that you are only using it there).

You could also improve this algorithm to make it work all the time but it will require some testing of corner cases. Consumers of Sirius Web such as SysON would be quite interested by such service.

if (diagramService.getDiagramContext() != null) {
return diagramService.getDiagramContext().getDiagram().getNodes().isEmpty() && diagramService.getDiagramContext().getViewCreationRequests().isEmpty() ||
diagramService.getDiagramContext().getDiagram().getNodes().size() == 1 && !diagramService.getDiagramContext().getViewDeletionRequests().isEmpty();
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@ public interface IDiagramServices {
boolean isHidden(IDiagramElement diagramElement);

boolean isFaded(IDiagramElement diagramElement);

boolean isDiagramEmpty(IDiagramService diagramService);
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,14 @@ type Diagram implements Representation {
position: Position!
nodes: [Node!]!
edges: [Edge!]!
style: DiagramStyle!
layoutData: DiagramLayoutData!
}

type DiagramStyle {
background: String
}

type DiagramLayoutData {
nodeLayoutData: [NodeLayoutData!]!
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.eclipse.sirius.components.core.api.IPayload;
import org.eclipse.sirius.components.core.api.IRepresentationDescriptionSearchService;
import org.eclipse.sirius.components.diagrams.Diagram;
import org.eclipse.sirius.components.diagrams.DiagramStyle;
import org.eclipse.sirius.components.diagrams.Position;
import org.eclipse.sirius.components.diagrams.Size;
import org.junit.jupiter.api.Test;
Expand All @@ -56,6 +57,7 @@ public class DiagramEventProcessorTests {
.size(Size.UNDEFINED)
.nodes(List.of())
.edges(List.of())
.style(DiagramStyle.newDiagramStyle().build())
.build();

private final IDiagramCreationService diagramCreationService = new MockDiagramCreationService(INITIAL_TEST_DIAGRAM);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.eclipse.sirius.components.core.api.IPayload;
import org.eclipse.sirius.components.core.api.IRepresentationDescriptionSearchService;
import org.eclipse.sirius.components.diagrams.Diagram;
import org.eclipse.sirius.components.diagrams.DiagramStyle;
import org.eclipse.sirius.components.diagrams.description.DiagramDescription;
import org.eclipse.sirius.components.representations.Failure;
import org.eclipse.sirius.components.representations.IRepresentationDescription;
Expand Down Expand Up @@ -64,6 +65,7 @@ public Optional<IRepresentationDescription> findById(IEditingContext editingCont
.nodeDescriptions(new ArrayList<>())
.targetObjectIdProvider(variableManager -> "targetObjectId")
.dropHandler(variableManager -> new Failure(""))
.styleProvider(variableManager -> DiagramStyle.newDiagramStyle().build())
.build();
// @formatter:on

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.eclipse.sirius.components.core.api.IRepresentationDescriptionSearchService;
import org.eclipse.sirius.components.diagrams.CollapsingState;
import org.eclipse.sirius.components.diagrams.Diagram;
import org.eclipse.sirius.components.diagrams.DiagramStyle;
import org.eclipse.sirius.components.diagrams.FreeFormLayoutStrategy;
import org.eclipse.sirius.components.diagrams.InsideLabel;
import org.eclipse.sirius.components.diagrams.InsideLabelLocation;
Expand Down Expand Up @@ -171,6 +172,7 @@ public void testGetConnectorTools() {
.edgeDescriptions(new ArrayList<>())
.palettes(List.of(palette))
.dropHandler(variableManager -> new Failure(""))
.styleProvider(variableManager -> DiagramStyle.newDiagramStyle().build())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to have some of the DiagramStyle in the tests with the default (transparent) background and others with .bkacground("#FAFAFA") like the one below in the same file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, in fact, I started by adding a value at instantiation and then adding a default value.
I changed to use the default value in the tests

.build();

Node sourceNode = this.getNode(SOURCE_NODE_ID, SOURCE_NODE_TARGET_ID);
Expand Down Expand Up @@ -237,6 +239,7 @@ private Diagram getDiagram(String id, List<Node> nodes) {
.size(Size.UNDEFINED)
.nodes(nodes)
.edges(List.of())
.style(DiagramStyle.newDiagramStyle().build())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.eclipse.sirius.components.core.api.IPayload;
import org.eclipse.sirius.components.core.api.IRepresentationDescriptionSearchService;
import org.eclipse.sirius.components.diagrams.Diagram;
import org.eclipse.sirius.components.diagrams.DiagramStyle;
import org.eclipse.sirius.components.diagrams.Position;
import org.eclipse.sirius.components.diagrams.Size;
import org.eclipse.sirius.components.diagrams.description.NodeDescription;
Expand Down Expand Up @@ -83,6 +84,7 @@ public Optional<IRepresentationDescription> findById(IEditingContext editingCont
}
return desc;
}

@Override
public Map<String, IRepresentationDescription> findAll(IEditingContext editingContext) {
var descriptions = new HashMap<String, IRepresentationDescription>();
Expand Down Expand Up @@ -114,6 +116,7 @@ public Diagram getDiagram() {
.nodes(List.of())
.size(Size.UNDEFINED)
.targetObjectId("")
.style(DiagramStyle.newDiagramStyle().build())
.build();
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.eclipse.sirius.components.core.api.IEditingContext;
import org.eclipse.sirius.components.core.api.IPayload;
import org.eclipse.sirius.components.diagrams.Diagram;
import org.eclipse.sirius.components.diagrams.DiagramStyle;
import org.eclipse.sirius.components.diagrams.Position;
import org.eclipse.sirius.components.diagrams.Size;
import org.eclipse.sirius.components.diagrams.description.DiagramDescription;
Expand All @@ -47,6 +48,7 @@
* @author arichard
*/
public class RenameDiagramEventHandlerTests {

private static final String OLD_LABEL = "oldLabel";

private static final String NEW_LABEL = "newLabel";
Expand All @@ -59,7 +61,6 @@ public void testRenameRepresentation() {

DiagramDescription diagramDescription = new TestDiagramDescriptionBuilder().getDiagramDescription(UUID.randomUUID().toString(), List.of(), List.of(), List.of());

// @formatter:off
Diagram diagram = Diagram.newDiagram(representationId)
.label(OLD_LABEL)
.descriptionId(diagramDescription.getId())
Expand All @@ -68,8 +69,8 @@ public void testRenameRepresentation() {
.position(Position.at(0, 0))
.nodes(Collections.emptyList())
.edges(Collections.emptyList())
.style(DiagramStyle.newDiagramStyle().build())
.build();
// @formatter:on
IRepresentationSearchService representationSearchService = new IRepresentationSearchService() {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.eclipse.sirius.components.diagrams.ArrowStyle;
import org.eclipse.sirius.components.diagrams.CollapsingState;
import org.eclipse.sirius.components.diagrams.Diagram;
import org.eclipse.sirius.components.diagrams.DiagramStyle;
import org.eclipse.sirius.components.diagrams.Edge;
import org.eclipse.sirius.components.diagrams.EdgeStyle;
import org.eclipse.sirius.components.diagrams.FreeFormLayoutStrategy;
Expand Down Expand Up @@ -62,9 +63,14 @@ public Diagram getDiagram(String id) {
.size(Size.UNDEFINED)
.nodes(List.of())
.edges(List.of())
.style(this.getDiagramStyle())
.build();
}

public DiagramStyle getDiagramStyle() {
return DiagramStyle.newDiagramStyle().build();
}

public RectangularNodeStyle getRectangularNodeStyle() {
return RectangularNodeStyle.newRectangularNodeStyle()
.borderColor("#000000")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.function.Function;

import org.eclipse.sirius.components.diagrams.ArrowStyle;
import org.eclipse.sirius.components.diagrams.DiagramStyle;
import org.eclipse.sirius.components.diagrams.EdgeStyle;
import org.eclipse.sirius.components.diagrams.FreeFormLayoutStrategy;
import org.eclipse.sirius.components.diagrams.INodeStyle;
Expand Down Expand Up @@ -55,6 +56,7 @@ public DiagramDescription getDiagramDescription(String diagramDescriptionId, Lis
.edgeDescriptions(edgeDescriptions)
.palettes(palettes)
.dropHandler(variableManager -> new Failure(""))
.styleProvider(variableManager -> DiagramStyle.newDiagramStyle().build())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
*/
@Immutable
public final class Diagram implements IRepresentation {

public static final String KIND = IRepresentation.KIND_PREFIX + "?type=Diagram";

private String id;
Expand All @@ -50,6 +51,8 @@ public final class Diagram implements IRepresentation {

private DiagramLayoutData layoutData;

private DiagramStyle style;

private Diagram() {
// Prevent instantiation
}
Expand Down Expand Up @@ -99,6 +102,10 @@ public DiagramLayoutData getLayoutData() {
return this.layoutData;
}

public DiagramStyle getStyle() {
return this.style;
}

public static Builder newDiagram(String id) {
return new Builder(id);
}
Expand All @@ -120,9 +127,10 @@ public String toString() {
*/
@SuppressWarnings("checkstyle:HiddenField")
public static final class Builder {
private String id;

private String kind = KIND;
private final String id;

private final String kind = KIND;

private String targetObjectId;

Expand All @@ -138,6 +146,8 @@ public static final class Builder {

private List<Edge> edges;

private DiagramStyle style;

private DiagramLayoutData layoutData = new DiagramLayoutData(Map.of(), Map.of(), Map.of());

private Builder(String id) {
Expand All @@ -153,6 +163,7 @@ private Builder(Diagram diagram) {
this.size = diagram.getSize();
this.nodes = diagram.getNodes();
this.edges = diagram.getEdges();
this.style = diagram.getStyle();
this.layoutData = diagram.getLayoutData();
}

Expand Down Expand Up @@ -191,6 +202,11 @@ public Builder edges(List<Edge> edges) {
return this;
}

public Builder style(DiagramStyle style) {
this.style = Objects.requireNonNull(style);
return this;
}

public Builder layoutData(DiagramLayoutData layoutData) {
this.layoutData = Objects.requireNonNull(layoutData);
return this;
Expand All @@ -207,6 +223,7 @@ public Diagram build() {
diagram.size = Objects.requireNonNull(this.size);
diagram.nodes = Objects.requireNonNull(this.nodes);
diagram.edges = Objects.requireNonNull(this.edges);
diagram.style = Objects.requireNonNull(this.style);
diagram.layoutData = Objects.requireNonNull(this.layoutData);
return diagram;
}
Expand Down
Loading