KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > core > gui > plugin > PluginTreeTableModel


1 /*
2  * Created on 06.08.2003
3  *
4  * To change the template for this generated file go to
5  * Window>Preferences>Java>Code Generation>Code and Comments
6  */

7 package org.columba.core.gui.plugin;
8
9 import javax.swing.tree.DefaultTreeModel JavaDoc;
10 import javax.swing.tree.TreePath JavaDoc;
11
12 import org.frapuccino.treetable.AbstractTreeTableModel;
13
14
15 /**
16  * @author fdietz
17  *
18  * To change the template for this generated type comment go to
19  * Window>Preferences>Java>Code Generation>Code and Comments
20  */

21 public class PluginTreeTableModel extends AbstractTreeTableModel {
22     PluginNode root;
23
24     /**
25  * @param tree
26  * @param columns
27  */

28     public PluginTreeTableModel(String JavaDoc[] columns) {
29         super(columns);
30
31         PluginNode root = new PluginNode();
32         root.setId("root");
33     }
34
35     public Class JavaDoc getColumnClass(int c) {
36         // first column is a tree
37
if (c == 0) {
38             return tree.getClass();
39         }
40
41         if (c == 1) {
42             return String JavaDoc.class;
43         } else {
44             // third column is a JCheckBox column
45
return Boolean JavaDoc.class;
46         }
47     }
48
49     public Object JavaDoc getValueAt(int row, int col) {
50         PluginNode node = (PluginNode) tree.getPathForRow(row)
51                                            .getLastPathComponent();
52
53         return node;
54     }
55
56     public void set(PluginNode root) {
57         tree.setRootNode(root);
58
59         ((DefaultTreeModel JavaDoc) tree.getModel()).nodeStructureChanged(root);
60
61         fireTableDataChanged();
62     }
63
64     /* (non-Javadoc)
65  * @see javax.swing.table.TableModel#setValueAt(java.lang.Object, int, int)
66  */

67     public void setValueAt(Object JavaDoc value, int row, int col) {
68         if (col == 2) {
69             // checkbox pressed
70
TreePath JavaDoc path = tree.getPathForRow(row);
71             PluginNode node = (PluginNode) path.getLastPathComponent();
72
73             if (node.isCategory()) {
74                 return;
75             }
76
77             // enable/disable tree node
78
node.setEnabled(((Boolean JavaDoc) value).booleanValue());
79
80             // TODO implement
81
/*
82             PluginManager.getInstance().setEnabled(id,
83                 ((Boolean) value).booleanValue());
84                 */

85         }
86     }
87
88     /* (non-Javadoc)
89  * @see javax.swing.table.TableModel#isCellEditable(int, int)
90  */

91     public boolean isCellEditable(int row, int col) {
92         // enabled/disabled checkbox must be editable
93
if (col == 2) {
94             return false;
95         }
96
97         // tree must be editable, otherwise you can't collapse/expand tree nodes
98
if (col == 0) {
99             return true;
100         }
101
102         return false;
103     }
104 }
105
Popular Tags