Skip to content

Commit 71155dc

Browse files
florianbarbinmcharfadi
authored andcommitted
[3981] Display the diagram palette tools and tool sections in a list
Bug: #3981 Signed-off-by: Florian Barbin <florian.barbin@obeo.fr>
1 parent 8c17f04 commit 71155dc

File tree

54 files changed

+1804
-1029
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1804
-1029
lines changed

CHANGELOG.adoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131

3232
- https://github.com/eclipse-sirius/sirius-web/issues/4110[#4110] [form] Add layout capabilities for form widgets
3333
- https://github.com/eclipse-sirius/sirius-web/issues/4177[#4177] [table] Add table representation support
34+
- https://github.com/eclipse-sirius/sirius-web/issues/3990[#3990] [diagram] The palette can now be dragged
35+
- https://github.com/eclipse-sirius/sirius-web/issues/3981[#3981] [diagram] The palette palette sections are showed as list
3436

3537
=== Improvements
3638

@@ -363,7 +365,6 @@ A migration participant has been added to automatically keep compatible all diag
363365
- https://github.com/eclipse-sirius/sirius-web/issues/3932[#3932] [forms] Do not display the 'Delete' button (even disabled) for non-deletable lists
364366
- https://github.com/eclipse-sirius/sirius-web/issues/3951[#3951] [sirius-web] Provide an error page to redirect users in case of error
365367
- https://github.com/eclipse-sirius/sirius-web/issues/3974[#3974] [diagram] Add support for `<` and `>` to trigger direct edit
366-
- https://github.com/eclipse-sirius/sirius-web/issues/3990[#3990] [diagram] Make the diagram contextual palette draggable
367368

368369

369370
== v2024.7.0

packages/compatibility/backend/sirius-components-compatibility/src/main/java/org/eclipse/sirius/components/compatibility/services/diagrams/CompatibilityPaletteProvider.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.eclipse.emf.ecore.EObject;
2424
import org.eclipse.sirius.components.collaborative.diagrams.api.DiagramImageConstants;
2525
import org.eclipse.sirius.components.collaborative.diagrams.api.IPaletteProvider;
26+
import org.eclipse.sirius.components.collaborative.diagrams.dto.IPaletteEntry;
2627
import org.eclipse.sirius.components.collaborative.diagrams.dto.ITool;
2728
import org.eclipse.sirius.components.collaborative.diagrams.dto.Palette;
2829
import org.eclipse.sirius.components.collaborative.diagrams.dto.SingleClickOnDiagramElementTool;
@@ -95,7 +96,7 @@ public Palette handle(Object targetElement, Object diagramElement, Object diagra
9596
.map(org.eclipse.sirius.diagram.description.DiagramDescription.class::cast)
9697
.findFirst();
9798

98-
List<ToolSection> toolSections = new ArrayList<>();
99+
List<IPaletteEntry> toolSections = new ArrayList<>();
99100
if (optionalSiriusDiagramDescription.isPresent()) {
100101
org.eclipse.sirius.diagram.description.DiagramDescription siriusDiagramDescription = optionalSiriusDiagramDescription.get();
101102
List<ToolSection> filteredToolSections = this.getToolSectionFromDiagramDescriptionToolSection(diagramDescription).stream()
@@ -107,7 +108,10 @@ public Palette handle(Object targetElement, Object diagramElement, Object diagra
107108
toolSections.addAll(this.createExtraToolSections(diagramElementDescription));
108109
}
109110
String paletteId = "siriusComponents://palette?diagramId=" + optionalVsmElementId.get();
110-
return Palette.newPalette(paletteId).tools(List.of()).toolSections(toolSections).build();
111+
return Palette.newPalette(paletteId)
112+
.quickAccessTools(List.of())
113+
.paletteEntries(toolSections)
114+
.build();
111115
}
112116

113117
private List<ToolSection> getToolSectionFromDiagramDescriptionToolSection(DiagramDescription diagramDescription) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 Obeo.
3+
* This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v2.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* Obeo - initial API and implementation
12+
*******************************************************************************/
13+
package org.eclipse.sirius.components.collaborative.diagrams.dto;
14+
15+
/**
16+
* The common interface for elements displayed in the palette.
17+
*
18+
* @author fbarbin
19+
*/
20+
public interface IPaletteEntry {
21+
22+
String id();
23+
}

packages/diagrams/backend/sirius-components-collaborative-diagrams/src/main/java/org/eclipse/sirius/components/collaborative/diagrams/dto/ITool.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2023 Obeo.
2+
* Copyright (c) 2023, 2024 Obeo.
33
* This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v2.0
55
* which accompanies this distribution, and is available at
@@ -19,9 +19,7 @@
1919
*
2020
* @author mcharfadi
2121
*/
22-
public interface ITool {
23-
24-
String id();
22+
public interface ITool extends IPaletteEntry {
2523

2624
String label();
2725

packages/diagrams/backend/sirius-components-collaborative-diagrams/src/main/java/org/eclipse/sirius/components/collaborative/diagrams/dto/Palette.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2023 Obeo.
2+
* Copyright (c) 2023, 2024 Obeo.
33
* This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v2.0
55
* which accompanies this distribution, and is available at
@@ -20,12 +20,12 @@
2020
*
2121
* @author frouene
2222
*/
23-
public record Palette(String id, List<ITool> tools, List<ToolSection> toolSections) {
23+
public record Palette(String id, List<ITool> quickAccessTools, List<IPaletteEntry> paletteEntries) {
2424

2525
public Palette {
2626
Objects.requireNonNull(id);
27-
Objects.requireNonNull(tools);
28-
Objects.requireNonNull(toolSections);
27+
Objects.requireNonNull(quickAccessTools);
28+
Objects.requireNonNull(paletteEntries);
2929
}
3030

3131
public static Builder newPalette(String id) {
@@ -43,26 +43,26 @@ public static final class Builder {
4343

4444
private final String id;
4545

46-
private List<ITool> tools;
46+
private List<ITool> quickAccessTools;
4747

48-
private List<ToolSection> toolSections;
48+
private List<IPaletteEntry> paletteEntries;
4949

5050
private Builder(String id) {
5151
this.id = Objects.requireNonNull(id);
5252
}
5353

54-
public Builder tools(List<ITool> tools) {
55-
this.tools = Objects.requireNonNull(tools);
54+
public Builder quickAccessTools(List<ITool> quickAccessTools) {
55+
this.quickAccessTools = Objects.requireNonNull(quickAccessTools);
5656
return this;
5757
}
5858

59-
public Builder toolSections(List<ToolSection> toolSections) {
60-
this.toolSections = Objects.requireNonNull(toolSections);
59+
public Builder paletteEntries(List<IPaletteEntry> paletteEntries) {
60+
this.paletteEntries = Objects.requireNonNull(paletteEntries);
6161
return this;
6262
}
6363

6464
public Palette build() {
65-
return new Palette(this.id, this.tools, this.toolSections);
65+
return new Palette(this.id, this.quickAccessTools, this.paletteEntries);
6666
}
6767
}
6868

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 Obeo.
3+
* This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v2.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* Obeo - initial API and implementation
12+
*******************************************************************************/
13+
package org.eclipse.sirius.components.collaborative.diagrams.dto;
14+
15+
import java.util.Objects;
16+
17+
/**
18+
* Represents a divider between tools or tool sections in the palette.
19+
*
20+
* @author fbarbin
21+
*/
22+
public record PaletteDivider(String id) implements IPaletteEntry {
23+
24+
public PaletteDivider {
25+
Objects.requireNonNull(id);
26+
}
27+
}

packages/diagrams/backend/sirius-components-collaborative-diagrams/src/main/java/org/eclipse/sirius/components/collaborative/diagrams/dto/SingleClickOnDiagramElementTool.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@
2222
*
2323
* @author mcharfadi
2424
*/
25-
public record SingleClickOnDiagramElementTool(String id, String label, List<String> iconURL, List<IDiagramElementDescription> targetDescriptions, String dialogDescriptionId,
26-
boolean appliesToDiagramRoot) implements ITool {
25+
public record SingleClickOnDiagramElementTool(
26+
String id,
27+
String label,
28+
List<String> iconURL,
29+
List<IDiagramElementDescription> targetDescriptions,
30+
String dialogDescriptionId,
31+
boolean appliesToDiagramRoot) implements ITool {
2732

2833
public SingleClickOnDiagramElementTool {
2934
Objects.requireNonNull(id);

packages/diagrams/backend/sirius-components-collaborative-diagrams/src/main/java/org/eclipse/sirius/components/collaborative/diagrams/dto/SingleClickOnTwoDiagramElementsTool.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@
2020
*
2121
* @author mcharfadi
2222
*/
23-
public record SingleClickOnTwoDiagramElementsTool(String id, String label, List<String> iconURL, List<SingleClickOnTwoDiagramElementsCandidate> candidates, String dialogDescriptionId) implements ITool {
23+
public record SingleClickOnTwoDiagramElementsTool(
24+
String id,
25+
String label,
26+
List<String> iconURL,
27+
List<SingleClickOnTwoDiagramElementsCandidate> candidates,
28+
String dialogDescriptionId) implements ITool {
2429

2530
public SingleClickOnTwoDiagramElementsTool {
2631
Objects.requireNonNull(id);

packages/diagrams/backend/sirius-components-collaborative-diagrams/src/main/java/org/eclipse/sirius/components/collaborative/diagrams/dto/ToolSection.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2023 Obeo.
2+
* Copyright (c) 2023, 2024 Obeo.
33
* This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v2.0
55
* which accompanies this distribution, and is available at
@@ -20,7 +20,7 @@
2020
*
2121
* @author mcharfadi
2222
*/
23-
public record ToolSection(String id, String label, List<String> iconURL, List<ITool> tools) {
23+
public record ToolSection(String id, String label, List<String> iconURL, List<ITool> tools) implements IPaletteEntry {
2424

2525
public ToolSection {
2626
Objects.requireNonNull(id);

packages/diagrams/backend/sirius-components-collaborative-diagrams/src/main/resources/schema/diagram.graphqls

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,18 @@ type Size {
266266

267267
type Palette {
268268
id: ID!
269-
tools: [Tool]!
270-
toolSections: [ToolSection]!
269+
quickAccessTools: [Tool]!
270+
paletteEntries: [PaletteEntry]!
271+
}
272+
273+
union PaletteEntry =
274+
ToolSection
275+
| SingleClickOnDiagramElementTool
276+
| SingleClickOnTwoDiagramElementsTool
277+
| PaletteDivider
278+
279+
type PaletteDivider {
280+
id: ID!
271281
}
272282

273283
type ToolSection {

packages/diagrams/backend/sirius-components-diagrams-tests/src/main/java/org/eclipse/sirius/components/diagrams/tests/graphql/PaletteQueryRunner.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,18 @@ query getPalette($editingContextId: ID!, $representationId: ID!, $diagramElement
3636
... on DiagramDescription {
3737
palette(diagramElementId: $diagramElementId) {
3838
id
39-
tools {
39+
quickAccessTools {
4040
...ToolFields
4141
}
42-
toolSections {
43-
id
44-
label
45-
iconURL
46-
tools {
47-
...ToolFields
42+
paletteEntries {
43+
...ToolFields
44+
... on ToolSection {
45+
id
46+
label
47+
iconURL
48+
tools {
49+
...ToolFields
50+
}
4851
}
4952
}
5053
}

packages/diagrams/frontend/sirius-components-diagrams/src/index.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,13 @@ export type { NodeContextValue } from './renderer/node/NodeContext.types';
5858
export { NodeTypeContribution } from './renderer/node/NodeTypeContribution';
5959
export type { DiagramNodeType } from './renderer/node/NodeTypes.types';
6060
export { DiagramElementPalette } from './renderer/palette/DiagramElementPalette';
61-
export type { DiagramPaletteToolContributionComponentProps } from './renderer/palette/DiagramPaletteToolContribution.types';
62-
export type { GQLToolVariable, GQLToolVariableType } from './renderer/palette/Palette.types';
63-
export type { DiagramPaletteToolComponentProps } from './renderer/palette/tool/DiagramPaletteTool.types';
64-
export { diagramPaletteToolExtensionPoint } from './renderer/palette/tool/DiagramPaletteToolExtensionPoints';
61+
export type { DiagramPaletteToolComponentProps } from './renderer/palette/extensions/DiagramPaletteTool.types';
62+
export type {
63+
DiagramPaletteToolContributionComponentProps,
64+
DiagramPaletteToolContributionProps,
65+
} from './renderer/palette/extensions/DiagramPaletteToolContribution.types';
66+
export { diagramPaletteToolExtensionPoint } from './renderer/palette/extensions/DiagramPaletteToolExtensionPoints';
67+
export type { GQLToolVariable, GQLToolVariableType } from './renderer/palette/usePalette.types';
6568
export type { DiagramPanelActionProps } from './renderer/panel/DiagramPanel.types';
6669
export { diagramPanelActionExtensionPoint } from './renderer/panel/DiagramPanelExtensionPoints';
6770
export { DiagramRepresentation } from './representation/DiagramRepresentation';

packages/diagrams/frontend/sirius-components-diagrams/src/renderer/connector/useConnector.types.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,24 @@ export interface GQLDiagramDescription extends GQLRepresentationDescription {
6060

6161
export interface GQLPalette {
6262
id: string;
63+
paletteEntries: GQLPaletteEntry[];
64+
}
65+
66+
export interface GQLPaletteEntry {
67+
id: string;
68+
__typename: string;
69+
}
70+
export interface GQLPaletteDivider extends GQLPaletteEntry {}
71+
72+
export interface GQLToolSection extends GQLPaletteEntry {
73+
label: string;
74+
iconURL: string[];
6375
tools: GQLTool[];
64-
toolSections: GQLToolSection[];
6576
}
6677

6778
export interface GQLToolSection {
6879
id: string;
6980
label: string;
70-
imageURL: string;
7181
tools: GQLTool[];
7282
__typename: string;
7383
}

packages/diagrams/frontend/sirius-components-diagrams/src/renderer/delete/useDiagramDelete.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
GQLDeleteFromDiagramVariables,
2626
GQLDeletionPolicy,
2727
GQLErrorPayload,
28-
} from '../palette/Palette.types';
28+
} from '../palette/usePalette.types';
2929
import { UseDiagramDeleteValue } from './useDiagramDelete.types';
3030

3131
export const deleteFromDiagramMutation = gql`

packages/diagrams/frontend/sirius-components-diagrams/src/renderer/handles/useConnectionCandidatesQuery.ts

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ import {
1919
GQLGetToolSectionsData,
2020
GQLGetToolSectionsVariables,
2121
GQLNodeDescription,
22+
GQLPaletteEntry,
2223
GQLRepresentationDescription,
2324
GQLSingleClickOnTwoDiagramElementsTool,
25+
GQLToolSection,
2426
} from '../connector/useConnector.types';
2527
import { NodeData } from '../DiagramRenderer.types';
26-
import { GQLTool } from '../palette/Palette.types';
2728

2829
const getToolSectionsQuery = gql`
2930
query getToolSections($editingContextId: ID!, $diagramId: ID!, $diagramElementId: ID!) {
@@ -33,12 +34,12 @@ const getToolSectionsQuery = gql`
3334
description {
3435
... on DiagramDescription {
3536
palette(diagramElementId: $diagramElementId) {
36-
tools {
37+
paletteEntries {
3738
...ToolFields
38-
}
39-
toolSections {
40-
tools {
41-
...ToolFields
39+
... on ToolSection {
40+
tools {
41+
...ToolFields
42+
}
4243
}
4344
}
4445
}
@@ -68,9 +69,10 @@ const getToolSectionsQuery = gql`
6869
const isDiagramDescription = (
6970
representationDescription: GQLRepresentationDescription
7071
): representationDescription is GQLDiagramDescription => representationDescription.__typename === 'DiagramDescription';
71-
const isSingleClickOnTwoDiagramElementsTool = (tool: GQLTool): tool is GQLSingleClickOnTwoDiagramElementsTool =>
72-
tool.__typename === 'SingleClickOnTwoDiagramElementsTool';
73-
72+
const isSingleClickOnTwoDiagramElementsTool = (
73+
entry: GQLPaletteEntry
74+
): entry is GQLSingleClickOnTwoDiagramElementsTool => entry.__typename === 'SingleClickOnTwoDiagramElementsTool';
75+
const isToolSection = (entry: GQLPaletteEntry): entry is GQLToolSection => entry.__typename === 'ToolSection';
7476
export const useConnectionCandidatesQuery = (
7577
editingContextId: string,
7678
diagramId: string,
@@ -90,17 +92,24 @@ export const useConnectionCandidatesQuery = (
9092
const diagramDescription: GQLRepresentationDescription | null =
9193
data?.viewer.editingContext.representation.description ?? null;
9294

93-
const nodeCandidates: GQLNodeDescription[] = useMemo(() => {
95+
const collectConnectionToolsFromPaletteEntry = (entry: GQLPaletteEntry): GQLNodeDescription[] => {
9496
const candidates: GQLNodeDescription[] = [];
95-
if (diagramDescription && isDiagramDescription(diagramDescription)) {
96-
diagramDescription.palette.tools.filter(isSingleClickOnTwoDiagramElementsTool).forEach((tool) => {
97+
if (isSingleClickOnTwoDiagramElementsTool(entry)) {
98+
entry.candidates.forEach((candidate) => candidates.push(...candidate.targets));
99+
} else if (isToolSection(entry)) {
100+
entry.tools.filter(isSingleClickOnTwoDiagramElementsTool).forEach((tool) => {
97101
tool.candidates.forEach((candidate) => candidates.push(...candidate.targets));
98102
});
99-
diagramDescription.palette.toolSections.forEach((toolSection) => {
100-
toolSection.tools.filter(isSingleClickOnTwoDiagramElementsTool).forEach((tool) => {
101-
tool.candidates.forEach((candidate) => candidates.push(...candidate.targets));
102-
});
103-
});
103+
}
104+
return candidates;
105+
};
106+
107+
const nodeCandidates: GQLNodeDescription[] = useMemo(() => {
108+
const candidates: GQLNodeDescription[] = [];
109+
if (diagramDescription && isDiagramDescription(diagramDescription)) {
110+
diagramDescription.palette.paletteEntries.forEach((entry) =>
111+
candidates.push(...collectConnectionToolsFromPaletteEntry(entry))
112+
);
104113
}
105114

106115
return candidates;

0 commit comments

Comments
 (0)