/// <summary> /// Callback from SelectionChangedEvent. /// </summary> /// <param name="eventArgs">SelectionChangedEventArgs.</param> private void ReactOnViewSelection(SelectionChangedEventArgs eventArgs) { this.selectedModelElement = null; if (eventArgs.SelectedItems != null) if (eventArgs.SelectedItems.Count == 1) this.selectedModelElement = eventArgs.SelectedItems[0] as DomainModelElement; }
/// <summary> /// Verifies if the given model element belongs to the domain model (can be reached from the domain model element). /// </summary> /// <param name="modelContextId">Model context Id.</param> /// <param name="modelElement">Model element.</param> /// <returns>True if the element belongs to the domain model. False otherwise.</returns> public bool IsIncludedInModel(Guid modelContextId, DomainModelElement modelElement) { if (modelElement == null) { return(false); } return(IsIncludedInModel(modelContextId, modelElement.GetDomainClassId())); }
/// <summary> /// Verifies if the given reference link belongs to the domain model (can be reached from the domain model element). /// </summary> /// <param name="modelLinkDCId">Model link domain class Id.</param> /// <param name="modelContextId">Model context Id.</param> /// <returns>True if the refrence link belongs to the domain model. False otherwise.</returns> public bool IsReferenceIncludedInModel(Guid modelContextId, Guid modelLinkDCId) { DomainRelationshipInfo info = this.Store.DomainDataDirectory.FindDomainRelationship(modelLinkDCId); if (IsIncludedInModel(modelContextId, DomainModelElement.GetSourceDomainRole(info).RolePlayer.Id)) { return(true); } if (IsIncludedInModel(modelContextId, DomainModelElement.GetTargetDomainRole(info).RolePlayer.Id)) { return(true); } return(false); }
/// <summary> /// Verifies if the given reference link belongs to the domain model (can be reached from the domain model element). /// </summary> /// <param name="modelLink">Model link.</param> /// <param name="modelContextId">Model context Id.</param> /// <returns>True if the refrence link belongs to the domain model. False otherwise.</returns> public bool IsReferenceIncludedInModel(Guid modelContextId, DomainModelLink modelLink) { if (modelLink.IsEmbedding) { return(false); } DomainModelElement m = DomainRoleInfo.GetSourceRolePlayer(modelLink) as DomainModelElement; if (IsIncludedInModel(modelContextId, m)) { return(true); } m = DomainRoleInfo.GetTargetRolePlayer(modelLink) as DomainModelElement; if (IsIncludedInModel(modelContextId, m)) { return(true); } return(false); }
private void ProcessInitializationInfo(Guid modelContextId, Guid domainClassId, List <Guid> processedClasses) { EmbeddingRelationshipOrderInfo info; this.embRelationshipOrderDictionary.TryGetValue(domainClassId, out info); if (info != null) { parentChildrenMapping[modelContextId].Add(domainClassId, new List <Guid>()); parentChildrenMapping[modelContextId][domainClassId].AddRange(info.EmbeddingRelationships); parentChildrenCMMapping[modelContextId].Add(domainClassId, new List <Guid>()); parentChildrenCMMapping[modelContextId][domainClassId].AddRange(info.EmbeddingRelationshipsTargetIncludedSubmodel); for (int i = 0; i < info.EmbeddingRelationships.Length; i++) { DomainRelationshipInfo rInfo = this.Store.DomainDataDirectory.GetDomainRelationship(info.EmbeddingRelationships[i]); DomainClassInfo cInfo = DomainModelElement.GetTargetDomainRole(rInfo).RolePlayer; if (!processedClasses.Contains(cInfo.Id)) { processedClasses.Add(cInfo.Id); ProcessInitializationInfo(modelContextId, cInfo.Id, processedClasses); } foreach (DomainClassInfo dInfo in cInfo.AllDescendants) { if (!processedClasses.Contains(dInfo.Id)) { processedClasses.Add(dInfo.Id); ProcessInitializationInfo(modelContextId, dInfo.Id, processedClasses); } } } } }
/// <summary> /// Constructor. The view model constructed this way does not react on model changes, as such DoHookUpEvents is false. /// </summary> /// <param name="viewModelStore">The store this view model belongs to.</param> /// <param name="element">Element represented by this view model.</param> public ExampleElementViewModel(ViewModelStore viewModelStore, DomainModelElement element) : base(viewModelStore, element) { LocalChildrenCount = element.GetLocalChildren().Count.ToString(); ChildrenCount = element.GetChildren().Count.ToString(); }
/// <summary> /// Adds a proto element to the current element. /// </summary> /// <param name="protoElement">Proto element representation of the element that is to be added.</param> /// <param name="groupMerger"> /// Group merger class used to track id mapping, merge errors/warnings and /// postprocess merging by rebuilding reference relationships. /// </param> /// <param name="isRoot">Root element?</param> public virtual void ModelMerge(ModelProtoElement protoElement, ModelProtoGroupMerger groupMerger, bool isRoot) { if (!ModelIsPasteAllowed(groupMerger.ProtoGroup.Operation)) { // add warning message groupMerger.MergeResult.AddMessage(new ValidationMessage(ModelValidationMessageIds.ModelMergePasteDisallowedId, ModelValidationViolationType.Warning, "Element couldn't be addded to " + this.DomainElementFullName + " because paste is not allowed.")); return; } if (protoElement != null) { DomainClassInfo elementDomainInfo = this.Partition.DomainDataDirectory.GetDomainClass(protoElement.DomainClassId); foreach (DomainRoleInfo info in elementDomainInfo.AllDomainRolesPlayed) { if (!info.IsSource) { if (info.OppositeDomainRole.RolePlayer.Id == this.GetDomainClassId()) { if (this.Store.DomainDataAdvDirectory.IsEmbeddingRelationship(info.DomainRelationship.Id) && !this.Store.DomainDataAdvDirectory.IsAbstractRelationship(info.DomainRelationship.Id)) { // create element id Guid newElementId = this.GetDomainModelServices().ElementIdProvider.GenerateNewKey(); // create property assignments PropertyAssignment[] propertyAssignemnts = protoElement.GetPropertyAssignments(this.Store.DefaultPartition, newElementId); // create the actual model element DomainModelElement element = this.Store.ElementFactory.CreateElement(elementDomainInfo, propertyAssignemnts) as DomainModelElement; if (element == null) { throw new System.ArgumentNullException("Element is null in ModelMerge: " + elementDomainInfo.Name); } if (!element.ModelIsPasteAllowed(groupMerger.ProtoGroup.Operation)) { // add warning message groupMerger.MergeResult.AddMessage(new ValidationMessage(ModelValidationMessageIds.ModelMergePasteDisallowedId, ModelValidationViolationType.Warning, "Element couldn't be addded to <#= role.RolePlayer.Name #> because paste is not allowed.")); element.Delete(); return; } // set name if (isRoot && groupMerger.ProtoGroup.Operation != ModelProtoGroupOperation.Move) { if (element.DomainElementHasName) { element.GetDomainModelServices().ElementNameProvider.SetName(element, "Copy of " + element.DomainElementName); } } // update id mapping groupMerger.SetIdMapping(protoElement.ElementId, newElementId); // add child element if (info.OppositeDomainRole.Multiplicity == Multiplicity.One || info.OppositeDomainRole.Multiplicity == Multiplicity.ZeroOne) { DomainRoleInfo.SetLinkedElement(this, info.OppositeDomainRole.Id, element); } else { RoleAssignment[] assignments = new RoleAssignment[2]; assignments[0] = new RoleAssignment(info.OppositeDomainRole.Id, this); assignments[1] = new RoleAssignment(info.Id, element); this.Store.ElementFactory.CreateElementLink(info.DomainRelationship, assignments); } // continue with child elements (Embedding Relationship) System.Collections.Generic.List <ModelProtoElement> embeddedProtoElements = groupMerger.GetEmbeddedElements(this.Store.DefaultPartition, protoElement); if (embeddedProtoElements.Count > 0) { foreach (ModelProtoElement p in embeddedProtoElements) { (element as IModelMergeElements).ModelMerge(p, groupMerger, false); } } return; } } } } } }
/// <summary> /// Processes a proto element representation of the element and adds required proto links. /// This method is called on base classes from derived classes. /// /// Hint: Properties do not need to be added in this method. /// </summary> /// <param name="protoElement">Proto element representation of the element.</param> /// <param name="protoGroup">Proto group the proto element belongs to.</param> public virtual void ModelProcessMergeCopy(ModelProtoElement protoElement, ModelProtoGroup protoGroup) { foreach (ElementLink link in DomainRoleInfo.GetAllElementLinks(this)) { if (link is DomainModelLink) { DomainModelLink modelLink = link as DomainModelLink; DomainRelationshipAdvancedInfo info = this.Store.DomainDataAdvDirectory.GetRelationshipInfo(modelLink.GetDomainClassId()); if (info is ReferenceRelationshipAdvancedInfo) { if (DomainRoleInfo.GetSourceRolePlayer(modelLink) == this) { if (!(info as ReferenceRelationshipAdvancedInfo).PropagatesCopyToTarget) { continue; } } else if (!(info as ReferenceRelationshipAdvancedInfo).PropagatesCopyToSource) { continue; } ModelProtoLink protoLink = new ModelProtoLink(link); protoGroup.AddNewReferenceLink(protoLink); } else { DomainModelElement child = DomainRoleInfo.GetTargetRolePlayer(link) as DomainModelElement; if (child == this || child == null) { continue; } if ((info as EmbeddingRelationshipAdvancedInfo).PropagatesCopyToChild) { if (!(info as EmbeddingRelationshipAdvancedInfo).IsTargetIncludedSubmodel) { ModelProtoLink protoLink = new ModelProtoLink(link); protoGroup.AddNewEmbeddingLink(protoLink); child.ModelCreateMergeCopy(protoGroup); } else if (child is IParentModelElement) { ModelProtoLink protoLink = new ModelProtoLink(link); protoLink.IsTargetIncludedSubmodel = true; protoLink.DomainFilePath = (child as IParentModelElement).DomainFilePath; protoGroup.AddNewReferenceLink(protoLink); } } } } } /* * // process reference relationships * List<ReferenceRelationshipAdvancedInfo> infos = this.Store.DomainDataAdvDirectory.FindDomainClassSourceReferences(this.GetDomainClassId()); * if (infos != null) * foreach (ReferenceRelationshipAdvancedInfo info in infos) * { * if (info.PropagatesCopyToTarget) * { * System.Collections.ObjectModel.ReadOnlyCollection<ElementLink> links = DomainRoleInfo.GetElementLinks<ElementLink>(this, info.SourceRoleId); * foreach (ElementLink link in links) * { * ModelProtoLink protoLink = new ModelProtoLink(link); * protoGroup.AddNewReferenceLink(protoLink); * } * } * } * infos = this.Store.DomainDataAdvDirectory.FindDomainClassTargetReferences(this.GetDomainClassId()); * if (infos != null) * foreach (ReferenceRelationshipAdvancedInfo info in infos) * { * if (info.PropagatesCopyToSource) * { * System.Collections.ObjectModel.ReadOnlyCollection<ElementLink> links = DomainRoleInfo.GetElementLinks<ElementLink>(this, info.TargetRoleId); * foreach (ElementLink link in links) * { * ModelProtoLink protoLink = new ModelProtoLink(link); * protoGroup.AddNewReferenceLink(protoLink); * } * } * } * * // process embedding relationships * List<EmbeddingRelationshipAdvancedInfo> infosEmb = this.Store.DomainDataAdvDirectory.FindDomainClassSourceEmbeddings(this.GetDomainClassId()); * if (infosEmb != null) * foreach (EmbeddingRelationshipAdvancedInfo info in infosEmb) * { * if (info.PropagatesCopyToChild) * { * System.Collections.ObjectModel.ReadOnlyCollection<ElementLink> links = DomainRoleInfo.GetElementLinks<ElementLink>(this, info.SourceRoleId); * foreach (ElementLink link in links) * { * ModelProtoLink protoLink = new ModelProtoLink(link); * protoGroup.AddNewEmbeddingLink(protoLink); * * DomainModelElement child = DomainRoleInfo.GetTargetRolePlayer(link) as DomainModelElement; * if( child != null ) * child.ModelCreateMergeCopy(protoGroup); * } * } * } */ }
/// <summary> /// Verifies if the given model element belongs to the domain model (can be reached from the domain model element). /// </summary> /// <param name="modelElement">Model element.</param> /// <returns>True if the element belongs to the domain model. False otherwise.</returns> public bool IsIncludedInModel(DomainModelElement modelElement) { return(IsIncludedInModel(Guid.Empty, modelElement)); }