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