Skip to content

Commit

Permalink
[3873] Add the SelectionDialog on the EdgeTool
Browse files Browse the repository at this point in the history
Bug: #3873
Signed-off-by: Florian Barbin <florian.barbin@obeo.fr>
  • Loading branch information
florianbarbin committed Oct 8, 2024
1 parent b456b93 commit f2be467
Show file tree
Hide file tree
Showing 48 changed files with 705 additions and 185 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ The new endpoints are:
description (optional).
** deleteProject (`POST /api/rest/projects/{projectId}`): Delete the project with the given id (projectId).
** updateProject (`PUT /projects/{projectId}`): Update the project with the given id (projectId).
- https://github.com/eclipse-sirius/sirius-web/issues/3873[#3873] [diagram] Make the Selection Dialog available for the EdgeTool

=== Improvements

Expand Down Expand Up @@ -200,6 +201,7 @@ Introduce new `IRewriteProxiesResourceFilter` interface, to register resource fi
image:doc/screenshots/treeItemLabelStyled.jpg[StyledString, 70%]
- https://github.com/eclipse-sirius/sirius-web/issues/3963[#3963] [core] Add support for optional GraphQLCodeRegistry post-processing/transformation.


=== Improvements

- https://github.com/eclipse-sirius/sirius-web/issues/3744[#3744] [diagram] Add support for helper lines during multi selection move
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private ITool convertTool(org.eclipse.sirius.components.diagrams.tools.ITool too
candidates.add(convertedCandidate);
});
convertedTool = new SingleClickOnTwoDiagramElementsTool(singleClickOnTwoDiagramElementsTool.getId(), singleClickOnTwoDiagramElementsTool.getLabel(),
singleClickOnTwoDiagramElementsTool.getIconURL(), candidates);
singleClickOnTwoDiagramElementsTool.getIconURL(), candidates, null);
}
return convertedTool;
}
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 All @@ -18,12 +18,15 @@
import java.util.stream.Stream;

import org.eclipse.sirius.components.collaborative.diagrams.api.IToolService;
import org.eclipse.sirius.components.collaborative.diagrams.dto.ToolVariable;
import org.eclipse.sirius.components.core.api.IEditingContext;
import org.eclipse.sirius.components.core.api.IObjectService;
import org.eclipse.sirius.components.core.api.IRepresentationDescriptionSearchService;
import org.eclipse.sirius.components.diagrams.Diagram;
import org.eclipse.sirius.components.diagrams.description.DiagramDescription;
import org.eclipse.sirius.components.diagrams.tools.ITool;
import org.eclipse.sirius.components.diagrams.tools.Palette;
import org.eclipse.sirius.components.representations.VariableManager;
import org.springframework.stereotype.Service;

/**
Expand All @@ -34,10 +37,15 @@
@Service
public class ToolService implements IToolService {

private static final String OBJECT_ID_ARRAY_SEPARATOR = ",";

private final IRepresentationDescriptionSearchService representationDescriptionSearchService;

public ToolService(IRepresentationDescriptionSearchService representationDescriptionSearchService) {
private final IObjectService objectService;

public ToolService(IRepresentationDescriptionSearchService representationDescriptionSearchService, IObjectService objectService) {
this.representationDescriptionSearchService = Objects.requireNonNull(representationDescriptionSearchService);
this.objectService = Objects.requireNonNull(objectService);
}

private List<Palette> getPalettes(IEditingContext editingContext, Diagram diagram) {
Expand All @@ -61,4 +69,31 @@ public Optional<ITool> findToolById(IEditingContext editingContext, Diagram diag
.findFirst();
}

@Override
public void addToolVariablesInVariableManager(List<ToolVariable> toolvariables, IEditingContext editingContext, VariableManager variableManager) {
toolvariables.forEach(toolVariable -> this.handleToolVariable(toolVariable, editingContext, variableManager));
}

private void handleToolVariable(ToolVariable toolvariable, IEditingContext editingContext, VariableManager variableManager) {
switch (toolvariable.type()) {
case STRING -> variableManager.put(toolvariable.name(), toolvariable.value());
case OBJECT_ID -> {
var optionalObject = this.objectService.getObject(editingContext, toolvariable.value());
variableManager.put(toolvariable.name(), optionalObject.orElse(null));
}
case OBJECT_ID_ARRAY -> {
String value = toolvariable.value();
List<String> objectsIds = List.of(value.split(OBJECT_ID_ARRAY_SEPARATOR));
List<Object> objects = objectsIds.stream()
.map(objectId -> this.objectService.getObject(editingContext, objectId))
.map(optionalObject -> optionalObject.orElse(null))
.toList();
variableManager.put(toolvariable.name(), objects);
}
default -> {
//We do nothing, the variable type is not supported
}
}
}

}
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,11 +12,14 @@
*******************************************************************************/
package org.eclipse.sirius.components.collaborative.diagrams.api;

import java.util.List;
import java.util.Optional;

import org.eclipse.sirius.components.collaborative.diagrams.dto.ToolVariable;
import org.eclipse.sirius.components.core.api.IEditingContext;
import org.eclipse.sirius.components.diagrams.Diagram;
import org.eclipse.sirius.components.diagrams.tools.ITool;
import org.eclipse.sirius.components.representations.VariableManager;

/**
* Interface used to manipulate tools.
Expand All @@ -27,6 +30,11 @@ public interface IToolService {

Optional<ITool> findToolById(IEditingContext editingContext, Diagram diagram, String toolId);

/**
* Used to compute and add variables providing by the tool from the graphQL API to the {@link VariableManager}.
*/
void addToolVariablesInVariableManager(List<ToolVariable> toolvariables, IEditingContext editingContext, VariableManager variableManager);

/**
* Implementation which does nothing, used for mocks in unit tests.
*
Expand All @@ -37,5 +45,9 @@ class NoOp implements IToolService {
public Optional<ITool> findToolById(IEditingContext editingContext, Diagram diagram, String toolId) {
return Optional.empty();
}

@Override
public void addToolVariablesInVariableManager(List<ToolVariable> toolvariables, IEditingContext editingContext, VariableManager variableManager) {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*******************************************************************************/
package org.eclipse.sirius.components.collaborative.diagrams.dto;

import java.util.List;
import java.util.UUID;

import org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramInput;
Expand All @@ -32,5 +33,6 @@ public record InvokeSingleClickOnTwoDiagramElementsToolInput(
double sourcePositionY,
double targetPositionX,
double targetPositionY,
String toolId) implements IDiagramInput {
String toolId,
List<ToolVariable> variables) implements IDiagramInput {
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023 Obeo.
* Copyright (c) 2023, 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 @@ -20,7 +20,7 @@
*
* @author mcharfadi
*/
public record SingleClickOnTwoDiagramElementsTool(String id, String label, List<String> iconURL, List<SingleClickOnTwoDiagramElementsCandidate> candidates) implements ITool {
public record SingleClickOnTwoDiagramElementsTool(String id, String label, List<String> iconURL, List<SingleClickOnTwoDiagramElementsCandidate> candidates, String dialogDescriptionId) implements ITool {

public SingleClickOnTwoDiagramElementsTool {
Objects.requireNonNull(id);
Expand Down Expand Up @@ -50,6 +50,8 @@ public static final class Builder {

private List<SingleClickOnTwoDiagramElementsCandidate> candidates;

private String dialogDescriptionId;

private Builder(String id) {
this.id = Objects.requireNonNull(id);
}
Expand All @@ -69,8 +71,13 @@ public SingleClickOnTwoDiagramElementsTool.Builder candidates(List<SingleClickOn
return this;
}

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

public SingleClickOnTwoDiagramElementsTool build() {
return new SingleClickOnTwoDiagramElementsTool(this.id, this.label, this.iconURL, this.candidates);
return new SingleClickOnTwoDiagramElementsTool(this.id, this.label, this.iconURL, this.candidates, this.dialogDescriptionId);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
@Service
public class InvokeSingleClickOnDiagramElementToolEventHandler implements IDiagramEventHandler {

private static final String OBJECT_ID_ARRAY_SEPARATOR = ",";

private final Logger logger = LoggerFactory.getLogger(InvokeSingleClickOnDiagramElementToolEventHandler.class);

Expand Down Expand Up @@ -142,9 +141,7 @@ private IStatus executeTool(IEditingContext editingContext, IDiagramContext diag
if (self.isPresent()) {
VariableManager variableManager = this.populateVariableManager(editingContext, diagramContext, node, edge, self);
var dialogDescriptionId = tool.getDialogDescriptionId();
if (dialogDescriptionId != null) {
variables.forEach(toolVariable -> this.handleToolVariable(toolVariable, editingContext, variableManager));
}
this.toolService.addToolVariablesInVariableManager(variables, editingContext, variableManager);

//We do not apply the tool if a dialog is defined but no variables have been provided
if (dialogDescriptionId == null || !variables.isEmpty()) {
Expand All @@ -154,26 +151,6 @@ private IStatus executeTool(IEditingContext editingContext, IDiagramContext diag
return result;
}

private void handleToolVariable(ToolVariable toolvariable, IEditingContext editingContext, VariableManager variableManager) {
switch (toolvariable.type()) {
case STRING -> variableManager.put(toolvariable.name(), toolvariable.value());
case OBJECT_ID -> {
var optionalObject = this.objectService.getObject(editingContext, toolvariable.value());
variableManager.put(toolvariable.name(), optionalObject.orElse(null));
}
case OBJECT_ID_ARRAY -> {
String value = toolvariable.value();
List<String> objectsIds = List.of(value.split(OBJECT_ID_ARRAY_SEPARATOR));
List<Object> objects = objectsIds.stream()
.map(objectId -> this.objectService.getObject(editingContext, objectId))
.map(optionalObject -> optionalObject.orElse(null))
.toList();
variableManager.put(toolvariable.name(), objects);
}
default -> this.logger.warn("Unexpected value: " + toolvariable.type());
}
}

private Optional<Object> getCurrentContext(IEditingContext editingContext, String diagramElementId, SingleClickOnDiagramElementTool tool, Diagram diagram, Optional<Node> node,
Optional<Edge> edge) {
Optional<Object> self = Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDesc
.map(SingleClickOnTwoDiagramElementsTool.class::cast)
.or(this.findConnectorToolById(input.diagramSourceElementId(), input.diagramTargetElementId(), editingContext, diagram, input.toolId()));
if (optionalTool.isPresent()) {
IStatus status = this.executeTool(editingContext, diagramContext, input.diagramSourceElementId(), input.diagramTargetElementId(), optionalTool.get());
IStatus status = this.executeTool(editingContext, diagramContext, input, optionalTool.get());
if (status instanceof Success success) {
WorkbenchSelection newSelection = null;
Object newSelectionParameter = success.getParameters().get(Success.NEW_SELECTION);
Expand All @@ -131,7 +131,9 @@ public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDesc
changeDescriptionSink.tryEmitNext(changeDescription);
}

private IStatus executeTool(IEditingContext editingContext, IDiagramContext diagramContext, String sourceNodeId, String targetNodeId, SingleClickOnTwoDiagramElementsTool tool) {
private IStatus executeTool(IEditingContext editingContext, IDiagramContext diagramContext, InvokeSingleClickOnTwoDiagramElementsToolInput input, SingleClickOnTwoDiagramElementsTool tool) {
String sourceNodeId = input.diagramSourceElementId();
String targetNodeId = input.diagramTargetElementId();
IStatus result = new Failure("");
Diagram diagram = diagramContext.getDiagram();
Optional<Node> sourceNode = this.diagramQueryService.findNodeById(diagram, sourceNodeId);
Expand All @@ -157,6 +159,7 @@ private IStatus executeTool(IEditingContext editingContext, IDiagramContext diag
variableManager.put(EdgeDescription.SEMANTIC_EDGE_TARGET, target.get());
variableManager.put(EdgeDescription.EDGE_SOURCE, sourceView);
variableManager.put(EdgeDescription.EDGE_TARGET, targetView);
this.toolService.addToolVariablesInVariableManager(input.variables(), editingContext, variableManager);

result = tool.getHandler().apply(variableManager);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ type SingleClickOnTwoDiagramElementsTool implements Tool {
id: ID!
label: String!
iconURL: [String!]!
dialogDescriptionId: String
candidates: [SingleClickOnTwoDiagramElementsCandidate]!
}

Expand Down Expand Up @@ -436,6 +437,7 @@ input InvokeSingleClickOnTwoDiagramElementsToolInput {
sourcePositionY: Float!
targetPositionX: Float!
targetPositionY: Float!
variables: [ToolVariable!]!
}

union InvokeSingleClickOnTwoDiagramElementsToolPayload = ErrorPayload | InvokeSingleClickOnTwoDiagramElementsToolSuccessPayload
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.eclipse.sirius.components.collaborative.api.ChangeDescription;
import org.eclipse.sirius.components.collaborative.api.ChangeKind;
import org.eclipse.sirius.components.collaborative.diagrams.DiagramContext;
import org.eclipse.sirius.components.collaborative.diagrams.ToolService;
import org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramContext;
import org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramQueryService;
import org.eclipse.sirius.components.collaborative.diagrams.api.IToolService;
Expand All @@ -37,6 +38,7 @@
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.ArrowStyle;
import org.eclipse.sirius.components.diagrams.CollapsingState;
import org.eclipse.sirius.components.diagrams.Diagram;
Expand Down Expand Up @@ -241,7 +243,7 @@ public Optional<Node> findNodeById(Diagram diagram, String nodeId) {

var tool = this.createTool(TOOL_ID, false, List.of(nodeDescription), DIALOG_DESCRIPTION_ID, toolHandler);

var toolService = new IToolService.NoOp() {
var toolService = new ToolService(new IRepresentationDescriptionSearchService.NoOp(), objectService) {
@Override
public Optional<ITool> findToolById(IEditingContext editingContext, Diagram diagram, String toolId) {
return Optional.of(tool);
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 @@ -40,6 +40,8 @@ public final class SingleClickOnTwoDiagramElementsTool implements ITool {

private List<SingleClickOnTwoDiagramElementsCandidate> candidates;

private String dialogDescriptionId;

private SingleClickOnTwoDiagramElementsTool() {
// Prevent instantiation
}
Expand Down Expand Up @@ -72,6 +74,10 @@ public Function<VariableManager, IStatus> getHandler() {
return this.handler;
}

public String getDialogDescriptionId() {
return this.dialogDescriptionId;
}

@Override
public String toString() {
String pattern = "{0} '{'id: {1}, label: {2}'}'";
Expand All @@ -96,6 +102,8 @@ public static final class Builder {

private List<SingleClickOnTwoDiagramElementsCandidate> candidates;

private String dialogDescriptionId;

private Builder(String id) {
this.id = Objects.requireNonNull(id);
}
Expand All @@ -120,13 +128,20 @@ public Builder handler(Function<VariableManager, IStatus> handler) {
return this;
}

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

public SingleClickOnTwoDiagramElementsTool build() {
SingleClickOnTwoDiagramElementsTool tool = new SingleClickOnTwoDiagramElementsTool();
tool.id = Objects.requireNonNull(this.id);
tool.iconURL = Objects.requireNonNull(this.iconURL);
tool.label = Objects.requireNonNull(this.label);
tool.handler = Objects.requireNonNull(this.handler);
tool.candidates = Objects.requireNonNull(this.candidates);
//The dialog description id can be null.
tool.dialogDescriptionId = this.dialogDescriptionId;
return tool;
}
}
Expand Down
Loading

0 comments on commit f2be467

Please sign in to comment.