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 Sep 12, 2024
1 parent 36df83b commit 601cfc5
Show file tree
Hide file tree
Showing 54 changed files with 678 additions and 193 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
=== New Features

- https://github.com/eclipse-sirius/sirius-web/issues/3763[#3763] [diagram] Make it possible to display semantic candidates in the selection dialog using a tree
- https://github.com/eclipse-sirius/sirius-web/issues/3873[#3873] [diagram] Make the Selection Dialog available for the EdgeTool


=== Improvements
Expand Down Expand Up @@ -146,6 +147,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 @@ -63,7 +63,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 @@ -144,9 +143,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 @@ -158,26 +155,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 @@ -120,7 +120,7 @@ public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDesc
if (optionalTool.isPresent()) {
Position sourcePosition = Position.at(input.sourcePositionX(), input.sourcePositionY());
Position targetPosition = Position.at(input.targetPositionX(), input.targetPositionY());
IStatus status = this.executeTool(editingContext, diagramContext, input.diagramSourceElementId(), input.diagramTargetElementId(), optionalTool.get(), sourcePosition, targetPosition);
IStatus status = this.executeTool(editingContext, diagramContext, input, optionalTool.get(), sourcePosition, targetPosition);
if (status instanceof Success success) {
WorkbenchSelection newSelection = null;
Object newSelectionParameter = success.getParameters().get(Success.NEW_SELECTION);
Expand All @@ -139,8 +139,10 @@ 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,
Position sourcePosition, Position targetPosition) {
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 @@ -166,6 +168,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 @@ -299,6 +299,7 @@ type SingleClickOnTwoDiagramElementsTool implements Tool {
id: ID!
label: String!
iconURL: [String!]!
dialogDescriptionId: String
candidates: [SingleClickOnTwoDiagramElementsCandidate]!
}

Expand Down Expand Up @@ -366,8 +367,12 @@ extend type Mutation {
arrangeAll(input: ArrangeAllInput!): ArrangeAllPayload!
deleteFromDiagram(input: DeleteFromDiagramInput!): DeleteFromDiagramPayload!
editLabel(input: EditLabelInput!): EditLabelPayload!
invokeSingleClickOnDiagramElementTool(input: InvokeSingleClickOnDiagramElementToolInput!): InvokeSingleClickOnDiagramElementToolPayload!
invokeSingleClickOnTwoDiagramElementsTool(input: InvokeSingleClickOnTwoDiagramElementsToolInput!): InvokeSingleClickOnTwoDiagramElementsToolPayload!
invokeSingleClickOnDiagramElementTool(
input: InvokeSingleClickOnDiagramElementToolInput!
): InvokeSingleClickOnDiagramElementToolPayload!
invokeSingleClickOnTwoDiagramElementsTool(
input: InvokeSingleClickOnTwoDiagramElementsToolInput!
): InvokeSingleClickOnTwoDiagramElementsToolPayload!
updateNodeBounds(input: UpdateNodeBoundsInput!): UpdateNodeBoundsPayload!
updateNodePosition(input: UpdateNodePositionInput!): UpdateNodePositionPayload!
dropOnDiagram(input: DropOnDiagramInput!): DropOnDiagramPayload!
Expand Down Expand Up @@ -448,10 +453,11 @@ input InvokeSingleClickOnTwoDiagramElementsToolInput {
sourcePositionY: Float!
targetPositionX: Float!
targetPositionY: Float!
variables: [ToolVariable!]!
}

union InvokeSingleClickOnTwoDiagramElementsToolPayload =
ErrorPayload
ErrorPayload
| InvokeSingleClickOnTwoDiagramElementsToolSuccessPayload

type InvokeSingleClickOnTwoDiagramElementsToolSuccessPayload {
Expand Down Expand Up @@ -483,9 +489,7 @@ enum ToolVariableType {
OBJECT_ID_ARRAY
}

union InvokeSingleClickOnDiagramElementToolPayload =
ErrorPayload
| InvokeSingleClickOnDiagramElementToolSuccessPayload
union InvokeSingleClickOnDiagramElementToolPayload = ErrorPayload | InvokeSingleClickOnDiagramElementToolSuccessPayload

type InvokeSingleClickOnDiagramElementToolSuccessPayload {
id: ID!
Expand Down Expand Up @@ -520,9 +524,7 @@ input UpdateNodePositionInput {
newPositionY: Float!
}

union UpdateNodePositionPayload =
ErrorPayload
| UpdateNodePositionSuccessPayload
union UpdateNodePositionPayload = ErrorPayload | UpdateNodePositionSuccessPayload

type UpdateNodePositionSuccessPayload {
id: ID!
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 @@ -243,7 +245,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
Loading

0 comments on commit 601cfc5

Please sign in to comment.