package editor;

import utility.Observer;
import xml.Element;

import javax.swing.*;

/**
 * The ElementTreeView controls the section of the GUI that displays the tree
 * representation of an XML element tree.
 */
public class ElementTreeView extends JPanel implements Observer {
    private JTree tree;
    private Element root;

    /**
     * Create the tree view and associate it with a particular model (root of
     * the XML element tree)
     * @param root The root element of the XML element tree.
     */
    public ElementTreeView(Element root) {
        root.registerObserver(this);
        this.root = root;

        tree = new JTree();
        add(tree);

        setVisible(false);
    }

    /**
     * When the associated element tree root has changed, change the view
     */
    public void notifyObserver() {
        if (root != null) {
            // TODO: Change the tree
            System.out.println("[DEBUG] root has changed");
            setVisible(true);
        }
    }
}

@@ -77,16 +77,106 @@
 swing.*;
+%0Aimport javax.swing.tree.DefaultMutableTreeNode;%0Aimport javax.swing.tree.DefaultTreeModel;
 %0A%0A/**%0A *
@@ -408,24 +408,105 @@
 lement root;
+%0A    private DefaultMutableTreeNode treeNode;%0A    private DefaultTreeModel model;
 %0A%0A    /**%0A  
@@ -802,20 +802,129 @@
 tree
- = new JTree
+Node = new DefaultMutableTreeNode();%0A        tree = new JTree(treeNode);%0A        model = (DefaultTreeModel) tree.getModel
 ();%0A
@@ -1126,24 +1126,24 @@
  != null) %7B%0A
-
             
@@ -1167,16 +1167,107 @@
 he tree%0A
+            treeNode.setUserObject(%22DEBUG_ROOT%22);%0A            model.nodeChanged(treeNode);%0A
         

Add the setting of root element label