Ejemplo n.º 1
0
        private void Node_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            Label  nodeLabel = sender as Label;
            string newName   = Interaction.InputBox("Please enter the new keyword:", "Rename", nodeLabel.Content.ToString());

            if (!string.IsNullOrEmpty(newName))
            {
                ViewableTreeNode selected = nodeList.SelectedItem as ViewableTreeNode;
                tree.Rename(selected, newName);
            }
        }
Ejemplo n.º 2
0
        public void Add(ViewableTreeNode parent, string word)
        {
            Node parentNode = parent.treeNode;
            Node childNode  = new Node(word);

            tree.AddNode(parentNode, childNode);

            ViewableTreeNode childViewableNode = new ViewableTreeNode(childNode);

            parent.Children.Add(childViewableNode);
        }
Ejemplo n.º 3
0
        public void Remove(ViewableTreeNode toRemove)
        {
            if (toRemove.Keyword == tree.Root.KeyWord)
            {
                throw new InvalidOperationException();
            }
            Node parent = toRemove.treeNode.Parent;

            tree.RemoveNode(toRemove.treeNode);

            ViewableTreeNode parentViewable = FindParent(Root[0], toRemove);

            parentViewable.Children.Remove(toRemove);
        }
Ejemplo n.º 4
0
        private void Delete_Click(object sender, RoutedEventArgs e)
        {
            ViewableTreeNode selected = nodeList.SelectedItem as ViewableTreeNode;

            if (selected == null)
            {
                MessageBox.Show("You must select a word to delete");
            }
            else
            {
                try {
                    tree.Remove(selected);
                } catch (InvalidOperationException) {
                    MessageBox.Show("Cannot remove root of tree");
                }
            }
        }
Ejemplo n.º 5
0
        private void Add_Click(object sender, RoutedEventArgs e)
        {
            ViewableTreeNode selected = nodeList.SelectedItem as ViewableTreeNode;
            string           word     = wordBox.Text;

            if (selected == null)
            {
                MessageBox.Show("You must select a parent before adding a word");
            }
            else if (string.IsNullOrEmpty(word))
            {
                MessageBox.Show("You must enter a word to add to the tree");
            }
            else
            {
                tree.Add(selected, word);
                wordBox.Text = "";
            }
        }
Ejemplo n.º 6
0
        public ViewableTree(IBaseTree basetree)
        {
            List <ViewableTreeNode>             temp    = new List <ViewableTreeNode>();
            List <Node>                         orphans = new List <Node>();
            Dictionary <Node, ViewableTreeNode> nodes   = new Dictionary <Node, ViewableTreeNode>();

            tree = basetree;
            Root = new ObservableCollection <ViewableTreeNode>();
            ViewableTreeNode rootNode = new ViewableTreeNode(tree.Root);

            temp.Add(rootNode);
            nodes.Add(tree.Root, rootNode);
            Root.Add(rootNode);

            foreach (Node n in tree)
            {
                if (n != tree.Root)
                {
                    ViewableTreeNode node = new ViewableTreeNode(n);
                    temp.Add(node);
                    nodes.Add(n, node);
                    var result = temp.Where(t => n.Parent != null && t.Keyword == n.Parent.KeyWord).FirstOrDefault();
                    if (result != null)
                    {
                        result.Children.Add(node);
                    }
                    else
                    {
                        orphans.Add(n);
                    }
                }
            }

            foreach (Node n in orphans)
            {
                var result = temp.Where(t => n.Parent != null && t.Keyword == n.Parent.KeyWord).FirstOrDefault();
                if (result != null)
                {
                    result.Children.Add(nodes[n]);
                }
            }
        }
Ejemplo n.º 7
0
        private ViewableTreeNode FindParent(ViewableTreeNode current, ViewableTreeNode child)
        {
            ViewableTreeNode toReturn = null;

            foreach (ViewableTreeNode node in current.Children)
            {
                if (toReturn == null)
                {
                    if (current.Children.Contains(child))
                    {
                        toReturn = current;
                    }
                    else
                    {
                        toReturn = FindParent(node, child);
                    }
                }
            }
            return(toReturn);
        }
Ejemplo n.º 8
0
 public void Rename(ViewableTreeNode node, string newName)
 {
     tree.Rename(node.treeNode, newName);
     node.Keyword = newName;
 }