public override void ElementPropertyChanged(ElementPropertyChangedEventArgs e) { base.ElementPropertyChanged(e); ModelDiagramData element = (ModelDiagramData)e.ModelElement; if (element.IsDeleted) { return; } Store store = element.Store; Transaction currentTransaction = store.TransactionManager.CurrentTransaction; if (currentTransaction.IsSerializing) { return; } if (Equals(e.NewValue, e.OldValue)) { return; } List <string> errorMessages = new List <string>(); switch (e.DomainProperty.Name) { case "Name": if (string.IsNullOrWhiteSpace(e.NewValue?.ToString())) { errorMessages.Add("Diagram must have a name"); break; } if (store.ElementDirectory.AllElements.OfType <ModelDiagramData>().Where(d => d != element).Any(d => d.Name == e.NewValue.ToString())) { errorMessages.Add("Diagram must have a unique name"); break; } ModelDiagramData.CloseDiagram?.Invoke(element.GetDiagram()); element.GetDiagram().Name = element.Name = e.NewValue.ToString(); break; } errorMessages = errorMessages.Where(m => m != null).ToList(); if (errorMessages.Any()) { currentTransaction.Rollback(); ErrorDisplay.Show(string.Join("\n", errorMessages)); } }
/// <inheritdoc /> public override void ElementDeleting(ElementDeletingEventArgs e) { base.ElementDeleting(e); ModelDiagramData element = (ModelDiagramData)e.ModelElement; Store store = element.Store; Transaction current = store.TransactionManager.CurrentTransaction; if (current.IsSerializing || ModelRoot.BatchUpdating) { return; } if (BooleanQuestionDisplay.Show($"About to permanently delete diagram named {element.Name} - are you sure?") != true) { current.Rollback(); return; } EFModelDiagram diagram = element.GetDiagram(); ModelDiagramData.CloseDiagram?.Invoke(diagram); diagram.Delete(); }
/// <summary> /// public virtual method for the client to have his own user-defined delete rule class /// </summary> /// <param name="e"></param> public override void ElementDeleted(ElementDeletedEventArgs e) { base.ElementDeleted(e); ModelDiagramData element = (ModelDiagramData)e.ModelElement; Store store = element.Store; Transaction current = store.TransactionManager.CurrentTransaction; if (current.IsSerializing || ModelRoot.BatchUpdating) { return; } EFModelDiagram diagram = element.GetDiagram(); ModelDiagramData.CloseDiagram?.Invoke(diagram); diagram.Delete(); }
public override void ElementAdded(ElementAddedEventArgs e) { base.ElementAdded(e); ModelDiagramData element = (ModelDiagramData)e.ModelElement; Store store = element.Store; Transaction current = store.TransactionManager.CurrentTransaction; if (current.IsSerializing || ModelRoot.BatchUpdating) { return; } ModelDiagramData.OpenDiagram?.Invoke(element); if (element.GetDiagram() == null) { element.SetDiagram(store.GetAll <EFModelDiagram>().FirstOrDefault(d => d.Name == store.ModelRoot().GetFileName())); } }
public override void ElementPropertyChanged(ElementPropertyChangedEventArgs e) { base.ElementPropertyChanged(e); ModelDiagramData element = (ModelDiagramData)e.ModelElement; if (element.IsDeleted) { return; } Store store = element.Store; Transaction currentTransaction = store.TransactionManager.CurrentTransaction; if (currentTransaction.IsSerializing) { return; } if (Equals(e.NewValue, e.OldValue)) { return; } List <string> errorMessages = new List <string>(); switch (e.DomainProperty.Name) { case "Name": EFModelDiagram diagram = element.GetDiagram(); if (diagram != null && string.IsNullOrWhiteSpace(diagram.Name)) { errorMessages.Add("Can't change default diagram name"); break; } if (string.IsNullOrWhiteSpace(element.Name)) { errorMessages.Add("Diagram must have a name"); break; } if (store.GetAll <ModelDiagramData>().Except(new[] { element }).Any(d => d.Name == element.Name)) { errorMessages.Add("Diagram must have a unique name"); break; } if (diagram != null) { diagram.Name = element.Name; ModelDiagramData.CloseDiagram(diagram); } break; } errorMessages = errorMessages.Where(m => m != null).ToList(); if (errorMessages.Any()) { currentTransaction.Rollback(); ErrorDisplay.Show(store, string.Join("\n", errorMessages)); } }