use of org.eclipse.sirius.components.collaborative.diagrams.dto.DeletionPolicy in project sirius-components by eclipse-sirius.
the class CanonicalBehaviors method deleteElement.
public IStatus deleteElement(VariableManager variableManager) {
// @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();
}
use of org.eclipse.sirius.components.collaborative.diagrams.dto.DeletionPolicy in project sirius-components by eclipse-sirius.
the class DeleteFromDiagramEventHandler method invokeDeleteEdgeTool.
private IStatus invokeDeleteEdgeTool(Edge edge, IEditingContext editingContext, IDiagramContext diagramContext, DeletionPolicy deletionPolicy) {
// $NON-NLS-1$
IStatus result = new Failure("");
var optionalEdgeDescription = this.findEdgeDescription(edge, diagramContext.getDiagram(), editingContext);
if (optionalEdgeDescription.isPresent()) {
var optionalSelf = this.objectService.getObject(editingContext, edge.getTargetObjectId());
if (optionalSelf.isPresent()) {
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);
variableManager.put(Environment.ENVIRONMENT, new Environment(Environment.SIRIUS_COMPONENTS));
// @formatter:off
this.diagramQueryService.findNodeById(diagramContext.getDiagram(), edge.getSourceId()).flatMap(node -> this.objectService.getObject(editingContext, node.getTargetObjectId())).ifPresent(semanticElement -> variableManager.put(EdgeDescription.SEMANTIC_EDGE_SOURCE, semanticElement));
this.diagramQueryService.findNodeById(diagramContext.getDiagram(), edge.getTargetId()).flatMap(node -> this.objectService.getObject(editingContext, node.getTargetObjectId())).ifPresent(semanticElement -> variableManager.put(EdgeDescription.SEMANTIC_EDGE_TARGET, semanticElement));
// @formatter:on
EdgeDescription edgeDescription = optionalEdgeDescription.get();
// $NON-NLS-1$
this.logger.debug("Deleted diagram edge {}", edge.getId());
result = edgeDescription.getDeleteHandler().apply(variableManager);
} else {
String message = this.messageService.semanticObjectNotFound(edge.getTargetObjectId());
this.logger.debug(message);
result = new Failure(message);
}
} else {
String message = this.messageService.edgeDescriptionNotFound(edge.getId().toString());
this.logger.debug(message);
result = new Failure(message);
}
return result;
}
use of org.eclipse.sirius.components.collaborative.diagrams.dto.DeletionPolicy in project sirius-components by eclipse-sirius.
the class ToolConverter method createDeleteToolHandler.
public Function<VariableManager, IStatus> createDeleteToolHandler(DeleteElementDescription deleteDescription) {
var optionalInitialOperation = Optional.ofNullable(deleteDescription).map(DeleteElementDescription::getInitialOperation);
if (optionalInitialOperation.isPresent()) {
InitialOperation initialOperation = optionalInitialOperation.get();
return variableManager -> {
Map<String, Object> variables = variableManager.getVariables();
// Sirius Desktop Delete Tools expect an "element" variable to be available with the value
// of the initial invocation context (self).
// $NON-NLS-1$
variables.put("element", variables.get(VariableManager.SELF));
var selectedNode = variableManager.get(Node.SELECTED_NODE, Node.class);
if (selectedNode.isPresent()) {
variables.put(ELEMENT_VIEW, selectedNode.get());
var diagramContext = variableManager.get(IDiagramContext.DIAGRAM_CONTEXT, IDiagramContext.class);
if (diagramContext.isPresent()) {
variableManager.put(CONTAINER_VIEW, this.getParentNode(selectedNode.get(), diagramContext.get().getDiagram()));
}
}
var modelOperationHandlerSwitch = this.modelOperationHandlerSwitchProvider.getModelOperationHandlerSwitch(this.interpreter);
return modelOperationHandlerSwitch.apply(initialOperation.getFirstModelOperations()).map(handler -> {
return handler.handle(variables);
}).orElse(// $NON-NLS-1$
new Failure(""));
};
} else {
// If no delete tool is defined, execute the default behavior: delete the underlying semantic element.
return variableManager -> {
var optionalObject = variableManager.get(VariableManager.SELF, Object.class);
var optionalSelectedNode = variableManager.get(Node.SELECTED_NODE, Node.class);
var optionalDiagramContext = variableManager.get(IDiagramContext.DIAGRAM_CONTEXT, IDiagramContext.class);
if (optionalObject.isPresent()) {
Object object = optionalObject.get();
DeletionPolicy deletionPolicy = variableManager.get(DeleteFromDiagramEventHandler.DELETION_POLICY, DeletionPolicy.class).orElse(DeletionPolicy.SEMANTIC);
if (DeletionPolicy.SEMANTIC == deletionPolicy) {
this.editService.delete(object);
} else if (optionalDiagramContext.isPresent() && optionalSelectedNode.isPresent()) {
IDiagramContext diagramContext = optionalDiagramContext.get();
Node selectedNode = optionalSelectedNode.get();
// @formatter:off
ViewDeletionRequest viewDeletionRequest = ViewDeletionRequest.newViewDeletionRequest().elementId(selectedNode.getId()).build();
// @formatter:on
diagramContext.getViewDeletionRequests().add(viewDeletionRequest);
}
return new Success();
}
// $NON-NLS-1$
return new Failure("");
};
}
}
Aggregations