Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / SelectableDataSource.java @ 1283

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