svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.ui / src / main / java / org / gvsig / gui / beans / swing / treeTable / TreeTableModelAdapter.java @ 40561
History | View | Annotate | Download (4.47 KB)
1 | 40561 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | *
|
||
4 | * Copyright (C) 2007-2013 gvSIG Association.
|
||
5 | *
|
||
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | * as published by the Free Software Foundation; either version 3
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
19 | * MA 02110-1301, USA.
|
||
20 | *
|
||
21 | * For any additional information, do not hesitate to contact us
|
||
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | */
|
||
24 | 40435 | jjdelcerro | package org.gvsig.gui.beans.swing.treeTable; |
25 | |||
26 | import javax.swing.JTree; |
||
27 | import javax.swing.event.TreeExpansionEvent; |
||
28 | import javax.swing.event.TreeExpansionListener; |
||
29 | import javax.swing.table.AbstractTableModel; |
||
30 | import javax.swing.tree.TreePath; |
||
31 | |||
32 | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
||
33 | *
|
||
34 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
35 | *
|
||
36 | * This program is free software; you can redistribute it and/or
|
||
37 | * modify it under the terms of the GNU General Public License
|
||
38 | * as published by the Free Software Foundation; either version 2
|
||
39 | * of the License, or (at your option) any later version.
|
||
40 | *
|
||
41 | * This program is distributed in the hope that it will be useful,
|
||
42 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
43 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
44 | * GNU General Public License for more details.
|
||
45 | *
|
||
46 | * You should have received a copy of the GNU General Public License
|
||
47 | * along with this program; if not, write to the Free Software
|
||
48 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
49 | *
|
||
50 | * For more information, contact:
|
||
51 | *
|
||
52 | * Generalitat Valenciana
|
||
53 | * Conselleria d'Infraestructures i Transport
|
||
54 | * Av. Blasco Ib??ez, 50
|
||
55 | * 46010 VALENCIA
|
||
56 | * SPAIN
|
||
57 | *
|
||
58 | * +34 963862235
|
||
59 | * gvsig@gva.es
|
||
60 | * www.gvsig.gva.es
|
||
61 | *
|
||
62 | * or
|
||
63 | *
|
||
64 | * IVER T.I. S.A
|
||
65 | * Salamanca 50
|
||
66 | * 46005 Valencia
|
||
67 | * Spain
|
||
68 | *
|
||
69 | * +34 963163400
|
||
70 | * dac@iver.es
|
||
71 | */
|
||
72 | /* CVS MESSAGES:
|
||
73 | *
|
||
74 | * $Id: TreeTableModelAdapter.java 13655 2007-09-12 16:28:55Z bsanchez $
|
||
75 | * $Log$
|
||
76 | * Revision 1.2 2007-09-12 16:28:23 bsanchez
|
||
77 | * *** empty log message ***
|
||
78 | *
|
||
79 | * Revision 1.1 2007/08/20 08:34:46 evercher
|
||
80 | * He fusionado LibUI con LibUIComponents
|
||
81 | *
|
||
82 | * Revision 1.3 2006/10/25 14:45:52 jorpiell
|
||
83 | * A?adidos los renderers al arbol
|
||
84 | *
|
||
85 | * Revision 1.2 2006/10/24 08:04:13 jorpiell
|
||
86 | * nodeFroRow es ahora public
|
||
87 | *
|
||
88 | * Revision 1.1 2006/10/23 08:18:39 jorpiell
|
||
89 | * A?adida la clase treetable
|
||
90 | *
|
||
91 | *
|
||
92 | */
|
||
93 | /**
|
||
94 | * @author Jorge Piera Llodr? (piera_jor@gva.es)
|
||
95 | */
|
||
96 | public class TreeTableModelAdapter extends AbstractTableModel{ |
||
97 | private static final long serialVersionUID = -5509267189480739255L; |
||
98 | JTree tree;
|
||
99 | TreeTableModel treeTableModel; |
||
100 | |||
101 | public TreeTableModelAdapter(TreeTableModel treeTableModel, JTree tree) { |
||
102 | this.tree = tree;
|
||
103 | this.treeTableModel = treeTableModel;
|
||
104 | |||
105 | tree.addTreeExpansionListener(new TreeExpansionListener() { |
||
106 | // Don't use fireTableRowsInserted() here;
|
||
107 | // the selection model would get updated twice.
|
||
108 | public void treeExpanded(TreeExpansionEvent event) { |
||
109 | fireTableDataChanged(); |
||
110 | } |
||
111 | public void treeCollapsed(TreeExpansionEvent event) { |
||
112 | fireTableDataChanged(); |
||
113 | } |
||
114 | }); |
||
115 | } |
||
116 | |||
117 | // Wrappers, implementing TableModel interface.
|
||
118 | |||
119 | public int getColumnCount() { |
||
120 | return treeTableModel.getColumnCount();
|
||
121 | } |
||
122 | |||
123 | public String getColumnName(int column) { |
||
124 | return treeTableModel.getColumnName(column);
|
||
125 | } |
||
126 | |||
127 | public Class getColumnClass(int column) { |
||
128 | return treeTableModel.getColumnClass(column);
|
||
129 | } |
||
130 | |||
131 | public int getRowCount() { |
||
132 | return tree.getRowCount();
|
||
133 | } |
||
134 | |||
135 | public Object nodeForRow(int row) { |
||
136 | TreePath treePath = tree.getPathForRow(row);
|
||
137 | return treePath.getLastPathComponent();
|
||
138 | } |
||
139 | |||
140 | public Object getValueAt(int row, int column) { |
||
141 | return treeTableModel.getValueAt(nodeForRow(row), column);
|
||
142 | } |
||
143 | |||
144 | public boolean isCellEditable(int row, int column) { |
||
145 | return treeTableModel.isCellEditable(nodeForRow(row), column);
|
||
146 | } |
||
147 | |||
148 | public void setValueAt(Object value, int row, int column) { |
||
149 | treeTableModel.setValueAt(value, nodeForRow(row), column); |
||
150 | } |
||
151 | } |
||
152 |