svn-gvsig-desktop / tags / Root_v06 / applications / appgvSIG / src / com / iver / cit / gvsig / project / ProjectTable.java @ 4811
History | View | Annotate | Download (22.2 KB)
1 | 1222 | fernando | /* 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 | 2565 | fernando | import java.io.IOException; |
44 | import java.text.DateFormat; |
||
45 | import java.util.Date; |
||
46 | |||
47 | 2708 | fjp | import javax.swing.JOptionPane; |
48 | |||
49 | 2542 | fernando | import com.hardcode.driverManager.DriverLoadException; |
50 | 1222 | fernando | import com.hardcode.gdbms.engine.data.DataSource; |
51 | 2183 | fernando | import com.hardcode.gdbms.engine.data.DataSourceFactory; |
52 | 1222 | fernando | import com.hardcode.gdbms.engine.data.NoSuchTableException; |
53 | 2183 | fernando | import com.hardcode.gdbms.engine.data.driver.ObjectDriver; |
54 | 2760 | fjp | import com.hardcode.gdbms.engine.instruction.FieldNotFoundException; |
55 | 1830 | fernando | import com.hardcode.gdbms.engine.instruction.SemanticException; |
56 | 1774 | fernando | import com.hardcode.gdbms.parser.ParseException; |
57 | 2708 | fjp | import com.iver.andami.PluginServices; |
58 | 1222 | fernando | import com.iver.cit.gvsig.fmap.DriverException; |
59 | import com.iver.cit.gvsig.fmap.layers.FLayer; |
||
60 | 2611 | caballero | import com.iver.cit.gvsig.fmap.layers.FLayers; |
61 | 2629 | fjp | import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
62 | 1774 | fernando | import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
63 | 1222 | fernando | import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
64 | import com.iver.cit.gvsig.fmap.layers.XMLException; |
||
65 | import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
||
66 | 2183 | fernando | import com.iver.cit.gvsig.fmap.layers.layerOperations.SingleLayer; |
67 | 2708 | fjp | import com.iver.cit.gvsig.fmap.rendering.ClassifiedLegend; |
68 | import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
||
69 | 3183 | caballero | import com.iver.cit.gvsig.gui.project.OpenException; |
70 | import com.iver.cit.gvsig.gui.project.SaveException; |
||
71 | 1222 | fernando | import com.iver.utiles.XMLEntity; |
72 | |||
73 | |||
74 | /**
|
||
75 | * Tabla del proyecto
|
||
76 | *
|
||
77 | * @author Fernando Gonz?lez Cort?s
|
||
78 | */
|
||
79 | public class ProjectTable extends ProjectElement { |
||
80 | 2542 | fernando | private static int numTables = 0; |
81 | private SelectableDataSource modelo;
|
||
82 | private SelectableDataSource original;
|
||
83 | private String linkTable; |
||
84 | private String field1; |
||
85 | private String field2; |
||
86 | 1222 | fernando | |
87 | 2542 | fernando | /* No es necesaria para operar, s?lo para guardar el proyecto */
|
88 | private AlphanumericData associatedTable;
|
||
89 | 1222 | fernando | |
90 | 2565 | fernando | private int[] mapping; |
91 | private String[] alias; |
||
92 | |||
93 | 2542 | fernando | /**
|
94 | * Establece a true el bit index-?simo del bitmap de campos visibles. Los
|
||
95 | * campos cuyos bits est?n a true se considerar?n visibles y viceversa
|
||
96 | *
|
||
97 | * @param index indice del bit que se quiere establecer a true
|
||
98 | */
|
||
99 | public void set(int index) { |
||
100 | //TODO implementar bien
|
||
101 | // modelo.set(index);
|
||
102 | 2760 | fjp | |
103 | 2542 | fernando | change.firePropertyChange("visibles", true, true); |
104 | } |
||
105 | 1222 | fernando | |
106 | 2542 | fernando | /**
|
107 | * Obtiene el valor del bit index-?simo del bitmap de campos visibles
|
||
108 | *
|
||
109 | * @param index indice del bit que se quiere obtener
|
||
110 | *
|
||
111 | * @return devuelve true si el campo index-?simo es visible y false en caso
|
||
112 | * contrario
|
||
113 | */
|
||
114 | public boolean get(int index) { |
||
115 | //TODO implementar bien
|
||
116 | // return modelo.get(index);
|
||
117 | return false; |
||
118 | } |
||
119 | 1222 | fernando | |
120 | 2542 | fernando | /**
|
121 | * Obtiene el modelo de la Tabla. Es decir, una clase con capacidad para
|
||
122 | * leer la informaci?n de la tabla
|
||
123 | *
|
||
124 | * @return
|
||
125 | */
|
||
126 | public SelectableDataSource getModelo() {
|
||
127 | return modelo;
|
||
128 | } |
||
129 | 1222 | fernando | |
130 | 2542 | fernando | /**
|
131 | * Establece el valor del bit index-?simo al valor 'value'
|
||
132 | *
|
||
133 | * @param bitIndex indice del bit que se quiere tocar
|
||
134 | * @param value valor que se quiere establecer en el bit indicado
|
||
135 | */
|
||
136 | public void set(int bitIndex, boolean value) { |
||
137 | //TODO implementar bien
|
||
138 | // modelo.set(bitIndex, value);
|
||
139 | change.firePropertyChange("visibles", value, value);
|
||
140 | } |
||
141 | 1222 | fernando | |
142 | 2542 | fernando | /**
|
143 | * DOCUMENT ME!
|
||
144 | *
|
||
145 | * @param name DOCUMENT ME!
|
||
146 | * @param sds DOCUMENT ME!
|
||
147 | *
|
||
148 | * @return
|
||
149 | 2565 | fernando | * @throws com.hardcode.gdbms.engine.data.driver.DriverException
|
150 | 2542 | fernando | */
|
151 | 2565 | fernando | public static ProjectTable createTable(String name, SelectableDataSource sds) throws com.hardcode.gdbms.engine.data.driver.DriverException { |
152 | 2542 | fernando | ProjectTable t = new ProjectTable();
|
153 | t.modelo = sds; |
||
154 | 1222 | fernando | |
155 | 2572 | fernando | t.createAlias(); |
156 | |||
157 | 2542 | fernando | t.setName(name); |
158 | t.setCreationDate(DateFormat.getInstance().format(new Date())); |
||
159 | numTables++; |
||
160 | 1222 | fernando | |
161 | 2542 | fernando | return t;
|
162 | } |
||
163 | 1222 | fernando | |
164 | 2565 | fernando | private void createAlias() throws com.hardcode.gdbms.engine.data.driver.DriverException{ |
165 | mapping = new int[modelo.getFieldCount()]; |
||
166 | alias = new String[modelo.getFieldCount()]; |
||
167 | for (int i = 0; i < modelo.getFieldCount(); i++) { |
||
168 | mapping[i] = i; |
||
169 | alias[i] = modelo.getFieldName(i); |
||
170 | } |
||
171 | } |
||
172 | |||
173 | 2542 | fernando | /**
|
174 | * DOCUMENT ME!
|
||
175 | *
|
||
176 | * @param sds DOCUMENT ME!
|
||
177 | */
|
||
178 | public void setDataSource(SelectableDataSource sds) { |
||
179 | modelo = sds; |
||
180 | 1222 | fernando | |
181 | 2542 | fernando | setName(sds.getName()); |
182 | setCreationDate(DateFormat.getInstance().format(new Date())); |
||
183 | change.firePropertyChange("model", modelo, modelo);
|
||
184 | } |
||
185 | 2183 | fernando | |
186 | 2542 | fernando | /**
|
187 | * DOCUMENT ME!
|
||
188 | *
|
||
189 | * @param ds DOCUMENT ME!
|
||
190 | 2581 | fernando | * @throws com.hardcode.gdbms.engine.data.driver.DriverException
|
191 | 2542 | fernando | */
|
192 | 2581 | fernando | public void replaceDataSource(SelectableDataSource ds) throws com.hardcode.gdbms.engine.data.driver.DriverException { |
193 | if (original == null){ |
||
194 | original = modelo; |
||
195 | } |
||
196 | 2542 | fernando | modelo = ds; |
197 | 2605 | fernando | ds.setSelectionSupport(original.getSelectionSupport()); |
198 | 2581 | fernando | createAlias(); |
199 | 2629 | fjp | |
200 | // FJP:
|
||
201 | // Si la tabla proviene de un layer, cambiamos su recordset
|
||
202 | if (associatedTable != null) |
||
203 | { |
||
204 | if (associatedTable instanceof FLyrVect) |
||
205 | { |
||
206 | 2760 | fjp | try {
|
207 | ((FLyrVect) associatedTable).setRecordset(ds); |
||
208 | } catch (FieldNotFoundException e) {
|
||
209 | // TODO Auto-generated catch block
|
||
210 | e.printStackTrace(); |
||
211 | } catch (DriverException e) {
|
||
212 | // TODO Auto-generated catch block
|
||
213 | e.printStackTrace(); |
||
214 | } |
||
215 | 2672 | fjp | ((FLyrVect) associatedTable).setIsJoined(true);
|
216 | 2629 | fjp | } |
217 | } |
||
218 | |||
219 | 2542 | fernando | change.firePropertyChange("model", original, modelo);
|
220 | } |
||
221 | 2183 | fernando | |
222 | 2542 | fernando | /**
|
223 | * DOCUMENT ME!
|
||
224 | 2581 | fernando | * @throws com.hardcode.gdbms.engine.data.driver.DriverException
|
225 | 2542 | fernando | */
|
226 | 2581 | fernando | public void restoreDataSource() throws com.hardcode.gdbms.engine.data.driver.DriverException { |
227 | 2629 | fjp | // FJP:
|
228 | // Si la tabla proviene de un layer, cambiamos su recordset
|
||
229 | if (associatedTable != null) |
||
230 | { |
||
231 | if (associatedTable instanceof FLyrVect) |
||
232 | 2708 | fjp | { |
233 | // Miramos si la leyenda que est? usando es una
|
||
234 | // leyenda basada en un campo de los de la uni?n.
|
||
235 | 2725 | fjp | // Si lo es, no dejamos pegarle el cambiazo al recordset
|
236 | 2708 | fjp | FLyrVect lyr = ((FLyrVect) associatedTable); |
237 | if (lyr.getLegend() instanceof ClassifiedLegend) |
||
238 | { |
||
239 | ClassifiedLegend legend = (ClassifiedLegend) lyr.getLegend(); |
||
240 | VectorialLegend aux = (VectorialLegend) legend; |
||
241 | String fieldName = legend.getFieldName();
|
||
242 | int idField = original.getFieldIndexByName(fieldName);
|
||
243 | 2725 | fjp | int idLabelField = -2; |
244 | 2708 | fjp | if (aux.getLabelField() != null) |
245 | 2725 | fjp | { |
246 | 2708 | fjp | idLabelField = original.getFieldIndexByName(aux.getLabelField()); |
247 | 2725 | fjp | } |
248 | 2708 | fjp | if ((idField == -1) || (idLabelField == -1)) |
249 | { |
||
250 | // No se ha encontrado ese campo, o se est? etiquetando por ese campo
|
||
251 | 2725 | fjp | JOptionPane.showMessageDialog(null, |
252 | PluginServices.getText(this, "leyenda_campo_unido") |
||
253 | ); |
||
254 | 2708 | fjp | |
255 | 2725 | fjp | return;
|
256 | 2708 | fjp | } |
257 | } |
||
258 | |||
259 | 2760 | fjp | try {
|
260 | lyr.setRecordset(original); |
||
261 | } catch (FieldNotFoundException e) {
|
||
262 | // TODO Auto-generated catch block
|
||
263 | e.printStackTrace(); |
||
264 | } catch (DriverException e) {
|
||
265 | // TODO Auto-generated catch block
|
||
266 | e.printStackTrace(); |
||
267 | } |
||
268 | 2708 | fjp | lyr.setIsJoined(false);
|
269 | 2629 | fjp | } |
270 | } |
||
271 | 2708 | fjp | |
272 | 2629 | fjp | |
273 | 2708 | fjp | modelo = original; |
274 | original = null;
|
||
275 | createAlias(); |
||
276 | |||
277 | |||
278 | 2542 | fernando | change.firePropertyChange("model", original, modelo);
|
279 | } |
||
280 | 2183 | fernando | |
281 | 2542 | fernando | /**
|
282 | * DOCUMENT ME!
|
||
283 | *
|
||
284 | * @return DOCUMENT ME!
|
||
285 | 3183 | caballero | * @throws SaveException
|
286 | 2542 | fernando | *
|
287 | * @throws XMLException
|
||
288 | */
|
||
289 | 3183 | caballero | public XMLEntity getXMLEntity() throws SaveException { |
290 | 2542 | fernando | XMLEntity xml = super.getXMLEntity();
|
291 | 3183 | caballero | try {
|
292 | 2542 | fernando | //xml.putProperty("nameClass", this.getClass().getName());
|
293 | xml.putProperty("numTables", numTables);
|
||
294 | 2183 | fernando | |
295 | 2542 | fernando | if (getLinkTable() != null) { |
296 | xml.putProperty("linkTable", linkTable);
|
||
297 | xml.putProperty("field1", field1);
|
||
298 | xml.putProperty("field2", field2);
|
||
299 | } |
||
300 | 2183 | fernando | |
301 | 2542 | fernando | if (getOriginal() != null) { |
302 | xml.addChild(getOriginal().getXMLEntity()); |
||
303 | } |
||
304 | 2183 | fernando | |
305 | 2542 | fernando | xml.addChild(modelo.getXMLEntity()); |
306 | 1222 | fernando | |
307 | 2542 | fernando | Object di = LayerFactory.getDataSourceFactory().getDriverInfo(modelo.getName());
|
308 | 1222 | fernando | |
309 | 2542 | fernando | if (associatedTable != null) { |
310 | xml.putProperty("layerName", ((FLayer) associatedTable).getName());
|
||
311 | xml.putProperty("viewName",
|
||
312 | project.getView((FLayer) associatedTable)); |
||
313 | } |
||
314 | 2567 | fernando | |
315 | xml.putProperty("mapping", mapping);
|
||
316 | xml.putProperty("aliases", alias);
|
||
317 | 3183 | caballero | }catch (Exception e) { |
318 | throw new SaveException(e,this.getClass().getName()); |
||
319 | } |
||
320 | 2542 | fernando | return xml;
|
321 | } |
||
322 | 2183 | fernando | |
323 | 2542 | fernando | /**
|
324 | * DOCUMENT ME!
|
||
325 | *
|
||
326 | * @param xml DOCUMENT ME!
|
||
327 | * @param p DOCUMENT ME!
|
||
328 | *
|
||
329 | * @throws XMLException
|
||
330 | * @throws DriverException
|
||
331 | *
|
||
332 | * @see com.iver.cit.gvsig.project.ProjectElement#setXMLEntity(com.iver.utiles.XMLEntity)
|
||
333 | */
|
||
334 | public void setXMLEntity03(XMLEntity xml, Project p) |
||
335 | throws XMLException, DriverException {
|
||
336 | numTables = xml.getIntProperty("numTables");
|
||
337 | 2183 | fernando | |
338 | 2542 | fernando | if (xml.getStringProperty("type").equals("otherDriverFile")) { |
339 | LayerFactory.getDataSourceFactory().addFileDataSource(xml.getStringProperty( |
||
340 | "driverName"), xml.getStringProperty("gdbmsname"), |
||
341 | xml.getStringProperty("file"));
|
||
342 | 1222 | fernando | |
343 | 2542 | fernando | setSelectableDataSource03(xml); |
344 | } else if (xml.getStringProperty("type").equals("sameDriverFile")) { |
||
345 | String layerName = xml.getStringProperty("layerName"); |
||
346 | 2183 | fernando | |
347 | 2542 | fernando | ProjectView vista = project.getViewByName(xml.getStringProperty( |
348 | "viewName"));
|
||
349 | FLayer layer = vista.getMapContext().getLayers().getLayer(layerName); |
||
350 | 1222 | fernando | |
351 | 2542 | fernando | modelo = ((AlphanumericData) layer).getRecordset(); |
352 | associatedTable = (AlphanumericData) layer; |
||
353 | 1222 | fernando | |
354 | 2542 | fernando | LayerFactory.getDataSourceFactory().addDataSource((ObjectDriver) ((SingleLayer) layer).getSource() |
355 | .getDriver(), |
||
356 | xml.getStringProperty("gdbmsname"));
|
||
357 | } else if (xml.getStringProperty("type").equals("db")) { |
||
358 | LayerFactory.getDataSourceFactory().addDBDataSourceByTable(xml.getStringProperty( |
||
359 | "gdbmsname"), xml.getStringProperty("host"), |
||
360 | xml.getIntProperty("port"), xml.getStringProperty("user"), |
||
361 | xml.getStringProperty("password"),
|
||
362 | xml.getStringProperty("dbName"),
|
||
363 | xml.getStringProperty("tableName"),
|
||
364 | xml.getStringProperty("driverInfo"));
|
||
365 | 2183 | fernando | |
366 | 2542 | fernando | setSelectableDataSource03(xml); |
367 | } |
||
368 | 2183 | fernando | |
369 | 2542 | fernando | setName(xml.getStringProperty("name"));
|
370 | } |
||
371 | 2183 | fernando | |
372 | 2542 | fernando | /**
|
373 | * DOCUMENT ME!
|
||
374 | *
|
||
375 | * @param xml DOCUMENT ME!
|
||
376 | * @param p DOCUMENT ME!
|
||
377 | *
|
||
378 | * @throws XMLException
|
||
379 | * @throws DriverException
|
||
380 | 3183 | caballero | * @throws OpenException
|
381 | 2542 | fernando | *
|
382 | * @see com.iver.cit.gvsig.project.ProjectElement#setXMLEntity(com.iver.utiles.XMLEntity)
|
||
383 | */
|
||
384 | public void setXMLEntity(XMLEntity xml, Project p) |
||
385 | 3183 | caballero | throws XMLException, DriverException, OpenException {
|
386 | try{
|
||
387 | setName(xml.getStringProperty("name"));
|
||
388 | 2542 | fernando | numTables = xml.getIntProperty("numTables");
|
389 | 2183 | fernando | |
390 | 2542 | fernando | setSelectableDataSource(xml); |
391 | 1830 | fernando | |
392 | 2542 | fernando | /*
|
393 | if (xml.getStringProperty("type").equals("otherDriverFile")) {
|
||
394 | } else if (xml.getStringProperty("type").equals("sameDriverFile")) {
|
||
395 | String layerName = xml.getStringProperty("layerName");
|
||
396 | ProjectView vista = project.getViewByName(xml.getStringProperty(
|
||
397 | "viewName"));
|
||
398 | FLayer layer = vista.getMapContext().getLayers().getLayer(layerName);
|
||
399 | |||
400 | modelo = ((AlphanumericData) layer).getRecordset();
|
||
401 | associatedTable = (AlphanumericData) layer;
|
||
402 | } else if (xml.getStringProperty("type").equals("db")) {
|
||
403 | setSelectableDataSource(xml);
|
||
404 | }
|
||
405 | */
|
||
406 | setName(xml.getStringProperty("name"));
|
||
407 | 2183 | fernando | |
408 | 2542 | fernando | if (xml.contains("linkTable")) { |
409 | setLinkTable(xml.getStringProperty("linkTable"),
|
||
410 | xml.getStringProperty("field1"), xml.getStringProperty("field2")); |
||
411 | } |
||
412 | 2567 | fernando | |
413 | 4469 | jaume | if (xml.contains("mapping")) { |
414 | mapping = (int[]) xml.getIntArrayProperty("mapping"); |
||
415 | alias = (String[]) xml.getStringArrayProperty("aliases"); |
||
416 | } else {
|
||
417 | try {
|
||
418 | createAlias(); |
||
419 | } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
||
420 | throw new XMLException(e); |
||
421 | } |
||
422 | 2565 | fernando | } |
423 | 3183 | caballero | }catch (Exception e) { |
424 | 4469 | jaume | throw new OpenException(e,this.getClass().getName()); |
425 | } |
||
426 | 2542 | fernando | } |
427 | |||
428 | /**
|
||
429 | * DOCUMENT ME!
|
||
430 | *
|
||
431 | * @param xml DOCUMENT ME!
|
||
432 | *
|
||
433 | * @throws XMLException DOCUMENT ME!
|
||
434 | * @throws DriverException DOCUMENT ME!
|
||
435 | */
|
||
436 | private void setSelectableDataSource03(XMLEntity xml) |
||
437 | throws XMLException, DriverException {
|
||
438 | String layerName = null; |
||
439 | |||
440 | if (xml.contains("layerName")) { |
||
441 | layerName = xml.getStringProperty("layerName");
|
||
442 | } |
||
443 | |||
444 | if (layerName == null) { |
||
445 | DataSource dataSource;
|
||
446 | |||
447 | try {
|
||
448 | dataSource = LayerFactory.getDataSourceFactory() |
||
449 | .createRandomDataSource(xml.getStringProperty( |
||
450 | "gdbmsname"),
|
||
451 | 2667 | fernando | DataSourceFactory.AUTOMATIC_OPENING); |
452 | 2565 | fernando | |
453 | SelectableDataSource sds = new SelectableDataSource(dataSource);
|
||
454 | |||
455 | sds.setXMLEntity03(xml.getChild(0));
|
||
456 | |||
457 | setDataSource(sds); |
||
458 | 2542 | fernando | } catch (NoSuchTableException e) {
|
459 | 2183 | fernando | throw new XMLException(e); |
460 | 2542 | fernando | } catch (DriverLoadException e) {
|
461 | throw new XMLException(e); |
||
462 | } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
||
463 | throw new XMLException(e); |
||
464 | 2183 | fernando | } |
465 | |||
466 | 2542 | fernando | } else {
|
467 | ProjectView vista = project.getViewByName(xml.getStringProperty( |
||
468 | "viewName"));
|
||
469 | FLayer layer = vista.getMapContext().getLayers().getLayer(layerName); |
||
470 | 2183 | fernando | |
471 | 2542 | fernando | modelo = ((AlphanumericData) layer).getRecordset(); |
472 | associatedTable = (AlphanumericData) layer; |
||
473 | } |
||
474 | } |
||
475 | 2183 | fernando | |
476 | 2542 | fernando | /**
|
477 | * DOCUMENT ME!
|
||
478 | *
|
||
479 | * @param xml DOCUMENT ME!
|
||
480 | *
|
||
481 | * @throws XMLException DOCUMENT ME!
|
||
482 | * @throws DriverException DOCUMENT ME!
|
||
483 | */
|
||
484 | private void setSelectableDataSource(XMLEntity xml) |
||
485 | throws XMLException, DriverException {
|
||
486 | String layerName = null; |
||
487 | 2629 | fjp | boolean bNeedToReplace = false; |
488 | XMLEntity xmlAux = null;
|
||
489 | 2183 | fernando | |
490 | 2542 | fernando | try {
|
491 | SelectableDataSource sds; |
||
492 | 2183 | fernando | |
493 | 2542 | fernando | if (xml.contains("layerName")) { |
494 | layerName = xml.getStringProperty("layerName");
|
||
495 | 2183 | fernando | |
496 | 2542 | fernando | ProjectView vista = project.getViewByName(xml.getStringProperty( |
497 | "viewName"));
|
||
498 | 2611 | caballero | FLayer layer=getLayer(vista.getMapContext().getLayers(),layerName); |
499 | 2542 | fernando | sds = ((AlphanumericData) layer).getRecordset(); |
500 | } else {
|
||
501 | sds = SelectableDataSource.createSelectableDataSource(xml.getChild( |
||
502 | 0));
|
||
503 | } |
||
504 | 2183 | fernando | |
505 | 2542 | fernando | setDataSource(sds); |
506 | 2183 | fernando | |
507 | 2542 | fernando | if (xml.getNumChild() == 2) { |
508 | 2629 | fjp | bNeedToReplace = true;
|
509 | xmlAux = xml.getChild(1);
|
||
510 | 2542 | fernando | } |
511 | 4469 | jaume | |
512 | if (bNeedToReplace) {
|
||
513 | if (layerName != null) { |
||
514 | ProjectView vista = project.getViewByName(xml |
||
515 | .getStringProperty("viewName"));
|
||
516 | FLayer layer = getLayer(vista.getMapContext().getLayers(), |
||
517 | layerName); |
||
518 | |||
519 | // modelo = ((AlphanumericData) layer).getRecordset();
|
||
520 | associatedTable = (AlphanumericData) layer; |
||
521 | } |
||
522 | replaceDataSource(SelectableDataSource.createSelectableDataSource(xmlAux)); |
||
523 | } |
||
524 | 2542 | fernando | } catch (NoSuchTableException e) {
|
525 | throw new XMLException(e); |
||
526 | } catch (ParseException e) { |
||
527 | throw new XMLException(e); |
||
528 | } catch (DriverLoadException e) {
|
||
529 | throw new XMLException(e); |
||
530 | } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
||
531 | throw new XMLException(e); |
||
532 | } catch (SemanticException e) {
|
||
533 | throw new XMLException(e); |
||
534 | } catch (IOException e) { |
||
535 | throw new XMLException(e); |
||
536 | } |
||
537 | 1830 | fernando | |
538 | 2542 | fernando | if (layerName != null) { |
539 | ProjectView vista = project.getViewByName(xml.getStringProperty( |
||
540 | "viewName"));
|
||
541 | 2611 | caballero | FLayer layer=getLayer(vista.getMapContext().getLayers(),layerName); |
542 | 2183 | fernando | |
543 | 2542 | fernando | // modelo = ((AlphanumericData) layer).getRecordset();
|
544 | associatedTable = (AlphanumericData) layer; |
||
545 | 2629 | fjp | |
546 | if (bNeedToReplace)
|
||
547 | { |
||
548 | try {
|
||
549 | replaceDataSource(SelectableDataSource.createSelectableDataSource(xmlAux)); |
||
550 | } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
||
551 | // TODO Auto-generated catch block
|
||
552 | e.printStackTrace(); |
||
553 | } catch (NoSuchTableException e) {
|
||
554 | // TODO Auto-generated catch block
|
||
555 | e.printStackTrace(); |
||
556 | } catch (ParseException e) { |
||
557 | // TODO Auto-generated catch block
|
||
558 | e.printStackTrace(); |
||
559 | } catch (DriverLoadException e) {
|
||
560 | // TODO Auto-generated catch block
|
||
561 | e.printStackTrace(); |
||
562 | } catch (SemanticException e) {
|
||
563 | // TODO Auto-generated catch block
|
||
564 | e.printStackTrace(); |
||
565 | } catch (IOException e) { |
||
566 | // TODO Auto-generated catch block
|
||
567 | e.printStackTrace(); |
||
568 | } catch (XMLException e) {
|
||
569 | // TODO Auto-generated catch block
|
||
570 | e.printStackTrace(); |
||
571 | } |
||
572 | } |
||
573 | 2542 | fernando | } |
574 | } |
||
575 | 2611 | caballero | private FLayer getLayer(FLayers layers,String name){ |
576 | for (int i=0;i<layers.getLayersCount();i++){ |
||
577 | if (layers.getLayer(i) instanceof FLayers){ |
||
578 | return getLayer((FLayers)layers.getLayer(i),name);
|
||
579 | }else if (layers.getLayer(i).getName().equals(name)){ |
||
580 | return layers.getLayer(i);
|
||
581 | } |
||
582 | } |
||
583 | return null; |
||
584 | } |
||
585 | 2542 | fernando | /**
|
586 | * DOCUMENT ME!
|
||
587 | *
|
||
588 | * @return DOCUMENT ME!
|
||
589 | */
|
||
590 | public AlphanumericData getAssociatedTable() {
|
||
591 | return associatedTable;
|
||
592 | } |
||
593 | 1830 | fernando | |
594 | 2542 | fernando | /**
|
595 | * DOCUMENT ME!
|
||
596 | *
|
||
597 | * @param associatedTable DOCUMENT ME!
|
||
598 | */
|
||
599 | public void setAssociatedTable(AlphanumericData associatedTable) { |
||
600 | this.associatedTable = associatedTable;
|
||
601 | } |
||
602 | 2183 | fernando | |
603 | 2542 | fernando | /**
|
604 | * Obtiene la fuente de datos original de la tabla si se ha invocado
|
||
605 | * replaceDataSource. Si no se invoc? este m?todo o se invoc?
|
||
606 | * posteriormente restoreDataSource se devuelve null
|
||
607 | *
|
||
608 | * @return Returns the original.
|
||
609 | */
|
||
610 | public SelectableDataSource getOriginal() {
|
||
611 | return original;
|
||
612 | } |
||
613 | 2183 | fernando | |
614 | 2542 | fernando | /**
|
615 | * Devuelve el identificador de la tabla que contiene el link.
|
||
616 | *
|
||
617 | * @return identificador ?nico de la tabla.
|
||
618 | */
|
||
619 | public String getLinkTable() { |
||
620 | return linkTable;
|
||
621 | } |
||
622 | 2183 | fernando | |
623 | 2542 | fernando | /**
|
624 | * Devuelve el nombre del campo de la tabla a enlazar.
|
||
625 | *
|
||
626 | * @return Nombre del campo de la tabla a enlazar.
|
||
627 | */
|
||
628 | public String getField1() { |
||
629 | return field1;
|
||
630 | } |
||
631 | 2183 | fernando | |
632 | 2542 | fernando | /**
|
633 | * Devuelve el nombre del campo de la tabla enlazada.
|
||
634 | *
|
||
635 | * @return Nombre del campo de la tabla enlazada.
|
||
636 | */
|
||
637 | public String getField2() { |
||
638 | return field2;
|
||
639 | } |
||
640 | 2183 | fernando | |
641 | 2542 | fernando | /**
|
642 | * Inserta el identificador de la tabla, el campo de la primera tabla y el
|
||
643 | * campo de la segunda tabla.
|
||
644 | *
|
||
645 | * @param lt identificado de la tabla.
|
||
646 | * @param f1 nombre del campo de la primera tabla.
|
||
647 | * @param f2 nombre del campo de la segunda tabla.
|
||
648 | */
|
||
649 | public void setLinkTable(String lt, String f1, String f2) { |
||
650 | linkTable = lt; |
||
651 | field1 = f1; |
||
652 | field2 = f2; |
||
653 | } |
||
654 | |||
655 | /**
|
||
656 | * Borra el identificador de la tabla y elimina del array de listener los
|
||
657 | * listener que sean del tipo: LinkSelectionListenr
|
||
658 | */
|
||
659 | public void removeLinkTable() { |
||
660 | linkTable = null;
|
||
661 | getModelo().removeLinksSelectionListener(); |
||
662 | } |
||
663 | 2565 | fernando | public String[] getAliases() { |
664 | return alias;
|
||
665 | } |
||
666 | public void setAliases(String[] alias) { |
||
667 | this.alias = alias;
|
||
668 | } |
||
669 | public int[] getMapping() { |
||
670 | return mapping;
|
||
671 | } |
||
672 | public void setMapping(int[] mapping) { |
||
673 | this.mapping = mapping;
|
||
674 | } |
||
675 | 1222 | fernando | } |