/// <summary>
        /// Finds a view model that is representing the given model element.
        /// </summary>
        /// <param name="element">Model element.</param>
        /// <returns>View model if found; Null otherwise.</returns>
        public virtual BaseModelElementTreeViewModel FindViewModel(ModelElement element)
        {
            if (element == null)
            {
                return(null);
            }

            if (element == this.Element)
            {
                return(this);
            }

            // search the children (without their children) first
            foreach (BaseModelElementTreeViewModel viewModel in this.ChildrenStorage)
            {
                if (viewModel.Element == element)
                {
                    return(viewModel);
                }
            }

            // continue search among children's children
            foreach (BaseModelElementTreeViewModel viewModel in this.ChildrenStorage)
            {
                BaseModelElementTreeViewModel modelFound = viewModel.FindViewModel(element);
                if (modelFound != null)
                {
                    return(modelFound);
                }
            }

            return(null);
        }
 /// <summary>
 /// Method which removes the given view model from the children property
 /// </summary>
 /// <param name="viewModel">Domain model representing the child element to be removed from the children property.</param>
 public virtual void DeleteElementFromCollection(BaseModelElementTreeViewModel viewModel)
 {
     if (childrenCollectionStorage.Contains(viewModel))
     {
         childrenCollectionStorage.Remove(viewModel);
     }
 }
        /// <summary>
        /// Clear resources.
        /// </summary>
        protected override void OnDispose()
        {
            if (contextMenu != null)
            {
                contextMenu.Dispose();
            }
            contextMenu = null;

            base.OnDispose();

            this.IsSelected = false;

            if (this.Parent != null)
            {
                if (Parent.Children != null)
                {
                    this.Parent.DeleteElementFromCollection(this);
                }
            }

            if (this.childrenCollectionStorage != null)
            {
                for (var i = childrenCollectionStorage.Count - 1; i >= 0; i--)
                {
                    childrenCollectionStorage[i].Dispose();
                }
            }

            this.parent = null;
            this.childrenCollectionStorage         = null;
            this.childrenCollectionStorageReadOnly = null;
            //this.localContextMenuProvider = null;
            //this.localSortingProvider = null;
        }
Пример #4
0
        protected override void Initialize()
        {
            base.Initialize();

            List <Guid> relationshipOrder;

            ParentChildrenMapping[this.ModelData.CurrentModelContext.ModelContextId].TryGetValue(this.ElementInfo.Id, out relationshipOrder);

            if (relationshipOrder != null)
            {
                foreach (Guid relationshipDCId in relationshipOrder)
                {
                    DomainRelationshipInfo relationshipInfo = this.Store.DomainDataDirectory.GetDomainRelationship(relationshipDCId);
                    if (DoHookUpEvents)
                    {
                        DomainRelationshipAdvancedInfo advancedInfo = this.Store.DomainDataAdvDirectory.GetRelationshipInfo(relationshipDCId);
                        //if (!advancedInfo.TargetRoleIsUIBrowsable || !advancedInfo.TargetRoleIsGenerated)
                        //if (!advancedInfo.SourceRoleIsUIBrowsable || !advancedInfo.SourceRoleIsGenerated)
                        if (!advancedInfo.SourceRoleIsUIBrowsable)
                        {
                            continue;
                        }

                        // Subscribe to add and delete element events
                        this.EventManager.GetEvent <ModelElementLinkAddedEvent>().Subscribe(
                            this.Store.DomainDataDirectory.GetDomainRelationship(relationshipInfo.Id), true,
                            this.Element.Id, new System.Action <ElementAddedEventArgs>(OnChildElementAdded));

                        this.EventManager.GetEvent <ModelElementLinkDeletedEvent>().Subscribe(
                            this.Store.DomainDataDirectory.GetDomainRelationship(relationshipInfo.Id), true,
                            this.Element.Id, new System.Action <ElementDeletedEventArgs>(OnChildElementDeleted));

                        // Subscribe to role player change events
                        this.EventManager.GetEvent <ModelRolePlayerChangedEvent>().Subscribe(
                            this.Store.DomainDataDirectory.GetDomainRelationship(relationshipInfo.Id), true,
                            this.Element.Id, new System.Action <RolePlayerChangedEventArgs>(OnRolePlayerChanged));

                        this.EventManager.GetEvent <ModelRolePlayerMovedEvent>().Subscribe(
                            this.Store.DomainDataDirectory.GetDomainRelationship(relationshipInfo.Id),
                            this.Element.Id, new System.Action <RolePlayerOrderChangedEventArgs>(OnRolePlayerMoved));
                    }

                    // element link order
                    this.ElementLinkOrder.Add(relationshipInfo.Id);

                    System.Collections.ObjectModel.ReadOnlyCollection <ElementLink> links = DomainRoleInfo.GetElementLinks <ElementLink>(this.Element, GetSourceDomainRole(relationshipInfo).Id);
                    foreach (ElementLink link in links)
                    {
                        BaseModelElementTreeViewModel vm = AddChildElement(link, DomainRoleInfo.GetTargetRolePlayer(link), true);
                        vm.RelationshipInfo = relationshipInfo;
                        vm.ElementInfo      = GetTargetDomainRole(relationshipInfo).RolePlayer;
                    }
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Deletes a view model for the given element from the children collection of the current vm.
        /// </summary>
        /// <param name="element">Element.</param>
        protected virtual void RemoveChildElement(ModelElement element)
        {
            // remove VModellvariante from children collection
            BaseModelElementTreeViewModel viewModel = this.FindViewModel(element);

            if (viewModel != null)
            {
                viewModel.Dispose();
            }
            viewModel = null;
        }
        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();
        }
        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>
        /// Reset selection.
        /// </summary>
        protected override void OnReset()
        {
            if (this.selectedItemViewModel != null)
                this.selectedItemViewModel.IsSelected = false;

            this.clickedItemViewModel = null;
            this.selectedItemViewModel = null;

            this.contextMenu = null;
            this.contextMenu = this.defaultContextMenu;

            if (rootViewModels != null)
                rootViewModels.Clear();
            rootViewModels = null;

            if (rootTreeViewItemViewModelStorage != null)
                rootTreeViewItemViewModelStorage.Dispose();
            rootTreeViewItemViewModelStorage = null;

            base.OnReset();
        }
 /// <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>
        /// Clear resources.
        /// </summary>
        protected override void OnDispose()
        {
            if (contextMenu != null)
                contextMenu.Dispose();
            contextMenu = null;

            base.OnDispose();

            this.IsSelected = false;

            if (this.Parent != null)
                if( Parent.Children != null )
                    this.Parent.DeleteElementFromCollection(this);

            if (this.childrenCollectionStorage != null)
            {
                for (var i = childrenCollectionStorage.Count - 1; i >= 0; i--)
                {
                    childrenCollectionStorage[i].Dispose();
                }
            }

            this.parent = null;
            this.childrenCollectionStorage = null;
            this.childrenCollectionStorageReadOnly = null;
            //this.localContextMenuProvider = null;
            //this.localSortingProvider = null;
        }
 /// <summary>
 /// Method which removes the given view model from the children property
 /// </summary>
 /// <param name="viewModel">Domain model representing the child element to be removed from the children property.</param>
 public virtual void DeleteElementFromCollection(BaseModelElementTreeViewModel viewModel)
 {
     if (childrenCollectionStorage.Contains(viewModel))
         childrenCollectionStorage.Remove(viewModel);
 }
 /// <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);
 }
        /// <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>
        /// 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>
 /// 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)
 {
 }
        private void SetSelectedElementInTree(BaseModelElementTreeViewModel treeElement, ModelElement modelElement)
        {
            if (treeElement.Element.Id == modelElement.Id)
            {
                //ModelTreeSelectedElement = treeElement;
                treeElement.IsSelected = true;
                treeElement.IsExpanded = true;
                return;
            }

            foreach (BaseModelElementTreeViewModel v in treeElement.Children)
                SetSelectedElementInTree(v, modelElement);
        }
        private void InitVM()
        {
            if (rootViewModels == null && this.ModelData.CurrentModelContext.RootElement != null)
            {
                rootTreeViewItemViewModelStorage = this.ViewModelStore.Factory.CreateModelElementTreeViewModel(this.ModelData.CurrentModelContext.RootElement, true, true, null);
                rootViewModels = new System.Collections.ObjectModel.ObservableCollection<BaseModelElementTreeViewModel>();
                rootViewModels.Add(rootTreeViewItemViewModelStorage);
            }

            OnPropertyChanged("RootViewModels");
        }
        private void ResetVM()
        {
            SelectedPath = "";

            if (rootViewModels != null)
                rootViewModels.Clear();
            rootViewModels = null;

            if (rootTreeViewItemViewModelStorage != null)
                rootTreeViewItemViewModelStorage.Dispose();
            rootTreeViewItemViewModelStorage = null;

            OnPropertyChanged("RootViewModels");
        }
 /// <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);
 }
        /// <summary>
        /// Finds a view model that is representing the given model element.
        /// </summary>
        /// <param name="elementId">Model element id.</param>
        /// <returns>View model if found; Null otherwise.</returns>
        public virtual string FindViewModel(Guid elementId, BaseModelElementTreeViewModel vm)
        {
            // search the children (without their children) first
            foreach (BaseModelElementTreeViewModel viewModel in vm.Children)
                if (viewModel.Element.Id == elementId)
                    return viewModel.Id.ToString();

            // continue search among children's children
            foreach (BaseModelElementTreeViewModel viewModel in vm.Children)
            {
                string modelFound = FindViewModel(elementId, viewModel);
                if (modelFound != null)
                    return viewModel.Id + "\\" + modelFound;
            }

            return null;
        }