001: /*
002: * Created on 06.08.2003
003: *
004: * To change the template for this generated file go to
005: * Window>Preferences>Java>Code Generation>Code and Comments
006: */
007: package org.columba.core.gui.plugin;
008:
009: import javax.swing.tree.DefaultTreeModel;
010: import javax.swing.tree.TreePath;
011:
012: import org.frapuccino.treetable.AbstractTreeTableModel;
013:
014: /**
015: * @author fdietz
016: *
017: * To change the template for this generated type comment go to
018: * Window>Preferences>Java>Code Generation>Code and Comments
019: */
020: public class PluginTreeTableModel extends AbstractTreeTableModel {
021: PluginNode root;
022:
023: /**
024: * @param tree
025: * @param columns
026: */
027: public PluginTreeTableModel(String[] columns) {
028: super (columns);
029:
030: PluginNode root = new PluginNode();
031: root.setId("root");
032: }
033:
034: public Class getColumnClass(int c) {
035: // first column is a tree
036: if (c == 0) {
037: return tree.getClass();
038: }
039:
040: if (c == 1) {
041: return String.class;
042: } else {
043: // third column is a JCheckBox column
044: return Boolean.class;
045: }
046: }
047:
048: public Object getValueAt(int row, int col) {
049: PluginNode node = (PluginNode) tree.getPathForRow(row)
050: .getLastPathComponent();
051:
052: return node;
053: }
054:
055: public void set(PluginNode root) {
056: tree.setRootNode(root);
057:
058: ((DefaultTreeModel) tree.getModel()).nodeStructureChanged(root);
059:
060: fireTableDataChanged();
061: }
062:
063: /* (non-Javadoc)
064: * @see javax.swing.table.TableModel#setValueAt(java.lang.Object, int, int)
065: */
066: public void setValueAt(Object value, int row, int col) {
067: if (col == 2) {
068: // checkbox pressed
069: TreePath path = tree.getPathForRow(row);
070: PluginNode node = (PluginNode) path.getLastPathComponent();
071:
072: if (node.isCategory()) {
073: return;
074: }
075:
076: // enable/disable tree node
077: node.setEnabled(((Boolean) value).booleanValue());
078:
079: // TODO implement
080: /*
081: PluginManager.getInstance().setEnabled(id,
082: ((Boolean) value).booleanValue());
083: */
084: }
085: }
086:
087: /* (non-Javadoc)
088: * @see javax.swing.table.TableModel#isCellEditable(int, int)
089: */
090: public boolean isCellEditable(int row, int col) {
091: // enabled/disabled checkbox must be editable
092: if (col == 2) {
093: return false;
094: }
095:
096: // tree must be editable, otherwise you can't collapse/expand tree nodes
097: if (col == 0) {
098: return true;
099: }
100:
101: return false;
102: }
103: }
|