Exemplo n.º 1
0
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            DataTemplate     retval  = null;
            FrameworkElement element = container as FrameworkElement;

            if (element != null && item != null && item is HierarchyItemViewModel)
            {
                HierarchyItemViewModel hierarchyItem = item as HierarchyItemViewModel;
                if (hierarchyItem.DataItem != null)
                {
                    if (hierarchyItem.DataItem.GetType() == typeof(ProjectModel))
                    {
                        retval = element.FindResource("ProjectTemplate") as DataTemplate;
                    }
                    else if (hierarchyItem.DataItem.GetType() == typeof(ControllerModel))
                    {
                        retval = element.FindResource("ControllerTemplate") as DataTemplate;
                    }
                    else if (hierarchyItem.DataItem.GetType() == typeof(ControllerNodeModel))
                    {
                        retval = element.FindResource("ControllerNodeTemplate") as DataTemplate;
                    }
                    else if (hierarchyItem.DataItem.GetType() == typeof(LoopModel))
                    {
                        retval = element.FindResource("LoopTemplate") as DataTemplate;
                    }
                }
            }

            return(retval);
        }
Exemplo n.º 2
0
        private List <HierarchyItemViewModel> BuildHierarchyList <T>(List <T> sourceList, Func <T, T, bool> isSelected, object selectedEntity, Func <T, List <HierarchyItemViewModel> > getChildren)
        {
            List <HierarchyItemViewModel> result = new List <HierarchyItemViewModel>();

            foreach (T item in sourceList)
            {
                // create the hierarchy item and add to the list
                var hierarchyItem = new HierarchyItemViewModel(item);
                result.Add(hierarchyItem);

                // check if this is the selected item
                if (selectedEntity != null && selectedEntity.GetType() == typeof(T) && (isSelected.Invoke(item, (T)selectedEntity)))
                {
                    _selectedItem = hierarchyItem;
                }

                if (getChildren != null)
                {
                    var children = getChildren.Invoke(item);
                    children.ForEach(x => x.Parent = hierarchyItem);
                    hierarchyItem.Children         = new CollectionView(children);
                }
            }

            return(result);
        }
Exemplo n.º 3
0
 public void GetDetailsExecute()
 {
     HierarchyItemViewModel o = this._selectedItem;
     // this.lstMessages.Items.Add(message);
 }
Exemplo n.º 4
0
        public void Initialize(List <ProjectModel> projects, object selectedEntity)
        {
            // create the top level collectionview for the customers
            var projectHierarchyItemsList = new List <HierarchyItemViewModel>();

            foreach (var p in projects)
            {
                // create the hierarchy item and add to the list
                var projectHierarchyItem = new HierarchyItemViewModel(p);

                projectHierarchyItemsList.Add(projectHierarchyItem);

                // check if this is the selected item
                if (selectedEntity != null && selectedEntity.GetType() == typeof(ProjectModel) && (selectedEntity as ProjectModel).Equals(p))
                {
                    _selectedItem = projectHierarchyItem;
                }

                // if there are any orders in projectHierarchyItem
                if (p.Controllers.Count != 0)
                {
                    // create a new list of HierarchyItems
                    var controllerHierarchyItemsList = new List <HierarchyItemViewModel>();
                    // loop through the orders and add them
                    foreach (var c in p.Controllers)
                    {
                        // create the hierarchy item and add to the list
                        var controllerHierarchyItem = new HierarchyItemViewModel(c);
                        controllerHierarchyItem.Parent = projectHierarchyItem;
                        controllerHierarchyItemsList.Add(controllerHierarchyItem);

                        // check if this is the selected item
                        if (selectedEntity != null && selectedEntity.GetType() == typeof(ControllerModel) && (selectedEntity as ControllerModel).Equals(c))
                        {
                            _selectedItem = controllerHierarchyItem;
                        }


                        IControllerConfig     config    = ControllerConfigManager.GetConfigObject(c.Type);
                        ControllerNodeModel[] nodeModel = config.GetNodes();
                        if (nodeModel.Length != 0)
                        {
                            var controllerNodeHierarchyItemList = new List <HierarchyItemViewModel>();
                            foreach (var cNode in nodeModel)
                            {
                                var nodeHierarchyItem = new HierarchyItemViewModel(cNode);
                                nodeHierarchyItem.Parent = controllerHierarchyItem;
                                controllerNodeHierarchyItemList.Add(nodeHierarchyItem);
                                if (selectedEntity != null && selectedEntity.GetType() == typeof(ControllerNodeModel) && (selectedEntity as ControllerNodeModel).Equals(cNode))
                                {
                                    _selectedItem = controllerHierarchyItem;
                                }
                                if (cNode.Type == ControllerNodeType.Loop) //回路数据应该加载回路信息
                                {
                                    if (c.Loops.Count > 0)                 //加载回路数据
                                    {
                                        var loopHierarchyItemList = new List <HierarchyItemViewModel>();
                                        foreach (var l in c.Loops)
                                        {
                                            var loopHierarchyItem = new HierarchyItemViewModel(l);
                                            loopHierarchyItem.Parent = nodeHierarchyItem;
                                            loopHierarchyItemList.Add(loopHierarchyItem);
                                            if (selectedEntity != null && selectedEntity.GetType() == typeof(LoopModel) && (selectedEntity as LoopModel).Equals(l))
                                            {
                                                _selectedItem = loopHierarchyItem;
                                            }
                                        }
                                        nodeHierarchyItem.Children = new CollectionView(loopHierarchyItemList);
                                    }
                                }
                            }
                            controllerHierarchyItem.Children = new CollectionView(controllerNodeHierarchyItemList);
                        }
                    }
                    // create the children of the customer
                    projectHierarchyItem.Children = new CollectionView(controllerHierarchyItemsList);
                }
            }

            this.Projects = new CollectionView(projectHierarchyItemsList);

            // select the selected item and expand it'type parents
            if (_selectedItem != null)
            {
                _selectedItem.IsSelected = true;
                HierarchyItemViewModel current = _selectedItem.Parent;

                while (current != null)
                {
                    current.IsExpanded = true;
                    current            = current.Parent;
                }
            }
        }