コード例 #1
0
        public ElementTreeItemViewModel(IMatrixViewModel matrixViewModel, IDsmElement element, int depth)
        {
            _children = new List <ElementTreeItemViewModel>();
            _parent   = null;
            Element   = element;
            Depth     = depth;
            Color     = MatrixColorConverter.GetColor(depth);

            MoveCommand                  = matrixViewModel.ChangeElementParentCommand;
            MoveUpElementCommand         = matrixViewModel.MoveUpElementCommand;
            MoveDownElementCommand       = matrixViewModel.MoveDownElementCommand;
            SortElementCommand           = matrixViewModel.SortElementCommand;
            ToggleElementExpandedCommand = matrixViewModel.ToggleElementExpandedCommand;
        }
コード例 #2
0
        private void DefineCellColors()
        {
            int matrixSize = _elementViewModelLeafs.Count;

            _cellColors = new List <List <MatrixColor> >();

            // Define background color
            for (int row = 0; row < matrixSize; row++)
            {
                _cellColors.Add(new List <MatrixColor>());
                for (int column = 0; column < matrixSize; column++)
                {
                    _cellColors[row].Add(MatrixColor.Background);
                }
            }

            // Define expanded block color
            for (int row = 0; row < matrixSize; row++)
            {
                ElementTreeItemViewModel viewModel = _elementViewModelLeafs[row];
                IDsmElement element = viewModel.Element;

                Stack <ElementTreeItemViewModel> viewModelHierarchy = new Stack <ElementTreeItemViewModel>();
                ElementTreeItemViewModel         child  = viewModel;
                ElementTreeItemViewModel         parent = viewModel.Parent;
                while ((parent != null) && (parent.Children[0] == child))
                {
                    viewModelHierarchy.Push(parent);
                    child  = parent;
                    parent = parent.Parent;
                }

                foreach (ElementTreeItemViewModel currentViewModel in viewModelHierarchy)
                {
                    int leafElements = 0;
                    CountLeafElements(currentViewModel.Element, ref leafElements);

                    if (leafElements > 0 && currentViewModel.Depth > 0)
                    {
                        MatrixColor expandedColor = MatrixColorConverter.GetColor(currentViewModel.Depth);

                        int begin = row;
                        int end   = row + leafElements;

                        for (int rowDelta = begin; rowDelta < end; rowDelta++)
                        {
                            for (int columnDelta = begin; columnDelta < end; columnDelta++)
                            {
                                _cellColors[rowDelta][columnDelta] = expandedColor;
                            }
                        }
                    }
                }
            }

            // Define diagonal color
            for (int row = 0; row < matrixSize; row++)
            {
                int         depth       = _elementViewModelLeafs[row].Depth;
                MatrixColor dialogColor = MatrixColorConverter.GetColor(depth);
                _cellColors[row][row] = dialogColor;
            }

            // Define cycle color
            for (int row = 0; row < matrixSize; row++)
            {
                for (int column = 0; column < matrixSize; column++)
                {
                    IDsmElement consumer  = _elementViewModelLeafs[column].Element;
                    IDsmElement provider  = _elementViewModelLeafs[row].Element;
                    CycleType   cycleType = _application.IsCyclicDependency(consumer, provider);
                    if (_application.ShowCycles)
                    {
                        if (cycleType == CycleType.Hierarchical)
                        {
                            _cellColors[row][column] = MatrixColor.HierarchicalCycle;
                        }

                        if (cycleType == CycleType.System)
                        {
                            _cellColors[row][column] = MatrixColor.SystemCycle;
                        }
                    }
                }
            }
        }