Skip to content

Commit

Permalink
[4192] Compute the icon of a representation
Browse files Browse the repository at this point in the history
Bug: eclipse-sirius#4192
Signed-off-by: Jerome Gout <[email protected]>
  • Loading branch information
jerome-obeo authored and sbegaudeau committed Dec 4, 2024
1 parent d2dd474 commit 17761aa
Show file tree
Hide file tree
Showing 146 changed files with 1,869 additions and 804 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ The following records parameters have been modified:
** to RestProject(UUID id, String type, OffsetDateTime created, Identified defaultBranch, String description, String name)
- https://github.com/eclipse-sirius/sirius-web/issues/4190[#4190] [core] The graphQL type `RepresentationMetadata` has now a property to hold icons for the representation.
This can be retrieve using either `EditingContext#representations` or `EditingContext#representation`
- https://github.com/eclipse-sirius/sirius-web/issues/4192[#4192] [core] `IRepresentationDescription` has a new provide `getIconURLsProvider`.
This provider is in charge of getting the icon list of the representation.

=== Dependency update

Expand All @@ -46,6 +48,7 @@ This can be retrieve using either `EditingContext#representations` or `EditingCo

- https://github.com/eclipse-sirius/sirius-web/issues/4190[#4190] [core] Display the icon of the representation in the workbench tab
- https://github.com/eclipse-sirius/sirius-web/issues/4110[#4110] [form] Add layout capabilities for form widgets
- https://github.com/eclipse-sirius/sirius-web/issues/4192[#4192] [core] Compute the icon of a representation
- https://github.com/eclipse-sirius/sirius-web/issues/4177[#4177] [table] Add table representation support
- https://github.com/eclipse-sirius/sirius-web/issues/3990[#3990] [diagram] The palette can now be dragged
- https://github.com/eclipse-sirius/sirius-web/issues/3981[#3981] [diagram] The palette sections are showed as list
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2022 Obeo.
* Copyright (c) 2022, 2024 Obeo.
* 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
Expand All @@ -17,15 +17,18 @@
import java.util.function.Function;
import java.util.function.Predicate;

import org.eclipse.sirius.components.annotations.Immutable;
import org.eclipse.sirius.components.representations.IRepresentationDescription;
import org.eclipse.sirius.components.representations.VariableManager;

/**
* Description of the hierarchy representation.
*
* @author sbegaudeau
* @author Jerome Gout
*/
public class HierarchyDescription implements IRepresentationDescription {
@Immutable
public final class HierarchyDescription implements IRepresentationDescription {
public static final String LABEL = "label";

private String id;
Expand All @@ -42,15 +45,14 @@ public class HierarchyDescription implements IRepresentationDescription {

private Function<VariableManager, List<Object>> childSemanticElementsProvider;

public HierarchyDescription(String id, String label, String kind, Predicate<VariableManager> canCreatePredicate, Function<VariableManager, String> targetObjectIdProvider,
Function<VariableManager, String> labelProvider, Function<VariableManager, List<Object>> childSemanticElementsProvider) {
this.id = Objects.requireNonNull(id);
this.label = Objects.requireNonNull(label);
this.kind = Objects.requireNonNull(kind);
this.canCreatePredicate = Objects.requireNonNull(canCreatePredicate);
this.targetObjectIdProvider = Objects.requireNonNull(targetObjectIdProvider);
this.labelProvider = Objects.requireNonNull(labelProvider);
this.childSemanticElementsProvider = Objects.requireNonNull(childSemanticElementsProvider);
private Function<VariableManager, List<String>> iconURLsProvider;

private HierarchyDescription() {
// Prevent instantiation
}

public static Builder newHierarchyDescription(String id) {
return new Builder(id);
}

@Override
Expand Down Expand Up @@ -83,4 +85,84 @@ public Function<VariableManager, String> getLabelProvider() {
public Function<VariableManager, List<Object>> getChildSemanticElementsProvider() {
return this.childSemanticElementsProvider;
}

public Function<VariableManager, List<String>> getIconURLsProvider() {
return this.iconURLsProvider;
}

/**
* Builder used to create the hierarchy description.
*
*/
@SuppressWarnings("checkstyle:HiddenField")
public static final class Builder {

private final String id;

private String label;

private String kind;

private Predicate<VariableManager> canCreatePredicate;

private Function<VariableManager, String> targetObjectIdProvider;

private Function<VariableManager, String> labelProvider;

private Function<VariableManager, List<Object>> childSemanticElementsProvider;

private Function<VariableManager, List<String>> iconURLsProvider;

public Builder(String id) {
this.id = Objects.requireNonNull(id);
}

public Builder label(String label) {
this.label = Objects.requireNonNull(label);
return this;
}

public Builder kind(String kind) {
this.kind = Objects.requireNonNull(kind);
return this;
}

public Builder canCreatePredicate(Predicate<VariableManager> canCreatePredicate) {
this.canCreatePredicate = Objects.requireNonNull(canCreatePredicate);
return this;
}

public Builder targetObjectIdProvider(Function<VariableManager, String> targetObjectIdProvider) {
this.targetObjectIdProvider = Objects.requireNonNull(targetObjectIdProvider);
return this;
}

public Builder labelProvider(Function<VariableManager, String> labelProvider) {
this.labelProvider = Objects.requireNonNull(labelProvider);
return this;
}

public Builder childSemanticElementsProvider(Function<VariableManager, List<Object>> childSemanticElementsProvider) {
this.childSemanticElementsProvider = Objects.requireNonNull(childSemanticElementsProvider);
return this;
}

public Builder iconURLsProvider(Function<VariableManager, List<String>> iconURLsProvider) {
this.iconURLsProvider = Objects.requireNonNull(iconURLsProvider);
return this;
}

public HierarchyDescription build() {
HierarchyDescription hierarchyDescription = new HierarchyDescription();
hierarchyDescription.id = Objects.requireNonNull(this.id);
hierarchyDescription.kind = Objects.requireNonNull(this.kind);
hierarchyDescription.label = Objects.requireNonNull(this.label);
hierarchyDescription.canCreatePredicate = Objects.requireNonNull(this.canCreatePredicate);
hierarchyDescription.targetObjectIdProvider = Objects.requireNonNull(this.targetObjectIdProvider);
hierarchyDescription.labelProvider = Objects.requireNonNull(this.labelProvider);
hierarchyDescription.childSemanticElementsProvider = Objects.requireNonNull(this.childSemanticElementsProvider);
hierarchyDescription.iconURLsProvider = Objects.requireNonNull(this.iconURLsProvider);
return hierarchyDescription;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*******************************************************************************/
package org.eclipse.sirius.components.collaborative.charts;

import java.util.List;
import java.util.Objects;
import java.util.Optional;

Expand Down Expand Up @@ -111,12 +112,14 @@ public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDesc
variableManager.put(VariableManager.SELF, object);
variableManager.put(HierarchyDescription.LABEL, createRepresentationInput.representationName());
String label = representationDescription.getLabelProvider().apply(variableManager);
List<String> iconURLs = representationDescription.getIconURLsProvider().apply(variableManager);

Hierarchy hierarchy = this.hierarchyCreationService.create(object, representationDescription, editingContext);
var representationMetadata = RepresentationMetadata.newRepresentationMetadata(hierarchy.getId())
.kind(hierarchy.getKind())
.label(label)
.descriptionId(hierarchy.getDescriptionId())
.iconURLs(iconURLs)
.build();

this.representationMetadataPersistenceService.save(createRepresentationInput, editingContext, representationMetadata, hierarchy.getTargetObjectId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public void initialize() {
.nodeDescriptions(List.of(this.getNodeDescription(UUID.randomUUID().toString())))
.edgeDescriptions(List.of())
.dropHandler(variableManager -> new Failure(""))
.iconURLsProvider(variableManager -> List.of())
.build();

Diagram diagram = Diagram.newDiagram(UUID.randomUUID().toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public void initialize() {
.nodeDescriptions(List.of(this.getNodeDescription(UUID.randomUUID().toString())))
.edgeDescriptions(List.of())
.dropHandler(variableManager -> new Failure(""))
.iconURLsProvider(variableManager -> List.of())
.build();

Node node = Node.newNode(UUID.randomUUID().toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*******************************************************************************/
package org.eclipse.sirius.components.compatibility.diagrams;

import java.util.List;
import java.util.Objects;

import org.eclipse.sirius.components.compatibility.api.IIdentifierProvider;
Expand Down Expand Up @@ -57,6 +58,7 @@ public SelectionDescription convert(SelectModelElementVariable selectModelElemen
.targetObjectIdProvider(variableManager -> variableManager.get(VariableManager.SELF, Object.class).map(this.objectService::getId).orElse(null))
.label("Selection Description")
.canCreatePredicate(variableManager -> false)
.iconURLsProvider(variableManager -> List.of())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2023 Obeo.
* Copyright (c) 2019, 2024 Obeo.
* 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
Expand Down Expand Up @@ -99,6 +99,7 @@ public FormDescription convert(ViewExtensionDescription viewExtensionDescription
.canCreatePredicate(variableManager -> false)
.targetObjectIdProvider(targetObjectIdProvider)
.pageDescriptions(pageDescriptions)
.iconURLsProvider(variableManager -> List.of())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public DiagramDescription convert(org.eclipse.sirius.diagram.description.Diagram
Builder builder = DiagramDescription.newDiagramDescription(this.identifierProvider.getIdentifier(siriusDiagramDescription))
.canCreatePredicate(canCreatePredicate)
.labelProvider(labelProvider)
.iconURLsProvider(variableManager -> List.of())
.autoLayout(this.isAutoLayoutMode(siriusDiagramDescription))
.arrangeLayoutDirection(ArrangeLayoutDirection.UNDEFINED);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,21 @@
package org.eclipse.sirius.components.core;

import java.text.MessageFormat;
import java.util.List;
import java.util.Objects;

/**
* The metadata of a representation.
*
* @author sbegaudeau
*/
public record RepresentationMetadata(String id, String kind, String label, String descriptionId) {
public record RepresentationMetadata(String id, String kind, String label, String descriptionId, List<String> iconURLs) {
public RepresentationMetadata {
Objects.requireNonNull(id);
Objects.requireNonNull(kind);
Objects.requireNonNull(label);
Objects.requireNonNull(descriptionId);
Objects.requireNonNull(iconURLs);
}

public static Builder newRepresentationMetadata(String id) {
Expand Down Expand Up @@ -57,6 +59,8 @@ public static final class Builder {

private String descriptionId;

private List<String> iconURLs;

private Builder(String id) {
this.id = Objects.requireNonNull(id);
}
Expand All @@ -83,12 +87,18 @@ public Builder descriptionId(String descriptionId) {
return this;
}

public Builder iconURLs(List<String> iconURLs) {
this.iconURLs = Objects.requireNonNull(iconURLs);
return this;
}

public RepresentationMetadata build() {
return new RepresentationMetadata(
Objects.requireNonNull(this.id),
Objects.requireNonNull(this.kind),
Objects.requireNonNull(this.label),
Objects.requireNonNull(this.descriptionId)
Objects.requireNonNull(this.descriptionId),
Objects.requireNonNull(this.iconURLs)
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2022 Obeo.
* Copyright (c) 2019, 2024 Obeo.
* 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*******************************************************************************/
package org.eclipse.sirius.components.collaborative.deck.handlers;

import java.util.List;
import java.util.Objects;
import java.util.Optional;

Expand Down Expand Up @@ -110,12 +111,14 @@ public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDesc
variableManager.put(VariableManager.SELF, object);
variableManager.put(DeckDescription.LABEL, createRepresentationInput.representationName());
String label = deckDescription.labelProvider().apply(variableManager);
List<String> iconURLs = deckDescription.getIconURLsProvider().apply(variableManager);

Deck deckDiagram = this.deckCreationService.create(object, deckDescription, editingContext);
var representationMetadata = RepresentationMetadata.newRepresentationMetadata(deckDiagram.id())
.kind(deckDiagram.getKind())
.label(label)
.descriptionId(deckDiagram.getDescriptionId())
.iconURLs(iconURLs)
.build();

this.representationMetadataPersistenceService.save(createRepresentationInput, editingContext, representationMetadata, deckDiagram.getTargetObjectId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
*/
@PublicApi
public record DeckDescription(String id, String label, Function<VariableManager, String> idProvider, Function<VariableManager, String> labelProvider,
Function<VariableManager, String> targetObjectIdProvider, Predicate<VariableManager> canCreatePredicate, List<LaneDescription> laneDescriptions, Consumer<VariableManager> dropLaneProvider, Function<VariableManager, DeckStyle> deckStyleProvider)
Function<VariableManager, String> targetObjectIdProvider, Predicate<VariableManager> canCreatePredicate, List<LaneDescription> laneDescriptions, Consumer<VariableManager> dropLaneProvider, Function<VariableManager, DeckStyle> deckStyleProvider,
Function<VariableManager, List<String>> iconURLsProvider)
implements IRepresentationDescription {

public static final String LABEL = "label";
Expand All @@ -58,6 +59,7 @@ public record DeckDescription(String id, String label, Function<VariableManager,
Objects.requireNonNull(laneDescriptions);
Objects.requireNonNull(dropLaneProvider);
Objects.requireNonNull(deckStyleProvider);
Objects.requireNonNull(iconURLsProvider);
}

@Override
Expand All @@ -75,6 +77,10 @@ public Predicate<VariableManager> getCanCreatePredicate() {
return this.canCreatePredicate;
}

public Function<VariableManager, List<String>> getIconURLsProvider() {
return this.iconURLsProvider;
}

@Override
public String toString() {
String pattern = "{0} '{'id: {1}, label: {2}'}'";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*******************************************************************************/
package org.eclipse.sirius.components.collaborative.diagrams.handlers;

import java.util.List;
import java.util.Objects;
import java.util.Optional;

Expand Down Expand Up @@ -111,12 +112,14 @@ public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDesc
variableManager.put(VariableManager.SELF, object);
variableManager.put(DiagramDescription.LABEL, createRepresentationInput.representationName());
String label = diagramDescription.getLabelProvider().apply(variableManager);
List<String> iconURLs = diagramDescription.getIconURLsProvider().apply(variableManager);

Diagram diagram = this.diagramCreationService.create(object, diagramDescription, editingContext);
var representationMetadata = RepresentationMetadata.newRepresentationMetadata(diagram.getId())
.kind(diagram.getKind())
.label(label)
.descriptionId(diagram.getDescriptionId())
.iconURLs(iconURLs)
.build();

this.representationMetadataPersistenceService.save(createRepresentationInput, editingContext, representationMetadata, diagram.getTargetObjectId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public Optional<IRepresentationDescription> findById(IEditingContext editingCont
.nodeDescriptions(new ArrayList<>())
.targetObjectIdProvider(variableManager -> "targetObjectId")
.dropHandler(variableManager -> new Failure(""))
.iconURLsProvider(variableManager -> List.of())
.build();

return Optional.of(diagramDescription);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ public void testGetConnectorTools() {
.edgeDescriptions(new ArrayList<>())
.palettes(List.of(palette))
.dropHandler(variableManager -> new Failure(""))
.iconURLsProvider(variableManager -> List.of())
.build();

Node sourceNode = this.getNode(SOURCE_NODE_ID, SOURCE_NODE_TARGET_ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public DiagramDescription getDiagramDescription(String diagramDescriptionId, Lis
.edgeDescriptions(edgeDescriptions)
.palettes(palettes)
.dropHandler(variableManager -> new Failure(""))
.iconURLsProvider(variableManager -> List.of())
.build();
}

Expand Down
Loading

0 comments on commit 17761aa

Please sign in to comment.