public override void ElementDeleting(ElementDeletingEventArgs e) { if (e.ModelElement != null) { if (e.ModelElement.Store.TransactionManager.CurrentTransaction != null) { if (e.ModelElement.Store.TransactionManager.CurrentTransaction.IsSerializing) { return; } } } if (e.ModelElement == null) { return; } if (ImmutabilityExtensionMethods.GetLocks(e.ModelElement) != Locks.None) { return; } ShapeRelationshipNode node = e.ModelElement as ShapeRelationshipNode; if (node != null) { if (node.RelationshipShapeClass != null) { node.RelationshipShapeClass.ReferenceRelationship = null; } } }
public override void ElementAdded(ElementAddedEventArgs e) { if (e.ModelElement != null) { if (e.ModelElement.Store.TransactionManager.CurrentTransaction != null) { if (e.ModelElement.Store.TransactionManager.CurrentTransaction.IsSerializing) { return; } } } if (e.ModelElement == null) { return; } if (ImmutabilityExtensionMethods.GetLocks(e.ModelElement) != Locks.None) { return; } RelationshipShapeClassReferencesReferenceRelationship con = e.ModelElement as RelationshipShapeClassReferencesReferenceRelationship; if (con != null) { if (con.DomainRelationship is ReferenceRelationship) { ReferenceRelationship rel = con.DomainRelationship as ReferenceRelationship; ReferenceRSNode node = rel.ReferenceRSNode; // create new shape relationship node ShapeRelationshipNode shapeNode = new ShapeRelationshipNode(con.Store); shapeNode.RelationshipShapeClass = con.RelationshipShapeClass; node.ShapeRelationshipNodes.Add(shapeNode); rel.ModelContext.ViewContext.DomainModelTreeView.ModelTreeNodes.Add(shapeNode); if (rel.SerializedReferenceRelationship != null) { if (!rel.SerializedReferenceRelationship.IsInFullSerialization) { if (System.Windows.MessageBox.Show("Shape mapping has been defined for the ReferenceRelationship '" + rel.Name + "'. The Relationship is not serialized in full form. Would you like to change the serialization of this relationship to full form (strongly adviced)?", "Serialization", System.Windows.MessageBoxButton.YesNo, System.Windows.MessageBoxImage.Question) == System.Windows.MessageBoxResult.Yes) { rel.SerializedReferenceRelationship.IsInFullSerialization = true; } } } } } }
public override void ElementDeleting(ElementDeletingEventArgs e) { if (e.ModelElement != null) { if (e.ModelElement.Store.TransactionManager.CurrentTransaction != null) { if (e.ModelElement.Store.TransactionManager.CurrentTransaction.IsSerializing) { return; } } } if (e.ModelElement == null) { return; } if (ImmutabilityExtensionMethods.GetLocks(e.ModelElement) != Locks.None) { return; } RelationshipShapeClassReferencesReferenceRelationship con = e.ModelElement as RelationshipShapeClassReferencesReferenceRelationship; if (con != null) { if (con.DomainRelationship is ReferenceRelationship) { RelationshipShapeClass shape = con.RelationshipShapeClass; ShapeRelationshipNode node = shape.ShapeRelationshipNode; if (node != null) { // delete ReferenceRelationship rel = con.DomainRelationship as ReferenceRelationship; ReferenceRSNode n = rel.ReferenceRSNode; if (n != null) { if (n.ShapeRelationshipNodes.Contains(node)) { n.ShapeRelationshipNodes.Remove(node); } } node.Delete(); } } } }
/// <summary> /// Deletes the shape node view model that is hosting the given node. /// </summary> /// <param name="node">Node.</param> public void DeleteShapeNode(ShapeRelationshipNode node) { for (int i = this.shapeNodeVMs.Count - 1; i >= 0; i--) { if (this.shapeNodeVMs[i].ShapeRelationshipNode.Id == node.Id) { this.shapeNodeVMs[i].Dispose(); this.shapeNodeVMs.RemoveAt(i); } } foreach (ShapeRelationshipNodeViewModel viewModel in this.shapeNodeVMs) { viewModel.UpdateNodePosition(); } OnPropertyChanged("HasShapeMappingNodes"); }
/// <summary> /// Adds a new reference rs view model for the given node. /// </summary> /// <param name="node">Node.</param> public void AddShapeNode(ShapeRelationshipNode node) { // verify that node hasnt been added yet foreach (ShapeRelationshipNodeViewModel viewModel in this.shapeNodeVMs) { if (viewModel.ShapeRelationshipNode.Id == node.Id) { return; } } ShapeRelationshipNodeViewModel vm = new ShapeRelationshipNodeViewModel(this.ViewModelStore, node, this); this.shapeNodeVMs.Add(vm); foreach (ShapeRelationshipNodeViewModel viewModel in this.shapeNodeVMs) { viewModel.UpdateNodePosition(); } OnPropertyChanged("HasShapeMappingNodes"); }
private static void FixUpDomainModelTreeView(LibraryModelContext model) { // create root nodes and embedding rs foreach (DomainClass domainClass in model.Classes) { if (!domainClass.HasParent()) { RootNode node = new RootNode(model.Store); node.DomainElement = domainClass; node.IsElementHolder = true; domainClass.ModelContext.ViewContext.DomainModelTreeView.RootNodes.Add(node); domainClass.ModelContext.ViewContext.DomainModelTreeView.ModelTreeNodes.Add(node); node.IsEmbeddingTreeExpanded = true; node.IsReferenceTreeExpanded = true; node.IsInheritanceTreeExpanded = true; node.IsShapeMappingTreeExpanded = true; FixUpDomainClassInTreeView(domainClass); } } // reference relationships + shapes foreach (DomainRelationship relationship in model.Relationships) { if (relationship is ReferenceRelationship) { ReferenceRelationship rel = relationship as ReferenceRelationship; ModelTreeHelper.AddNewReferenceRelationship(rel, rel.Source.RolePlayer as DomainClass, rel.Target.RolePlayer); // shape foreach (RelationshipShapeClass s in rel.RelationshipShapeClasses) { ReferenceRSNode node = rel.ReferenceRSNode; // create new shape relationship node ShapeRelationshipNode shapeNode = new ShapeRelationshipNode(rel.Store); shapeNode.RelationshipShapeClass = s; node.ShapeRelationshipNodes.Add(shapeNode); rel.ModelContext.ViewContext.DomainModelTreeView.ModelTreeNodes.Add(shapeNode); } } } // inheritance foreach (DomainClass domainClass in model.Classes) { if (domainClass.BaseClass != null) { DomainClassReferencesBaseClass refBase = DomainClassReferencesBaseClass.GetLink(domainClass, domainClass.BaseClass); if (refBase != null) { if (domainClass.DomainModelTreeNodes.Count > 0) { ModelTreeHelper.AddNewInheritanceRelationship(refBase, domainClass, domainClass.BaseClass, false); } else { ModelTreeHelper.AddNewInheritanceRelationship(refBase, domainClass, domainClass.BaseClass, true); } } } } // shapes foreach (DomainClass domainClass in model.Classes) { foreach (PresentationDomainClassElement p in domainClass.ShapeClasses) { foreach (TreeNode node in domainClass.DomainModelTreeNodes) { if (node.IsElementHolder) { ShapeClassNode shapeNode = new ShapeClassNode(domainClass.Store); shapeNode.ShapeClass = p; node.ShapeClassNodes.Add(shapeNode); domainClass.ModelContext.ViewContext.DomainModelTreeView.ModelTreeNodes.Add(shapeNode); break; } } } } }
/// <summary> /// Constuctor. /// </summary> /// <param name="viewModelStore">The store this view model belongs to.</param> /// <param name="shapeRelationshipNode">ShapeRelationshipNode.</param> /// <param name="parent">Parent.</param> public ShapeRelationshipNodeViewModel(ViewModelStore viewModelStore, ShapeRelationshipNode shapeRelationshipNode, ReferenceRSNodeViewModel parent) : base(viewModelStore, shapeRelationshipNode.RelationshipShapeClass) { this.shapeRelationshipNode = shapeRelationshipNode; this.parentTreeNode = parent; }
public override void RolePlayerChanged(RolePlayerChangedEventArgs e) { if (e.ElementLink != null) { if (e.ElementLink.Store.TransactionManager.CurrentTransaction != null) { if (e.ElementLink.Store.TransactionManager.CurrentTransaction.IsSerializing) { return; } } } if (e.ElementLink == null) { return; } if (ImmutabilityExtensionMethods.GetLocks(e.ElementLink) != Locks.None) { return; } RelationshipShapeClassReferencesReferenceRelationship con = e.ElementLink as RelationshipShapeClassReferencesReferenceRelationship; if (con != null) { RelationshipShapeClass shape = con.RelationshipShapeClass; ShapeRelationshipNode node = shape.ShapeRelationshipNode; // delete old ReferenceRelationship relOld = e.OldRolePlayer as ReferenceRelationship; if (relOld != null) { ReferenceRSNode nodeOld = relOld.ReferenceRSNode; if (nodeOld != null) { node.RelationshipShapeClass = null; if (nodeOld.ShapeRelationshipNodes.Contains(node)) { nodeOld.ShapeRelationshipNodes.Remove(node); } } node.Delete(); } // create new ReferenceRelationship rel = e.NewRolePlayer as ReferenceRelationship; if (rel != null) { ReferenceRSNode n = rel.ReferenceRSNode; // create new shape relationship node ShapeRelationshipNode shapeNode = new ShapeRelationshipNode(con.Store); shape.ShapeRelationshipNode = shapeNode; n.ShapeRelationshipNodes.Add(shapeNode); rel.ModelContext.ViewContext.DomainModelTreeView.ModelTreeNodes.Add(shapeNode); if (rel.SerializedReferenceRelationship != null) { if (!rel.SerializedReferenceRelationship.IsInFullSerialization) { if (System.Windows.MessageBox.Show("Shape mapping has been defined for the ReferenceRelationship '" + rel.Name + "'. The Relationship is not serialized in full form. Would you like to change the serialization of this relationship to full form (strongly adviced)?", "Serialization", System.Windows.MessageBoxButton.YesNo, System.Windows.MessageBoxImage.Question) == System.Windows.MessageBoxResult.Yes) { rel.SerializedReferenceRelationship.IsInFullSerialization = true; } } } } } }