/// <summary> /// Constructor. /// </summary> /// <param name="link">Element link.</param> public ModelProtoLink(ElementLink link) : base(link) { if (link == null) { throw new System.ArgumentNullException("link"); } IList <Microsoft.VisualStudio.Modeling.DomainRoleInfo> ilist = link.GetDomainRelationship().DomainRoles; rolePlayers = new System.Collections.Generic.List <ModelProtoRolePlayer>(2); for (int i = 0; i < 2; i++) { Microsoft.VisualStudio.Modeling.DomainRoleInfo domainRoleInfo = ilist[i]; Microsoft.VisualStudio.Modeling.ModelElement modelElement = domainRoleInfo.GetRolePlayer(link); System.Guid guid = modelElement != null ? modelElement.Id : System.Guid.Empty; if (modelElement is DomainClass) { rolePlayers.Add(new ModelProtoRolePlayer(domainRoleInfo.Id, guid, (modelElement as DomainClass).Name)); } else { rolePlayers.Add(new ModelProtoRolePlayer(domainRoleInfo.Id, guid, "")); } } }
/// <summary> /// Initializes the resources for each instance of the connector. /// </summary> protected override void InitializeInstanceResources() { base.InitializeInstanceResources(); // TODO: Need to find a better pattern for connectors, becuase this code never executes as a connector does not have a non-null MEL // to get to the target MEL from. // Set tailorable colors (based upon the target element) ElementLink link = this.Subject as ElementLink; if (link != null) { NamedElementSchema targetElement = DomainRoleInfo.GetTargetRolePlayer(link) as NamedElementSchema; if ((targetElement != null) && (targetElement.IsInheritedFromBase)) { // Set tailoring styles for this instance. this.SetShapeBrushColor(DiagramBrushes.ConnectionLineDecorator, this.TailoringColors.TextColor); this.SetShapePenColor(DiagramPens.ConnectionLine, this.TailoringColors.OutlineColor); this.SetShapePenColor(DiagramPens.ConnectionLineDecorator, this.TailoringColors.OutlineColor); this.SetShapeBrushColor(DiagramBrushes.ShapeText, this.TailoringColors.TextColor); } else { // Reset to orginally configured styles for this instance. this.InitializeResources(this.StyleSet); } } else { // Reset to orginally configured styles for this instance. this.InitializeResources(this.StyleSet); } }
/// <summary> /// Test if null is allowed for the provided link. /// </summary> /// <param name="link">The current element link for /// the component associated with this role player</param> /// <returns></returns> public virtual bool CanAllowNull(ElementLink link) { if (link == null) { return(true); } DomainRoleInfo targetDomainRole = DomainRoleInfo; DomainRoleInfo sourceDomainRole = targetDomainRole.OppositeDomainRole; bool sourceIsOptional = sourceDomainRole.IsOptional; if (sourceIsOptional && targetDomainRole.IsOptional) { // We previously determined that we always allow null. return(true); } if (sourceIsOptional) { // The source role is optional, but the target role isn't. However, // we need to check/ for other instances of this type of relationship // that satisfy that. if (targetDomainRole.Multiplicity == Multiplicity.OneMany) { ModelElement targetPlayer = targetDomainRole.GetRolePlayer(link); if (targetDomainRole.GetElementLinks <ElementLink>(targetPlayer).Count > 1) { // There is at least one other instance of this type of relationship, // which means that the "mandatory" on the target role would still be // satisfied even if this link were to be deleted. return(true); } } } return(false); }
private static ModelElement GetCompartmentElementFirstParentElement(this ModelElement modelElement) { // Get the domain class associated with model element. DomainClassInfo domainClass = modelElement.GetDomainClass(); if (domainClass != null) { // A element is only considered to be in a compartment if it participates in only 1 embedding relationship // This might be wrong for some models if (domainClass.AllEmbeddedByDomainRoles.Count == 1) { DomainRoleInfo roleInfo = domainClass.AllEmbeddedByDomainRoles[0]; // Get a collection of all the links to this model element // Since this is in a compartment there should be at least one // There can be only one. if (roleInfo != null) { ElementLink link = roleInfo.GetElementLinks(modelElement).FirstOrDefault(); // Get the model element participating in the link that isn't the current one // That will be the parent // Probably there is a better way to achieve the same result return(link?.LinkedElements?.FirstOrDefault(linkedElement => !modelElement.Equals(linkedElement))); } } } return(null); }
/// <summary> /// Constructor. /// </summary> /// <param name="link">Element link.</param> public ModelProtoLink(ElementLink link) : base(link) { if (link == null) { throw new System.ArgumentNullException("link"); } IList <Microsoft.VisualStudio.Modeling.DomainRoleInfo> ilist = link.GetDomainRelationship().DomainRoles; rolePlayers = new System.Collections.Generic.List <ModelProtoRolePlayer>(2); for (int i = 0; i < 2; i++) { Microsoft.VisualStudio.Modeling.DomainRoleInfo domainRoleInfo = ilist[i]; Microsoft.VisualStudio.Modeling.ModelElement modelElement = domainRoleInfo.GetRolePlayer(link); System.Guid guid = modelElement != null ? modelElement.Id : System.Guid.Empty; string name = ""; if (modelElement is IDomainModelOwnable) { if ((modelElement as IDomainModelOwnable).DomainElementHasName) { name = (modelElement as IDomainModelOwnable).DomainElementName; } } rolePlayers.Add(new ModelProtoRolePlayer(domainRoleInfo.Id, guid, name)); } this.isTargetIncludedSubmodel = false; this.domainFilePath = ""; }
/// <summary> /// Constructor. /// </summary> /// <param name="elementLink">Relationship instance.</param> /// <param name="category">Category of the dependency item.</param> public DependencyItem(string message, DependencyItemCategory category, ModelElement source, ModelElement target) { this.elementLink = null; this.itemCategory = category; this.SourceElement = source; this.TargetElement = target; this.Message = message; }
/// <summary> /// Constructor. /// </summary> /// <param name="elementLink">Relationship instance.</param> /// <param name="category">Category of the dependency item.</param> public DependencyItem(ElementLink elementLink, DependencyItemCategory category, ModelElement source, ModelElement target) { this.elementLink = elementLink; this.itemCategory = category; this.SourceElement = source; this.TargetElement = target; this.Message = null; }
/// <summary> /// Constructor. /// </summary> /// <param name="elementLink">Relationship instance.</param> /// <param name="category">Category of the dependency item.</param> public DependencyItem(string message, DependencyItemCategory category, ModelElement source, ModelElement target) { this.elementLink = null; this.itemCategory = category; this.SourceElement = source; this.TargetElement = target; this.Message = message; }
/// <summary> /// Constructor. /// </summary> /// <param name="elementLink">Relationship instance.</param> /// <param name="category">Category of the dependency item.</param> public DependencyItem(ElementLink elementLink, DependencyItemCategory category, ModelElement source, ModelElement target) { this.elementLink = elementLink; this.itemCategory = category; this.SourceElement = source; this.TargetElement = target; this.Message = null; }
protected virtual BaseModelElementTreeViewModel AddChildElement(ElementLink relationship, ModelElement element, bool isInDeserialization) { if (element == null || relationship == null) { return(null); } // check if already added if (!isInDeserialization) { foreach (Tum.PDE.ToolFramework.Modeling.Visualization.ViewModel.ModelTree.BaseModelElementTreeViewModel vm in this.Children) { // this can actually happen without any error occuring, because it depends on // the order of transactions.. e.g.: // 1. Add parent in first transaction. Add child in second --> this clause will not occur. // 2. Add parent and child in one transaction. This clause will occur, because parent // automatically adds its children and there is no easy way of preventing this method from // beeing called. if (vm.Element.Id == element.Id) { return(vm); } } } // create new view model for this specified element ModelElementTreeViewModel viewModel = this.ViewModelStore.Factory.CreateModelElementTreeViewModel(element, relationship, GetTargetDomainRole(relationship.GetDomainRelationship()).Id, this, DoHookUpEvents, DoCreateContextMenus, this.MainModelTreeViewModel); if (viewModel == null) { throw new System.ArgumentNullException("Could not resolve VM for " + element.ToString()); } // add new VModellvariante into children collection this.AddElementToCollection(relationship, viewModel); // set selection to new element if (!isInDeserialization) { if (this.MainModelTreeViewModel != null) { if (this.MainModelTreeViewModel.IsActiveView && !this.ViewModelStore.InLoad) { //viewModel.IsSelected = true; if (viewModel.Parent != null) { if (!viewModel.Parent.IsExpanded) { viewModel.Parent.IsExpanded = true; } } } } } return(viewModel); }
private void OnChildElementAdded(ElementAddedEventArgs args) { ElementLink relationship = args.ModelElement as ElementLink; if (DomainRoleInfo.GetSourceRolePlayer(relationship) == Element) { AddChildElement(relationship, DomainRoleInfo.GetTargetRolePlayer(relationship), false); } }
private void OnChildElementDeleted(ElementDeletedEventArgs args) { ElementLink relationship = args.ModelElement as ElementLink; if (DomainRoleInfo.GetSourceRolePlayer(relationship) == Element) { RemoveChildElement(DomainRoleInfo.GetTargetRolePlayer(relationship)); } }
private ModelElement GetTargetOfRelationship(DomainRelationshipInfo info, ElementLink elementLink) { if (elementLink == null) { return(null); } return(DomainRoleInfo.GetTargetRolePlayer(elementLink)); }
private NodeShape CreateChildShape(ElementLink link, bool bSource) { if (!bSource) { return(CreateShape(DomainRoleInfo.GetSourceRolePlayer(link))); } else { return(CreateShape(DomainRoleInfo.GetTargetRolePlayer(link))); } }
/// <summary> /// Called by the Action when the user releases the mouse. /// If we are still on the same compartment but in a different list item, /// move the starting item to the position of the current one. /// </summary> /// <param name="dragFrom"></param> /// <param name="e"></param> internal static void DoMouseUpForShape <TElement>(ModelElement dragFrom, DiagramMouseEventArgs e) where TElement : ModelElement { // Original or "from" item: TElement dragFromElement = dragFrom as TElement; // Current or "to" item: TElement dragToElement = e.HitDiagramItem.RepresentedElements.OfType <TElement>().FirstOrDefault(); if (dragFromElement != null && dragToElement != null) { // Find the common parent model element, and the relationship links: ElementLink parentToLink = GetEmbeddingLink(dragToElement); ElementLink parentFromLink = GetEmbeddingLink(dragFromElement); if (parentToLink != parentFromLink && parentFromLink != null && parentToLink != null) { // Get the static relationship and role (= end of relationship): DomainRelationshipInfo relationshipFrom = parentFromLink.GetDomainRelationship(); DomainRoleInfo parentFromRole = relationshipFrom.DomainRoles[0]; // Get the node in which the element is embedded, usually the element displayed in the shape: ModelElement parentFrom = parentFromLink.LinkedElements[0]; // Same again for the target: DomainRelationshipInfo relationshipTo = parentToLink.GetDomainRelationship(); DomainRoleInfo parentToRole = relationshipTo.DomainRoles[0]; ModelElement parentTo = parentToLink.LinkedElements[0]; // Mouse went down and up in same parent and same compartment: if (parentTo == parentFrom && relationshipTo == relationshipFrom) { // Find index of target position: int newIndex = 0; var elementLinks = parentToRole.GetElementLinks(parentTo); foreach (ElementLink link in elementLinks) { if (link == parentToLink) { break; } newIndex++; } if (newIndex < elementLinks.Count) { using (Transaction t = parentFrom.Store.TransactionManager.BeginTransaction("Move list item")) { parentFromLink.MoveToIndex(parentFromRole, newIndex); t.Commit(); } } } } } }
private GraphicalDependencyShape CreateHostShape(ElementLink link, DomainRelationshipInfo info) { GraphicalDependencyShape shape = new GraphicalDependencyShape(this.Store); shape.RelationshipName = info.DisplayName; shape.Element = link; shape.SetLocation(new PointD(5, 5)); shape.RelationshipTypeId = info.Id; this.Diagram.Children.Add(shape); return(shape); }
/// <summary> /// Called by the Action when the user releases the mouse. /// If we are still on the same compartment but in a different list item, /// move the starting item to the position of the current one. /// </summary> /// <param name="dragFrom"></param> /// <param name="e"></param> public void DoMouseUp(ModelElement dragFrom, DiagramMouseEventArgs e) { // Original or "from" item: #pragma warning disable IDE0019 // Use pattern matching ModelAttribute dragFromElement = dragFrom as ModelAttribute; #pragma warning restore IDE0019 // Use pattern matching // Current or "to" item: ModelAttribute dragToElement = e.HitDiagramItem.RepresentedElements.OfType <ModelAttribute>().FirstOrDefault(); if (dragFromElement != null && dragToElement != null) { // Find the common parent model element, and the relationship links: ElementLink parentToLink = GetEmbeddingLink(dragToElement); ElementLink parentFromLink = GetEmbeddingLink(dragFromElement); if (parentToLink != parentFromLink && parentFromLink != null && parentToLink != null) { // Get the static relationship and role (= end of relationship): DomainRelationshipInfo relationshipFrom = parentFromLink.GetDomainRelationship(); DomainRoleInfo parentFromRole = relationshipFrom.DomainRoles[0]; // Get the node in which the element is embedded, usually the element displayed in the shape: #pragma warning disable IDE0019 // Use pattern matching ModelClass parentFrom = parentFromLink.LinkedElements[0] as ModelClass; #pragma warning restore IDE0019 // Use pattern matching // Same again for the target: DomainRelationshipInfo relationshipTo = parentToLink.GetDomainRelationship(); DomainRoleInfo parentToRole = relationshipTo.DomainRoles[0]; // Mouse went down and up in same parent and same compartment: if (parentFrom != null && parentToLink.LinkedElements[0] is ModelClass parentTo && parentTo == parentFrom && relationshipTo == relationshipFrom) { // Find index of target position: int newIndex = parentToRole.GetElementLinks(parentTo).IndexOf(parentToLink); if (newIndex >= 0) { using (Transaction t = parentFrom.Store.TransactionManager.BeginTransaction("Move list item")) { parentFromLink.MoveToIndex(parentFromRole, newIndex); // HACK //parentTo.SetFlagValues(); t.Commit(); } } } } } }
private void OnRolePlayerChanged(RolePlayerChangedEventArgs args) { ElementLink relationship = args.ElementLink as ElementLink; if (args.OldRolePlayer == Element) { // remove VModellvariante from children collection RemoveChildElement(DomainRoleInfo.GetTargetRolePlayer(relationship)); } if (args.NewRolePlayer == Element) { AddChildElement(relationship, DomainRoleInfo.GetTargetRolePlayer(relationship), false); } }
public static DslModeling::ElementLink Connect(DslModeling::ModelElement source, DslModeling::ModelElement target) { if (source == null) { throw new global::System.ArgumentNullException("source"); } if (target == null) { throw new global::System.ArgumentNullException("target"); } if (CanAcceptSourceAndTarget(source, target)) { if (target is ExternalComponent) { if (source is DataLayer) { return(new DataLayerReferencesExternalComponent((DataLayer)source, (ExternalComponent)target)); } } // Enregistrement de la position initiale de l'élément initial pour aligner // les élements verticalement dans le cas d'une référence multicouches. IList <PresentationElement> shapes = null; // On privilégie la source if (source is ClassImplementation || source is ServiceContract) { shapes = PresentationViewsSubject.GetPresentation(source); } else if (target is ClassImplementation || target is ServiceContract) { shapes = PresentationViewsSubject.GetPresentation(target); } if (shapes != null && shapes.Count > 0) { UnplacedModelHelper.RegisterInitialPosition(source.Store, ((NodeShape)shapes[0]).AbsoluteBoundingBox.X); } ElementLink link = CreateLink(source, target); if (link != null) { return(link); } } global::System.Diagnostics.Debug.Fail("Having agreed that the connection can be accepted we should never fail to make one."); throw new global::System.InvalidOperationException(); }
/// <summary> /// /// </summary> /// <param name="elementLink">Relationship instance.</param> /// <param name="category">Category of the dependency item.</param> /// <param name="relationshipInfo">Relationship info.</param> /// <param name="roleInfo">Role info.</param> /// <returns></returns> public bool Contains(ElementLink elementLink, DependencyItemCategory category, DomainRelationshipInfo relationshipInfo, DomainRoleInfo roleInfo) { foreach (DependencyItem item in ActiveDependencies) { if (item.ElementLink == elementLink && item.Category == category && item.RelationshipInfo == relationshipInfo && item.RoleInfo == roleInfo) { return(true); } } return(false); }
public virtual VisitorFilterResult ShouldVisitRolePlayer( ElementWalker walker, ModelElement sourceElement, ElementLink elementLink, DomainRoleInfo targetDomainRole, ModelElement targetRolePlayer) { Guard.ArgumentNotNull(targetDomainRole, "targetDomainRole"); if (targetDomainRole.IsEmbedding) { return(VisitorFilterResult.DoNotCare); } return(VisitorFilterResult.Yes); }
/// <summary> /// If <see cref="CanResetValue"/> returns <see langword="true"/>, /// deletes <see cref="RolePlayerPropertyDescriptor.Link"/>. /// </summary> /// <remarks> /// Replaces <see cref="RolePlayerPropertyDescriptor.ResetValue"/>. /// </remarks> public override void ResetValue(object component) { ElementLink elementLink = this.Link; // We defer to CanResetValue rather than checking the conditions ourself // so that a derived type can add or alter the conditions without // having to override this method as well. if (elementLink != null && this.CanResetValue(component)) { using (Transaction transaction = this.BeginTransaction(elementLink.Store)) { elementLink.Delete(); transaction.Commit(); } } }
public virtual VisitorFilterResult ShouldVisitRolePlayer( ElementWalker walker, ModelElement sourceElement, ElementLink elementLink, DomainRoleInfo targetDomainRole, ModelElement targetRolePlayer) { Guard.ArgumentNotNull(targetDomainRole, "targetDomainRole"); if(targetDomainRole.IsEmbedding) { return VisitorFilterResult.DoNotCare; } return VisitorFilterResult.Yes; }
/// <summary> /// Applies the design-time policy to the given element properties. /// </summary> private static PropertyDescriptorCollection ApplyDesignPolicy(ElementLink link, IEnumerable<PropertyDescriptor> properties) { var descriptors = properties.ToDictionary(property => property.Name); // Get the target role as a NamedElement NamedElementSchema targetElement = DomainRoleInfo.GetTargetRolePlayer(link) as NamedElementSchema; if (targetElement != null) { if (targetElement.IsInheritedFromBase) { // Add read-only attribute to the Cardinality property of the element (and its relationship to the owning parent element) string propertyName = Reflector<ViewHasElements>.GetProperty(rellie => rellie.Cardinality).Name; var cardinalityProperty = descriptors[propertyName]; descriptors[cardinalityProperty.Name] = new DelegatingPropertyDescriptor(cardinalityProperty, new ReadOnlyAttribute(true)); } } return new PropertyDescriptorCollection(descriptors.Values.ToArray()); }
protected BaseModelElementTreeViewModel(ViewModelStore viewModelStore, ModelElement element, ElementLink link, Guid domainRoleId, BaseModelElementTreeViewModel parent, bool bHookUpEvents, bool bCreateContextMenus, MainModelTreeViewModel mainModelTreeVm) : base(viewModelStore, element, bHookUpEvents, false) { this.parent = parent; this.mainModelTreeVm = mainModelTreeVm; this.bCreateContextMenus = bCreateContextMenus; this.elementLink = link; this.domainRoleId = domainRoleId; this.elementLinkOrder = new List<Guid>(); if (link != null) this.linkDomainClassId = link.GetDomainClass().Id; else this.linkDomainClassId = Guid.Empty; Initialize(); }
/// <summary> /// Verifies if a specific model relationship should be excluded or not. /// </summary> /// <param name="elementLink">Model relationship to verify</param> /// <returns>True if the specified relationship should be excluded; False otherwise.</returns> public virtual bool ShouldExcludeDomainRelationship(ElementLink elementLink) { if (bUseExcludedDomainClasses || bUseIncludedDomainClasses || bUseExcludedDomainModels || bUseIncludedDomainModels) { Guid t = elementLink.GetDomainClass().Id; if (bUseExcludedDomainRelationships) { if (this.excludedDomainRelationships.Contains(t)) { return(true); } } if (bUseIncludedDomainRelationships) { if (!this.includedDomainRelationships.Contains(t)) { return(true); } } if (bUseExcludedDomainModels) { IDomainModelOwnable o = elementLink as IDomainModelOwnable; if (this.excludedDomainModels.Contains(o.GetDomainModelTypeId())) { return(true); } } if (bUseIncludedDomainModels) { IDomainModelOwnable o = elementLink as IDomainModelOwnable; if (!this.includedDomainModels.Contains(o.GetDomainModelTypeId())) { return(true); } } } return(false); }
private static ModelElement GetCompartmentElementFirstParentElement(this ModelElement modelElement) { // Get the domain class associated with model element. DomainClassInfo domainClass = modelElement.GetDomainClass(); if (domainClass?.AllEmbeddedByDomainRoles?.Count == 1) { DomainRoleInfo roleInfo = domainClass.AllEmbeddedByDomainRoles[0]; // Get a collection of all the links to this model element // Since this is in a compartment there should be at least one // There can be only one. ElementLink elementLink = roleInfo.GetElementLinks(modelElement)?.FirstOrDefault(); return(elementLink?.LinkedElements?.FirstOrDefault(e => !modelElement.Equals(e))); } return(null); }
/// <summary> /// Constructor. /// </summary> /// <param name="link">Element link.</param> public ModelProtoLink(ElementLink link) : base(link) { if (link == null) throw new System.ArgumentNullException("link"); IList<Microsoft.VisualStudio.Modeling.DomainRoleInfo> ilist = link.GetDomainRelationship().DomainRoles; rolePlayers = new System.Collections.Generic.List<ModelProtoRolePlayer>(2); for (int i = 0; i < 2; i++) { Microsoft.VisualStudio.Modeling.DomainRoleInfo domainRoleInfo = ilist[i]; Microsoft.VisualStudio.Modeling.ModelElement modelElement = domainRoleInfo.GetRolePlayer(link); System.Guid guid = modelElement != null ? modelElement.Id : System.Guid.Empty; if( modelElement is DomainClass ) rolePlayers.Add(new ModelProtoRolePlayer(domainRoleInfo.Id, guid, (modelElement as DomainClass).Name)); else rolePlayers.Add(new ModelProtoRolePlayer(domainRoleInfo.Id, guid, "")); } }
/// <summary> /// Applies the design-time policy to the given element properties. /// </summary> private static PropertyDescriptorCollection ApplyDesignPolicy(ElementLink link, IEnumerable <PropertyDescriptor> properties) { var descriptors = properties.ToDictionary(property => property.Name); // Get the target role as a NamedElement NamedElementSchema targetElement = DomainRoleInfo.GetTargetRolePlayer(link) as NamedElementSchema; if (targetElement != null) { if (targetElement.IsInheritedFromBase) { // Add read-only attribute to the Cardinality property of the element (and its relationship to the owning parent element) string propertyName = Reflector <ViewHasElements> .GetProperty(rellie => rellie.Cardinality).Name; var cardinalityProperty = descriptors[propertyName]; descriptors[cardinalityProperty.Name] = new DelegatingPropertyDescriptor(cardinalityProperty, new ReadOnlyAttribute(true)); } } return(new PropertyDescriptorCollection(descriptors.Values.ToArray())); }
private bool VisitElementAndLinks(ModelElement e) { bool keepVisiting = VisitElement(e); if (keepVisiting) { ElementLink thisLink = e as ElementLink; if (thisLink != null) { keepVisiting = VisitRolePlayers(thisLink); } if (keepVisiting) { IList <ModelElement> elems = GetRelatedElements(e); foreach (ModelElement child in elems) { if (!Visited(child)) { keepVisiting = DoVisitElement(child); } } ICrossModelingPropertyHolder holder = e as ICrossModelingPropertyHolder; if (holder != null) { ModelElement refElement = ModelBusReferenceResolver.ResolveAndCache(holder.Type); if (refElement != null) { DoVisitElement(refElement); } } } } return(keepVisiting); }
protected BaseModelElementTreeViewModel(ViewModelStore viewModelStore, ModelElement element, ElementLink link, Guid domainRoleId, BaseModelElementTreeViewModel parent, bool bHookUpEvents, bool bCreateContextMenus, MainModelTreeViewModel mainModelTreeVm) : base(viewModelStore, element, bHookUpEvents, false) { this.parent = parent; this.mainModelTreeVm = mainModelTreeVm; this.bCreateContextMenus = bCreateContextMenus; this.elementLink = link; this.domainRoleId = domainRoleId; this.elementLinkOrder = new List <Guid>(); if (link != null) { this.linkDomainClassId = link.GetDomainClass().Id; } else { this.linkDomainClassId = Guid.Empty; } Initialize(); }
private bool VisitRolePlayers(ElementLink link) { bool keepVisiting = true; DomainRelationshipInfo domainRelInfo = link.GetDomainRelationship(); IList <DomainRoleInfo> domainRoles = domainRelInfo.DomainRoles; for (int i = 0; i < domainRoles.Count && keepVisiting; i++) { DomainRoleInfo role = domainRoles[i]; // Since GetRolePlayer will do demand-loading, we first need to test here whether // role supports demand loading and if it is, don't load if not asked to. if (this.BypassDemandLoading) { Moniker rolePlayerMoniker = role.GetRolePlayerMoniker(link); if (rolePlayerMoniker != null && rolePlayerMoniker.ModelElement == null) { // skip this role if it's not resolved yet continue; } } ModelElement rolePlayer = role.GetRolePlayer(link); // Find each roleplayer and add them to the queue list // RolePlayer might be null if it is an unresolved moniker if ((rolePlayer != link) && (rolePlayer != null) && !Visited(rolePlayer) && (Filter.ShouldVisitRolePlayer(this, link, link, role, rolePlayer) == VisitorFilterResult.Yes)) { keepVisiting = DoVisitElement(rolePlayer); } } return(keepVisiting); }
public virtual VisitorFilterResult ShouldVisitRelationship( ElementWalker walker, ModelElement sourceElement, DomainRoleInfo sourceRoleInfo, DomainRelationshipInfo domainRelationshipInfo, ElementLink targetRelationship) { Guard.ArgumentNotNull(sourceElement, "sourceElement"); Guard.ArgumentNotNull(domainRelationshipInfo, "domainRelationshipInfo"); Guard.ArgumentNotNull(targetRelationship, "targetRelationship"); if(!(sourceElement is ShapeElement)) { foreach(DomainRoleInfo info in domainRelationshipInfo.DomainRoles) { if(info.GetRolePlayer(targetRelationship) == sourceElement) { return VisitorFilterResult.Yes; } } } return VisitorFilterResult.DoNotCare; }
public virtual VisitorFilterResult ShouldVisitRelationship( ElementWalker walker, ModelElement sourceElement, DomainRoleInfo sourceRoleInfo, DomainRelationshipInfo domainRelationshipInfo, ElementLink targetRelationship) { Guard.ArgumentNotNull(sourceElement, "sourceElement"); Guard.ArgumentNotNull(domainRelationshipInfo, "domainRelationshipInfo"); Guard.ArgumentNotNull(targetRelationship, "targetRelationship"); if (!(sourceElement is ShapeElement)) { foreach (DomainRoleInfo info in domainRelationshipInfo.DomainRoles) { if (info.GetRolePlayer(targetRelationship) == sourceElement) { return(VisitorFilterResult.Yes); } } } return(VisitorFilterResult.DoNotCare); }
/// <summary> /// Included relative and nested shapes in a default copy closure. /// The core design surface model does not do this in VS2010. /// </summary> public override VisitorFilterResult ShouldVisitRelationship(ElementWalker walker, ModelElement sourceElement, DomainRoleInfo sourceRoleInfo, DomainRelationshipInfo domainRelationshipInfo, ElementLink targetRelationship) { Guid roleId = sourceRoleInfo.Id; if (roleId == ParentShapeHasRelativeChildShapes.ParentShapeDomainRoleId || roleId == ParentShapeContainsNestedChildShapes.ParentShapeDomainRoleId) { return VisitorFilterResult.Yes; } return base.ShouldVisitRelationship(walker, sourceElement, sourceRoleInfo, domainRelationshipInfo, targetRelationship); }
/// <summary> /// Included relative and nested shapes in a default copy closure. /// The core design surface model does not do this in VS2010. /// </summary> public override VisitorFilterResult ShouldVisitRolePlayer(ElementWalker walker, ModelElement sourceElement, ElementLink elementLink, DomainRoleInfo targetDomainRole, ModelElement targetRolePlayer) { Guid roleId = targetDomainRole.Id; if (roleId == ParentShapeHasRelativeChildShapes.RelativeChildShapesDomainRoleId || roleId == ParentShapeContainsNestedChildShapes.NestedChildShapesDomainRoleId) { return VisitorFilterResult.Yes; } return base.ShouldVisitRolePlayer(walker, sourceElement, elementLink, targetDomainRole, targetRolePlayer); }
/// <summary> /// Test if null is allowed for the provided link. /// </summary> /// <param name="link">The current element link for /// the component associated with this role player</param> /// <returns></returns> public virtual bool CanAllowNull(ElementLink link) { if (link == null) { return true; } DomainRoleInfo targetDomainRole = DomainRoleInfo; DomainRoleInfo sourceDomainRole = targetDomainRole.OppositeDomainRole; bool sourceIsOptional = sourceDomainRole.IsOptional; if (sourceIsOptional && targetDomainRole.IsOptional) { // We previously determined that we always allow null. return true; } if (sourceIsOptional) { // The source role is optional, but the target role isn't. However, // we need to check/ for other instances of this type of relationship // that satisfy that. if (targetDomainRole.Multiplicity == Multiplicity.OneMany) { ModelElement targetPlayer = targetDomainRole.GetRolePlayer(link); if (targetDomainRole.GetElementLinks<ElementLink>(targetPlayer).Count > 1) { // There is at least one other instance of this type of relationship, // which means that the "mandatory" on the target role would still be // satisfied even if this link were to be deleted. return true; } } } return false; }
/// <summary>Implements ICustomSerializedElement.GetCustomSerializedLinkInfo</summary> protected CustomSerializedElementInfo GetCustomSerializedLinkInfo(DomainRoleInfo rolePlayedInfo, ElementLink elementLink) { Guid roleId = rolePlayedInfo.Id; if (roleId == EntityTypePlaysRole.RoleDomainRoleId) { return new CustomSerializedElementInfo(null, "Role", null, CustomSerializedElementWriteStyle.Element, null); } if (roleId == EntityTypeIsSubtypeOfEntityType.SubtypeDomainRoleId) { return new CustomSerializedElementInfo(null, "EntityType", null, CustomSerializedElementWriteStyle.Element, null); } if (roleId == EntityTypeIsSubtypeOfEntityType.SupertypeDomainRoleId) { return new CustomSerializedElementInfo(null, null, null, CustomSerializedElementWriteStyle.NotWritten, null); } return CustomSerializedElementInfo.Default; }
/// <summary>Implements ICustomSerializedElement.GetCustomSerializedLinkInfo</summary> protected CustomSerializedElementInfo GetCustomSerializedLinkInfo(DomainRoleInfo rolePlayedInfo, ElementLink elementLink) { Guid roleId = rolePlayedInfo.Id; if (roleId == GenerationSettingTargetsAbstractionModel.GeneratedAbstractionModelDomainRoleId) { return new CustomSerializedElementInfo(null, "AbstractionModel", null, CustomSerializedElementWriteStyle.Element, null); } return CustomSerializedElementInfo.Default; }
/// <summary> /// Calls <see cref="MultiShapeUtility.ShouldVisitOnDelete"/> to determine if the relationship should be visited /// and to reconfigure any links /// </summary> /// <param name="walker">The current <see cref="ElementWalker"/></param> /// <param name="sourceElement">The <see cref="ModelElement"/> being deleted</param> /// <param name="sourceRoleInfo">The role information</param> /// <param name="domainRelationshipInfo">The relationship information</param> /// <param name="targetRelationship">The other <see cref="ModelElement"/> in the relationship</param> /// <returns>Whether to visit the relationship</returns> public override VisitorFilterResult ShouldVisitRelationship(ElementWalker walker, ModelElement sourceElement, DomainRoleInfo sourceRoleInfo, DomainRelationshipInfo domainRelationshipInfo, ElementLink targetRelationship) { if (MultiShapeUtility.ShouldVisitOnDelete(walker, sourceElement, sourceRoleInfo, domainRelationshipInfo, targetRelationship)) { return base.ShouldVisitRelationship(walker, sourceElement, sourceRoleInfo, domainRelationshipInfo, targetRelationship); } else { return VisitorFilterResult.Never; } }
/// <summary> /// Constructor. /// </summary> /// <param name="viewModelStore">View model store containing view models.</param> /// <param name="element">Element represented by this view model.</param> /// <param name="link">Element link, targeting the hosted element.</param> /// <param name="domainRoleId">Domain role id of the role that the hosted element belongs to.</param> /// <param name="parent">Parent of this view model. Can be null.</param> /// <param name="mainModelTreeVm">Model tree view model, this element vm belongs to.</param> protected BaseModelElementTreeViewModel(ViewModelStore viewModelStore, ModelElement element, ElementLink link, Guid domainRoleId, BaseModelElementTreeViewModel parent, MainModelTreeViewModel mainModelTreeVm) :this(viewModelStore, element, link, domainRoleId, parent, false, false, mainModelTreeVm) { }
/// <summary> /// Included relative and nested shapes in a default copy closure. /// The core design surface model does not do this in VS2010. /// </summary> public override VisitorFilterResult ShouldVisitRelationship(ElementWalker walker, ModelElement sourceElement, DomainRoleInfo sourceRoleInfo, DomainRelationshipInfo domainRelationshipInfo, ElementLink targetRelationship) { Guid roleId = sourceRoleInfo.Id; if (roleId == ParentShapeHasRelativeChildShapes.ParentShapeDomainRoleId || roleId == ParentShapeContainsNestedChildShapes.ParentShapeDomainRoleId) { return(VisitorFilterResult.Yes); } return(base.ShouldVisitRelationship(walker, sourceElement, sourceRoleInfo, domainRelationshipInfo, targetRelationship)); }
/// <summary> /// Method used to add a element into a sorted collection without destroying the sorting order. /// </summary> /// <param name="parent">Parent model element vm.</param> /// <param name="collection">Sorted collection to add the new view models to.</param> /// <param name="link">Embedding relationship including the model element as the child (target).</param> /// <param name="c">View model representing the model element to be added to the collection.</param> public virtual void InsertElement(BaseModelElementTreeViewModel parent, ObservableCollection<BaseModelElementTreeViewModel> collection, ElementLink link, BaseModelElementTreeViewModel c) { // we are adding elements sorted first by type and name // if the element doesnt have a name, we add it at the end of the list (still sorted by type) if (!c.DomainElementHasName) { for (int i = collection.Count - 1; i >= 0; i--) { BaseModelElementTreeViewModel vm = collection[i]; if (vm.DomainElementTypeDisplayName == c.DomainElementTypeDisplayName) { collection.Insert(i + 1, c); return; } } } else { if (c.DomainElementName == null) throw new System.ArgumentNullException("DomainElementName can not be null"); bool bFoundType = false; for (int i = 0; i < collection.Count; ++i) { BaseModelElementTreeViewModel vm = collection[i]; if (vm.DomainElementTypeDisplayName == c.DomainElementTypeDisplayName) { bFoundType = true; if (c.DomainElementName.CompareTo(vm.DomainElementName) <= 0) { collection.Insert(i, c); return; } } else if (bFoundType) { collection.Insert(i, c); return; } } if (bFoundType) { collection.Add(c); return; } } // if no element of type of c is present, we add it sorted by type for (int i = 0; i < collection.Count; ++i) { BaseModelElementTreeViewModel vm = collection[i]; if (c.DomainElementTypeDisplayName.CompareTo(vm.DomainElementTypeDisplayName) <= 0) { collection.Insert(i, c); return; } } // if no element at all is present, add c at the end collection.Add(c); }
/// <summary>Implements ICustomSerializedElement.GetCustomSerializedLinkInfo</summary> CustomSerializedElementInfo ICustomSerializedElement.GetCustomSerializedLinkInfo(DomainRoleInfo rolePlayedInfo, ElementLink elementLink) { Guid roleId = rolePlayedInfo.Id; if (roleId == DiagramDisplayHasDiagramOrder.DiagramDomainRoleId) { return new CustomSerializedElementInfo(null, "Diagram", null, CustomSerializedElementWriteStyle.PrimaryLinkElement, null); } return CustomSerializedElementInfo.Default; }
/// <summary> /// Constructor. /// </summary> /// <param name="elementLink">Relationship instance.</param> /// <param name="category">Category of the dependency item.</param> /// <param name="relationshipInfo">Relationship info.</param> /// <param name="roleInfo">Role info.</param> public DependencyItem(ElementLink elementLink, DependencyItemCategory category, DomainRelationshipInfo relationshipInfo, DomainRoleInfo roleInfo) : base(elementLink.Id, relationshipInfo, roleInfo) { this.elementLink = elementLink; this.itemCategory = category; }
/// <summary> /// Creates the tree view model for the given model element. /// </summary> /// <param name="element">VModell represented by this view model.</param> /// <param name="link">Element link, targeting the hosted element.</param> /// <param name="domainRoleId">Domain role id of the role that the hosted element belongs to.</param> /// <param name="parent">Parent of this view model.</param> /// <param name="bHookUpEvents">Hook up into model events to update the created view model on changes in model if true.</param> /// <param name="bCreateContextMenus">Creates context menus for adding and deleting model elements if true.</param> /// <param name="mainModelTreeVm">Model tree view model, this element vm belongs to.</param> public abstract ModelElementTreeViewModel CreateModelElementTreeViewModel(ModelElement element, ElementLink link, System.Guid domainRoleId, ModelElementTreeViewModel parent, bool bHookUpEvents, bool bCreateContextMenus, MainModelTreeViewModel mainModelTreeVm);
/// <summary>Implements ICustomSerializedElement.GetCustomSerializedLinkInfo</summary> CustomSerializedElementInfo ICustomSerializedElement.GetCustomSerializedLinkInfo(DomainRoleInfo rolePlayedInfo, ElementLink elementLink) { Guid roleId = rolePlayedInfo.Id; if (roleId == CustomPropertyHasCustomPropertyDefinition.CustomPropertyDefinitionDomainRoleId) { return new CustomSerializedElementInfo(null, "Definition", null, CustomSerializedElementWriteStyle.Element, null); } return CustomSerializedElementInfo.Default; }
/// <summary>Implements ICustomSerializedElement.GetCustomSerializedLinkInfo</summary> protected CustomSerializedElementInfo GetCustomSerializedLinkInfo(DomainRoleInfo rolePlayedInfo, ElementLink elementLink) { Guid roleId = rolePlayedInfo.Id; if (roleId == BinaryAssociationContainsRole.BinaryAssociationDomainRoleId) { return new CustomSerializedElementInfo(null, null, null, CustomSerializedElementWriteStyle.NotWritten, null); } if (roleId == EntityTypePlaysRole.EntityTypeDomainRoleId) { return new CustomSerializedElementInfo(null, null, null, CustomSerializedElementWriteStyle.NotWritten, null); } if (roleId == ExclusiveArcSpansOptionalRole.ExclusiveArcDomainRoleId) { return new CustomSerializedElementInfo(null, null, null, CustomSerializedElementWriteStyle.NotWritten, null); } return CustomSerializedElementInfo.Default; }
/// <summary> /// Verifies if a specific model relationship should be excluded or not. /// </summary> /// <param name="elementLink">Model relationship to verify</param> /// <returns>True if the specified relationship should be excluded; False otherwise.</returns> public virtual bool ShouldExcludeDomainRelationship(ElementLink elementLink) { if (bUseExcludedDomainClasses || bUseIncludedDomainClasses || bUseExcludedDomainModels || bUseIncludedDomainModels) { Guid t = elementLink.GetDomainClass().Id; if (bUseExcludedDomainRelationships) if (this.excludedDomainRelationships.Contains(t)) return true; if (bUseIncludedDomainRelationships) if (!this.includedDomainRelationships.Contains(t)) return true; if (bUseExcludedDomainModels) { IDomainModelOwnable o = elementLink as IDomainModelOwnable; if (this.excludedDomainModels.Contains(o.GetDomainModelTypeId())) return true; } if (bUseIncludedDomainModels) { IDomainModelOwnable o = elementLink as IDomainModelOwnable; if (!this.includedDomainModels.Contains(o.GetDomainModelTypeId())) return true; } } return false; }
public ModelElementTreeViewModel(ViewModelStore viewModelStore, ModelElement element, ElementLink link, System.Guid domainRoleId, ModelElementTreeViewModel parent, bool bHookUpEvents, bool bCreateContextMenus, MainModelTreeViewModel mainModelTreeVm) : base(viewModelStore, element, link, domainRoleId, parent, bHookUpEvents, bCreateContextMenus, mainModelTreeVm) { }
/// <summary> /// Included relative and nested shapes in a default copy closure. /// The core design surface model does not do this in VS2010. /// </summary> public override VisitorFilterResult ShouldVisitRolePlayer(ElementWalker walker, ModelElement sourceElement, ElementLink elementLink, DomainRoleInfo targetDomainRole, ModelElement targetRolePlayer) { Guid roleId = targetDomainRole.Id; if (roleId == ParentShapeHasRelativeChildShapes.RelativeChildShapesDomainRoleId || roleId == ParentShapeContainsNestedChildShapes.NestedChildShapesDomainRoleId) { return(VisitorFilterResult.Yes); } return(base.ShouldVisitRolePlayer(walker, sourceElement, elementLink, targetDomainRole, targetRolePlayer)); }
private bool VisitRolePlayers(ElementLink link) { bool keepVisiting = true; DomainRelationshipInfo domainRelInfo = link.GetDomainRelationship(); IList<DomainRoleInfo> domainRoles = domainRelInfo.DomainRoles; for(int i = 0; i < domainRoles.Count && keepVisiting; i++) { DomainRoleInfo role = domainRoles[i]; // Since GetRolePlayer will do demand-loading, we first need to test here whether // role supports demand loading and if it is, don't load if not asked to. if(this.BypassDemandLoading) { Moniker rolePlayerMoniker = role.GetRolePlayerMoniker(link); if(rolePlayerMoniker != null && rolePlayerMoniker.ModelElement == null) { // skip this role if it's not resolved yet continue; } } ModelElement rolePlayer = role.GetRolePlayer(link); // Find each roleplayer and add them to the queue list // RolePlayer might be null if it is an unresolved moniker if((rolePlayer != link) && (rolePlayer != null) && !Visited(rolePlayer) && (Filter.ShouldVisitRolePlayer(this, link, link, role, rolePlayer) == VisitorFilterResult.Yes)) { keepVisiting = DoVisitElement(rolePlayer); } } return keepVisiting; }
/// <summary> /// Method used to add a element into a sorted collection without destroying the sorting order. /// </summary> /// <param name="parent">Parent model element vm.</param> /// <param name="collection">Sorted collection to add the new view models to.</param> /// <param name="link">Embedding relationship including the model element as the child (target).</param> /// <param name="c">View model representing the model element to be added to the collection.</param> public virtual void InsertElement(BaseModelElementTreeViewModel parent, ObservableCollection <BaseModelElementTreeViewModel> collection, ElementLink link, BaseModelElementTreeViewModel c) { // we are adding elements sorted first by type and name // if the element doesnt have a name, we add it at the end of the list (still sorted by type) if (!c.DomainElementHasName) { for (int i = collection.Count - 1; i >= 0; i--) { BaseModelElementTreeViewModel vm = collection[i]; if (vm.DomainElementTypeDisplayName == c.DomainElementTypeDisplayName) { collection.Insert(i + 1, c); return; } } } else { if (c.DomainElementName == null) { throw new System.ArgumentNullException("DomainElementName can not be null"); } bool bFoundType = false; for (int i = 0; i < collection.Count; ++i) { BaseModelElementTreeViewModel vm = collection[i]; if (vm.DomainElementTypeDisplayName == c.DomainElementTypeDisplayName) { bFoundType = true; if (c.DomainElementName.CompareTo(vm.DomainElementName) <= 0) { collection.Insert(i, c); return; } } else if (bFoundType) { collection.Insert(i, c); return; } } if (bFoundType) { collection.Add(c); return; } } // if no element of type of c is present, we add it sorted by type for (int i = 0; i < collection.Count; ++i) { BaseModelElementTreeViewModel vm = collection[i]; if (c.DomainElementTypeDisplayName.CompareTo(vm.DomainElementTypeDisplayName) <= 0) { collection.Insert(i, c); return; } } // if no element at all is present, add c at the end collection.Add(c); }
/// <summary>Implements ICustomSerializedElement.GetCustomSerializedLinkInfo</summary> protected CustomSerializedElementInfo GetCustomSerializedLinkInfo(DomainRoleInfo rolePlayedInfo, ElementLink elementLink) { throw new NotSupportedException(); }
/// <summary> /// Method which adds an element to the children property for treeview display. You can override /// this method to create custom sorting behaviour. /// </summary> /// <param name="link">Embedding relationship including the given model element as the child (target).</param> /// <param name="viewModel">Domain model representing the child element to be added to children property for treeview display.</param> public virtual void AddElementToCollection(ElementLink link, BaseModelElementTreeViewModel viewModel) { this.SortingProvider.InsertElement(this, this.childrenCollectionStorage, link, viewModel); }
CustomSerializedElementInfo ICustomSerializedElement.GetCustomSerializedLinkInfo(DomainRoleInfo rolePlayedInfo, ElementLink elementLink) { return this.GetCustomSerializedLinkInfo(rolePlayedInfo, elementLink); }
/// <summary> /// Initializes a new instance of the <see cref="ContainingLinkSchemaTypeDescriptor"/> class. /// </summary> /// <param name="elementLink">The model element.</param> public ContainingLinkSchemaTypeDescriptor(ElementLink elementLink) : base(elementLink) { }
/// <summary>Implements ICustomSerializedElement.GetCustomSerializedLinkInfo</summary> protected CustomSerializedElementInfo GetCustomSerializedLinkInfo(DomainRoleInfo rolePlayedInfo, ElementLink elementLink) { Guid roleId = rolePlayedInfo.Id; if (roleId == ExclusiveArcSpansOptionalRole.ConstrainedRoleDomainRoleId) { return new CustomSerializedElementInfo(null, "Role", null, CustomSerializedElementWriteStyle.Element, null); } return CustomSerializedElementInfo.Default; }
protected virtual BaseModelElementTreeViewModel AddChildElement(ElementLink relationship, ModelElement element, bool isInDeserialization) { if (element == null || relationship == null) return null; // check if already added if (!isInDeserialization) foreach (Tum.PDE.ToolFramework.Modeling.Visualization.ViewModel.ModelTree.BaseModelElementTreeViewModel vm in this.Children) // this can actually happen without any error occuring, because it depends on // the order of transactions.. e.g.: // 1. Add parent in first transaction. Add child in second --> this clause will not occur. // 2. Add parent and child in one transaction. This clause will occur, because parent // automatically adds its children and there is no easy way of preventing this method from // beeing called. if (vm.Element.Id == element.Id) return vm; // create new view model for this specified element ModelElementTreeViewModel viewModel = this.ViewModelStore.Factory.CreateModelElementTreeViewModel(element, relationship, GetTargetDomainRole(relationship.GetDomainRelationship()).Id, this, DoHookUpEvents, DoCreateContextMenus, this.MainModelTreeViewModel); if (viewModel == null) throw new System.ArgumentNullException("Could not resolve VM for " + element.ToString()); // add new VModellvariante into children collection this.AddElementToCollection(relationship, viewModel); // set selection to new element if (!isInDeserialization) if (this.MainModelTreeViewModel != null) if (this.MainModelTreeViewModel.IsActiveView && !this.ViewModelStore.InLoad) { //viewModel.IsSelected = true; if (viewModel.Parent != null) if (!viewModel.Parent.IsExpanded) viewModel.Parent.IsExpanded = true; } return viewModel; }
/// <summary>Implements ICustomSerializedElement.GetCustomSerializedLinkInfo</summary> protected new CustomSerializedElementInfo GetCustomSerializedLinkInfo(DomainRoleInfo rolePlayedInfo, ElementLink elementLink) { Guid roleId = rolePlayedInfo.Id; if (roleId == ORMSolutions.ORMArchitect.Core.ObjectModel.ORMModelElementHasExtensionModelError.ExtendedElementDomainRoleId) { return new CustomSerializedElementInfo(null, "ObjectType", null, CustomSerializedElementWriteStyle.Element, null); } if (0 != (CustomSerializedElementSupportedOperations.LinkInfo & base.SupportedCustomSerializedOperations)) { return base.GetCustomSerializedLinkInfo(rolePlayedInfo, elementLink); } return CustomSerializedElementInfo.Default; }