root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / SelectableDataSource.java @ 1773
History | View | Annotate | Download (7.14 KB)
1 |
/* 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.fmap.layers; |
42 |
|
43 |
import com.hardcode.gdbms.engine.data.DataSource; |
44 |
import com.hardcode.gdbms.engine.data.DataSourceFactory; |
45 |
import com.hardcode.gdbms.engine.data.DriverException; |
46 |
import com.hardcode.gdbms.engine.data.NoSuchTableException; |
47 |
import com.hardcode.gdbms.engine.data.ReadDriver; |
48 |
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException; |
49 |
import com.hardcode.gdbms.engine.values.Value; |
50 |
|
51 |
import com.iver.utiles.XMLEntity; |
52 |
|
53 |
import org.apache.log4j.Logger; |
54 |
|
55 |
import java.io.IOException; |
56 |
|
57 |
|
58 |
/**
|
59 |
* DataSource seleccionable.
|
60 |
*
|
61 |
* @author Fernando Gonz?lez Cort?s
|
62 |
*/
|
63 |
public class SelectableDataSource implements DataSource { |
64 |
private static Logger logger = Logger.getLogger(SelectableDataSource.class.getName()); |
65 |
private SelectionSupport selectionSupport = new SelectionSupport(); |
66 |
private DataSource dataSource; |
67 |
|
68 |
/**
|
69 |
* Crea un nuevo SelectableDataSource.
|
70 |
*
|
71 |
* @param name
|
72 |
* @param ds
|
73 |
*/
|
74 |
public SelectableDataSource(DataSource ds) { |
75 |
dataSource = ds; |
76 |
} |
77 |
|
78 |
/**
|
79 |
* A?ade el soporte para la selecci?n.
|
80 |
*
|
81 |
* @param selectionSupport
|
82 |
*/
|
83 |
public void setSelectionSupport(SelectionSupport selectionSupport) { |
84 |
this.selectionSupport = selectionSupport;
|
85 |
} |
86 |
|
87 |
/**
|
88 |
* Devuelve el DBMS.
|
89 |
*
|
90 |
* @return String.
|
91 |
*/
|
92 |
public String getDBMS() { |
93 |
return dataSource.getDBMS();
|
94 |
} |
95 |
|
96 |
/**
|
97 |
* Devuelve el n?mero de campos.
|
98 |
*
|
99 |
* @return N?mero de campos.
|
100 |
*
|
101 |
* @throws DriverException
|
102 |
*/
|
103 |
public int getFieldCount() throws DriverException { |
104 |
return dataSource.getFieldCount();
|
105 |
} |
106 |
|
107 |
/**
|
108 |
* Devuelve el ?ndice del campo a partir de su nombre.
|
109 |
*
|
110 |
* @param arg0 nombre del campo.
|
111 |
*
|
112 |
* @return ?ndice.
|
113 |
*
|
114 |
* @throws DriverException
|
115 |
* @throws FieldNotFoundException
|
116 |
*/
|
117 |
public int getFieldIndexByName(String arg0) |
118 |
throws DriverException {
|
119 |
return dataSource.getFieldIndexByName(arg0);
|
120 |
} |
121 |
|
122 |
/**
|
123 |
* Devuelve el nombre del campo a partir del ?ndice.
|
124 |
*
|
125 |
* @param arg0 ?ndice.
|
126 |
*
|
127 |
* @return nombre del campo.
|
128 |
*
|
129 |
* @throws DriverException
|
130 |
*/
|
131 |
public String getFieldName(int arg0) throws DriverException { |
132 |
return dataSource.getFieldName(arg0);
|
133 |
} |
134 |
|
135 |
/**
|
136 |
* Devuelve el valor a partir del n?mro de fila y columna.
|
137 |
*
|
138 |
* @param arg0 n?mero de registro.
|
139 |
* @param arg1 n?mero de campo.
|
140 |
*
|
141 |
* @return Valor.
|
142 |
*
|
143 |
* @throws DriverException
|
144 |
*/
|
145 |
public Value getFieldValue(long arg0, int arg1) throws DriverException { |
146 |
return dataSource.getFieldValue(arg0, arg1);
|
147 |
} |
148 |
|
149 |
/**
|
150 |
* Devuelve el nombre del DataSource.
|
151 |
*
|
152 |
* @return Nombre.
|
153 |
*/
|
154 |
public String getName() { |
155 |
return dataSource.getName();
|
156 |
} |
157 |
|
158 |
/**
|
159 |
* Devuelve el n?mro de filas en total.
|
160 |
*
|
161 |
* @return n?mero de filas.
|
162 |
*
|
163 |
* @throws DriverException
|
164 |
*/
|
165 |
public long getRowCount() throws DriverException { |
166 |
return dataSource.getRowCount();
|
167 |
} |
168 |
|
169 |
/**
|
170 |
* Inicializa el dataSource.
|
171 |
*
|
172 |
* @throws DriverException
|
173 |
*/
|
174 |
public void start() throws DriverException { |
175 |
logger.debug("dataSource.start()");
|
176 |
dataSource.start(); |
177 |
} |
178 |
|
179 |
/**
|
180 |
* Finaliza el DataSource.
|
181 |
*
|
182 |
* @throws DriverException
|
183 |
*/
|
184 |
public void stop() throws DriverException { |
185 |
logger.debug("dataSource.stop()");
|
186 |
dataSource.stop(); |
187 |
} |
188 |
|
189 |
/**
|
190 |
* Cuando ocurre un evento de cambio en la selecci?n, ?ste puede ser uno de
|
191 |
* una gran cantidad de eventos. Con el fin de no propagar todos estos
|
192 |
* eventos, se realiza la propagaci?n de manera manual al final de la
|
193 |
* "r?faga" de eventos
|
194 |
*/
|
195 |
public void fireSelectionEvents() { |
196 |
selectionSupport.fireSelectionEvents(); |
197 |
} |
198 |
|
199 |
/**
|
200 |
* A?ade un nuevo Listener al SelectionSupport.
|
201 |
*
|
202 |
* @param listener SelectionListener.
|
203 |
*/
|
204 |
public void addSelectionListener(SelectionListener listener) { |
205 |
selectionSupport.addSelectionListener(listener); |
206 |
} |
207 |
|
208 |
/**
|
209 |
* Borra un Listener al SelectionSupport.
|
210 |
*
|
211 |
* @param listener Listener a borrar.
|
212 |
*/
|
213 |
public void removeSelectionListener(SelectionListener listener) { |
214 |
selectionSupport.removeSelectionListener(listener); |
215 |
} |
216 |
|
217 |
/**
|
218 |
* Borra la selecci?n.
|
219 |
*/
|
220 |
public void clearSelection() { |
221 |
selectionSupport.clearSelection(); |
222 |
} |
223 |
|
224 |
/**
|
225 |
* Develve un FBitSet con los ?ndices de los elementos seleccionados.
|
226 |
*
|
227 |
* @return FBitset con los elementos seleccionados.
|
228 |
*/
|
229 |
public FBitSet getSelection() {
|
230 |
return selectionSupport.getSelection();
|
231 |
} |
232 |
|
233 |
/**
|
234 |
* Devuelve el SelectionSupport.
|
235 |
*
|
236 |
* @return SelectinSuport.
|
237 |
*/
|
238 |
public SelectionSupport getSelectionSupport() {
|
239 |
return selectionSupport;
|
240 |
} |
241 |
|
242 |
/**
|
243 |
* Devuelve true si el elemento est? seleccionado.
|
244 |
*
|
245 |
* @param recordIndex ?ndice del registro.
|
246 |
*
|
247 |
* @return True si el registro est? seleccionado.
|
248 |
*/
|
249 |
public boolean isSelected(int recordIndex) { |
250 |
return selectionSupport.isSelected(recordIndex);
|
251 |
} |
252 |
|
253 |
/**
|
254 |
* Inserta una nueva selecci?n.
|
255 |
*
|
256 |
* @param selection FBitSet.
|
257 |
*/
|
258 |
public void setSelection(FBitSet selection) { |
259 |
selectionSupport.setSelection(selection); |
260 |
} |
261 |
|
262 |
/**
|
263 |
* Inserta un nuevo nombre para el dataSource.
|
264 |
*
|
265 |
* @param name Nuevo nombre del DataSource.
|
266 |
*
|
267 |
* @throws RuntimeException
|
268 |
*/
|
269 |
public void setName(String name) { |
270 |
try {
|
271 |
LayerFactory.getDataSourceFactory().changeDataSourceName(dataSource.getName(), name); |
272 |
} catch (NoSuchTableException e) {
|
273 |
throw new RuntimeException("No se encuentra la tabla????"); |
274 |
} |
275 |
} |
276 |
|
277 |
/**
|
278 |
* Devuelve el XMLEntity con la informaci?n necesaria para reproducir el
|
279 |
* DataSource.
|
280 |
*
|
281 |
* @return XMLEntity.
|
282 |
*/
|
283 |
public XMLEntity getXMLEntity() {
|
284 |
XMLEntity xml = new XMLEntity();
|
285 |
xml.putProperty("className",this.getClass().getName()); |
286 |
xml.addChild(selectionSupport.getXMLEntity()); |
287 |
|
288 |
return xml;
|
289 |
} |
290 |
|
291 |
/**
|
292 |
* A partir del XMLEntity se rellenan los atributos del DataSource.
|
293 |
*
|
294 |
* @param child
|
295 |
*/
|
296 |
public void setXMLEntity(XMLEntity child) { |
297 |
selectionSupport.setXMLEntity(child.getChild(0));
|
298 |
} |
299 |
|
300 |
/**
|
301 |
* @see com.hardcode.gdbms.engine.data.DataSource#getWhereFilter()
|
302 |
*/
|
303 |
public long[] getWhereFilter() throws IOException { |
304 |
return dataSource.getWhereFilter();
|
305 |
} |
306 |
|
307 |
/**
|
308 |
* @see com.hardcode.gdbms.engine.data.ReadDriver#getFieldType(int)
|
309 |
*/
|
310 |
public int getFieldType(int i) throws DriverException { |
311 |
return dataSource.getFieldType(i);
|
312 |
} |
313 |
} |