Search in sources :

Example 1 with Environment

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;
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) IStatus(org.eclipse.sirius.components.representations.IStatus) Position(org.eclipse.sirius.components.diagrams.Position) Node(org.eclipse.sirius.components.diagrams.Node) DiagramDescription(org.eclipse.sirius.components.diagrams.description.DiagramDescription) Success(org.eclipse.sirius.components.representations.Success) Diagram(org.eclipse.sirius.components.diagrams.Diagram) SinglePositionEvent(org.eclipse.sirius.components.diagrams.events.SinglePositionEvent) Environment(org.eclipse.sirius.components.core.api.Environment) Failure(org.eclipse.sirius.components.representations.Failure)

Example 2 with Environment

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);
        }
    }
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) Environment(org.eclipse.sirius.components.core.api.Environment) EdgeDescription(org.eclipse.sirius.components.diagrams.description.EdgeDescription)

Example 3 with Environment

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;
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) ErrorPayload(org.eclipse.sirius.components.core.api.ErrorPayload) Edge(org.eclipse.sirius.components.diagrams.Edge) Node(org.eclipse.sirius.components.diagrams.Node) Environment(org.eclipse.sirius.components.core.api.Environment) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) IDiagramInput(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramInput) IObjectService(org.eclipse.sirius.components.core.api.IObjectService) LoggerFactory(org.slf4j.LoggerFactory) One(reactor.core.publisher.Sinks.One) DiagramDescription(org.eclipse.sirius.components.diagrams.description.DiagramDescription) NodeDescription(org.eclipse.sirius.components.diagrams.description.NodeDescription) ArrayList(java.util.ArrayList) IDiagramDescriptionService(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramDescriptionService) Diagram(org.eclipse.sirius.components.diagrams.Diagram) IStatus(org.eclipse.sirius.components.representations.IStatus) Monitoring(org.eclipse.sirius.components.collaborative.api.Monitoring) Service(org.springframework.stereotype.Service) ICollaborativeDiagramMessageService(org.eclipse.sirius.components.collaborative.diagrams.messages.ICollaborativeDiagramMessageService) DeleteFromDiagramInput(org.eclipse.sirius.components.collaborative.diagrams.dto.DeleteFromDiagramInput) IDiagramQueryService(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramQueryService) Counter(io.micrometer.core.instrument.Counter) ChangeKind(org.eclipse.sirius.components.collaborative.api.ChangeKind) Logger(org.slf4j.Logger) IDiagramContext(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramContext) Failure(org.eclipse.sirius.components.representations.Failure) Success(org.eclipse.sirius.components.representations.Success) ChangeDescription(org.eclipse.sirius.components.collaborative.api.ChangeDescription) DeleteFromDiagramSuccessPayload(org.eclipse.sirius.components.collaborative.diagrams.dto.DeleteFromDiagramSuccessPayload) IRepresentationDescriptionSearchService(org.eclipse.sirius.components.core.api.IRepresentationDescriptionSearchService) DeletionPolicy(org.eclipse.sirius.components.collaborative.diagrams.dto.DeletionPolicy) Objects(java.util.Objects) List(java.util.List) IPayload(org.eclipse.sirius.components.core.api.IPayload) EdgeDescription(org.eclipse.sirius.components.diagrams.description.EdgeDescription) IDiagramEventHandler(org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramEventHandler) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Many(reactor.core.publisher.Sinks.Many) Optional(java.util.Optional) VariableManager(org.eclipse.sirius.components.representations.VariableManager) IStatus(org.eclipse.sirius.components.representations.IStatus) Environment(org.eclipse.sirius.components.core.api.Environment) EdgeDescription(org.eclipse.sirius.components.diagrams.description.EdgeDescription) Failure(org.eclipse.sirius.components.representations.Failure)

Example 4 with Environment

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;
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) IStatus(org.eclipse.sirius.components.representations.IStatus) NodeDescription(org.eclipse.sirius.components.diagrams.description.NodeDescription) Environment(org.eclipse.sirius.components.core.api.Environment) Failure(org.eclipse.sirius.components.representations.Failure)

Example 5 with Environment

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);
        }
    }
}
Also used : VariableManager(org.eclipse.sirius.components.representations.VariableManager) NodeDescription(org.eclipse.sirius.components.diagrams.description.NodeDescription) Environment(org.eclipse.sirius.components.core.api.Environment)

Aggregations

Environment (org.eclipse.sirius.components.core.api.Environment)8 VariableManager (org.eclipse.sirius.components.representations.VariableManager)8 Diagram (org.eclipse.sirius.components.diagrams.Diagram)5 Failure (org.eclipse.sirius.components.representations.Failure)5 IStatus (org.eclipse.sirius.components.representations.IStatus)5 Node (org.eclipse.sirius.components.diagrams.Node)4 NodeDescription (org.eclipse.sirius.components.diagrams.description.NodeDescription)3 IDiagramContext (org.eclipse.sirius.components.collaborative.diagrams.api.IDiagramContext)2 Position (org.eclipse.sirius.components.diagrams.Position)2 DiagramDescription (org.eclipse.sirius.components.diagrams.description.DiagramDescription)2 EdgeDescription (org.eclipse.sirius.components.diagrams.description.EdgeDescription)2 Counter (io.micrometer.core.instrument.Counter)1 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 ChangeDescription (org.eclipse.sirius.components.collaborative.api.ChangeDescription)1 ChangeKind (org.eclipse.sirius.components.collaborative.api.ChangeKind)1 Monitoring (org.eclipse.sirius.components.collaborative.api.Monitoring)1