Skip to content

Commit

Permalink
Added the possibility to invoke tools that were declared in different…
Browse files Browse the repository at this point in the history
… View projects.

Bug : eclipse-sirius#1860

Signed-off-by: Michaël Charfadi <[email protected]>
  • Loading branch information
mcharfadi committed Mar 27, 2023
1 parent cb3e909 commit e9beec6
Show file tree
Hide file tree
Showing 12 changed files with 156 additions and 57 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ NodeDescription#descriptionId to siriusComponents://nodeDescription?sourceKind=v
EdgeDescription#descriptionId to vers siriusComponents://edgeDescription?sourceKind=view&sourceId=UUID_OF_DOCUMENT&sourceElementId=UUID_OF_SOURCE_ELEMENT
+
Added a common interface IDiagramElement that is implemented by Node and Edge
+
Added the possibility to invoke tools that were declared in different View projects.

- https://github.com/eclipse-sirius/sirius-components/issues/1643[1643] [core] Removed our dependencies to Spring Security
- https://github.com/eclipse-sirius/sirius-components/issues/1592[#1592] [view] In View-based diagram definition, all tools applicable on a given element are now configured inside the new _Palette_ element directly inside the element (diagram, node or edge) description.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@
import org.eclipse.sirius.components.compatibility.api.IIdentifierProvider;
import org.eclipse.sirius.components.compatibility.services.api.IODesignRegistry;
import org.eclipse.sirius.components.core.api.Environment;
import org.eclipse.sirius.components.core.api.IEditingContext;
import org.eclipse.sirius.components.core.api.IObjectService;
import org.eclipse.sirius.components.diagrams.Diagram;
import org.eclipse.sirius.components.diagrams.Edge;
import org.eclipse.sirius.components.diagrams.IDiagramElement;
import org.eclipse.sirius.components.diagrams.Node;
import org.eclipse.sirius.components.diagrams.description.DiagramDescription;
import org.eclipse.sirius.components.diagrams.description.EdgeDescription;
Expand Down Expand Up @@ -72,10 +76,14 @@ public class CompatibilityToolSectionsProvider implements IToolSectionsProvider

private final IAQLInterpreterFactory interpreterFactory;

public CompatibilityToolSectionsProvider(IIdentifierProvider identifierProvider, IODesignRegistry odesignRegistry, IAQLInterpreterFactory interpreterFactory) {
private final IObjectService objectService;

public CompatibilityToolSectionsProvider(IObjectService objectService, IIdentifierProvider identifierProvider, IODesignRegistry odesignRegistry, IAQLInterpreterFactory interpreterFactory) {
this.objectService = Objects.requireNonNull(objectService);
this.identifierProvider = Objects.requireNonNull(identifierProvider);
this.odesignRegistry = Objects.requireNonNull(odesignRegistry);
this.interpreterFactory = Objects.requireNonNull(interpreterFactory);

}

@Override
Expand All @@ -84,8 +92,15 @@ public boolean canHandle(DiagramDescription diagramDescription) {
}

@Override
public List<ToolSection> handle(Object targetElement, Object diagramElement, Object diagramElementDescription, DiagramDescription diagramDescription) {
var optionalVsmElementId = this.identifierProvider.findVsmElementId(diagramDescription.getId());
public List<ToolSection> handle(Object targetElement, IEditingContext editingContext, Object diagramElementOrDiagram) {
String id = "";
if (diagramElementOrDiagram instanceof Diagram diagram) {
id = this.objectService.getId(diagram.getId());
}
else if (diagramElementOrDiagram instanceof IDiagramElement diagramElement) {
id = this.objectService.getId(diagramElement.getDescriptionId());
}
var optionalVsmElementId = this.identifierProvider.findVsmElementId(id);

// @formatter:off
var optionalSiriusDiagramDescription = this.odesignRegistry.getODesigns().stream()
Expand All @@ -102,14 +117,14 @@ public List<ToolSection> handle(Object targetElement, Object diagramElement, Obj
org.eclipse.sirius.diagram.description.DiagramDescription siriusDiagramDescription = optionalSiriusDiagramDescription.get();

// @formatter:off
List<ToolSection> filteredToolSections = diagramDescription.getToolSections().stream()
/*List<ToolSection> filteredToolSections = ((DiagramDescription)diagramElementOrDiagram).getToolSections().stream()
.map(toolSection -> this.filteredTools(targetElement, diagramElement, toolSection, siriusDiagramDescription, diagramElementDescription))
.filter(toolSection -> !toolSection.getTools().isEmpty())
.toList();
.toList();*/
// @formatter:on

toolSections.addAll(filteredToolSections);
toolSections.addAll(this.createExtraToolSections(diagramElementDescription));
// toolSections.addAll(filteredToolSections);
toolSections.addAll(this.createExtraToolSections(diagramElementOrDiagram));
}
return toolSections;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2020 Obeo.
* Copyright (c) 2019, 2023 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,6 @@
import org.eclipse.sirius.components.collaborative.diagrams.api.IToolService;
import org.eclipse.sirius.components.core.api.IEditingContext;
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.ToolSection;
Expand All @@ -40,20 +39,20 @@ public ToolService(IRepresentationDescriptionSearchService representationDescrip
this.representationDescriptionSearchService = Objects.requireNonNull(representationDescriptionSearchService);
}

private List<ToolSection> getToolSections(IEditingContext editingContext, Diagram diagram) {
private List<ToolSection> getToolSections(IEditingContext editingContext) {
// @formatter:off
return this.representationDescriptionSearchService.findById(editingContext, diagram.getDescriptionId())
.filter(DiagramDescription.class::isInstance)
.map(DiagramDescription.class::cast)
.map(DiagramDescription::getToolSections)
.orElse(List.of());
return this.representationDescriptionSearchService.findAll(editingContext).values().stream()
.filter(DiagramDescription.class::isInstance)
.map(DiagramDescription.class::cast)
.flatMap(diagramDescription -> diagramDescription.getToolSections().stream())
.toList();
// @formatter:on
}

@Override
public Optional<ITool> findToolById(IEditingContext editingContext, Diagram diagram, String toolId) {
public Optional<ITool> findToolById(IEditingContext editingContext, String toolId) {
// @formatter:off
return this.getToolSections(editingContext, diagram)
return this.getToolSections(editingContext)
.stream()
.map(ToolSection::getTools)
.flatMap(Collection::stream)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2022 Obeo.
* Copyright (c) 2022, 2023 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 @@ -14,6 +14,7 @@

import java.util.List;

import org.eclipse.sirius.components.core.api.IEditingContext;
import org.eclipse.sirius.components.diagrams.description.DiagramDescription;
import org.eclipse.sirius.components.diagrams.tools.ToolSection;

Expand All @@ -26,5 +27,5 @@ public interface IToolSectionsProvider {

boolean canHandle(DiagramDescription diagramDescription);

List<ToolSection> handle(Object targetElement, Object diagramElement, Object diagramElementDescription, DiagramDescription diagramDescription);
List<ToolSection> handle(Object targetElement, IEditingContext editingContext, Object diagramElementOrDiagram);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019, 2022 Obeo.
* Copyright (c) 2019, 2023 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 @@ -15,7 +15,6 @@
import java.util.Optional;

import org.eclipse.sirius.components.core.api.IEditingContext;
import org.eclipse.sirius.components.diagrams.Diagram;
import org.eclipse.sirius.components.diagrams.tools.ITool;

/**
Expand All @@ -25,7 +24,7 @@
*/
public interface IToolService {

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

/**
* Implementation which does nothing, used for mocks in unit tests.
Expand All @@ -34,7 +33,7 @@ public interface IToolService {
*/
class NoOp implements IToolService {
@Override
public Optional<ITool> findToolById(IEditingContext editingContext, Diagram diagram, String toolId) {
public Optional<ITool> findToolById(IEditingContext editingContext, String toolId) {
return Optional.empty();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,10 @@ public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDesc
var optionalToolSectionsProvider = this.toolSectionsProviders.stream().filter(toolSectionProvider -> toolSectionProvider.canHandle(diagramDescription)).findFirst();
var optionalTargetElement = this.findTargetElement(diagram, diagramElementId, editingContext);
var optionalDiagramElement = this.findDiagramElement(diagram, diagramElementId);
var optionalDiagramElementDescription = this.findDiagramElementDescription(diagram, diagramElementId, diagramDescription, optionalDiagramElement.orElse(null));

if (optionalToolSectionsProvider.isPresent() && optionalTargetElement.isPresent() && optionalDiagramElementDescription.isPresent()) {
if (optionalToolSectionsProvider.isPresent() && optionalTargetElement.isPresent()) {
IToolSectionsProvider toolSectionsProvider = optionalToolSectionsProvider.get();
toolSections = toolSectionsProvider.handle(optionalTargetElement.get(), optionalDiagramElement.orElse(null), optionalDiagramElementDescription.get(),
diagramDescription);
toolSections = toolSectionsProvider.handle(optionalTargetElement.get(), editingContext, optionalDiagramElement.orElse(null));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@ public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDesc
ChangeDescription changeDescription = new ChangeDescription(ChangeKind.NOTHING, diagramInput.representationId(), diagramInput);

if (diagramInput instanceof InvokeSingleClickOnDiagramElementToolInput input) {
Diagram diagram = diagramContext.getDiagram();
// @formatter:off
var optionalTool = this.toolService.findToolById(editingContext, diagram, input.toolId())
var optionalTool = this.toolService.findToolById(editingContext, input.toolId())
.filter(SingleClickOnDiagramElementTool.class::isInstance)
.map(SingleClickOnDiagramElementTool.class::cast);

// @formatter:on
if (optionalTool.isPresent()) {
IStatus status = this.executeTool(editingContext, diagramContext, input.diagramElementId(), optionalTool.get(), input.startingPositionX(), input.startingPositionY(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void handle(One<IPayload> payloadSink, Many<ChangeDescription> changeDesc
if (diagramInput instanceof InvokeSingleClickOnTwoDiagramElementsToolInput input) {
Diagram diagram = diagramContext.getDiagram();
// @formatter:off
var optionalTool = this.toolService.findToolById(editingContext, diagram, input.toolId())
var optionalTool = this.toolService.findToolById(editingContext, input.toolId())
.filter(SingleClickOnTwoDiagramElementsTool.class::isInstance)
.map(SingleClickOnTwoDiagramElementsTool.class::cast)
.or(this.findConnectorToolById(input.diagramSourceElementId(), input.diagramTargetElementId(), editingContext, diagram, input.toolId()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public Optional<Object> getObject(IEditingContext editingContext, String objectI

var toolService = new IToolService.NoOp() {
@Override
public Optional<ITool> findToolById(IEditingContext editingContext, Diagram diagram, String toolId) {
public Optional<ITool> findToolById(IEditingContext editingContext, String toolId) {
return Optional.of(tool);
}
};
Expand Down Expand Up @@ -167,7 +167,7 @@ public Optional<Node> findNodeById(Diagram diagram, String nodeId) {

var toolService = new IToolService.NoOp() {
@Override
public Optional<ITool> findToolById(IEditingContext editingContext, Diagram diagram, String toolId) {
public Optional<ITool> findToolById(IEditingContext editingContext, String toolId) {
return Optional.of(tool);
}
};
Expand Down Expand Up @@ -224,7 +224,7 @@ public Optional<Node> findNodeById(Diagram diagram, String nodeId) {

var toolService = new IToolService.NoOp() {
@Override
public Optional<ITool> findToolById(IEditingContext editingContext, Diagram diagram, String toolId) {
public Optional<ITool> findToolById(IEditingContext editingContext, String toolId) {
return Optional.of(tool);
}
};
Expand Down Expand Up @@ -281,7 +281,7 @@ public Optional<Edge> findEdgeById(Diagram diagram, String edgeId) {

var toolService = new IToolService.NoOp() {
@Override
public Optional<ITool> findToolById(IEditingContext editingContext, Diagram diagram, String toolId) {
public Optional<ITool> findToolById(IEditingContext editingContext, String toolId) {
return Optional.of(tool);
}
};
Expand Down Expand Up @@ -338,7 +338,7 @@ public Optional<Edge> findEdgeById(Diagram diagram, String edgeId) {

var toolService = new IToolService.NoOp() {
@Override
public Optional<ITool> findToolById(IEditingContext editingContext, Diagram diagram, String toolId) {
public Optional<ITool> findToolById(IEditingContext editingContext, String toolId) {
return Optional.of(tool);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public IdDiagramProvider(IObjectService objectService) {
this.objectService = Objects.requireNonNull(objectService);
}


@Override
public String getIdDiagramDescription(DiagramDescription diagramDescription) {
String sourceId = this.getSourceIdFromElementDescription(diagramDescription);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ private List<ITool> createDiagramPaletteTools(DiagramDescription viewDiagramDesc
private List<ITool> createNodePaletteTools(NodeDescription nodeDescription, ViewDiagramDescriptionConverterContext converterContext) {
var capturedConvertedNodes = Map.copyOf(converterContext.getConvertedNodes());
List<ITool> tools = new ArrayList<>();

for (NodeTool nodeTool : new ToolFinder().findNodeTools(nodeDescription)) {
// @formatter:off
String toolId = this.idProvider.apply(nodeTool).toString();
Expand Down
Loading

0 comments on commit e9beec6

Please sign in to comment.