svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / table / gui / TableModelProperties.java @ 24529
History | View | Annotate | Download (5.23 KB)
1 | 10459 | caballero | /* 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.project.documents.table.gui; |
||
42 | |||
43 | |||
44 | import java.util.BitSet; |
||
45 | |||
46 | import javax.swing.table.AbstractTableModel; |
||
47 | |||
48 | 10626 | caballero | import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
49 | 10459 | caballero | import com.hardcode.gdbms.engine.data.driver.DriverException; |
50 | import com.iver.andami.PluginServices; |
||
51 | import com.iver.andami.messages.NotificationManager; |
||
52 | import com.iver.cit.gvsig.fmap.edition.IEditableSource; |
||
53 | import com.iver.cit.gvsig.project.documents.table.ProjectTable; |
||
54 | |||
55 | |||
56 | /**
|
||
57 | * Modelo para la JTable de MapProperties
|
||
58 | *
|
||
59 | * @author Fernando Gonz?lez Cort?s
|
||
60 | */
|
||
61 | public class TableModelProperties extends AbstractTableModel { |
||
62 | private BitSet visibles = new BitSet(); |
||
63 | private String[] alias; |
||
64 | private ProjectTable table;
|
||
65 | |||
66 | /**
|
||
67 | * Creates a new MyTableModel object.
|
||
68 | *
|
||
69 | * @param t Tabla del proyecto que se quiere mostrar
|
||
70 | * @throws DriverException
|
||
71 | */
|
||
72 | public TableModelProperties(ProjectTable t) {
|
||
73 | IEditableSource ds = t.getOriginal(); |
||
74 | if (ds == null) { |
||
75 | ds = t.getModelo(); |
||
76 | } |
||
77 | alias = t.getAliases(); |
||
78 | int[] mapping = t.getMapping(); |
||
79 | visibles = new BitSet(); |
||
80 | for (int i = 0; i < mapping.length; i++) { |
||
81 | visibles.set(mapping[i]); |
||
82 | } |
||
83 | |||
84 | table = t; |
||
85 | } |
||
86 | |||
87 | /**
|
||
88 | * @see javax.swing.table.TableModel#getColumnCount()
|
||
89 | */
|
||
90 | public int getColumnCount() { |
||
91 | return 3; |
||
92 | } |
||
93 | |||
94 | /* (non-Javadoc)
|
||
95 | * @see javax.swing.table.TableModel#getRowCount()
|
||
96 | */
|
||
97 | public int getRowCount() { |
||
98 | try {
|
||
99 | return table.getModelo().getRecordset().getFieldCount();
|
||
100 | 10626 | caballero | } catch (ReadDriverException e) {
|
101 | 10459 | caballero | NotificationManager.addError("No se pudo leer la informaci?n de la tabla", e);
|
102 | return 0; |
||
103 | 10661 | caballero | } |
104 | 10459 | caballero | } |
105 | |||
106 | /* (non-Javadoc)
|
||
107 | * @see javax.swing.table.TableModel#getValueAt(int, int)
|
||
108 | */
|
||
109 | public Object getValueAt(int rowIndex, int columnIndex) { |
||
110 | if (columnIndex == 0) { |
||
111 | return new Boolean(visibles.get(rowIndex)); |
||
112 | } else if (columnIndex == 1) { |
||
113 | try {
|
||
114 | return table.getModelo().getRecordset().getFieldName(rowIndex);
|
||
115 | 10626 | caballero | } catch (ReadDriverException e) {
|
116 | 10459 | caballero | NotificationManager.addError("Error accediendo al nombre del campo", e);
|
117 | return "error!"; |
||
118 | 10661 | caballero | } |
119 | 10459 | caballero | } else {
|
120 | // rowIndex++;
|
||
121 | return alias[rowIndex];
|
||
122 | } |
||
123 | } |
||
124 | |||
125 | /* (non-Javadoc)
|
||
126 | * @see javax.swing.table.TableModel#getColumnClass(int)
|
||
127 | */
|
||
128 | public Class getColumnClass(int columnIndex) { |
||
129 | if (columnIndex == 0) { |
||
130 | return Boolean.class; |
||
131 | } |
||
132 | |||
133 | return String.class; |
||
134 | } |
||
135 | |||
136 | /* (non-Javadoc)
|
||
137 | * @see javax.swing.table.TableModel#isCellEditable(int, int)
|
||
138 | */
|
||
139 | public boolean isCellEditable(int rowIndex, int columnIndex) { |
||
140 | return (columnIndex != 1); |
||
141 | } |
||
142 | |||
143 | /* (non-Javadoc)
|
||
144 | * @see javax.swing.table.TableModel#setValueAt(java.lang.Object, int, int)
|
||
145 | */
|
||
146 | public void setValueAt(Object aValue, int rowIndex, int columnIndex) { |
||
147 | if (columnIndex == 0) { |
||
148 | visibles.set(rowIndex, ((Boolean) aValue).booleanValue());
|
||
149 | } else {
|
||
150 | alias[rowIndex] = aValue.toString(); |
||
151 | } |
||
152 | } |
||
153 | |||
154 | /* (non-Javadoc)
|
||
155 | * @see javax.swing.table.TableModel#getColumnName(int)
|
||
156 | */
|
||
157 | public String getColumnName(int column) { |
||
158 | String ret = null; |
||
159 | |||
160 | switch (column) {
|
||
161 | case 0: |
||
162 | ret = PluginServices.getText(this, "visible"); |
||
163 | |||
164 | break;
|
||
165 | |||
166 | case 1: |
||
167 | ret = PluginServices.getText(this, "campo"); |
||
168 | |||
169 | break;
|
||
170 | |||
171 | case 2: |
||
172 | ret = PluginServices.getText(this, "alias"); |
||
173 | |||
174 | break;
|
||
175 | } |
||
176 | |||
177 | return ret;
|
||
178 | } |
||
179 | |||
180 | public String[] getAliases() { |
||
181 | // return table.getAliases();
|
||
182 | return alias;
|
||
183 | } |
||
184 | |||
185 | public int[] getFieldMapping() { |
||
186 | int[] mapping = new int[visibles.cardinality()]; |
||
187 | int index = 0; |
||
188 | for(int i=visibles.nextSetBit(0); i>=0; i=visibles.nextSetBit(i+1)) { |
||
189 | mapping[index] = i; |
||
190 | index++; |
||
191 | } |
||
192 | |||
193 | return mapping;
|
||
194 | } |
||
195 | } |