Skip to content

Commit

Permalink
[2253] Add the possibility of organizing palette tools into sections
Browse files Browse the repository at this point in the history
Bug: #2253
  • Loading branch information
frouene committed Aug 24, 2023
1 parent a32dc3a commit 293c464
Show file tree
Hide file tree
Showing 90 changed files with 4,499 additions and 638 deletions.
11 changes: 5 additions & 6 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

=== Shapes


=== Architectural decision records


=== Breaking changes

- https://github.com/eclipse-sirius/sirius-components/issues/2250[#2250] [core] Remove all references to notistack from `sirius-components-core`.
Expand Down Expand Up @@ -51,7 +49,7 @@ As a result the development of applications consuming Sirius Components packages
=== New Features

- https://github.com/eclipse-sirius/sirius-web/issues/2185[#2185] [diagram] Add support for drop tool from the explorer with React Flow.

- https://github.com/eclipse-sirius/sirius-web/issues/2253[#2253] [diagram] Add the possibility of organizing palette tools into sections

=== Improvements

Expand All @@ -61,7 +59,6 @@ As a result the development of applications consuming Sirius Components packages
- https://github.com/eclipse-sirius/sirius-web/issues/2298[#2298] [diagram] Support keyboard shortcut for "Delete from model" action on react-flow diagrams
- https://github.com/eclipse-sirius/sirius-web/issues/2231[#2231] [diagram] Extract the support for fullscreen in a dedicated hook


== v2023.8.0

=== Shapes
Expand Down Expand Up @@ -122,7 +119,8 @@ An absent/empty candidates expression now simply means the widget is empty.
- https://github.com/eclipse-sirius/sirius-components/issues/2194[#2194] [view] Fix an issue where it was impossible to set the None value to a color property in a View Node/Edge Description from the Details view.
- https://github.com/eclipse-sirius/sirius-components/issues/2225[#2225] [form] Fix an issue where tabs displaying page name could be hidden.
- https://github.com/eclipse-sirius/sirius-components/issues/2220[#2220] [vs-code] Fix an issue where some React contexts where missing, the treeID variable was missing in graphQLSubscription for the explorer and the Forms were not parts of the list of representations availables.
- https://github.com/eclipse-sirius/sirius-components/issues/2217[#2217] [diagram] Fix the svg export when the file extension was not available. It falls back to the image content type to determine the image type.
- https://github.com/eclipse-sirius/sirius-components/issues/2217[#2217] [diagram] Fix the svg export when the file extension was not available.
It falls back to the image content type to determine the image type.

=== New Features

Expand Down Expand Up @@ -209,7 +207,8 @@ The node palette with hide and fade:
+
image:doc/images/NodePaletteWithHideFade.png[Hide and Fade on node palette]
- https://github.com/eclipse-sirius/sirius-components/issues/2095[#2095] [diagram] Add support for the creation of new edges in the alternate diagram rendering solution
- https://github.com/eclipse-sirius/sirius-components/issues/2104[#2104] [diagram] Improve the frontend rendering. Labels and node list are rendered with css.
- https://github.com/eclipse-sirius/sirius-components/issues/2104[#2104] [diagram] Improve the frontend rendering.
Labels and node list are rendered with css.

== v2023.6.0

Expand Down
63 changes: 63 additions & 0 deletions integration-tests/cypress/e2e/project/edit/studio.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,67 @@ describe('/projects/:projectId/edit - Studio', () => {
cy.getByTestId('domain').get('[data-value="http://www.eclipse.org/sirius-web/view"]').should('exist');
cy.getByTestId('domain').get('[data-value="http://www.obeo.fr/dsl/designer/sample/flow"]').should('exist');
});

it('Check the DiagramPalette toolSection creation', () => {
cy.getByTestId('ViewNewModel').dblclick();
cy.getByTestId('View').dblclick();
cy.get('[data-testid$=" Diagram Description"]').dblclick();
cy.getByTestId('DiagramPalette').should('exist');
cy.getByTestId('DiagramPalette-more').click();
cy.getByTestId('new-object').click();
cy.getByTestId('childCreationDescription').find('input').invoke('val').should('not.be.empty');
cy.getByTestId('childCreationDescription').click();
cy.get('[data-value="Diagram Tool Section"]').should('exist').click();
cy.getByTestId('create-object').click();
cy.getByTestId('Tool Section').should('exist');
cy.getByTestId('Tool Section-more').click();
cy.getByTestId('new-object').click();
cy.getByTestId('childCreationDescription').find('input').invoke('val').should('not.be.empty');
cy.getByTestId('childCreationDescription').click();
cy.get('[data-value="Node Tool"]').should('exist');
cy.get('[data-value="Edge Tool"]').should('not.exist');
});

it('Check the NodePalette toolSection creation', () => {
cy.getByTestId('ViewNewModel').dblclick();
cy.getByTestId('View').dblclick();
cy.get('[data-testid$=" Diagram Description"]').dblclick();
cy.getByTestId('Entity1 Node').dblclick();
cy.getByTestId('NodePalette-more').click();
cy.getByTestId('new-object').click();
cy.getByTestId('childCreationDescription').find('input').invoke('val').should('not.be.empty');
cy.getByTestId('childCreationDescription').click();
cy.get('[data-value="Node Tool Section"]').should('exist').click();
cy.getByTestId('create-object').click();
cy.getByTestId('Tool Section').should('exist');
cy.getByTestId('Tool Section-more').click();
cy.getByTestId('new-object').click();
cy.getByTestId('childCreationDescription').find('input').invoke('val').should('not.be.empty');
cy.getByTestId('childCreationDescription').click();
cy.get('[data-value="Node Tool"]').should('exist');
cy.get('[data-value="Edge Tool"]').should('exist');
cy.get('[data-value="Source Edge End Reconnection Tool"]').should('not.exist');
});

it('Check the EdgePalette toolSection creation', () => {
cy.getByTestId('ViewNewModel').dblclick();
cy.getByTestId('View').dblclick();
cy.get('[data-testid$=" Diagram Description"]').dblclick();
cy.getByTestId('LinkedTo Edge').dblclick();
cy.getByTestId('EdgePalette-more').click();
cy.getByTestId('new-object').click();
cy.getByTestId('childCreationDescription').find('input').invoke('val').should('not.be.empty');
cy.getByTestId('childCreationDescription').click();
cy.get('[data-value="Edge Tool Section"]').should('exist').click();
cy.getByTestId('create-object').click();
cy.getByTestId('Tool Section').should('exist');
cy.getByTestId('Tool Section-more').click();
cy.getByTestId('new-object').click();
cy.getByTestId('childCreationDescription').find('input').invoke('val').should('not.be.empty');
cy.getByTestId('childCreationDescription').click();
cy.get('[data-value="Node Tool"]').should('exist');
cy.get('[data-value="Edge Tool"]').should('not.exist');
cy.get('[data-value="Source Edge End Reconnection Tool"]').should('exist');
cy.get('[data-value="Target Edge End Reconnection Tool"]').should('exist');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void initialize() {
.targetObjectIdProvider(variableManager -> "diagramTargetObjectId")
.canCreatePredicate(variableManager -> true)
.labelProvider(variableManager -> "Diagram")
.toolSections(List.of())
.palettes(List.of())
.nodeDescriptions(List.of(this.getNodeDescription(UUID.randomUUID().toString())))
.edgeDescriptions(List.of())
.dropHandler(variableManager -> new Failure(""))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
* @author arichard
*/
public class DeleteViewOperationHandlerTests {

private static final String AQL = "aql:";

private static final String VARIABLE_NAME = "myVariableName";
Expand All @@ -85,7 +86,7 @@ public void initialize() {
.targetObjectIdProvider(variableManager -> "diagramTargetObjectId")
.canCreatePredicate(variableManager -> true)
.labelProvider(variableManager -> "Diagram")
.toolSections(List.of())
.palettes(List.of())
.nodeDescriptions(List.of(this.getNodeDescription(UUID.randomUUID().toString())))
.edgeDescriptions(List.of())
.dropHandler(variableManager -> new Failure(""))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.sirius.components.collaborative.diagrams.api.DiagramImageConstants;
import org.eclipse.sirius.components.collaborative.diagrams.api.IToolSectionsProvider;
import org.eclipse.sirius.components.collaborative.diagrams.api.IPaletteProvider;
import org.eclipse.sirius.components.collaborative.diagrams.dto.ITool;
import org.eclipse.sirius.components.collaborative.diagrams.dto.Palette;
import org.eclipse.sirius.components.collaborative.diagrams.dto.SingleClickOnDiagramElementTool;
import org.eclipse.sirius.components.collaborative.diagrams.dto.SingleClickOnTwoDiagramElementsCandidate;
import org.eclipse.sirius.components.collaborative.diagrams.dto.SingleClickOnTwoDiagramElementsTool;
Expand Down Expand Up @@ -63,15 +64,15 @@
* @author arichard
*/
@Service
public class CompatibilityToolSectionsProvider implements IToolSectionsProvider {
public class CompatibilityPaletteProvider implements IPaletteProvider {

private final IIdentifierProvider identifierProvider;

private final IODesignRegistry odesignRegistry;

private final IAQLInterpreterFactory interpreterFactory;

public CompatibilityToolSectionsProvider(IIdentifierProvider identifierProvider, IODesignRegistry odesignRegistry, IAQLInterpreterFactory interpreterFactory) {
public CompatibilityPaletteProvider(IIdentifierProvider identifierProvider, IODesignRegistry odesignRegistry, IAQLInterpreterFactory interpreterFactory) {
this.identifierProvider = Objects.requireNonNull(identifierProvider);
this.odesignRegistry = Objects.requireNonNull(odesignRegistry);
this.interpreterFactory = Objects.requireNonNull(interpreterFactory);
Expand All @@ -83,60 +84,65 @@ public boolean canHandle(DiagramDescription diagramDescription) {
}

@Override
public List<ToolSection> handle(Object targetElement, Object diagramElement, Object diagramElementDescription, DiagramDescription diagramDescription) {
public Palette handle(Object targetElement, Object diagramElement, Object diagramElementDescription, DiagramDescription diagramDescription) {
var optionalVsmElementId = this.identifierProvider.findVsmElementId(diagramDescription.getId());

// @formatter:off
var optionalSiriusDiagramDescription = this.odesignRegistry.getODesigns().stream()
.map(EObject::eResource)
.map(resource -> resource.getResourceSet().getEObject(URI.createURI(optionalVsmElementId.get()), false))
.filter(Objects::nonNull)
.filter(org.eclipse.sirius.diagram.description.DiagramDescription.class::isInstance)
.map(org.eclipse.sirius.diagram.description.DiagramDescription.class::cast)
.findFirst();
// @formatter:on

List<ToolSection> toolSections = new ArrayList<>();
if (optionalSiriusDiagramDescription.isPresent()) {
org.eclipse.sirius.diagram.description.DiagramDescription siriusDiagramDescription = optionalSiriusDiagramDescription.get();
// @formatter:off
List<ToolSection> filteredToolSections = this.getToolSectionFromDiagramDescriptionToolSection(diagramDescription).stream()
.map(toolSection -> this.filteredTools(targetElement, diagramElement, toolSection, siriusDiagramDescription, diagramElementDescription))
.filter(toolSection -> !toolSection.tools().isEmpty())
.toList();
// @formatter:on

toolSections.addAll(filteredToolSections);
toolSections.addAll(this.createExtraToolSections(diagramElementDescription));
}
return toolSections;
String paletteId = "siriusComponents://palette?diagramId=" + optionalVsmElementId.get();
return Palette.newPalette(paletteId).tools(List.of()).toolSections(toolSections).build();
}

private List<ToolSection> getToolSectionFromDiagramDescriptionToolSection(DiagramDescription diagramDescription) {
List<ToolSection> toolSections = new ArrayList<>();
diagramDescription.getToolSections().forEach(toolSection -> {
List<ITool> tools = new ArrayList<>();
toolSection.getTools().forEach(tool -> {
if (tool instanceof org.eclipse.sirius.components.diagrams.tools.SingleClickOnDiagramElementTool singleClickOnDiagramElementTool) {
SingleClickOnDiagramElementTool convertedTool = new SingleClickOnDiagramElementTool(singleClickOnDiagramElementTool.getId(), singleClickOnDiagramElementTool.getLabel(), singleClickOnDiagramElementTool.getImageURL(), singleClickOnDiagramElementTool.getTargetDescriptions(), singleClickOnDiagramElementTool.getSelectionDescriptionId(), singleClickOnDiagramElementTool.isAppliesToDiagramRoot());
tools.add(convertedTool);
}
if (tool instanceof org.eclipse.sirius.components.diagrams.tools.SingleClickOnTwoDiagramElementsTool singleClickOnTwoDiagramElementsTool) {
List<SingleClickOnTwoDiagramElementsCandidate> candidates = new ArrayList<>();
singleClickOnTwoDiagramElementsTool.getCandidates().forEach(candidate -> {
SingleClickOnTwoDiagramElementsCandidate convertedCandidate = new SingleClickOnTwoDiagramElementsCandidate(candidate.getSources(), candidate.getTargets());
candidates.add(convertedCandidate);
});
SingleClickOnTwoDiagramElementsTool convertedTool = new SingleClickOnTwoDiagramElementsTool(singleClickOnTwoDiagramElementsTool.getId(), singleClickOnTwoDiagramElementsTool.getLabel(), singleClickOnTwoDiagramElementsTool.getImageURL(), candidates);
tools.add(convertedTool);
}
});
ToolSection convertedToolSection = new ToolSection(toolSection.getId(), toolSection.getLabel(), toolSection.getImageURL(), tools);
diagramDescription.getPalettes().forEach(palette -> {
List<ITool> tools = palette.getTools().stream().map(this::convertTool).filter(Objects::nonNull).toList();
ToolSection convertedToolSection = new ToolSection(palette.getId(), "", "", tools);
toolSections.add(convertedToolSection);
});
diagramDescription.getPalettes().stream()
.flatMap(palette -> palette.getToolSections().stream())
.forEach(toolSection -> {
List<ITool> tools = toolSection.getTools().stream().map(this::convertTool).filter(Objects::nonNull).toList();
ToolSection convertedToolSection = new ToolSection(toolSection.getId(), toolSection.getLabel(), toolSection.getImageURL(), tools);
toolSections.add(convertedToolSection);
});
return toolSections;
}

private ITool convertTool(org.eclipse.sirius.components.diagrams.tools.ITool tool) {
ITool convertedTool = null;
if (tool instanceof org.eclipse.sirius.components.diagrams.tools.SingleClickOnDiagramElementTool singleClickOnDiagramElementTool) {
convertedTool = new SingleClickOnDiagramElementTool(singleClickOnDiagramElementTool.getId(), singleClickOnDiagramElementTool.getLabel(), singleClickOnDiagramElementTool.getImageURL(), singleClickOnDiagramElementTool.getTargetDescriptions(), singleClickOnDiagramElementTool.getSelectionDescriptionId(), singleClickOnDiagramElementTool.isAppliesToDiagramRoot());
}
if (tool instanceof org.eclipse.sirius.components.diagrams.tools.SingleClickOnTwoDiagramElementsTool singleClickOnTwoDiagramElementsTool) {
List<SingleClickOnTwoDiagramElementsCandidate> candidates = new ArrayList<>();
singleClickOnTwoDiagramElementsTool.getCandidates().forEach(candidate -> {
SingleClickOnTwoDiagramElementsCandidate convertedCandidate = new SingleClickOnTwoDiagramElementsCandidate(candidate.getSources(), candidate.getTargets());
candidates.add(convertedCandidate);
});
convertedTool = new SingleClickOnTwoDiagramElementsTool(singleClickOnTwoDiagramElementsTool.getId(), singleClickOnTwoDiagramElementsTool.getLabel(), singleClickOnTwoDiagramElementsTool.getImageURL(), candidates);
}
return convertedTool;
}

private ToolSection filteredTools(Object targetElement, Object diagramElement, ToolSection toolSection, org.eclipse.sirius.diagram.description.DiagramDescription siriusDiagramDescription,
Object diagramElementDescription) {
// @formatter:off
Expand Down Expand Up @@ -245,9 +251,9 @@ private String getDescriptionId(Object diagramElementDescription) {
if (diagramElementDescription instanceof DiagramDescription) {
descriptionId = ((DiagramDescription) diagramElementDescription).getId();
} else if (diagramElementDescription instanceof NodeDescription) {
descriptionId = ((NodeDescription) diagramElementDescription).getId().toString();
descriptionId = ((NodeDescription) diagramElementDescription).getId();
} else if (diagramElementDescription instanceof EdgeDescription) {
descriptionId = ((EdgeDescription) diagramElementDescription).getId().toString();
descriptionId = ((EdgeDescription) diagramElementDescription).getId();
}
return descriptionId;
}
Expand Down
Loading

0 comments on commit 293c464

Please sign in to comment.