package editor.views;

import editor.ElementTreeModel;
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;
    private ElementTreeModel model;

    /**
     * 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;

        model = new ElementTreeModel(root);
        tree = new JTree(model);
        add(tree);

        setVisible(false);
    }

    /**
     * When the associated element tree root has changed, change the view
     */
    public void notifyObserver() {
        if (root != null) {
            model.elementChanged(root);
            setVisible(true);
        }
    }
}

@@ -115,16 +115,157 @@
 swing.*;
+%0Aimport javax.swing.tree.TreePath;%0Aimport java.awt.event.MouseAdapter;%0Aimport java.awt.event.MouseEvent;%0Aimport java.awt.event.MouseListener;
 %0A%0A/**%0A *
@@ -927,16 +927,771 @@
 tree);%0A%0A
+        MouseListener ml = new MouseAdapter() %7B%0A            public void mousePressed(MouseEvent e) %7B%0A                int selRow = tree.getRowForLocation(e.getX(), e.getY());%0A                TreePath selPath = tree.getPathForLocation(e.getX(), e.getY());%0A                Element elem = (Element) selPath.getLastPathComponent();%0A                if (selRow != -1) %7B%0A                    if (e.getClickCount() == 1) %7B%0A                        System.out.println(%22%5BDEBUG%5D Single-click, tag = %22 + elem.getTag());%0A                    %7D else if (e.getClickCount() == 2) %7B%0A                        System.out.println(%22%5BDEBUG%5D Double-click, tag = %22 + elem.getTag());%0A                    %7D%0A                %7D%0A            %7D%0A        %7D;%0A        tree.addMouseListener(ml);%0A%0A
         

Add stub of mouse listener to ElementTreeView