Exemplo n.º 1
0
        private void ProcessModelItemEvent(ModelItemEventBase modelItemEvent)
        {
            switch (modelItemEvent)
            {
            case ModelNodeUpdatedEvent modelNodeUpdated:
                var updatedNode = modelNodeUpdated.NewNode;
                DiagramService.UpdateModelNode(updatedNode);
                break;

            case ModelNodeRemovedEvent modelNodeRemovedEvent:
                var removedNode = modelNodeRemovedEvent.RemovedNode;
                DiagramService.RemoveNode(removedNode.Id);
                break;

            case ModelRelationshipAddedEvent modelRelationshipAddedEvent:
                var addedRelationship = modelRelationshipAddedEvent.AddedRelationship;
                ShowModelRelationshipIfBothEndsAreVisible(addedRelationship, DiagramService.LatestDiagram);
                break;

            case ModelRelationshipRemovedEvent modelRelationshipRemovedEvent:
                var modelRelationship = modelRelationshipRemovedEvent.RemovedRelationship;
                DiagramService.RemoveConnector(modelRelationship.Id);
                break;
            }
        }
        private void OnModelChanged(ModelEventBase modelEvent)
        {
            DiagramService.UpdateModel(modelEvent.NewModel);

            switch (modelEvent)
            {
            case ModelNodeUpdatedEvent modelNodeUpdatedEvent:
                DiagramService.UpdateModelNode(modelNodeUpdatedEvent.NewNode);
                break;

            case ModelNodeRemovedEvent modelNodeRemovedEvent:
                var removedNode = modelNodeRemovedEvent.RemovedNode;
                DiagramService.RemoveNode(removedNode.Id);
                break;

            case ModelRelationshipAddedEvent modelRelationshipAddedEvent:
                var addedRelationship = modelRelationshipAddedEvent.AddedRelationship;
                ShowModelRelationshipIfBothEndsAreVisible(addedRelationship, DiagramService.LatestDiagram);
                break;

            case ModelRelationshipRemovedEvent modelRelationshipRemovedEvent:
                var modelRelationship = modelRelationshipRemovedEvent.RemovedRelationship;
                DiagramService.RemoveConnector(modelRelationship.Id);
                break;

            case ModelClearedEvent _:
                DiagramService.ClearDiagram();
                break;
            }
        }
        private void OnModelChanged(ModelEventBase modelEvent)
        {
            var diagram = DiagramService.Diagram;

            switch (modelEvent)
            {
            case ModelNodeUpdatedEvent modelNodeUpdatedEvent:
                var newModelNode = modelNodeUpdatedEvent.NewNode;
                if (diagram.TryGetNode(newModelNode.Id, out var diagramNodeToUpdate))
                {
                    DiagramService.UpdateDiagramNodeModelNode(diagramNodeToUpdate, newModelNode);
                }
                break;

            case ModelNodeRemovedEvent modelNodeRemovedEvent:
                var removedModelNode = modelNodeRemovedEvent.RemovedNode;
                if (diagram.TryGetNode(removedModelNode.Id, out var diagramNodeToRemove))
                {
                    DiagramService.RemoveNode(diagramNodeToRemove.Id);
                }
                break;

            case ModelRelationshipAddedEvent modelRelationshipAddedEvent:
                var addedRelationship = modelRelationshipAddedEvent.AddedRelationship;
                ShowModelRelationshipIfBothEndsAreVisible(addedRelationship, diagram);
                break;

            case ModelRelationshipRemovedEvent modelRelationshipRemovedEvent:
                var modelRelationship = modelRelationshipRemovedEvent.RemovedRelationship;
                if (diagram.TryGetConnector(modelRelationship.Id, out var diagramConnector))
                {
                    DiagramService.RemoveConnector(diagramConnector.Id);
                }
                break;

            case ModelClearedEvent _:
                DiagramService.ClearDiagram();
                break;
            }
        }