Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

TreeTableModelAdapter.java

00001 /*
00002  * %W% %E%
00003  *
00004  * Copyright 1997, 1998 Sun Microsystems, Inc. All Rights Reserved.
00005  * 
00006  * Redistribution and use in source and binary forms, with or
00007  * without modification, are permitted provided that the following
00008  * conditions are met:
00009  * 
00010  * - Redistributions of source code must retain the above copyright
00011  *   notice, this list of conditions and the following disclaimer. 
00012  *   
00013  * - Redistribution in binary form must reproduce the above
00014  *   copyright notice, this list of conditions and the following
00015  *   disclaimer in the documentation and/or other materials
00016  *   provided with the distribution. 
00017  *   
00018  * Neither the name of Sun Microsystems, Inc. or the names of
00019  * contributors may be used to endorse or promote products derived
00020  * from this software without specific prior written permission.  
00021  * 
00022  * This software is provided "AS IS," without a warranty of any
00023  * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
00024  * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY,
00025  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
00026  * EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY
00027  * DAMAGES OR LIABILITIES SUFFERED BY LICENSEE AS A RESULT OF OR
00028  * RELATING TO USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE OR
00029  * ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE 
00030  * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT,   
00031  * SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER  
00032  * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF 
00033  * THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS 
00034  * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
00035  * 
00036  * You acknowledge that this software is not designed, licensed or
00037  * intended for use in the design, construction, operation or
00038  * maintenance of any nuclear facility.
00039  */
00040 package GuiComponents.Inspector.TreeTable;
00041 
00042 import javax.swing.table.AbstractTableModel;
00043 import javax.swing.JTree;
00044 import javax.swing.tree.TreePath;
00045 import javax.swing.event.TreeExpansionEvent;
00046 import javax.swing.event.TreeExpansionListener;
00047 
00061 public class TreeTableModelAdapter extends AbstractTableModel
00062 {
00063     JTree tree;
00064     TreeTableModel treeTableModel;
00065 
00066     public TreeTableModelAdapter(TreeTableModel treeTableModel, JTree tree) {
00067         this.tree = tree;
00068         this.treeTableModel = treeTableModel;
00069 
00070         tree.addTreeExpansionListener(new TreeExpansionListener() {
00071             // Don't use fireTableRowsInserted() here; 
00072             // the selection model would get  updated twice. 
00073             public void treeExpanded(TreeExpansionEvent event) {  
00074             fireTableDataChanged(); 
00075             }
00076         public void treeCollapsed(TreeExpansionEvent event) {  
00077             fireTableDataChanged(); 
00078             }
00079         });
00080     }
00081 
00082   // Wrappers, implementing TableModel interface. 
00083 
00084     public int getColumnCount() {
00085         return treeTableModel.getColumnCount();
00086     }
00087 
00088     public String getColumnName(int column) {
00089         return treeTableModel.getColumnName(column);
00090     }
00091 
00092     public Class getColumnClass(int column) {
00093         return treeTableModel.getColumnClass(column);
00094     }
00095 
00096     public int getRowCount() {
00097         return tree.getRowCount();
00098     }
00099 
00100     protected Object nodeForRow(int row) {
00101         TreePath treePath = tree.getPathForRow(row);
00102         return treePath.getLastPathComponent();         
00103     }
00104 
00105     public Object getValueAt(int row, int column) {
00106         return treeTableModel.getValueAt(nodeForRow(row), column);
00107     }
00108 
00109     public boolean isCellEditable(int row, int column) {
00110          return treeTableModel.isCellEditable(nodeForRow(row), column); 
00111     }
00112 
00113     public void setValueAt(Object value, int row, int column) {
00114         treeTableModel.setValueAt(value, nodeForRow(row), column);
00115     }
00116 }
00117 
00118 

Generated on Thu Jul 15 09:55:50 2004 for SCT DAQ/DCS Software - Java by doxygen 1.3.5