Skip to content

Commit

Permalink
[822] Handle 'Delete from Diagram' on studios
Browse files Browse the repository at this point in the history
The default delete behavior on studios must be made aware of the two
distinct DeletionPolicies we support now.

Also add the "selectedEdge" variable to the context when invoking a
deletion on an edge, similar to "selectedNode" for nodes deletion.

Bug: #822
Signed-off-by: Pierre-Charles David <pierre-charles.david@obeo.fr>
  • Loading branch information
pcdavid authored and sbegaudeau committed Jan 18, 2022
1 parent 6513643 commit 2f6c2ea
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ Currently it is not possible to compute different values for width and height.

- https://github.com/eclipse-sirius/sirius-components/issues/884[#884] [view] Add support for defining unsynchronized nodes and edges
- https://github.com/eclipse-sirius/sirius-components/issues/822[#822] [diagram] Add support for graphical deletion. We can now offer a dedicated menu in the user interface to perform a graphical deletion instead of a semantic one. On the backend, the compatibility layer has been updated to perform a `DeletionViewRequest` if there is no default deletion tool and a new variable named `deletionPolicy` is available to determine if the deletion should be performed graphically or semantically
- https://github.com/eclipse-sirius/sirius-components/issues/943[#943] Add support for optional begin & end labels on edges in views
- https://github.com/eclipse-sirius/sirius-components/issues/943[#943] [view] Add support for optional begin & end labels on edges in views
- https://github.com/eclipse-sirius/sirius-components/issues/822[#822] [view] Handle 'Delete from Diagram' in view-based diagrams

=== Improvements

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
*/
@Immutable
public final class Edge {

public static final String SELECTED_EDGE = "selectedEdge"; //$NON-NLS-1$

private String id;

private String type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,16 @@
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.sirius.web.core.api.IEditService;
import org.eclipse.sirius.web.core.api.IObjectService;
import org.eclipse.sirius.web.diagrams.Edge;
import org.eclipse.sirius.web.diagrams.Node;
import org.eclipse.sirius.web.diagrams.ViewDeletionRequest;
import org.eclipse.sirius.web.representations.IStatus;
import org.eclipse.sirius.web.representations.Success;
import org.eclipse.sirius.web.representations.VariableManager;
import org.eclipse.sirius.web.spring.collaborative.diagrams.DiagramContext;
import org.eclipse.sirius.web.spring.collaborative.diagrams.api.IDiagramContext;
import org.eclipse.sirius.web.spring.collaborative.diagrams.dto.DeletionPolicy;
import org.eclipse.sirius.web.spring.collaborative.diagrams.handlers.DeleteFromDiagramEventHandler;
import org.eclipse.sirius.web.view.EdgeDescription;

/**
Expand Down Expand Up @@ -77,7 +84,32 @@ public IStatus editLabel(VariableManager variableManager, String newLabel) {
}

public IStatus deleteElement(VariableManager variableManager) {
this.self(variableManager).ifPresent(this.editService::delete);
// @formatter:off
DeletionPolicy deletionPolicy = variableManager.get(DeleteFromDiagramEventHandler.DELETION_POLICY, DeletionPolicy.class)
.orElse(DeletionPolicy.SEMANTIC);
// @formatter:on
switch (deletionPolicy) {
case SEMANTIC:
this.self(variableManager).ifPresent(this.editService::delete);
break;
case GRAPHICAL:
var optionalDiagramContext = variableManager.get(IDiagramContext.DIAGRAM_CONTEXT, DiagramContext.class);
if (optionalDiagramContext.isPresent()) {
String elementId = null;
if (variableManager.get(Node.SELECTED_NODE, Node.class).isPresent()) {
elementId = variableManager.get(Node.SELECTED_NODE, Node.class).get().getId();
} else if (variableManager.get(Edge.SELECTED_EDGE, Edge.class).isPresent()) {
elementId = variableManager.get(Edge.SELECTED_EDGE, Edge.class).get().getId();
}
if (elementId != null) {
ViewDeletionRequest viewDeletionRequest = ViewDeletionRequest.newViewDeletionRequest().elementId(elementId).build();
optionalDiagramContext.get().getViewDeletionRequests().add(viewDeletionRequest);
}
}
break;
default:
break;
}
return new Success();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ private IStatus invokeDeleteEdgeTool(Edge edge, IEditingContext editingContext,
VariableManager variableManager = new VariableManager();
variableManager.put(VariableManager.SELF, optionalSelf.get());
variableManager.put(IDiagramContext.DIAGRAM_CONTEXT, diagramContext);
variableManager.put(Edge.SELECTED_EDGE, edge);
variableManager.put(DELETION_POLICY, deletionPolicy);

// @formatter:off
Expand Down

0 comments on commit 2f6c2ea

Please sign in to comment.