Skip to content

Commit

Permalink
[2759] Provides the dialog type value in the NodeTool
Browse files Browse the repository at this point in the history
The front needs to know which kind of dialog it has to retrieve in the extension-point

Bug: #2759
Signed-off-by: Florian Barbin <[email protected]>
  • Loading branch information
florianbarbin committed Jun 25, 2024
1 parent 45357b8 commit f048137
Show file tree
Hide file tree
Showing 22 changed files with 215 additions and 86 deletions.
29 changes: 29 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,35 @@ More existing APIs will be migrated to this new common pattern.
- https://github.com/eclipse-sirius/sirius-web/issues/3634[#3634] [sirius-web] Remove `GraphQLNodeStyleFragment` from `NodeTypeRegistry`, you can specify additional fields to be retreived by the subscription using the `DocumentTransform` GraphQL API and the `apolloClientOptionsConfigurersExtensionPoint` extension point
- https://github.com/eclipse-sirius/sirius-web/issues/3641[#3641] [core] `IRepresentationMetadataProvider` now defined a single method `Optional<RepresentationMetadata> getMetadata(String representationId)` instead of separate `canHandle` and `handle` methods.

- https://github.com/eclipse-sirius/sirius-web/issues/2759[#2759] [diagram] Update the diagram GraphQL API.

* The `InvokeSingleClickOnDiagramElementToolInput#selectedObjectId` has been replaced by a `variables: [ToolVariable!]!` to make it possible to provide any kind of variable to the backend context.

```
input InvokeSingleClickOnDiagramElementToolInput {
id: ID!
editingContextId: ID!
representationId: ID!
variables: [ToolVariable!]!
diagramElementId: ID!
startingPositionX: Float!
startingPositionY: Float!
toolId: ID!
}
```

* The `SingleClickOnDiagramElementTool#dialogDescriptionId` has been replaced by a `dialog: Dialog` field to provide the information about the dialog that the frontend needs to retrieve in the extension point.
```
type SingleClickOnDiagramElementTool implements Tool {
id: ID!
label: String!
iconURL: [String!]!
appliesToDiagramRoot: Boolean!
dialog: Dialog
targetDescriptions: [DiagramElementDescription!]!
}
```

=== Dependency update

- https://github.com/eclipse-sirius/sirius-web/issues/3510[#3510] [releng] Switch to Spring Boot 3.2.5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private ITool convertTool(org.eclipse.sirius.components.diagrams.tools.ITool too
if (tool instanceof org.eclipse.sirius.components.diagrams.tools.SingleClickOnDiagramElementTool singleClickOnDiagramElementTool) {
convertedTool = new SingleClickOnDiagramElementTool(singleClickOnDiagramElementTool.getId(), singleClickOnDiagramElementTool.getLabel(),
singleClickOnDiagramElementTool.getIconURL(), singleClickOnDiagramElementTool.getTargetDescriptions(),
singleClickOnDiagramElementTool.getDialogDescriptionId(), singleClickOnDiagramElementTool.isAppliesToDiagramRoot());
singleClickOnDiagramElementTool.getDialog(), singleClickOnDiagramElementTool.isAppliesToDiagramRoot());
}
if (tool instanceof org.eclipse.sirius.components.diagrams.tools.SingleClickOnTwoDiagramElementsTool singleClickOnTwoDiagramElementsTool) {
List<SingleClickOnTwoDiagramElementsCandidate> candidates = new ArrayList<>();
Expand Down Expand Up @@ -314,20 +314,20 @@ private List<ToolSection> createExtraToolSections(Object diagramElementDescripti
// Graphical Delete Tool for unsynchronized mapping only (the handler is never called)
if (diagramElementDescription instanceof NodeDescription || diagramElementDescription instanceof EdgeDescription) {
// Edit Tool (the handler is never called)
SingleClickOnDiagramElementTool editTool = new SingleClickOnDiagramElementTool("edit", "Edit", List.of(DiagramImageConstants.EDIT_SVG), targetDescriptions, "", false);
SingleClickOnDiagramElementTool editTool = new SingleClickOnDiagramElementTool("edit", "Edit", List.of(DiagramImageConstants.EDIT_SVG), targetDescriptions, null, false);
var editToolSection = new ToolSection("edit-section", "", List.of(), List.of(editTool));
extraToolSections.add(editToolSection);

if (unsynchronizedMapping) {
SingleClickOnDiagramElementTool graphicalDeleteTool = new SingleClickOnDiagramElementTool("graphical-delete", "Delete from diagram",
List.of(DiagramImageConstants.GRAPHICAL_DELETE_SVG), targetDescriptions, "", false);
List.of(DiagramImageConstants.GRAPHICAL_DELETE_SVG), targetDescriptions, null, false);
var graphicalDeleteToolSection = new ToolSection("graphical-delete-section", "", List.of(), List.of(graphicalDeleteTool));
extraToolSections.add(graphicalDeleteToolSection);
}

// Semantic Delete Tool (the handler is never called)
SingleClickOnDiagramElementTool semanticDeleteTool = new SingleClickOnDiagramElementTool("semantic-delete", "Delete from model",
List.of(DiagramImageConstants.SEMANTIC_DELETE_SVG), targetDescriptions, "", false);
List.of(DiagramImageConstants.SEMANTIC_DELETE_SVG), targetDescriptions, null, false);
var graphicalDeleteToolSection = new ToolSection("semantic-delete-section", "", List.of(), List.of(semanticDeleteTool));
extraToolSections.add(graphicalDeleteToolSection);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.eclipse.sirius.components.diagrams.description.EdgeDescription;
import org.eclipse.sirius.components.diagrams.description.IDiagramElementDescription;
import org.eclipse.sirius.components.diagrams.description.NodeDescription;
import org.eclipse.sirius.components.diagrams.tools.Dialog;
import org.eclipse.sirius.components.diagrams.tools.ITool;
import org.eclipse.sirius.components.diagrams.tools.Palette;
import org.eclipse.sirius.components.diagrams.tools.SingleClickOnDiagramElementTool;
Expand All @@ -45,6 +46,7 @@
import org.eclipse.sirius.components.representations.IStatus;
import org.eclipse.sirius.components.representations.Success;
import org.eclipse.sirius.components.representations.VariableManager;
import org.eclipse.sirius.components.selection.description.SelectionDescription;
import org.eclipse.sirius.diagram.description.AbstractNodeMapping;
import org.eclipse.sirius.diagram.description.AdditionalLayer;
import org.eclipse.sirius.diagram.description.ContainerMapping;
Expand Down Expand Up @@ -234,18 +236,17 @@ private SingleClickOnDiagramElementTool convertNodeCreationDescription(Map<Strin
List<String> imagePath = this.toolImageProvider.getIcon(nodeCreationTool);
List<IDiagramElementDescription> targetDescriptions = this.getParentNodeDescriptions(nodeCreationTool.getNodeMappings(), id2NodeDescriptions);
var selectModelElementVariableOpt = new SelectModelElementVariableProvider().getSelectModelElementVariable(nodeCreationTool.getVariable());
String dialogDescriptionId = null;
if (selectModelElementVariableOpt.isPresent()) {
dialogDescriptionId = this.identifierProvider.getIdentifier(selectModelElementVariableOpt.get());
}
Dialog dialog = selectModelElementVariableOpt
.map(selectModelElementVariable -> new Dialog(this.identifierProvider.getIdentifier(selectModelElementVariable), SelectionDescription.TYPE))
.orElse(null);
// @formatter:off
return SingleClickOnDiagramElementTool.newSingleClickOnDiagramElementTool(id)
.label(label)
.iconURL(imagePath)
.handler(this.createNodeCreationHandler(interpreter, nodeCreationTool))
.targetDescriptions(targetDescriptions)
.appliesToDiagramRoot(this.atLeastOneRootMapping(nodeCreationTool.getNodeMappings()))
.dialogDescriptionId(dialogDescriptionId)
.dialog(dialog)
.build();
// @formatter:on
}
Expand All @@ -257,18 +258,17 @@ private SingleClickOnDiagramElementTool convertContainerCreationDescription(Map<
List<String> imagePath = this.toolImageProvider.getIcon(containerCreationDescription);
List<IDiagramElementDescription> targetDescriptions = this.getParentNodeDescriptions(containerCreationDescription.getContainerMappings(), id2NodeDescriptions);
var selectModelElementVariableOpt = new SelectModelElementVariableProvider().getSelectModelElementVariable(containerCreationDescription.getVariable());
String dialogDescriptionId = null;
if (selectModelElementVariableOpt.isPresent()) {
dialogDescriptionId = this.identifierProvider.getIdentifier(selectModelElementVariableOpt.get());
}
Dialog dialog = selectModelElementVariableOpt
.map(selectModelElementVariable -> new Dialog(this.identifierProvider.getIdentifier(selectModelElementVariable), SelectionDescription.TYPE))
.orElse(null);
// @formatter:off
return SingleClickOnDiagramElementTool.newSingleClickOnDiagramElementTool(id)
.label(label)
.iconURL(imagePath)
.handler(this.createContainerCreationHandler(interpreter, containerCreationDescription))
.targetDescriptions(targetDescriptions)
.appliesToDiagramRoot(this.atLeastOneRootMapping(containerCreationDescription.getContainerMappings()))
.dialogDescriptionId(dialogDescriptionId)
.dialog(dialog)
.build();
// @formatter:on
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
import java.util.Objects;

import org.eclipse.sirius.components.diagrams.description.IDiagramElementDescription;
import org.eclipse.sirius.components.diagrams.tools.Dialog;

/**
* A tool triggered by a single click in the palette on a diagram element.
*
* @author mcharfadi
*/
public record SingleClickOnDiagramElementTool(String id, String label, List<String> iconURL, List<IDiagramElementDescription> targetDescriptions, String dialogDescriptionId,
public record SingleClickOnDiagramElementTool(String id, String label, List<String> iconURL, List<IDiagramElementDescription> targetDescriptions, Dialog dialog,
boolean appliesToDiagramRoot) implements ITool {

public SingleClickOnDiagramElementTool {
Expand Down Expand Up @@ -53,7 +54,7 @@ public static final class Builder {

private List<IDiagramElementDescription> targetDescriptions;

private String dialogDescriptionId;
private Dialog dialog;

private boolean appliesToDiagramRoot;

Expand Down Expand Up @@ -81,13 +82,13 @@ public Builder appliesToDiagramRoot(boolean appliesToDiagramRoot) {
return this;
}

public Builder dialogDescriptionId(String dialogDescriptionId) {
this.dialogDescriptionId = dialogDescriptionId;
public Builder dialog(Dialog dialog) {
this.dialog = dialog;
return this;
}

public SingleClickOnDiagramElementTool build() {
return new SingleClickOnDiagramElementTool(this.id, this.label, this.iconURL, this.targetDescriptions, this.dialogDescriptionId, this.appliesToDiagramRoot);
return new SingleClickOnDiagramElementTool(this.id, this.label, this.iconURL, this.targetDescriptions, this.dialog, this.appliesToDiagramRoot);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.eclipse.sirius.components.core.api.IEditingContext;
import org.eclipse.sirius.components.core.api.IObjectService;
import org.eclipse.sirius.components.core.api.IPayload;
import org.eclipse.sirius.components.core.api.IRepresentationDescriptionSearchService;
import org.eclipse.sirius.components.diagrams.Diagram;
import org.eclipse.sirius.components.diagrams.Edge;
import org.eclipse.sirius.components.diagrams.Node;
Expand Down Expand Up @@ -78,11 +77,8 @@ public class InvokeSingleClickOnDiagramElementToolEventHandler implements IDiagr

private final Counter counter;

private final IRepresentationDescriptionSearchService representationDescriptionSearchService;


public InvokeSingleClickOnDiagramElementToolEventHandler(IObjectService objectService, IDiagramQueryService diagramQueryService, IToolService toolService,
ICollaborativeDiagramMessageService messageService, MeterRegistry meterRegistry, IRepresentationDescriptionSearchService representationDescriptionSearchService) {
ICollaborativeDiagramMessageService messageService, MeterRegistry meterRegistry) {
this.objectService = Objects.requireNonNull(objectService);
this.diagramQueryService = Objects.requireNonNull(diagramQueryService);
this.toolService = Objects.requireNonNull(toolService);
Expand All @@ -93,8 +89,6 @@ public InvokeSingleClickOnDiagramElementToolEventHandler(IObjectService objectSe
.tag(Monitoring.NAME, this.getClass().getSimpleName())
.register(meterRegistry);
// @formatter:on

this.representationDescriptionSearchService = Objects.requireNonNull(representationDescriptionSearchService);
}

@Override
Expand Down Expand Up @@ -154,13 +148,13 @@ private IStatus executeTool(IEditingContext editingContext, IDiagramContext diag

if (self.isPresent()) {
VariableManager variableManager = this.populateVariableManager(editingContext, diagramContext, node, edge, self);
String dialogDescriptionId = tool.getDialogDescriptionId();
if (dialogDescriptionId != null && !variables.isEmpty()) {
var dialog = tool.getDialog();
if (dialog != null && !variables.isEmpty()) {
this.handleDialogVariables(editingContext, variableManager, variables);
}

//We do not apply the tool if a dialog is defined but no variables have been provided
if (dialogDescriptionId == null || !variables.isEmpty()) {
if (dialog == null || !variables.isEmpty()) {
result = tool.getHandler().apply(variableManager);
Position newPosition = Position.at(startingPositionX, startingPositionY);
diagramContext.getDiagramEvents().add(new SinglePositionEvent(diagramElementId, newPosition));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,15 @@ type SingleClickOnDiagramElementTool implements Tool {
label: String!
iconURL: [String!]!
appliesToDiagramRoot: Boolean!
dialogDescriptionId: String
dialog: Dialog
targetDescriptions: [DiagramElementDescription!]!
}

type Dialog {
dialogDescriptionId: String!
dialogDescriptionType: String!
}

type SingleClickOnTwoDiagramElementsTool implements Tool {
id: ID!
label: String!
Expand Down
Loading

0 comments on commit f048137

Please sign in to comment.