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