Statistics
| Revision:

root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / SelectableDataSource.java @ 1773

History | View | Annotate | Download (7.14 KB)

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