Beispiel #1
0
        /// <summary>
        /// Constuctor.
        /// </summary>
        /// <param name="viewModelStore">The store this view model belongs to.</param>
        /// <param name="bSubscribeToEvents">True, if changes in the model need to be reflected on this view model.</param>
        public DependenciesViewModel(ViewModelStore viewModelStore, bool bSubscribeToEvents)
            : base(viewModelStore)
        {
            this.allDependencies         = new ObservableCollection <DependencyItemViewModel>();
            this.displayedDependencies   = new ObservableCollection <DependencyItemViewModel>();
            this.displayedDependenciesRO = new ReadOnlyObservableCollection <DependencyItemViewModel>(displayedDependencies);

            this.sortOrder   = DependenciesSortOrder.DependencyCategory;
            this.isAscending = true;

            this.doSubscribeToEvents = bSubscribeToEvents;
            this.hiddenCategories    = new List <DependencyItemCategory>();
            this.hiddenCategories.Add(DependencyItemCategory.Embedded);
            this.hiddenCategories.Add(DependencyItemCategory.Embedding);

            toggleEmbeddedCategoryCommand    = new DelegateCommand(ToggleEmbeddedCategoryCommand_Executed);
            toggleEmbeddingCategoryCommand   = new DelegateCommand(ToggleEmbeddingCategoryCommand_Executed);
            toggleReferencedCategoryCommand  = new DelegateCommand(ToggleReferencedCategoryCommand_Executed);
            toggleReferencingCategoryCommand = new DelegateCommand(ToggleReferencingCategoryCommand_Executed);

            sortByNumberCommand             = new DelegateCommand(SortByNumberCommand_Executed);
            sortByCategoryCommand           = new DelegateCommand(SortByCategoryCommand_Executed);
            sortBySourceModelElementCommand = new DelegateCommand(SortBySourceModelElementCommand_Executed);
            sortByTargetModelElementCommand = new DelegateCommand(SortByTargetModelElementCommand_Executed);
            sortByLinkElementCommand        = new DelegateCommand(SortByLinkElementCommand_Executed);

            navigateToSourceCommand = new DelegateCommand(NavigateToSourceCommand_Executed);
            navigateToTargetCommand = new DelegateCommand(NavigateToTargetCommand_Executed);

            // create menu
            menuOptions = new ObservableCollection <MenuItemViewModel>();

            navigateToSourceMenuItem         = new MenuItemViewModel(viewModelStore, "Navigate to source element");
            navigateToSourceMenuItem.Command = this.NavigateToSourceCommand;
            menuOptions.Add(navigateToSourceMenuItem);

            navigateToTargetMenuItem         = new MenuItemViewModel(viewModelStore, "Navigate to target element");
            navigateToTargetMenuItem.Command = this.NavigateToTargetCommand;
            menuOptions.Add(navigateToTargetMenuItem);
        }
        /// <summary>
        /// Constuctor.
        /// </summary>
        /// <param name="viewModelStore">The store this view model belongs to.</param>
        /// <param name="bSubscribeToEvents">True, if changes in the model need to be reflected on this view model.</param>
        public DependenciesViewModel(ViewModelStore viewModelStore, bool bSubscribeToEvents)
            : base(viewModelStore)
        {
            this.allDependencies = new ObservableCollection<DependencyItemViewModel>();
            this.displayedDependencies = new ObservableCollection<DependencyItemViewModel>();
            this.displayedDependenciesRO = new ReadOnlyObservableCollection<DependencyItemViewModel>(displayedDependencies);

            this.sortOrder = DependenciesSortOrder.DependencyCategory;
            this.isAscending = true;

            this.doSubscribeToEvents = bSubscribeToEvents;
            this.hiddenCategories = new List<DependencyItemCategory>();
            this.hiddenCategories.Add(DependencyItemCategory.Embedded);
            this.hiddenCategories.Add(DependencyItemCategory.Embedding);

            toggleEmbeddedCategoryCommand = new DelegateCommand(ToggleEmbeddedCategoryCommand_Executed);
            toggleEmbeddingCategoryCommand = new DelegateCommand(ToggleEmbeddingCategoryCommand_Executed);
            toggleReferencedCategoryCommand = new DelegateCommand(ToggleReferencedCategoryCommand_Executed);
            toggleReferencingCategoryCommand = new DelegateCommand(ToggleReferencingCategoryCommand_Executed);

            sortByNumberCommand = new DelegateCommand(SortByNumberCommand_Executed);
            sortByCategoryCommand = new DelegateCommand(SortByCategoryCommand_Executed);
            sortBySourceModelElementCommand = new DelegateCommand(SortBySourceModelElementCommand_Executed);
            sortByTargetModelElementCommand = new DelegateCommand(SortByTargetModelElementCommand_Executed);
            sortByLinkElementCommand = new DelegateCommand(SortByLinkElementCommand_Executed);

            navigateToSourceCommand = new DelegateCommand(NavigateToSourceCommand_Executed);
            navigateToTargetCommand = new DelegateCommand(NavigateToTargetCommand_Executed);

            // create menu
            menuOptions = new ObservableCollection<MenuItemViewModel>();

            navigateToSourceMenuItem = new MenuItemViewModel(viewModelStore, "Navigate to source element");
            navigateToSourceMenuItem.Command = this.NavigateToSourceCommand;
            menuOptions.Add(navigateToSourceMenuItem);

            navigateToTargetMenuItem = new MenuItemViewModel(viewModelStore, "Navigate to target element");
            navigateToTargetMenuItem.Command = this.NavigateToTargetCommand;
            menuOptions.Add(navigateToTargetMenuItem);
        }
Beispiel #3
0
        /// <summary>
        /// Sorts the dependencies list.
        /// </summary>
        /// <param name="order">Order to sort the dependencies list by.</param>
        /// <param name="bAscending">Ascending or descending order.</param>
        public void Sort(DependenciesSortOrder order, bool bAscending)
        {
            IOrderedEnumerable <DependencyItemViewModel> items = null;

            switch (order)
            {
            case DependenciesSortOrder.DependencyCategory:
                if (bAscending)
                {
                    items = this.DisplayedDependencies.OrderBy <DependencyItemViewModel, DependencyItemCategory>((x) => (x.Category));
                }
                else
                {
                    items = this.DisplayedDependencies.OrderByDescending <DependencyItemViewModel, DependencyItemCategory>((x) => (x.Category));
                }
                break;

            case DependenciesSortOrder.NumberAdded:
                if (bAscending)
                {
                    items = this.DisplayedDependencies.OrderBy <DependencyItemViewModel, int>((x) => (x.Number));
                }
                else
                {
                    items = this.DisplayedDependencies.OrderByDescending <DependencyItemViewModel, int>((x) => (x.Number));
                }
                break;

            case DependenciesSortOrder.SourceModelElement:
                if (bAscending)
                {
                    items = this.DisplayedDependencies.OrderBy <DependencyItemViewModel, string>((x) => (x.SourceModelElementName));
                }
                else
                {
                    items = this.DisplayedDependencies.OrderByDescending <DependencyItemViewModel, string>((x) => (x.SourceModelElementName));
                }
                break;

            case DependenciesSortOrder.TargetModelElement:
                if (bAscending)
                {
                    items = this.DisplayedDependencies.OrderBy <DependencyItemViewModel, string>((x) => (x.TargetModelElementName));
                }
                else
                {
                    items = this.DisplayedDependencies.OrderByDescending <DependencyItemViewModel, string>((x) => (x.TargetModelElementName));
                }
                break;

            case DependenciesSortOrder.LinkElement:
                if (bAscending)
                {
                    items = this.DisplayedDependencies.OrderBy <DependencyItemViewModel, string>((x) => (x.LinkElementName));
                }
                else
                {
                    items = this.DisplayedDependencies.OrderByDescending <DependencyItemViewModel, string>((x) => (x.LinkElementName));
                }
                break;

            default:
                throw new NotSupportedException();
            }

            ObservableCollection <DependencyItemViewModel> temp = new ObservableCollection <DependencyItemViewModel>();

            foreach (DependencyItemViewModel item in items)
            {
                temp.Add(item);
            }

            this.displayedDependencies   = temp;
            this.displayedDependenciesRO = new ReadOnlyObservableCollection <DependencyItemViewModel>(this.displayedDependencies);
            OnPropertyChanged("DisplayedDependencies");
        }
        /// <summary>
        /// Sorts the dependencies list.
        /// </summary>
        /// <param name="order">Order to sort the dependencies list by.</param>
        /// <param name="bAscending">Ascending or descending order.</param>
        public void Sort(DependenciesSortOrder order, bool bAscending)
        {
            IOrderedEnumerable<DependencyItemViewModel> items = null;
            switch (order)
            {
                case DependenciesSortOrder.DependencyCategory:
                    if (bAscending)
                        items = this.DisplayedDependencies.OrderBy<DependencyItemViewModel, DependencyItemCategory>((x) => (x.Category));
                    else
                        items = this.DisplayedDependencies.OrderByDescending<DependencyItemViewModel, DependencyItemCategory>((x) => (x.Category));
                    break;

                case DependenciesSortOrder.NumberAdded:
                    if (bAscending)
                        items = this.DisplayedDependencies.OrderBy<DependencyItemViewModel, int>((x) => (x.Number));
                    else
                        items = this.DisplayedDependencies.OrderByDescending<DependencyItemViewModel, int>((x) => (x.Number));
                        break;

                case DependenciesSortOrder.SourceModelElement:
                        if (bAscending)
                            items = this.DisplayedDependencies.OrderBy<DependencyItemViewModel, string>((x) => (x.SourceModelElementName));
                        else
                            items = this.DisplayedDependencies.OrderByDescending<DependencyItemViewModel, string>((x) => (x.SourceModelElementName));
                        break;

                case DependenciesSortOrder.TargetModelElement:
                    if (bAscending)
                        items = this.DisplayedDependencies.OrderBy<DependencyItemViewModel, string>((x) => (x.TargetModelElementName));
                    else
                        items = this.DisplayedDependencies.OrderByDescending<DependencyItemViewModel, string>((x) => (x.TargetModelElementName));
                    break;

                case DependenciesSortOrder.LinkElement:
                    if (bAscending)
                        items = this.DisplayedDependencies.OrderBy<DependencyItemViewModel, string>((x) => (x.LinkElementName));
                    else
                        items = this.DisplayedDependencies.OrderByDescending<DependencyItemViewModel, string>((x) => (x.LinkElementName));
                    break;

                default:
                    throw new NotSupportedException();
            }

            ObservableCollection<DependencyItemViewModel> temp = new ObservableCollection<DependencyItemViewModel>();
            foreach (DependencyItemViewModel item in items)
                temp.Add(item);

            this.displayedDependencies = temp;
            this.displayedDependenciesRO = new ReadOnlyObservableCollection<DependencyItemViewModel>(this.displayedDependencies);
            OnPropertyChanged("DisplayedDependencies");        
        }