KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > admin > dso > RootsPanel


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

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 JavaDoc;
12 import java.awt.event.MouseAdapter JavaDoc;
13 import java.awt.event.MouseEvent JavaDoc;
14
15 import javax.swing.JScrollPane JavaDoc;
16 import javax.swing.event.TreeSelectionEvent JavaDoc;
17 import javax.swing.event.TreeSelectionListener JavaDoc;
18 import javax.swing.tree.TreePath JavaDoc;
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 JavaDoc());
26
27     m_cc = cc;
28     m_tree = new XTree();
29     m_tree.setShowsRootHandles(true);
30     m_tree.addMouseListener(new MouseAdapter JavaDoc() {
31       public void mouseClicked(MouseEvent JavaDoc me) {
32         TreePath JavaDoc 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 JavaDoc() {
45       public void valueChanged(TreeSelectionEvent JavaDoc tse) {
46         TreePath JavaDoc 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 JavaDoc(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