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

[4192] Compute the icon of a representation #4202

Open
wants to merge 2 commits 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
5 changes: 2 additions & 3 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,14 @@


=== New Features


- 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/4192[#4192] [core] Compute the icon of a representation

=== Improvements





== v2024.11.0

=== Shapes
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,85 @@ public Function<VariableManager, String> getLabelProvider() {
public Function<VariableManager, List<Object>> getChildSemanticElementsProvider() {
return this.childSemanticElementsProvider;
}

@Override
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 = this.childSemanticElementsProvider; // Optional on purpose.
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(vm -> List.of())
.autoLayout(this.isAutoLayoutMode(siriusDiagramDescription))
.arrangeLayoutDirection(ArrangeLayoutDirection.UNDEFINED);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type RepresentationMetadata {
label: String!
kind: String!
description: RepresentationDescription!
iconURLs: [String!]!
}

interface Representation {
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 All @@ -12,6 +12,8 @@
*******************************************************************************/
package org.eclipse.sirius.components.representations;

import java.util.List;
import java.util.function.Function;
import java.util.function.Predicate;

import org.eclipse.sirius.components.annotations.PublicApi;
Expand All @@ -31,4 +33,6 @@ public interface IRepresentationDescription {
String getLabel();

Predicate<VariableManager> getCanCreatePredicate();

Function<VariableManager, List<String>> getIconURLsProvider();
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const getRepresentationMetadata = gql`
id
label
kind
iconURLs
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface GQLRepresentationMetadata {
id: string;
label: string;
kind: string;
iconURLs: string[];
}

export interface GQLRepresentationMetadataQueryVariables {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import CloseIcon from '@mui/icons-material/Close';
import Tab from '@mui/material/Tab';
import Tabs from '@mui/material/Tabs';
import { makeStyles } from 'tss-react/mui';
import { IconOverlay } from '../icon/IconOverlay';
import { RepresentationNavigationProps } from './RepresentationNavigation.types';
import { RepresentationMetadata } from './Workbench.types';

Expand All @@ -34,6 +35,9 @@ const useRepresentationNavigationStyles = makeStyles()((theme) => ({
alignItems: 'center',
width: 'inherit',
},
tabRepresentationIcon: {
marginRight: theme.spacing(1),
},
tabLabelText: {
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
Expand Down Expand Up @@ -62,11 +66,12 @@ export const RepresentationNavigation = ({
const onChange = (_event: React.ChangeEvent<{}>, value: string) => {
const representationSelected = representations.find((representation) => representation.id === value);
if (representationSelected) {
const { id, label, kind } = representationSelected;
const { id, label, kind, iconURLs } = representationSelected;
const representation: RepresentationMetadata = {
id,
label,
kind,
iconURLs,
};
onRepresentationClick(representation);
}
Expand Down Expand Up @@ -94,6 +99,9 @@ export const RepresentationNavigation = ({
value={representation.id}
label={
<div className={classes.tabLabel}>
<div className={classes.tabRepresentationIcon}>
<IconOverlay iconURL={representation.iconURLs} alt="representation icon" />
</div>
<div className={classes.tabLabelText}>{representation.label}</div>
<CloseIcon
className={classes.tabCloseIcon}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export type RepresentationMetadata = {
id: string;
label: string;
kind: string;
iconURLs: string[];
};

export type WorkbenchViewSide = 'left' | 'right';
Expand Down
Loading
Loading