00001 package edu.ksu.cis.bandera.abstraction.gui;
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 import javax.swing.JTree;
00018 import javax.swing.SwingUtilities;
00019 import javax.swing.table.AbstractTableModel;
00020 import javax.swing.tree.TreePath;
00021 import javax.swing.event.TreeExpansionEvent;
00022 import javax.swing.event.TreeExpansionListener;
00023 import javax.swing.event.TreeModelEvent;
00024 import javax.swing.event.TreeModelListener;
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 public class TreeTableModelAdapter extends AbstractTableModel
00038 {
00039 JTree tree;
00040 TreeTableModel treeTableModel;
00041
00042 public TreeTableModelAdapter(TreeTableModel treeTableModel, JTree tree) {
00043 this.tree = tree;
00044 this.treeTableModel = treeTableModel;
00045
00046 tree.addTreeExpansionListener(new TreeExpansionListener() {
00047
00048
00049 public void treeExpanded(TreeExpansionEvent event) {
00050 fireTableDataChanged();
00051 }
00052 public void treeCollapsed(TreeExpansionEvent event) {
00053 fireTableDataChanged();
00054 }
00055 });
00056
00057
00058
00059
00060
00061 treeTableModel.addTreeModelListener(new TreeModelListener() {
00062 public void treeNodesChanged(TreeModelEvent e) {
00063 delayedFireTableDataChanged();
00064 }
00065
00066 public void treeNodesInserted(TreeModelEvent e) {
00067 delayedFireTableDataChanged();
00068 }
00069
00070 public void treeNodesRemoved(TreeModelEvent e) {
00071 delayedFireTableDataChanged();
00072 }
00073
00074 public void treeStructureChanged(TreeModelEvent e) {
00075 delayedFireTableDataChanged();
00076 }
00077 });
00078 }
00079
00080
00081
00082
00083 protected void delayedFireTableDataChanged() {
00084 SwingUtilities.invokeLater(new Runnable() {
00085 public void run() {
00086 fireTableDataChanged();
00087 }
00088 });
00089 }
00090 public Class getColumnClass(int column) {
00091 return treeTableModel.getColumnClass(column);
00092 }
00093
00094
00095 public int getColumnCount() {
00096 return treeTableModel.getColumnCount();
00097 }
00098 public String getColumnName(int column) {
00099 return treeTableModel.getColumnName(column);
00100 }
00101 public int getRowCount() {
00102 return tree.getRowCount();
00103 }
00104 public Object getValueAt(int row, int column) {
00105 return treeTableModel.getValueAt(nodeForRow(row), column);
00106 }
00107 public boolean isCellEditable(int row, int column) {
00108 return treeTableModel.isCellEditable(nodeForRow(row), column);
00109 }
00110 public Object nodeForRow(int row) {
00111 TreePath treePath = tree.getPathForRow(row);
00112 return treePath.getLastPathComponent();
00113 }
00114 public void setValueAt(Object value, int row, int column) {
00115 treeTableModel.setValueAt(value, nodeForRow(row), column);
00116 }
00117 }