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
Signed-off-by: Florian ROUËNÉ <florian.rouene@obeosoft.com>
  • Loading branch information
frouene authored and pcdavid committed Sep 1, 2023
1 parent cfccbf4 commit 10dc4d1
Show file tree
Hide file tree
Showing 90 changed files with 4,380 additions and 639 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ As a result the development of applications consuming Sirius Components packages
- 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/2117[#2117] [form] Add a modal to select new values for multi-valued references
- https://github.com/eclipse-sirius/sirius-web/issues/2118[#2118] [form] Add a modal to create new objects on a widget reference
- https://github.com/eclipse-sirius/sirius-web/issues/2253[#2253] [diagram] Add the possibility of organizing palette tools into sections

=== Improvements

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('not.exist');
cy.get('[data-value="Target Edge End Reconnection Tool"]').should('not.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 10dc4d1

Please sign in to comment.