Ejemplo n.º 1
0
        /// <summary>
        /// Builds a TreeModel from the available property keys.
        /// </summary>
        private TreeNode BuildTreeModel()
        {
            var sep   = Path.DirectorySeparatorChar.ToString();
            var root  = new ParameterDatabaseTreeNode(directory.FullName + sep + filename);
            var model = new ParameterDatabaseTreeModel(root);

            _buildTreeModel(model, root);

            model.Sort(root, new AnonymousClassComparator());

            // In order to add elements to the tree model, the leaves need to be
            // visible. This is because some properties have values *and* sub-
            // properties. Otherwise, if the nodes representing these properties did
            // not yet have children, then they would be invisible and the tree model
            // would be unable to add child nodes to them.
            model.VisibleLeaves = false;

            //        addListener(new ParameterDatabaseAdapter() {
            //           public void ParameterSet(ParameterDatabaseEvent evt) {
            //               model.setVisibleLeaves(true);
            //               _addNodeForParameter(model, root, evt.getParameter().Param);
            //               model.setVisibleLeaves(false);
            //           }
            //        });

            return(model);
        }
Ejemplo n.º 2
0
        /// <param name="comp">
        /// </param>
        public virtual void  Sort(IComparer comp)
        {
            if (this.Children == null)
            {
                return;
            }
            IEnumerator e = Children.GetEnumerator();

            while (e.MoveNext())
            {
                ParameterDatabaseTreeNode n = (ParameterDatabaseTreeNode)e.Current;
                n.Sort(comp);
            }
        }
Ejemplo n.º 3
0
        private void _addNodeForParameter(TreeNode model, TreeNode root, string key)
        {
            if (key.IndexOf("parent.") == -1)
            {
                var tok  = new Tokenizer(key, ".");
                var path = new string[tok.Count];
                var t    = 0;
                while (tok.HasMoreTokens())
                {
                    path[t++] = tok.NextToken();
                }
                var parent = root;

                for (var i = 0; i < path.Length; ++i)
                {
                    var children = model is ParameterDatabaseTreeModel
                        ? ((ParameterDatabaseTreeModel)model).GetChildCount(parent)
                        : parent.Nodes.Count;
                    if (children > 0)
                    {
                        var c = 0;
                        for (; c < children; ++c)
                        {
                            var child = parent.Nodes[c];
                            if (child.Tag.Equals(path[i]))
                            {
                                parent = child;
                                break;
                            }
                        }

                        if (c == children)
                        {
                            TreeNode child = new ParameterDatabaseTreeNode(path[i]);
                            parent.Nodes.Insert(parent.Nodes.Count, child);
                            parent = child;
                        }
                    }
                    // If the parent has no children, just add the node.
                    else
                    {
                        TreeNode child = new ParameterDatabaseTreeNode(path[i]);
                        parent.Nodes.Insert(0, child);
                        parent = child;
                    }
                }
            }
        }