use of org.eclipse.sirius.components.core.api.Environment in project sirius-components by eclipse-sirius.
the class DropOnDiagramEventHandler method executeTool.
private IStatus executeTool(IEditingContext editingContext, IDiagramContext diagramContext, List<Object> objects, String diagramElementId, double startingPositionX, double startingPositionY) {
// $NON-NLS-1$
IStatus result = new Failure("");
Diagram diagram = diagramContext.getDiagram();
Optional<Node> node = this.diagramQueryService.findNodeById(diagram, diagramElementId);
// @formatter:off
var optionalDropHandler = this.representationDescriptionSearchService.findById(editingContext, diagram.getDescriptionId()).filter(DiagramDescription.class::isInstance).map(DiagramDescription.class::cast).map(DiagramDescription::getDropHandler);
if (optionalDropHandler.isPresent()) {
result = new Success();
var dropHandler = optionalDropHandler.get();
Position newPosition = Position.at(startingPositionX, startingPositionY);
diagramContext.setDiagramEvent(new SinglePositionEvent(newPosition));
for (Object self : objects) {
VariableManager variableManager = new VariableManager();
if (node.isPresent()) {
variableManager.put(Node.SELECTED_NODE, node.get());
}
variableManager.put(IEditingContext.EDITING_CONTEXT, editingContext);
variableManager.put(IDiagramContext.DIAGRAM_CONTEXT, diagramContext);
variableManager.put(Environment.ENVIRONMENT, new Environment(Environment.SIRIUS_COMPONENTS));
variableManager.put(VariableManager.SELF, self);
IStatus dropResult = dropHandler.apply(variableManager);
if (dropResult instanceof Failure) {
// Let all drops finished but keep the error state
result = dropResult;
}
}
}
return result;
}
use of org.eclipse.sirius.components.core.api.Environment in project sirius-components by eclipse-sirius.
the class EditLabelEventHandler method invokeDirectEditTool.
private void invokeDirectEditTool(Edge edge, IEditingContext editingContext, Diagram diagram, String newText) {
var optionalEdgeDescription = this.findEdgeDescription(edge, diagram, editingContext);
if (optionalEdgeDescription.isPresent()) {
EdgeDescription edgeDescription = optionalEdgeDescription.get();
var optionalSelf = this.objectService.getObject(editingContext, edge.getTargetObjectId());
if (optionalSelf.isPresent()) {
Object self = optionalSelf.get();
VariableManager variableManager = new VariableManager();
variableManager.put(Environment.ENVIRONMENT, new Environment(Environment.SIRIUS_COMPONENTS));
variableManager.put(VariableManager.SELF, self);
edgeDescription.getLabelEditHandler().apply(variableManager, newText);
// $NON-NLS-1$
this.logger.debug("Edited label of diagram element {} to {}", edge.getId(), newText);
}
}
}
use of org.eclipse.sirius.components.core.api.Environment 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.core.api.Environment in project sirius-components by eclipse-sirius.
the class DeleteFromDiagramEventHandler method invokeDeleteNodeTool.
private IStatus invokeDeleteNodeTool(Node node, IEditingContext editingContext, IDiagramContext diagramContext, DeletionPolicy deletionPolicy) {
// $NON-NLS-1$
IStatus result = new Failure("");
var optionalNodeDescription = this.findNodeDescription(node, diagramContext.getDiagram(), editingContext);
if (optionalNodeDescription.isPresent()) {
var optionalSelf = this.objectService.getObject(editingContext, node.getTargetObjectId());
if (optionalSelf.isPresent()) {
VariableManager variableManager = new VariableManager();
variableManager.put(VariableManager.SELF, optionalSelf.get());
variableManager.put(IDiagramContext.DIAGRAM_CONTEXT, diagramContext);
variableManager.put(Node.SELECTED_NODE, node);
variableManager.put(DELETION_POLICY, deletionPolicy);
variableManager.put(Environment.ENVIRONMENT, new Environment(Environment.SIRIUS_COMPONENTS));
NodeDescription nodeDescription = optionalNodeDescription.get();
// $NON-NLS-1$
this.logger.debug("Deleted diagram element {}", node.getId());
result = nodeDescription.getDeleteHandler().apply(variableManager);
} else {
String message = this.messageService.semanticObjectNotFound(node.getTargetObjectId());
this.logger.debug(message);
result = new Failure(message);
}
} else {
String message = this.messageService.nodeDescriptionNotFound(node.getId().toString());
this.logger.debug(message);
result = new Failure(message);
}
return result;
}
use of org.eclipse.sirius.components.core.api.Environment in project sirius-components by eclipse-sirius.
the class EditLabelEventHandler method invokeDirectEditTool.
private void invokeDirectEditTool(Node node, IEditingContext editingContext, Diagram diagram, String newText) {
var optionalNodeDescription = this.findNodeDescription(node, diagram, editingContext);
if (optionalNodeDescription.isPresent()) {
NodeDescription nodeDescription = optionalNodeDescription.get();
var optionalSelf = this.objectService.getObject(editingContext, node.getTargetObjectId());
if (optionalSelf.isPresent()) {
Object self = optionalSelf.get();
VariableManager variableManager = new VariableManager();
variableManager.put(Environment.ENVIRONMENT, new Environment(Environment.SIRIUS_COMPONENTS));
variableManager.put(VariableManager.SELF, self);
nodeDescription.getLabelEditHandler().apply(variableManager, newText);
// $NON-NLS-1$
this.logger.debug("Edited label of diagram element {} to {}", node.getId(), newText);
}
}
}
Aggregations