1 4 package com.tc.admin.dso; 5 6 import com.tc.admin.ConnectionContext; 7 import com.tc.admin.common.XContainer; 8 import com.tc.admin.common.XTree; 9 import com.tc.admin.common.XTreeNode; 10 11 import java.awt.BorderLayout ; 12 import java.awt.event.MouseAdapter ; 13 import java.awt.event.MouseEvent ; 14 15 import javax.swing.JScrollPane ; 16 import javax.swing.event.TreeSelectionEvent ; 17 import javax.swing.event.TreeSelectionListener ; 18 import javax.swing.tree.TreePath ; 19 20 public class RootsPanel extends XContainer { 21 private ConnectionContext m_cc; 22 private XTree m_tree; 23 24 public RootsPanel(ConnectionContext cc, DSORoot[] roots) { 25 super(new BorderLayout ()); 26 27 m_cc = cc; 28 m_tree = new XTree(); 29 m_tree.setShowsRootHandles(true); 30 m_tree.addMouseListener(new MouseAdapter () { 31 public void mouseClicked(MouseEvent me) { 32 TreePath path = m_tree.getPathForLocation(me.getX(), me.getY()); 33 34 if(path != null) { 35 m_tree.requestFocus(); 36 37 XTreeNode node = (XTreeNode)path.getLastPathComponent(); 38 if(node != null) { 39 node.nodeClicked(me); 40 } 41 } 42 } 43 }); 44 m_tree.addTreeSelectionListener(new TreeSelectionListener () { 45 public void valueChanged(TreeSelectionEvent tse) { 46 TreePath path = tse.getNewLeadSelectionPath(); 47 XTreeNode node; 48 49 if(path != null) { 50 m_tree.requestFocus(); 51 52 node = (XTreeNode)path.getLastPathComponent(); 53 if(node != null) { 54 node.nodeSelected(tse); 55 } 56 } 57 } 58 }); 59 add(new JScrollPane (m_tree), BorderLayout.CENTER); 60 setRoots(roots); 61 } 62 63 public void setRoots(DSORoot[] roots) { 64 m_tree.setModel(new RootTreeModel(m_cc, roots)); 65 m_tree.revalidate(); 66 m_tree.repaint(); 67 } 68 69 public void refresh() { 70 ((RootTreeModel)m_tree.getModel()).refresh(); 71 } 72 73 public void add(DSORoot root) { 74 ((RootTreeModel)m_tree.getModel()).add(root); 75 m_tree.revalidate(); 76 m_tree.repaint(); 77 } 78 } 79 | Popular Tags |