01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.admin.dso;
05:
06: import com.tc.admin.ConnectionContext;
07: import com.tc.admin.common.XContainer;
08: import com.tc.admin.common.XTree;
09: 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
33: .getY());
34:
35: if (path != null) {
36: m_tree.requestFocus();
37:
38: XTreeNode node = (XTreeNode) path
39: .getLastPathComponent();
40: if (node != null) {
41: node.nodeClicked(me);
42: }
43: }
44: }
45: });
46: m_tree.addTreeSelectionListener(new TreeSelectionListener() {
47: public void valueChanged(TreeSelectionEvent tse) {
48: TreePath path = tse.getNewLeadSelectionPath();
49: XTreeNode node;
50:
51: if (path != null) {
52: m_tree.requestFocus();
53:
54: node = (XTreeNode) path.getLastPathComponent();
55: if (node != null) {
56: node.nodeSelected(tse);
57: }
58: }
59: }
60: });
61: add(new JScrollPane(m_tree), BorderLayout.CENTER);
62: setRoots(roots);
63: }
64:
65: public void setRoots(DSORoot[] roots) {
66: m_tree.setModel(new RootTreeModel(m_cc, roots));
67: m_tree.revalidate();
68: m_tree.repaint();
69: }
70:
71: public void refresh() {
72: ((RootTreeModel) m_tree.getModel()).refresh();
73: }
74:
75: public void add(DSORoot root) {
76: ((RootTreeModel) m_tree.getModel()).add(root);
77: m_tree.revalidate();
78: m_tree.repaint();
79: }
80: }
|