svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / project / TableModel.java @ 3718
History | View | Annotate | Download (5.07 KB)
1 | 2565 | fernando | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
4 | *
|
||
5 | * This program is free software; you can redistribute it and/or
|
||
6 | * modify it under the terms of the GNU General Public License
|
||
7 | * as published by the Free Software Foundation; either version 2
|
||
8 | * of the License, or (at your option) any later version.
|
||
9 | *
|
||
10 | * This program is distributed in the hope that it will be useful,
|
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | * GNU General Public License for more details.
|
||
14 | *
|
||
15 | * You should have received a copy of the GNU General Public License
|
||
16 | * along with this program; if not, write to the Free Software
|
||
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
18 | *
|
||
19 | * For more information, contact:
|
||
20 | *
|
||
21 | * Generalitat Valenciana
|
||
22 | * Conselleria d'Infraestructures i Transport
|
||
23 | * Av. Blasco Ib??ez, 50
|
||
24 | * 46010 VALENCIA
|
||
25 | * SPAIN
|
||
26 | *
|
||
27 | * +34 963862235
|
||
28 | * gvsig@gva.es
|
||
29 | * www.gvsig.gva.es
|
||
30 | *
|
||
31 | * or
|
||
32 | *
|
||
33 | * IVER T.I. S.A
|
||
34 | * Salamanca 50
|
||
35 | * 46005 Valencia
|
||
36 | * Spain
|
||
37 | *
|
||
38 | * +34 963163400
|
||
39 | * dac@iver.es
|
||
40 | */
|
||
41 | package com.iver.cit.gvsig.gui.project; |
||
42 | |||
43 | |||
44 | import java.util.BitSet; |
||
45 | |||
46 | import javax.swing.table.AbstractTableModel; |
||
47 | |||
48 | import com.hardcode.gdbms.engine.data.driver.DriverException; |
||
49 | import com.iver.andami.PluginServices; |
||
50 | import com.iver.andami.messages.NotificationManager; |
||
51 | import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
||
52 | import com.iver.cit.gvsig.project.ProjectTable; |
||
53 | |||
54 | |||
55 | /**
|
||
56 | * Modelo para la JTable de MapProperties
|
||
57 | *
|
||
58 | * @author Fernando Gonz?lez Cort?s
|
||
59 | */
|
||
60 | public class TableModel extends AbstractTableModel { |
||
61 | private BitSet visibles = new BitSet(); |
||
62 | private String[] alias; |
||
63 | private ProjectTable table;
|
||
64 | |||
65 | /**
|
||
66 | * Creates a new MyTableModel object.
|
||
67 | *
|
||
68 | * @param t Tabla del proyecto que se quiere mostrar
|
||
69 | * @throws DriverException
|
||
70 | */
|
||
71 | public TableModel(ProjectTable t) throws DriverException { |
||
72 | SelectableDataSource ds = t.getOriginal(); |
||
73 | if (ds == null) { |
||
74 | ds = t.getModelo(); |
||
75 | } |
||
76 | alias = t.getAliases(); |
||
77 | int[] mapping = t.getMapping(); |
||
78 | visibles = new BitSet(); |
||
79 | for (int i = 0; i < mapping.length; i++) { |
||
80 | visibles.set(mapping[i]); |
||
81 | } |
||
82 | |||
83 | table = t; |
||
84 | } |
||
85 | |||
86 | /**
|
||
87 | * @see javax.swing.table.TableModel#getColumnCount()
|
||
88 | */
|
||
89 | public int getColumnCount() { |
||
90 | return 3; |
||
91 | } |
||
92 | |||
93 | /* (non-Javadoc)
|
||
94 | * @see javax.swing.table.TableModel#getRowCount()
|
||
95 | */
|
||
96 | public int getRowCount() { |
||
97 | try {
|
||
98 | return table.getModelo().getFieldCount();
|
||
99 | } catch (DriverException e) {
|
||
100 | NotificationManager.addError("No se pudo leer la informaci?n de la tabla", e);
|
||
101 | return 0; |
||
102 | } |
||
103 | } |
||
104 | |||
105 | /* (non-Javadoc)
|
||
106 | * @see javax.swing.table.TableModel#getValueAt(int, int)
|
||
107 | */
|
||
108 | public Object getValueAt(int rowIndex, int columnIndex) { |
||
109 | if (columnIndex == 0) { |
||
110 | return new Boolean(visibles.get(rowIndex)); |
||
111 | } else if (columnIndex == 1) { |
||
112 | try {
|
||
113 | return table.getModelo().getFieldName(rowIndex);
|
||
114 | } catch (DriverException e) {
|
||
115 | NotificationManager.addError("Error accediendo al nombre del campo", e);
|
||
116 | return "error!"; |
||
117 | } |
||
118 | } else {
|
||
119 | return alias[rowIndex];
|
||
120 | } |
||
121 | } |
||
122 | |||
123 | /* (non-Javadoc)
|
||
124 | * @see javax.swing.table.TableModel#getColumnClass(int)
|
||
125 | */
|
||
126 | public Class getColumnClass(int columnIndex) { |
||
127 | if (columnIndex == 0) { |
||
128 | return Boolean.class; |
||
129 | } |
||
130 | |||
131 | return String.class; |
||
132 | } |
||
133 | |||
134 | /* (non-Javadoc)
|
||
135 | * @see javax.swing.table.TableModel#isCellEditable(int, int)
|
||
136 | */
|
||
137 | public boolean isCellEditable(int rowIndex, int columnIndex) { |
||
138 | return (columnIndex != 1); |
||
139 | } |
||
140 | |||
141 | /* (non-Javadoc)
|
||
142 | * @see javax.swing.table.TableModel#setValueAt(java.lang.Object, int, int)
|
||
143 | */
|
||
144 | public void setValueAt(Object aValue, int rowIndex, int columnIndex) { |
||
145 | if (columnIndex == 0) { |
||
146 | visibles.set(rowIndex, ((Boolean) aValue).booleanValue());
|
||
147 | } else {
|
||
148 | alias[rowIndex] = aValue.toString(); |
||
149 | } |
||
150 | } |
||
151 | |||
152 | /* (non-Javadoc)
|
||
153 | * @see javax.swing.table.TableModel#getColumnName(int)
|
||
154 | */
|
||
155 | public String getColumnName(int column) { |
||
156 | String ret = null; |
||
157 | |||
158 | switch (column) {
|
||
159 | case 0: |
||
160 | ret = PluginServices.getText(this, "visible"); |
||
161 | |||
162 | break;
|
||
163 | |||
164 | case 1: |
||
165 | ret = PluginServices.getText(this, "campo"); |
||
166 | |||
167 | break;
|
||
168 | |||
169 | case 2: |
||
170 | ret = PluginServices.getText(this, "alias"); |
||
171 | |||
172 | break;
|
||
173 | } |
||
174 | |||
175 | return ret;
|
||
176 | } |
||
177 | |||
178 | public String[] getAliases() { |
||
179 | return alias;
|
||
180 | } |
||
181 | |||
182 | public int[] getFieldMapping() { |
||
183 | int[] mapping = new int[visibles.cardinality()]; |
||
184 | int index = 0; |
||
185 | for(int i=visibles.nextSetBit(0); i>=0; i=visibles.nextSetBit(i+1)) { |
||
186 | mapping[index] = i; |
||
187 | index++; |
||
188 | } |
||
189 | |||
190 | return mapping;
|
||
191 | } |
||
192 | } |