Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libUI / src / org / gvsig / gui / beans / swing / treeTable / TreeTableModelAdapter.java @ 8279

History | View | Annotate | Download (3.15 KB)

1
package org.gvsig.gui.beans.swing.treeTable;
2

    
3
import javax.swing.JTree;
4
import javax.swing.event.TreeExpansionEvent;
5
import javax.swing.event.TreeExpansionListener;
6
import javax.swing.table.AbstractTableModel;
7
import javax.swing.tree.TreePath;
8

    
9
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
10
 *
11
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
12
 *
13
 * This program is free software; you can redistribute it and/or
14
 * modify it under the terms of the GNU General Public License
15
 * as published by the Free Software Foundation; either version 2
16
 * of the License, or (at your option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 * GNU General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU General Public License
24
 * along with this program; if not, write to the Free Software
25
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
26
 *
27
 * For more information, contact:
28
 *
29
 *  Generalitat Valenciana
30
 *   Conselleria d'Infraestructures i Transport
31
 *   Av. Blasco Ib??ez, 50
32
 *   46010 VALENCIA
33
 *   SPAIN
34
 *
35
 *      +34 963862235
36
 *   gvsig@gva.es
37
 *      www.gvsig.gva.es
38
 *
39
 *    or
40
 *
41
 *   IVER T.I. S.A
42
 *   Salamanca 50
43
 *   46005 Valencia
44
 *   Spain
45
 *
46
 *   +34 963163400
47
 *   dac@iver.es
48
 */
49
/* CVS MESSAGES:
50
 *
51
 * $Id: TreeTableModelAdapter.java 8279 2006-10-24 08:04:13Z jorpiell $
52
 * $Log$
53
 * Revision 1.2  2006-10-24 08:04:13  jorpiell
54
 * nodeFroRow es ahora public
55
 *
56
 * Revision 1.1  2006/10/23 08:18:39  jorpiell
57
 * A?adida la clase treetable
58
 *
59
 *
60
 */
61
/**
62
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
63
 */
64
public class TreeTableModelAdapter extends AbstractTableModel{
65
        JTree tree;
66
        TreeTableModel treeTableModel;
67
        
68
        public TreeTableModelAdapter(TreeTableModel treeTableModel, JTree tree) {
69
                this.tree = tree;
70
                this.treeTableModel = treeTableModel;
71
                
72
                tree.addTreeExpansionListener(new TreeExpansionListener() {
73
                        // Don't use fireTableRowsInserted() here; 
74
                        // the selection model would get  updated twice. 
75
                        public void treeExpanded(TreeExpansionEvent event) {  
76
                                fireTableDataChanged(); 
77
                        }
78
                        public void treeCollapsed(TreeExpansionEvent event) {  
79
                                fireTableDataChanged(); 
80
                        }
81
                });
82
        }
83
        
84
        // Wrappers, implementing TableModel interface. 
85
        
86
        public int getColumnCount() {
87
                return treeTableModel.getColumnCount();
88
        }
89
        
90
        public String getColumnName(int column) {
91
                return treeTableModel.getColumnName(column);
92
        }
93
        
94
        public Class getColumnClass(int column) {
95
                return treeTableModel.getColumnClass(column);
96
        }
97
        
98
        public int getRowCount() {
99
                return tree.getRowCount();
100
        }
101
        
102
        public Object nodeForRow(int row) {
103
                TreePath treePath = tree.getPathForRow(row);
104
                return treePath.getLastPathComponent();         
105
        }
106
        
107
        public Object getValueAt(int row, int column) {
108
                return treeTableModel.getValueAt(nodeForRow(row), column);
109
        }
110
        
111
        public boolean isCellEditable(int row, int column) {
112
                return treeTableModel.isCellEditable(nodeForRow(row), column); 
113
        }
114
        
115
        public void setValueAt(Object value, int row, int column) {
116
                treeTableModel.setValueAt(value, nodeForRow(row), column);
117
        }
118
}
119

    
120