Example #1
0
        public void t07_TreeViewViewModel()
        {
            SIEETreeView Folders = new SIEETreeView(null);
            TVIViewModel tviVM;
            TVIViewModel tviVMa;

            string testPath = Path.GetTempPath();

            testPath = testPath.Substring(0, testPath.Length - 1);      // Remove trailing "\"
            findFolderBruteForce(testPath);

            string           startPath = testPath.Split('\\').First() + @"\"; // e.g. "C:\"
            FilesystemFolder startFsf  = new FilesystemFolder(null, new DirectoryInfo(startPath));

            // Select a folder and verify results
            Folders.AddItem(new TVIViewModel(startFsf, null, true));
            Assert.AreEqual(startPath, Folders[0].GetDisplayNamePath(), "t0");
            tviVM = Folders.FindNodeInTree(testPath);
            verifySelectedNode(tviVM, testPath, "t1");

            // Serialize and reinstantiate
            List <string> serializedPath = tviVM.GetSerializedPath();

            Folders.Clear();
            Folders.AddItem(new TVIViewModel(startFsf, null, true));
            tviVM = Folders.InitializeTree(serializedPath, typeof(FilesystemFolder));
            verifySelectedNode(tviVM, testPath, "t2");
            tviVMa = Folders.FindNodeInTree(testPath);
            verifySelectedNode(tviVMa, testPath, "t3");
        }
Example #2
0
        // Find the node in the tree starting at the current node
        // Expand tree if necessary
        public TVIViewModel FindNodeInTree(string idPath)
        {
            if (this.Count() == 0)
            {
                return(null);
            }
            string concatString = this[0].Tvim.GetPathConcatenationString();

            string[] tokens = idPath.Split(new[] { concatString }, StringSplitOptions.None);

            TVIViewModel currNode = null;
            SIEETreeView currTree = this;

            for (int i = 0; i != tokens.Length; i++)
            {
                if (tokens[i] == string.Empty)
                {
                    continue;
                }
                currNode = currTree.findChild(tokens[i]);
                if (currNode == null)
                {
                    return(null);
                }
                currNode.IsExpanded = true;
                currTree            = currNode.Children;
            }
            return(currNode);
        }
Example #3
0
        public TVIViewModel(TVIModel model, TVIViewModel parent, bool lazyLoadChildren)
        {
            Tvim        = model;
            this.parent = parent;
            Tvim.Depth  = parent == null ? 0 : parent.Tvim.Depth + 1;

            children = new SIEETreeView(null);
            if (lazyLoadChildren && Tvim.IsFolder)
            {
                children.Add(DummyChild);
            }
        }
Example #4
0
        // Open the tree view according to the serialzed path.
        // Expands all nodes on the way
        public TVIViewModel InitializeTree(List <string> serializedPath, Type modelType)
        {
            if (serializedPath == null)
            {
                return(null);
            }

            SIEETreeView currentTree = this;
            TVIViewModel currItem    = null;

            try
            {
                for (int i = 0; i != serializedPath.Count; i++)
                {
                    TVIModel tvim = (TVIModel)TVIViewModel.deSerialize(serializedPath[i], modelType);

                    currItem = currentTree.findChild(tvim.Id);
                    if (currItem == null)
                    {
                        throw new Exception(tvim.DisplayName + " not found");
                    }
                    currItem.IsExpanded = true;
                    currItem.IsSelected = true;
                    currentTree         = currItem.Children;
                }
            }
            catch (Exception e)
            {
                string errMsg = "No items in tree view";
                string title  = "Error";
                if (this.Count() > 0)
                {
                    TVIModel someModel = this[0].Tvim;
                    errMsg = "Could not locate " + someModel.GetTypeName() + ". Reason:\n" + e.Message;
                    title  = "Navigate to " + someModel.GetTypeName();
                }
                SIEEMessageBox.Show(errMsg, title, System.Windows.MessageBoxImage.Error);
            }
            return(currItem);
        }