root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / ProjectTable.java @ 2183
History | View | Annotate | Download (12.7 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.project; |
42 |
|
43 |
import java.io.IOException; |
44 |
import java.text.DateFormat; |
45 |
import java.util.Date; |
46 |
|
47 |
import com.hardcode.driverManager.DriverLoadException; |
48 |
import com.hardcode.gdbms.engine.data.DataSource; |
49 |
import com.hardcode.gdbms.engine.data.DataSourceFactory; |
50 |
import com.hardcode.gdbms.engine.data.NoSuchTableException; |
51 |
import com.hardcode.gdbms.engine.data.driver.ObjectDriver; |
52 |
import com.hardcode.gdbms.engine.instruction.SemanticException; |
53 |
import com.hardcode.gdbms.parser.ParseException; |
54 |
import com.iver.cit.gvsig.fmap.DriverException; |
55 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
56 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
57 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
58 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
59 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
60 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.SingleLayer; |
61 |
import com.iver.utiles.XMLEntity; |
62 |
|
63 |
|
64 |
/**
|
65 |
* Tabla del proyecto
|
66 |
*
|
67 |
* @author Fernando Gonz?lez Cort?s
|
68 |
*/
|
69 |
public class ProjectTable extends ProjectElement { |
70 |
private static int numTables = 0; |
71 |
private SelectableDataSource modelo;
|
72 |
private SelectableDataSource original;
|
73 |
private String linkTable; |
74 |
private String field1; |
75 |
private String field2; |
76 |
|
77 |
/* No es necesaria para operar, s?lo para guardar el proyecto */
|
78 |
private AlphanumericData associatedTable;
|
79 |
|
80 |
/**
|
81 |
* Establece a true el bit index-?simo del bitmap de campos visibles. Los
|
82 |
* campos cuyos bits est?n a true se considerar?n visibles y viceversa
|
83 |
*
|
84 |
* @param index indice del bit que se quiere establecer a true
|
85 |
*/
|
86 |
public void set(int index) { |
87 |
//TODO implementar bien
|
88 |
// modelo.set(index);
|
89 |
change.firePropertyChange("visibles", true, true); |
90 |
} |
91 |
|
92 |
/**
|
93 |
* Obtiene el valor del bit index-?simo del bitmap de campos visibles
|
94 |
*
|
95 |
* @param index indice del bit que se quiere obtener
|
96 |
*
|
97 |
* @return devuelve true si el campo index-?simo es visible y false en caso
|
98 |
* contrario
|
99 |
*/
|
100 |
public boolean get(int index) { |
101 |
//TODO implementar bien
|
102 |
// return modelo.get(index);
|
103 |
return false; |
104 |
} |
105 |
|
106 |
/**
|
107 |
* Obtiene el modelo de la Tabla. Es decir, una clase con capacidad para
|
108 |
* leer la informaci?n de la tabla
|
109 |
*
|
110 |
* @return
|
111 |
*/
|
112 |
public SelectableDataSource getModelo() {
|
113 |
return modelo;
|
114 |
} |
115 |
|
116 |
/**
|
117 |
* Establece el valor del bit index-?simo al valor 'value'
|
118 |
*
|
119 |
* @param bitIndex indice del bit que se quiere tocar
|
120 |
* @param value valor que se quiere establecer en el bit indicado
|
121 |
*/
|
122 |
public void set(int bitIndex, boolean value) { |
123 |
//TODO implementar bien
|
124 |
// modelo.set(bitIndex, value);
|
125 |
change.firePropertyChange("visibles", value, value);
|
126 |
} |
127 |
|
128 |
/**
|
129 |
* DOCUMENT ME!
|
130 |
*
|
131 |
* @param name DOCUMENT ME!
|
132 |
* @param sds DOCUMENT ME!
|
133 |
*
|
134 |
* @return
|
135 |
*/
|
136 |
public static ProjectTable createTable(String name, SelectableDataSource sds) { |
137 |
ProjectTable t = new ProjectTable();
|
138 |
t.modelo = sds; |
139 |
|
140 |
t.setName(name); |
141 |
t.setCreationDate(DateFormat.getInstance().format(new Date())); |
142 |
numTables++; |
143 |
|
144 |
return t;
|
145 |
} |
146 |
|
147 |
/**
|
148 |
* DOCUMENT ME!
|
149 |
*
|
150 |
* @param sds DOCUMENT ME!
|
151 |
*/
|
152 |
public void setDataSource(SelectableDataSource sds) { |
153 |
modelo = sds; |
154 |
|
155 |
setName(sds.getName()); |
156 |
setCreationDate(DateFormat.getInstance().format(new Date())); |
157 |
change.firePropertyChange("model", modelo, modelo);
|
158 |
} |
159 |
|
160 |
/**
|
161 |
* DOCUMENT ME!
|
162 |
*
|
163 |
* @param ds DOCUMENT ME!
|
164 |
*/
|
165 |
public void replaceDataSource(SelectableDataSource ds) { |
166 |
original = modelo; |
167 |
modelo = ds; |
168 |
change.firePropertyChange("model", original, modelo);
|
169 |
} |
170 |
|
171 |
/**
|
172 |
* DOCUMENT ME!
|
173 |
*/
|
174 |
public void restoreDataSource() { |
175 |
modelo = original; |
176 |
original = null;
|
177 |
change.firePropertyChange("model", original, modelo);
|
178 |
} |
179 |
|
180 |
/**
|
181 |
* DOCUMENT ME!
|
182 |
*
|
183 |
* @return DOCUMENT ME!
|
184 |
*
|
185 |
* @throws XMLException
|
186 |
*/
|
187 |
public XMLEntity getXMLEntity() throws XMLException { |
188 |
XMLEntity xml = super.getXMLEntity();
|
189 |
|
190 |
//xml.putProperty("nameClass", this.getClass().getName());
|
191 |
xml.putProperty("numTables", numTables);
|
192 |
|
193 |
if (getLinkTable() != null) { |
194 |
xml.putProperty("linkTable", linkTable);
|
195 |
xml.putProperty("field1", field1);
|
196 |
xml.putProperty("field2", field2);
|
197 |
} |
198 |
|
199 |
if (getOriginal() != null) { |
200 |
xml.addChild(getOriginal().getXMLEntity()); |
201 |
} |
202 |
|
203 |
xml.addChild(modelo.getXMLEntity()); |
204 |
|
205 |
Object di = LayerFactory.getDataSourceFactory().getDriverInfo(modelo.getName());
|
206 |
|
207 |
if (associatedTable != null) { |
208 |
xml.putProperty("layerName", ((FLayer) associatedTable).getName());
|
209 |
xml.putProperty("viewName",
|
210 |
project.getView((FLayer) associatedTable)); |
211 |
} |
212 |
|
213 |
return xml;
|
214 |
} |
215 |
|
216 |
/**
|
217 |
* DOCUMENT ME!
|
218 |
*
|
219 |
* @param xml DOCUMENT ME!
|
220 |
* @param p DOCUMENT ME!
|
221 |
*
|
222 |
* @throws XMLException
|
223 |
* @throws DriverException
|
224 |
*
|
225 |
* @see com.iver.cit.gvsig.project.ProjectElement#setXMLEntity(com.iver.utiles.XMLEntity)
|
226 |
*/
|
227 |
public void setXMLEntity03(XMLEntity xml, Project p) |
228 |
throws XMLException, DriverException {
|
229 |
numTables = xml.getIntProperty("numTables");
|
230 |
|
231 |
|
232 |
|
233 |
if (xml.getStringProperty("type").equals("otherDriverFile")) { |
234 |
LayerFactory.getDataSourceFactory().addFileDataSource(xml.getStringProperty( |
235 |
"driverName"), xml.getStringProperty("gdbmsname"), |
236 |
xml.getStringProperty("file"), xml.getStringProperty("dbms"), null); |
237 |
|
238 |
setSelectableDataSource03(xml); |
239 |
} else if (xml.getStringProperty("type").equals("sameDriverFile")) { |
240 |
String layerName = xml.getStringProperty("layerName"); |
241 |
|
242 |
ProjectView vista = project.getViewByName(xml.getStringProperty( |
243 |
"viewName"));
|
244 |
FLayer layer = vista.getMapContext().getLayers().getLayer(layerName); |
245 |
|
246 |
modelo = ((AlphanumericData) layer).getRecordset(); |
247 |
associatedTable = (AlphanumericData) layer; |
248 |
|
249 |
LayerFactory.getDataSourceFactory().addDataSource((ObjectDriver) ((SingleLayer)layer).getSource().getDriver(), xml.getStringProperty("gdbmsname"));
|
250 |
} else if (xml.getStringProperty("type").equals("db")) { |
251 |
LayerFactory.getDataSourceFactory().addDBDataSourceByTable(xml.getStringProperty("gdbmsname"),
|
252 |
xml.getStringProperty("host"), xml.getIntProperty("port"), |
253 |
xml.getStringProperty("user"),
|
254 |
xml.getStringProperty("password"),
|
255 |
xml.getStringProperty("dbName"),
|
256 |
xml.getStringProperty("tableName"),
|
257 |
xml.getStringProperty("driverInfo"), null); |
258 |
|
259 |
setSelectableDataSource03(xml); |
260 |
} |
261 |
|
262 |
setName(xml.getStringProperty("name"));
|
263 |
} |
264 |
|
265 |
/**
|
266 |
* DOCUMENT ME!
|
267 |
*
|
268 |
* @param xml DOCUMENT ME!
|
269 |
* @param p DOCUMENT ME!
|
270 |
*
|
271 |
* @throws XMLException
|
272 |
* @throws DriverException
|
273 |
*
|
274 |
* @see com.iver.cit.gvsig.project.ProjectElement#setXMLEntity(com.iver.utiles.XMLEntity)
|
275 |
*/
|
276 |
public void setXMLEntity(XMLEntity xml, Project p) |
277 |
throws XMLException, DriverException {
|
278 |
setName(xml.getStringProperty("name"));
|
279 |
numTables = xml.getIntProperty("numTables");
|
280 |
|
281 |
setSelectableDataSource(xml); |
282 |
|
283 |
/*
|
284 |
if (xml.getStringProperty("type").equals("otherDriverFile")) {
|
285 |
} else if (xml.getStringProperty("type").equals("sameDriverFile")) {
|
286 |
String layerName = xml.getStringProperty("layerName");
|
287 |
ProjectView vista = project.getViewByName(xml.getStringProperty(
|
288 |
"viewName"));
|
289 |
FLayer layer = vista.getMapContext().getLayers().getLayer(layerName);
|
290 |
|
291 |
modelo = ((AlphanumericData) layer).getRecordset();
|
292 |
associatedTable = (AlphanumericData) layer;
|
293 |
} else if (xml.getStringProperty("type").equals("db")) {
|
294 |
setSelectableDataSource(xml);
|
295 |
}
|
296 |
*/
|
297 |
setName(xml.getStringProperty("name"));
|
298 |
|
299 |
if (xml.contains("linkTable")) { |
300 |
setLinkTable(xml.getStringProperty("linkTable"),
|
301 |
xml.getStringProperty("field1"), xml.getStringProperty("field2")); |
302 |
} |
303 |
} |
304 |
|
305 |
private void setSelectableDataSource03(XMLEntity xml) throws XMLException, DriverException{ |
306 |
String layerName = null; |
307 |
|
308 |
if (xml.contains("layerName")) |
309 |
layerName = xml.getStringProperty("layerName");
|
310 |
|
311 |
if (layerName == null) { |
312 |
DataSource dataSource;
|
313 |
|
314 |
try {
|
315 |
dataSource = LayerFactory.getDataSourceFactory().createRandomDataSource(xml.getStringProperty( |
316 |
"gdbmsname"), DataSourceFactory.CLOSING_AUTOMATIC_MODE);
|
317 |
} catch (NoSuchTableException e) {
|
318 |
throw new XMLException(e); |
319 |
} catch (DriverLoadException e) {
|
320 |
throw new XMLException(e); |
321 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
322 |
throw new XMLException(e); |
323 |
} |
324 |
|
325 |
SelectableDataSource sds = new SelectableDataSource(dataSource);
|
326 |
|
327 |
sds.setXMLEntity03(xml.getChild(0));
|
328 |
|
329 |
setDataSource(sds); |
330 |
} else {
|
331 |
ProjectView vista = project.getViewByName(xml.getStringProperty( |
332 |
"viewName"));
|
333 |
FLayer layer = vista.getMapContext().getLayers().getLayer(layerName); |
334 |
|
335 |
modelo = ((AlphanumericData) layer).getRecordset(); |
336 |
associatedTable = (AlphanumericData) layer; |
337 |
} |
338 |
} |
339 |
|
340 |
/**
|
341 |
* DOCUMENT ME!
|
342 |
*
|
343 |
* @param xml DOCUMENT ME!
|
344 |
*
|
345 |
* @throws XMLException DOCUMENT ME!
|
346 |
* @throws DriverException DOCUMENT ME!
|
347 |
*/
|
348 |
private void setSelectableDataSource(XMLEntity xml) |
349 |
throws XMLException, DriverException {
|
350 |
String layerName = null; |
351 |
|
352 |
if (xml.contains("layerName")) { |
353 |
layerName = xml.getStringProperty("layerName");
|
354 |
} |
355 |
|
356 |
SelectableDataSource sds; |
357 |
|
358 |
try {
|
359 |
sds = SelectableDataSource.createSelectableDataSource(xml.getChild( |
360 |
0));
|
361 |
setDataSource(sds); |
362 |
|
363 |
if (xml.getNumChild() == 2) { |
364 |
replaceDataSource(SelectableDataSource.createSelectableDataSource( |
365 |
xml.getChild(1)));
|
366 |
} |
367 |
} catch (NoSuchTableException e) {
|
368 |
throw new XMLException(e); |
369 |
} catch (ParseException e) { |
370 |
throw new XMLException(e); |
371 |
} catch (DriverLoadException e) {
|
372 |
throw new XMLException(e); |
373 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
374 |
throw new XMLException(e); |
375 |
} catch (SemanticException e) {
|
376 |
throw new XMLException(e); |
377 |
} catch (IOException e) { |
378 |
throw new XMLException(e); |
379 |
} |
380 |
|
381 |
if (layerName != null) { |
382 |
ProjectView vista = project.getViewByName(xml.getStringProperty( |
383 |
"viewName"));
|
384 |
FLayer layer = vista.getMapContext().getLayers().getLayer(layerName); |
385 |
|
386 |
// modelo = ((AlphanumericData) layer).getRecordset();
|
387 |
associatedTable = (AlphanumericData) layer; |
388 |
} |
389 |
} |
390 |
|
391 |
/**
|
392 |
* DOCUMENT ME!
|
393 |
*
|
394 |
* @return DOCUMENT ME!
|
395 |
*/
|
396 |
public AlphanumericData getAssociatedTable() {
|
397 |
return associatedTable;
|
398 |
} |
399 |
|
400 |
/**
|
401 |
* DOCUMENT ME!
|
402 |
*
|
403 |
* @param associatedTable DOCUMENT ME!
|
404 |
*/
|
405 |
public void setAssociatedTable(AlphanumericData associatedTable) { |
406 |
this.associatedTable = associatedTable;
|
407 |
} |
408 |
|
409 |
/**
|
410 |
* Obtiene la fuente de datos original de la tabla si se ha invocado
|
411 |
* replaceDataSource. Si no se invoc? este m?todo o se invoc?
|
412 |
* posteriormente restoreDataSource se devuelve null
|
413 |
*
|
414 |
* @return Returns the original.
|
415 |
*/
|
416 |
public SelectableDataSource getOriginal() {
|
417 |
return original;
|
418 |
} |
419 |
|
420 |
/**
|
421 |
* Devuelve el identificador de la tabla que contiene el link.
|
422 |
*
|
423 |
* @return identificador ?nico de la tabla.
|
424 |
*/
|
425 |
public String getLinkTable() { |
426 |
return linkTable;
|
427 |
} |
428 |
|
429 |
/**
|
430 |
* Devuelve el nombre del campo de la tabla a enlazar.
|
431 |
*
|
432 |
* @return Nombre del campo de la tabla a enlazar.
|
433 |
*/
|
434 |
public String getField1() { |
435 |
return field1;
|
436 |
} |
437 |
|
438 |
/**
|
439 |
* Devuelve el nombre del campo de la tabla enlazada.
|
440 |
*
|
441 |
* @return Nombre del campo de la tabla enlazada.
|
442 |
*/
|
443 |
public String getField2() { |
444 |
return field2;
|
445 |
} |
446 |
|
447 |
/**
|
448 |
* Inserta el identificador de la tabla, el campo de la primera tabla y el campo de la segunda tabla.
|
449 |
*
|
450 |
* @param lt identificado de la tabla.
|
451 |
* @param f1 nombre del campo de la primera tabla.
|
452 |
* @param f2 nombre del campo de la segunda tabla.
|
453 |
*/
|
454 |
public void setLinkTable(String lt, String f1, String f2) { |
455 |
linkTable = lt; |
456 |
field1 = f1; |
457 |
field2 = f2; |
458 |
} |
459 |
|
460 |
/**
|
461 |
* Borra el identificador de la tabla y elimina del array de listener los listener que sean del tipo: LinkSelectionListenr
|
462 |
*/
|
463 |
public void removeLinkTable() { |
464 |
linkTable = null;
|
465 |
getModelo().removeLinksSelectionListener(); |
466 |
} |
467 |
} |