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