1 19 20 package org.netbeans.modules.tasklist.usertasks.treetable; 21 22 import java.util.Arrays ; 23 import java.util.Comparator ; 24 25 import javax.swing.event.TreeModelEvent ; 26 import javax.swing.event.TreeModelListener ; 27 import javax.swing.tree.DefaultTreeModel ; 28 import javax.swing.tree.TreePath ; 29 import org.netbeans.modules.tasklist.core.table.SortingModel; 30 31 34 public class DefaultTreeTableModel extends DefaultTreeModel implements 35 TreeTableModel { 36 private static final long serialVersionUID = 1; 37 38 private String columnNames[]; 39 40 47 public DefaultTreeTableModel(TreeTableNode root, String [] columnNames) { 48 super(root); 49 this.columnNames = columnNames; 50 } 51 52 63 public DefaultTreeTableModel(TreeTableNode root, boolean asksAllowsChildren, 64 int columnNumber) { 65 super(root, asksAllowsChildren); 66 this.columnNames = new String [columnNumber]; 67 Arrays.fill(columnNames, ""); } 69 70 public int getColumnCount() { 71 return columnNames.length; 72 } 73 74 public String getColumnName(int column) { 75 return columnNames[column]; 76 } 77 78 public Class getColumnClass(int column) { 79 if (column == 0) 80 return TreeTableModel.class; 81 else 82 return Object .class; 83 } 84 85 public Object getValueAt(Object node, int column) { 86 return ((TreeTableNode) node).getValueAt(column); 87 } 88 89 public boolean isCellEditable(Object node, int column) { 90 return ((TreeTableNode) node).isCellEditable(column); 93 } 94 95 public void setValueAt(Object aValue, Object node, int column) { 96 ((TreeTableNode) node).setValueAt(aValue, column); 97 } 98 99 public static class ToStringComparator implements Comparator { 100 public int compare(Object obj1, Object obj2) { 101 String s1 = (obj1 == null) ? "" : obj1.toString(); String s2 = (obj2 == null) ? "" : obj2.toString(); if (s1 == null) 104 s1 = ""; if (s2 == null) 106 s2 = ""; return s1.compareTo(s2); 108 } 109 } 110 111 118 public void fireTreeStructureChanged(Object source, Object [] path) { 119 Object [] listeners = listenerList.getListenerList(); 121 TreeModelEvent e = null; 122 TreePath tp = path == null ? null : new TreePath (path); 123 for (int i = listeners.length-2; i>=0; i-=2) { 126 if (listeners[i]==TreeModelListener .class) { 127 if (e == null) 129 e = new TreeModelEvent (source, tp); 130 ((TreeModelListener )listeners[i+1]).treeStructureChanged(e); 131 } 132 } 133 } 134 135 public void fireTreeNodesRemoved(Object source, Object [] path, 136 int[] childIndices, Object [] children) { 137 super.fireTreeNodesRemoved(source, path, childIndices, children); 138 } 139 140 public void fireTreeNodesInserted(Object source, Object [] path, 141 int[] childIndices, Object [] children) { 142 super.fireTreeNodesInserted(source, path, childIndices, children); 143 } 144 145 public void fireTreeNodesChanged(Object source, Object [] path, 146 int[] childIndices, Object [] children) { 147 super.fireTreeNodesChanged(source, path, childIndices, children); 148 } 149 150 public void fireTreeStructureChanged(Object source, Object [] path, 151 int[] childIndices, Object [] children) { 152 super.fireTreeStructureChanged(source, path, childIndices, children); 153 } 154 155 public void sort(SortingModel sm) { 156 } 157 } 158 | Popular Tags |