Esempio n. 1
0
        /// <summary>
        /// Select the next node in the view. The next node is defined as the next one
        /// down in the tree view. It will go through child nodes if they exist.
        /// Will return true if next node was successfully selected. Will return
        /// false if no more nodes to select.
        /// </summary>
        /// <returns>True when node is selected</returns>
        /// <exception cref="System.Exception">Cannot find the current selected model in the .apsimx file</exception>
        public bool SelectNextNode()
        {
            this.HideRightHandPanel();

            // Get a complete list of all models in this file.
            List <IModel> allModels = Apsim.ChildrenRecursivelyVisible(this.ApsimXFile);

            allModels.Insert(0, ApsimXFile);

            /* If the current node path is '.Simulations' (the root node) then
             * select the first item in the 'allModels' list. */
            if (this.view.Tree.SelectedNode == string.Empty)
            {
                this.view.Tree.SelectedNode = Apsim.FullPath(allModels[0]);
                return(true);
            }

            // Find the current node in this list.
            int index = -1;

            for (int i = 0; i < allModels.Count; i++)
            {
                if (Apsim.FullPath(allModels[i]) == this.view.Tree.SelectedNode)
                {
                    index = i;
                    break;
                }
            }

            if (index == -1)
            {
                throw new Exception("Cannot find the current selected model in the .apsimx file");
            }

            // If the current model is the last one in the list then return false.
            if (index >= allModels.Count - 1)
            {
                return(false);
            }

            // Select the next node.
            this.view.Tree.SelectedNode = Apsim.FullPath(allModels[index + 1]);
            return(true);
        }