svn-gvsig-desktop / tags / v10_RC2c / applications / appgvSIG / src / com / iver / cit / gvsig / project / ProjectTable.java @ 8745
History | View | Annotate | Download (23 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 | 1830 | fernando | import com.hardcode.gdbms.engine.instruction.SemanticException; |
55 | 1774 | fernando | import com.hardcode.gdbms.parser.ParseException; |
56 | 2708 | fjp | import com.iver.andami.PluginServices; |
57 | 6313 | fjp | import com.iver.andami.messages.NotificationManager; |
58 | 7422 | cesar | import com.iver.andami.ui.mdiManager.WindowInfo; |
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 | 6865 | jaume | |
212 | 4456 | fjp | } |
213 | 6865 | jaume | |
214 | 6336 | fjp | 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 | 5035 | caballero | xml.addChild(columns.getXMLEntity()); |
374 | 5137 | fjp | xml.putProperty("columns", true); |
375 | 7422 | cesar | |
376 | 4456 | fjp | return xml;
|
377 | } |
||
378 | 1222 | fernando | |
379 | 4456 | fjp | /**
|
380 | * DOCUMENT ME!
|
||
381 | 5254 | caballero | *
|
382 | 4456 | fjp | * @param xml
|
383 | * DOCUMENT ME!
|
||
384 | * @param p
|
||
385 | * DOCUMENT ME!
|
||
386 | 5254 | caballero | *
|
387 | 4456 | fjp | * @throws XMLException
|
388 | * @throws DriverException
|
||
389 | 5254 | caballero | *
|
390 | 4456 | fjp | * @see com.iver.cit.gvsig.project.ProjectElement#setXMLEntity(com.iver.utiles.XMLEntity)
|
391 | */
|
||
392 | public void setXMLEntity03(XMLEntity xml, Project p) throws XMLException, |
||
393 | DriverException { |
||
394 | numTables = xml.getIntProperty("numTables");
|
||
395 | 1222 | fernando | |
396 | 4456 | fjp | if (xml.getStringProperty("type").equals("otherDriverFile")) { |
397 | LayerFactory.getDataSourceFactory().addFileDataSource( |
||
398 | xml.getStringProperty("driverName"),
|
||
399 | xml.getStringProperty("gdbmsname"),
|
||
400 | xml.getStringProperty("file"));
|
||
401 | 3940 | caballero | |
402 | 4456 | fjp | setSelectableDataSource03(xml); |
403 | } else if (xml.getStringProperty("type").equals("sameDriverFile")) { |
||
404 | String layerName = xml.getStringProperty("layerName"); |
||
405 | 2183 | fernando | |
406 | 4456 | fjp | ProjectView vista = project.getViewByName(xml |
407 | .getStringProperty("viewName"));
|
||
408 | FLayer layer = vista.getMapContext().getLayers() |
||
409 | .getLayer(layerName); |
||
410 | 2183 | fernando | |
411 | 4456 | fjp | esModel = (VectorialEditableAdapter) ((FLyrVect) layer).getSource(); |
412 | associatedTable = (AlphanumericData) layer; |
||
413 | 1222 | fernando | |
414 | 4456 | fjp | LayerFactory.getDataSourceFactory().addDataSource( |
415 | (ObjectDriver) ((SingleLayer) layer).getSource() |
||
416 | .getDriver(), xml.getStringProperty("gdbmsname"));
|
||
417 | } else if (xml.getStringProperty("type").equals("db")) { |
||
418 | LayerFactory.getDataSourceFactory().addDBDataSourceByTable( |
||
419 | xml.getStringProperty("gdbmsname"),
|
||
420 | xml.getStringProperty("host"), xml.getIntProperty("port"), |
||
421 | xml.getStringProperty("user"),
|
||
422 | xml.getStringProperty("password"),
|
||
423 | xml.getStringProperty("dbName"),
|
||
424 | xml.getStringProperty("tableName"),
|
||
425 | xml.getStringProperty("driverInfo"));
|
||
426 | 2183 | fernando | |
427 | 4456 | fjp | setSelectableDataSource03(xml); |
428 | } |
||
429 | 1222 | fernando | |
430 | 4456 | fjp | setName(xml.getStringProperty("name"));
|
431 | } |
||
432 | 1222 | fernando | |
433 | 4456 | fjp | /**
|
434 | * DOCUMENT ME!
|
||
435 | 5254 | caballero | *
|
436 | 4456 | fjp | * @param xml
|
437 | * DOCUMENT ME!
|
||
438 | * @param p
|
||
439 | * DOCUMENT ME!
|
||
440 | 5254 | caballero | *
|
441 | 4456 | fjp | * @throws XMLException
|
442 | * @throws DriverException
|
||
443 | * @throws OpenException
|
||
444 | 5254 | caballero | *
|
445 | 4456 | fjp | * @see com.iver.cit.gvsig.project.ProjectElement#setXMLEntity(com.iver.utiles.XMLEntity)
|
446 | */
|
||
447 | public void setXMLEntity(XMLEntity xml, Project p) throws XMLException, |
||
448 | DriverException, OpenException { |
||
449 | try {
|
||
450 | setName(xml.getStringProperty("name"));
|
||
451 | numTables = xml.getIntProperty("numTables");
|
||
452 | 2183 | fernando | |
453 | 4456 | fjp | setSelectableDataSource(xml); |
454 | 2183 | fernando | |
455 | 4456 | fjp | /*
|
456 | * if (xml.getStringProperty("type").equals("otherDriverFile")) { }
|
||
457 | * else if (xml.getStringProperty("type").equals("sameDriverFile")) {
|
||
458 | * String layerName = xml.getStringProperty("layerName");
|
||
459 | * ProjectView vista = project.getViewByName(xml.getStringProperty(
|
||
460 | * "viewName")); FLayer layer =
|
||
461 | * vista.getMapContext().getLayers().getLayer(layerName);
|
||
462 | 5254 | caballero | *
|
463 | 4456 | fjp | * modelo = ((AlphanumericData) layer).getRecordset();
|
464 | * associatedTable = (AlphanumericData) layer; } else if
|
||
465 | * (xml.getStringProperty("type").equals("db")) {
|
||
466 | * setSelectableDataSource(xml); }
|
||
467 | */
|
||
468 | setName(xml.getStringProperty("name"));
|
||
469 | 2183 | fernando | |
470 | 4456 | fjp | if (xml.contains("linkTable")) { |
471 | setLinkTable(xml.getStringProperty("linkTable"), xml
|
||
472 | .getStringProperty("field1"), xml
|
||
473 | .getStringProperty("field2"));
|
||
474 | } |
||
475 | 2183 | fernando | |
476 | 4456 | fjp | if (xml.contains("mapping")) { |
477 | mapping = (int[]) xml.getIntArrayProperty("mapping"); |
||
478 | alias = (String[]) xml.getStringArrayProperty("aliases"); |
||
479 | 6313 | fjp | // we check if all fields are real there (may be some external program has changed them.
|
480 | // If we detect any change, we discard all mapping and aliases.
|
||
481 | 6336 | fjp | if (mapping.length != getModelo().getRecordset().getFieldCount())
|
482 | 6313 | fjp | { |
483 | createAlias(); |
||
484 | 6336 | fjp | // columns.clear();
|
485 | // for (int i = 0; i < esModel.getRecordset().getFieldCount(); i++) {
|
||
486 | // addColumn(new Column());
|
||
487 | // }
|
||
488 | 6313 | fjp | return;
|
489 | |||
490 | } |
||
491 | 6865 | jaume | |
492 | 4456 | fjp | } else {
|
493 | try {
|
||
494 | createAlias(); |
||
495 | } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
||
496 | throw new XMLException(e); |
||
497 | } |
||
498 | } |
||
499 | } catch (Exception e) { |
||
500 | throw new OpenException(e, this.getClass().getName()); |
||
501 | } |
||
502 | 6865 | jaume | |
503 | 5152 | fjp | if (xml.contains("columns")) { |
504 | 6356 | fjp | columns.clear(); |
505 | 5152 | fjp | columns = Columns |
506 | 6865 | jaume | .createColumns(xml.getChild(xml.getChildrenCount() - 1));
|
507 | 5137 | fjp | } |
508 | 4456 | fjp | } |
509 | 1830 | fernando | |
510 | 4456 | fjp | /**
|
511 | * DOCUMENT ME!
|
||
512 | 5254 | caballero | *
|
513 | 4456 | fjp | * @param xml
|
514 | * DOCUMENT ME!
|
||
515 | 5254 | caballero | *
|
516 | 4456 | fjp | * @throws XMLException
|
517 | * DOCUMENT ME!
|
||
518 | * @throws DriverException
|
||
519 | * DOCUMENT ME!
|
||
520 | */
|
||
521 | private void setSelectableDataSource03(XMLEntity xml) throws XMLException, |
||
522 | DriverException { |
||
523 | String layerName = null; |
||
524 | 3940 | caballero | |
525 | 4456 | fjp | if (xml.contains("layerName")) { |
526 | layerName = xml.getStringProperty("layerName");
|
||
527 | } |
||
528 | 2183 | fernando | |
529 | 4456 | fjp | if (layerName == null) { |
530 | DataSource dataSource;
|
||
531 | 2567 | fernando | |
532 | 4456 | fjp | try {
|
533 | dataSource = LayerFactory.getDataSourceFactory() |
||
534 | .createRandomDataSource( |
||
535 | xml.getStringProperty("gdbmsname"),
|
||
536 | DataSourceFactory.AUTOMATIC_OPENING); |
||
537 | 2542 | fernando | |
538 | 4456 | fjp | SelectableDataSource sds = new SelectableDataSource(dataSource);
|
539 | 2542 | fernando | |
540 | 4456 | fjp | sds.setXMLEntity03(xml.getChild(0));
|
541 | EditableAdapter auxea = new EditableAdapter();
|
||
542 | auxea.setOriginalDataSource(sds); |
||
543 | setDataSource(auxea); |
||
544 | } catch (NoSuchTableException e) {
|
||
545 | throw new XMLException(e); |
||
546 | } catch (DriverLoadException e) {
|
||
547 | throw new XMLException(e); |
||
548 | } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
||
549 | throw new XMLException(e); |
||
550 | } |
||
551 | 2542 | fernando | |
552 | 4456 | fjp | } else {
|
553 | ProjectView vista = project.getViewByName(xml |
||
554 | .getStringProperty("viewName"));
|
||
555 | FLayer layer = vista.getMapContext().getLayers() |
||
556 | .getLayer(layerName); |
||
557 | 2542 | fernando | |
558 | 4456 | fjp | esModel = (VectorialEditableAdapter) ((FLyrVect) layer).getSource(); |
559 | associatedTable = (AlphanumericData) layer; |
||
560 | } |
||
561 | } |
||
562 | 2565 | fernando | |
563 | 4456 | fjp | /**
|
564 | * DOCUMENT ME!
|
||
565 | 5254 | caballero | *
|
566 | 4456 | fjp | * @param xml
|
567 | * DOCUMENT ME!
|
||
568 | 5254 | caballero | *
|
569 | 4456 | fjp | * @throws XMLException
|
570 | * DOCUMENT ME!
|
||
571 | * @throws DriverException
|
||
572 | * DOCUMENT ME!
|
||
573 | */
|
||
574 | private void setSelectableDataSource(XMLEntity xml) throws XMLException, |
||
575 | DriverException { |
||
576 | String layerName = null; |
||
577 | boolean bNeedToReplace = false; |
||
578 | XMLEntity xmlAux = null;
|
||
579 | 2565 | fernando | |
580 | 4456 | fjp | try {
|
581 | EditableAdapter es; |
||
582 | 2183 | fernando | |
583 | 4456 | fjp | if (xml.contains("layerName")) { |
584 | layerName = xml.getStringProperty("layerName");
|
||
585 | 2183 | fernando | |
586 | 4456 | fjp | ProjectView vista = project.getViewByName(xml |
587 | .getStringProperty("viewName"));
|
||
588 | FLayer layer = getLayer(vista.getMapContext().getLayers(), |
||
589 | layerName); |
||
590 | EditableAdapter ea = new EditableAdapter();
|
||
591 | SelectableDataSource sds = ((FLyrVect) layer).getRecordset(); |
||
592 | // sds.setSelectionSupport(((FLyrVect)
|
||
593 | // layer).getSelectionSupport());
|
||
594 | ea.setOriginalDataSource(sds); |
||
595 | 6610 | jmvivo | associatedTable = (AlphanumericData) layer; |
596 | 2183 | fernando | |
597 | 4456 | fjp | es = ea; |
598 | } else {
|
||
599 | es = new EditableAdapter();
|
||
600 | es.setOriginalDataSource(SelectableDataSource |
||
601 | .createSelectableDataSource(xml.getChild(0)));
|
||
602 | } |
||
603 | 2183 | fernando | |
604 | 4456 | fjp | setDataSource(es); |
605 | 2183 | fernando | |
606 | 6865 | jaume | if (xml.getChildrenCount() == 2 && !(xml.contains("columns")) |
607 | || (xml.contains("columns") && (xml.getChildrenCount() == 3))) { |
||
608 | 4456 | fjp | bNeedToReplace = true;
|
609 | xmlAux = xml.getChild(1);
|
||
610 | es = new EditableAdapter();
|
||
611 | // es.setRecordSet(SelectableDataSource.createSelectableDataSource(xmlAux));
|
||
612 | 2183 | fernando | |
613 | 4456 | fjp | // replaceDataSource(SelectableDataSource.createSelectableDataSource(xml.getChild(1)));
|
614 | } |
||
615 | 3960 | caballero | |
616 | 4456 | fjp | if (bNeedToReplace) {
|
617 | if (layerName != null) { |
||
618 | ProjectView vista = project.getViewByName(xml |
||
619 | .getStringProperty("viewName"));
|
||
620 | FLayer layer = getLayer(vista.getMapContext().getLayers(), |
||
621 | layerName); |
||
622 | 2183 | fernando | |
623 | 4456 | fjp | // modelo = ((AlphanumericData) layer).getRecordset();
|
624 | associatedTable = (AlphanumericData) layer; |
||
625 | } |
||
626 | 2183 | fernando | |
627 | 4456 | fjp | EditableAdapter auxea = new EditableAdapter();
|
628 | auxea.setOriginalDataSource(SelectableDataSource |
||
629 | .createSelectableDataSource(xmlAux)); |
||
630 | replaceDataSource(auxea); |
||
631 | } |
||
632 | } catch (DriverLoadException e) {
|
||
633 | 5035 | caballero | throw new DriverException(e); |
634 | 4456 | fjp | } catch (NoSuchTableException e) {
|
635 | 5035 | caballero | throw new DriverException(e); |
636 | 4456 | fjp | } catch (ParseException e) { |
637 | 5035 | caballero | throw new DriverException(e); |
638 | 4456 | fjp | } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
639 | 5035 | caballero | throw new DriverException(e); |
640 | 4456 | fjp | } catch (SemanticException e) {
|
641 | 5035 | caballero | throw new DriverException(e); |
642 | 4456 | fjp | } catch (IOException e) { |
643 | 5035 | caballero | throw new DriverException(e); |
644 | 4456 | fjp | } catch (XMLException e) {
|
645 | 5035 | caballero | throw new DriverException(e); |
646 | 4456 | fjp | } |
647 | } |
||
648 | 1830 | fernando | |
649 | 4456 | fjp | private FLayer getLayer(FLayers layers, String name) { |
650 | for (int i = 0; i < layers.getLayersCount(); i++) { |
||
651 | if (layers.getLayer(i) instanceof FLayers) { |
||
652 | return getLayer((FLayers) layers.getLayer(i), name);
|
||
653 | } else if (layers.getLayer(i).getName().equals(name)) { |
||
654 | return layers.getLayer(i);
|
||
655 | } |
||
656 | } |
||
657 | return null; |
||
658 | } |
||
659 | 2183 | fernando | |
660 | 4456 | fjp | /**
|
661 | * DOCUMENT ME!
|
||
662 | 5254 | caballero | *
|
663 | 4456 | fjp | * @return DOCUMENT ME!
|
664 | */
|
||
665 | public AlphanumericData getAssociatedTable() {
|
||
666 | return associatedTable;
|
||
667 | } |
||
668 | 3940 | caballero | |
669 | 4456 | fjp | /**
|
670 | * DOCUMENT ME!
|
||
671 | 5254 | caballero | *
|
672 | 4456 | fjp | * @param associatedTable
|
673 | * DOCUMENT ME!
|
||
674 | */
|
||
675 | public void setAssociatedTable(AlphanumericData associatedTable) { |
||
676 | this.associatedTable = associatedTable;
|
||
677 | } |
||
678 | 1830 | fernando | |
679 | 4456 | fjp | /**
|
680 | * Obtiene la fuente de datos original de la tabla si se ha invocado
|
||
681 | * replaceDataSource. Si no se invoc? este m?todo o se invoc? posteriormente
|
||
682 | * restoreDataSource se devuelve null
|
||
683 | 5254 | caballero | *
|
684 | 4456 | fjp | * @return Returns the original.
|
685 | */
|
||
686 | public IEditableSource getOriginal() {
|
||
687 | return original;
|
||
688 | } |
||
689 | 2183 | fernando | |
690 | 4456 | fjp | /**
|
691 | * Devuelve el identificador de la tabla que contiene el link.
|
||
692 | 5254 | caballero | *
|
693 | 4456 | fjp | * @return identificador ?nico de la tabla.
|
694 | */
|
||
695 | public String getLinkTable() { |
||
696 | return linkTable;
|
||
697 | 3940 | caballero | } |
698 | 2183 | fernando | |
699 | 4456 | fjp | /**
|
700 | * Devuelve el nombre del campo de la tabla a enlazar.
|
||
701 | 5254 | caballero | *
|
702 | 4456 | fjp | * @return Nombre del campo de la tabla a enlazar.
|
703 | */
|
||
704 | public String getField1() { |
||
705 | return field1;
|
||
706 | } |
||
707 | 2183 | fernando | |
708 | 4456 | fjp | /**
|
709 | * Devuelve el nombre del campo de la tabla enlazada.
|
||
710 | 5254 | caballero | *
|
711 | 4456 | fjp | * @return Nombre del campo de la tabla enlazada.
|
712 | */
|
||
713 | public String getField2() { |
||
714 | return field2;
|
||
715 | } |
||
716 | 2183 | fernando | |
717 | 4456 | fjp | /**
|
718 | * Inserta el identificador de la tabla, el campo de la primera tabla y el
|
||
719 | * campo de la segunda tabla.
|
||
720 | 5254 | caballero | *
|
721 | 4456 | fjp | * @param lt
|
722 | * identificado de la tabla.
|
||
723 | * @param f1
|
||
724 | * nombre del campo de la primera tabla.
|
||
725 | * @param f2
|
||
726 | * nombre del campo de la segunda tabla.
|
||
727 | */
|
||
728 | public void setLinkTable(String lt, String f1, String f2) { |
||
729 | linkTable = lt; |
||
730 | field1 = f1; |
||
731 | field2 = f2; |
||
732 | } |
||
733 | 2183 | fernando | |
734 | 4456 | fjp | /**
|
735 | * Borra el identificador de la tabla y elimina del array de listener los
|
||
736 | * listener que sean del tipo: LinkSelectionListenr
|
||
737 | */
|
||
738 | public void removeLinkTable() { |
||
739 | linkTable = null;
|
||
740 | try {
|
||
741 | ((SelectableDataSource) getModelo().getRecordset()) |
||
742 | .removeLinksSelectionListener(); |
||
743 | 3940 | caballero | } catch (DriverLoadException e) {
|
744 | e.printStackTrace(); |
||
745 | } |
||
746 | 4456 | fjp | } |
747 | |||
748 | public String[] getAliases() { |
||
749 | return alias;
|
||
750 | } |
||
751 | |||
752 | public void setAliases(String[] alias) { |
||
753 | this.alias = alias;
|
||
754 | } |
||
755 | |||
756 | public int[] getMapping() { |
||
757 | return mapping;
|
||
758 | } |
||
759 | |||
760 | public void setMapping(int[] mapping) { |
||
761 | this.mapping = mapping;
|
||
762 | } |
||
763 | |||
764 | public void setModel(IEditableSource ies) { |
||
765 | esModel = ies; |
||
766 | 6336 | fjp | try {
|
767 | createAlias(); |
||
768 | } catch (DriverLoadException e) {
|
||
769 | e.printStackTrace(); |
||
770 | NotificationManager.addError(e); |
||
771 | } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
||
772 | e.printStackTrace(); |
||
773 | NotificationManager.addError(e); |
||
774 | } |
||
775 | 4456 | fjp | } |
776 | 5137 | fjp | |
777 | public Column getColumn(int i) { |
||
778 | 6336 | fjp | // if (i==0){
|
779 | // Column column=new Column();
|
||
780 | // column.setWidth(45);
|
||
781 | // return column;
|
||
782 | // }
|
||
783 | // i--;
|
||
784 | 6256 | caballero | return (Column) columns.get(mapping[i]);
|
785 | 4706 | caballero | } |
786 | 5137 | fjp | |
787 | public void addColumn(Column column) { |
||
788 | 4706 | caballero | columns.add(column); |
789 | } |
||
790 | |||
791 | public int getColumnCount() { |
||
792 | 6336 | fjp | return columns.size();
|
793 | 4706 | caballero | } |
794 | 6888 | jaume | |
795 | // public int computeSignature() {
|
||
796 | // int result = 17;
|
||
797 | //
|
||
798 | // Class clazz = getClass();
|
||
799 | // Field[] fields = clazz.getDeclaredFields();
|
||
800 | // for (int i = 0; i < fields.length; i++) {
|
||
801 | // try {
|
||
802 | // String type = fields[i].getType().getName();
|
||
803 | // if (type.equals("boolean")) {
|
||
804 | // result += 37 + ((fields[i].getBoolean(this)) ? 1 : 0);
|
||
805 | // } else if (type.equals("java.lang.String")) {
|
||
806 | // Object v = fields[i].get(this);
|
||
807 | // if (v == null) {
|
||
808 | // result += 37;
|
||
809 | // continue;
|
||
810 | // }
|
||
811 | // char[] chars = ((String) v).toCharArray();
|
||
812 | // for (int j = 0; j < chars.length; j++) {
|
||
813 | // result += 37 + (int) chars[i];
|
||
814 | // }
|
||
815 | // } else if (type.equals("byte")) {
|
||
816 | // result += 37 + (int) fields[i].getByte(this);
|
||
817 | // } else if (type.equals("char")) {
|
||
818 | // result += 37 + (int) fields[i].getChar(this);
|
||
819 | // } else if (type.equals("short")) {
|
||
820 | // result += 37 + (int) fields[i].getShort(this);
|
||
821 | // } else if (type.equals("int")) {
|
||
822 | // result += 37 + fields[i].getInt(this);
|
||
823 | // } else if (type.equals("long")) {
|
||
824 | // long f = fields[i].getLong(this) ;
|
||
825 | // result += 37 + (f ^ (f >>> 32));
|
||
826 | // } else if (type.equals("float")) {
|
||
827 | // result += 37 + Float.floatToIntBits(fields[i].getFloat(this));
|
||
828 | // } else if (type.equals("double")) {
|
||
829 | // long f = Double.doubleToLongBits(fields[i].getDouble(this));
|
||
830 | // result += 37 + (f ^ (f >>> 32));
|
||
831 | // } else {
|
||
832 | // Object obj = fields[i].get(this);
|
||
833 | // result += 37 + ((obj != null)? obj.hashCode() : 0);
|
||
834 | // }
|
||
835 | // } catch (Exception e) { e.printStackTrace(); }
|
||
836 | //
|
||
837 | // }
|
||
838 | // return result;
|
||
839 | // }
|
||
840 | 1222 | fernando | } |