package editor.views;

import editor.ElementTreeModel;
import editor.controllers.ElementTreeController;
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.
     * @param controller The controller for this tree view
     */
    public ElementTreeView(Element root, ElementTreeController controller) {
        root.registerObserver(this);
        this.root = root;

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

        controller.setTree(tree);
        tree.addMouseListener(controller);

        setVisible(false);
    }

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

@@ -1225,32 +1225,68 @@
 tChanged(root);%0A
+            if (!isVisible()) %7B%0A    
             setV
@@ -1307,17 +1307,275 @@
         
+ 
-%7D
+   %7D%0A        %7D%0A    %7D%0A%0A    /**%0A     * Get the currently-selected element%0A     * @return the currently-selected element%0A     */%0A    public Element getSelectedElement() %7B%0A        Element elem = (Element) tree.getLastSelectedPathComponent();%0A        return elem;
 %0A    %7D%0A%7D

Add function to get selected tree node