Revision 4456 trunk/applications/appgvSIG/src/com/iver/cit/gvsig/project/ProjectTable.java

View differences:

ProjectTable.java
56 56
import com.iver.andami.PluginServices;
57 57
import com.iver.cit.gvsig.fmap.DriverException;
58 58
import com.iver.cit.gvsig.fmap.edition.EditableAdapter;
59
import com.iver.cit.gvsig.fmap.edition.EditionException;
59 60
import com.iver.cit.gvsig.fmap.edition.IEditableSource;
60 61
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter;
61 62
import com.iver.cit.gvsig.fmap.layers.FLayer;
......
63 64
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
64 65
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
65 66
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
66
import com.iver.cit.gvsig.fmap.layers.VectorialAdapter;
67 67
import com.iver.cit.gvsig.fmap.layers.XMLException;
68 68
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData;
69 69
import com.iver.cit.gvsig.fmap.layers.layerOperations.SingleLayer;
......
73 73
import com.iver.cit.gvsig.gui.project.SaveException;
74 74
import com.iver.utiles.XMLEntity;
75 75

  
76

  
77 76
/**
78 77
 * Tabla del proyecto
79
 *
78
 * 
80 79
 * @author Fernando Gonz?lez Cort?s
81 80
 */
82 81
public class ProjectTable extends ProjectElement {
83
    private static int numTables = 0;
84
    private IEditableSource esModel;
85
    private IEditableSource original;
86
    private String linkTable;
87
    private String field1;
88
    private String field2;
82
	private static int numTables = 0;
89 83

  
90
    /* No es necesaria para operar, s?lo para guardar el proyecto */
91
    private AlphanumericData associatedTable;
84
	private IEditableSource esModel;
92 85

  
86
	private IEditableSource original;
87

  
88
	private String linkTable;
89

  
90
	private String field1;
91

  
92
	private String field2;
93

  
94
	/* No es necesaria para operar, s?lo para guardar el proyecto */
95
	private AlphanumericData associatedTable;
96

  
93 97
	private int[] mapping;
98

  
94 99
	private String[] alias;
95 100

  
96
    /**
97
     * Establece a true el bit index-?simo del bitmap de campos visibles. Los
98
     * campos cuyos bits est?n a true se considerar?n visibles y viceversa
99
     *
100
     * @param index indice del bit que se quiere establecer a true
101
     */
102
    public void set(int index) {
103
        //TODO implementar bien
104
        //        modelo.set(index);
101
	/**
102
	 * Establece a true el bit index-?simo del bitmap de campos visibles. Los
103
	 * campos cuyos bits est?n a true se considerar?n visibles y viceversa
104
	 * 
105
	 * @param index
106
	 *            indice del bit que se quiere establecer a true
107
	 */
108
	public void set(int index) {
109
		// TODO implementar bien
110
		// modelo.set(index);
105 111

  
106
        change.firePropertyChange("visibles", true, true);
107
    }
112
		change.firePropertyChange("visibles", true, true);
113
	}
108 114

  
109
    /**
110
     * Obtiene el valor del bit index-?simo del bitmap de campos visibles
111
     *
112
     * @param index indice del bit que se quiere obtener
113
     *
114
     * @return devuelve true si el campo index-?simo es visible y false en caso
115
     *         contrario
116
     */
117
    public boolean get(int index) {
118
        //TODO implementar bien
119
        //        return modelo.get(index);
120
        return false;
121
    }
115
	/**
116
	 * Obtiene el valor del bit index-?simo del bitmap de campos visibles
117
	 * 
118
	 * @param index
119
	 *            indice del bit que se quiere obtener
120
	 * 
121
	 * @return devuelve true si el campo index-?simo es visible y false en caso
122
	 *         contrario
123
	 */
124
	public boolean get(int index) {
125
		// TODO implementar bien
126
		// return modelo.get(index);
127
		return false;
128
	}
122 129

  
123
    /**
124
     * Obtiene el modelo de la Tabla. Es decir, una clase con capacidad para
125
     * leer la informaci?n de la tabla
126
     *
127
     * @return
128
     */
129
    public IEditableSource getModelo() {
130
        return esModel;
131
    }
130
	/**
131
	 * Obtiene el modelo de la Tabla. Es decir, una clase con capacidad para
132
	 * leer la informaci?n de la tabla
133
	 * 
134
	 * @return
135
	 */
136
	public IEditableSource getModelo() {
137
		return esModel;
138
	}
132 139

  
133
    /**
134
     * Establece el valor del bit index-?simo al valor  'value'
135
     *
136
     * @param bitIndex indice del bit que se quiere tocar
137
     * @param value valor que se quiere establecer en el bit indicado
138
     */
139
    public void set(int bitIndex, boolean value) {
140
        //TODO implementar bien
141
        //        modelo.set(bitIndex, value);
142
        change.firePropertyChange("visibles", value, value);
143
    }
140
	/**
141
	 * Establece el valor del bit index-?simo al valor 'value'
142
	 * 
143
	 * @param bitIndex
144
	 *            indice del bit que se quiere tocar
145
	 * @param value
146
	 *            valor que se quiere establecer en el bit indicado
147
	 */
148
	public void set(int bitIndex, boolean value) {
149
		// TODO implementar bien
150
		// modelo.set(bitIndex, value);
151
		change.firePropertyChange("visibles", value, value);
152
	}
144 153

  
145
    /**
146
     * DOCUMENT ME!
147
     *
148
     * @param name DOCUMENT ME!
149
     * @param sds DOCUMENT ME!
150
     *
151
     * @return
152
     * @throws com.hardcode.gdbms.engine.data.driver.DriverException
153
     */
154
    public static ProjectTable createTable(String name, IEditableSource es) throws com.hardcode.gdbms.engine.data.driver.DriverException {
155
        ProjectTable t = new ProjectTable();
156
        t.esModel = es;
154
	/**
155
	 * DOCUMENT ME!
156
	 * 
157
	 * @param name
158
	 *            DOCUMENT ME!
159
	 * @param sds
160
	 *            DOCUMENT ME!
161
	 * 
162
	 * @return
163
	 * @throws com.hardcode.gdbms.engine.data.driver.DriverException
164
	 */
165
	public static ProjectTable createTable(String name, IEditableSource es)
166
			throws com.hardcode.gdbms.engine.data.driver.DriverException {
167
		ProjectTable t = new ProjectTable();
168
		t.esModel = es;
157 169

  
158
        try {
170
		try {
159 171
			t.createAlias();
160 172
		} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
161 173
			// TODO Auto-generated catch block
......
165 177
			e.printStackTrace();
166 178
		}
167 179

  
168
        t.setName(name);
169
        t.setCreationDate(DateFormat.getInstance().format(new Date()));
170
        numTables++;
180
		t.setName(name);
181
		t.setCreationDate(DateFormat.getInstance().format(new Date()));
182
		numTables++;
171 183

  
172
        return t;
173
    }
184
		return t;
185
	}
174 186

  
175
    private void createAlias() throws com.hardcode.gdbms.engine.data.driver.DriverException, DriverLoadException {
176
        mapping = new int[esModel.getRecordset().getFieldCount()];
187
	private void createAlias()
188
			throws com.hardcode.gdbms.engine.data.driver.DriverException,
189
			DriverLoadException {
190
		mapping = new int[esModel.getRecordset().getFieldCount()];
177 191
		alias = new String[esModel.getRecordset().getFieldCount()];
178 192
		for (int i = 0; i < esModel.getRecordset().getFieldCount(); i++) {
179
            mapping[i] = i;
180
            alias[i] = esModel.getRecordset().getFieldName(i);
181
        }
182
    }
193
			mapping[i] = i;
194
			alias[i] = esModel.getRecordset().getFieldName(i);
195
		}
196
	}
183 197

  
184
    /**
185
     * DOCUMENT ME!
186
     *
187
     * @param sds DOCUMENT ME!
188
     * @throws DriverLoadException
189
     */
190
    public void setDataSource(IEditableSource es) throws DriverLoadException {
191
        esModel = es;
198
	/**
199
	 * DOCUMENT ME!
200
	 * 
201
	 * @param sds
202
	 *            DOCUMENT ME!
203
	 * @throws DriverLoadException
204
	 */
205
	public void setDataSource(IEditableSource es) throws DriverLoadException {
206
		esModel = es;
192 207

  
193
        setName(esModel.getRecordset().getName());
194
        setCreationDate(DateFormat.getInstance().format(new Date()));
195
        change.firePropertyChange("model", esModel, esModel);
196
    }
208
		setName(esModel.getRecordset().getName());
209
		setCreationDate(DateFormat.getInstance().format(new Date()));
210
		change.firePropertyChange("model", esModel, esModel);
211
	}
197 212

  
198
    /**
199
     * DOCUMENT ME!
200
     *
201
     * @param ds DOCUMENT ME!
202
     * @throws com.hardcode.gdbms.engine.data.driver.DriverException
203
     */
204
    public void replaceDataSource(IEditableSource es) throws com.hardcode.gdbms.engine.data.driver.DriverException {
205
        if (original == null){
206
            original = esModel;
207
        }
208
        esModel = es;
209
        try {
210
        	((SelectableDataSource)es.getRecordset()).setSelectionSupport(((SelectableDataSource)original.getRecordset()).getSelectionSupport());
213
	/**
214
	 * DOCUMENT ME!
215
	 * 
216
	 * @param ds
217
	 *            DOCUMENT ME!
218
	 * @throws com.hardcode.gdbms.engine.data.driver.DriverException
219
	 */
220
	public void replaceDataSource(IEditableSource es)
221
			throws com.hardcode.gdbms.engine.data.driver.DriverException {
222
		if (original == null) {
223
			original = esModel;
224
		}
225
		esModel = es;
226
		try {
227
			((SelectableDataSource) es.getRecordset())
228
					.setSelectionSupport(((SelectableDataSource) original
229
							.getRecordset()).getSelectionSupport());
211 230

  
212
        createAlias();
213
        } catch (DriverLoadException e1) {
231
			createAlias();
232
		} catch (DriverLoadException e1) {
214 233
			// TODO Auto-generated catch block
215 234
			e1.printStackTrace();
216 235
		}
217
        // FJP:
218
        // Si la tabla proviene de un layer, cambiamos su recordset
219
        if (associatedTable != null)
220
        {
221
            if (associatedTable instanceof FLyrVect)
222
            {
223
                try {
224
					// ((EditableAdapter)((FLyrVect) associatedTable).getSource()).setRecordSet((SelectableDataSource)es.getRecordset());
225
                	FLyrVect lyrVect = (FLyrVect) associatedTable;
226
                	lyrVect.setRecordset(es.getRecordset());
227
                    ((FLyrVect) associatedTable).setIsJoined(true);
236
		// FJP:
237
		// Si la tabla proviene de un layer, cambiamos su recordset
238
		if (associatedTable != null) {
239
			if (associatedTable instanceof FLyrVect) {
240
				try {
241
					// ((EditableAdapter)((FLyrVect)
242
					// associatedTable).getSource()).setRecordSet((SelectableDataSource)es.getRecordset());
243
					FLyrVect lyrVect = (FLyrVect) associatedTable;
244
					lyrVect.setRecordset(es.getRecordset());
245
					((FLyrVect) associatedTable).setIsJoined(true);
228 246
				} catch (DriverLoadException e) {
229 247
					// TODO Auto-generated catch block
230 248
					e.printStackTrace();
231 249
				}
232
            }
233
        }
250
			}
251
		}
234 252

  
235
        change.firePropertyChange("model", original, esModel);
236
    }
253
		change.firePropertyChange("model", original, esModel);
254
	}
237 255

  
238
    /**
239
     * DOCUMENT ME!
240
     * @throws com.hardcode.gdbms.engine.data.driver.DriverException
241
     * @throws DriverLoadException
242
     */
243
    public void restoreDataSource() throws com.hardcode.gdbms.engine.data.driver.DriverException, DriverLoadException {
244
        // FJP:
245
        // Si la tabla proviene de un layer, cambiamos su recordset
246
        if (associatedTable != null)
247
        {
248
            if (associatedTable instanceof FLyrVect)
249
            {
250
                // Miramos si la leyenda que est? usando es una
251
                // leyenda basada en un campo de los de la uni?n.
252
                // Si lo es, no dejamos pegarle el cambiazo al recordset
253
                FLyrVect lyr = ((FLyrVect) associatedTable);
254
                if (lyr.getLegend() instanceof ClassifiedLegend)
255
                {
256
                    ClassifiedLegend legend = (ClassifiedLegend) lyr.getLegend();
257
                    VectorialLegend aux = (VectorialLegend) legend;
258
                    String fieldName = legend.getFieldName();
259
                    int idField = original.getRecordset().getFieldIndexByName(fieldName);
260
                    int idLabelField = -2;
261
                    if (aux.getLabelField() != null)
262
                    {
263
                        idLabelField = original.getRecordset().getFieldIndexByName(aux.getLabelField());
264
                    }
265
                    if ((idField == -1) || (idLabelField == -1))
266
                    {
267
                        // No se ha encontrado ese campo, o se est? etiquetando por ese campo
268
                        JOptionPane.showMessageDialog(null,
269
                                PluginServices.getText(this, "leyenda_campo_unido")
270
                                );
256
	/**
257
	 * DOCUMENT ME!
258
	 * 
259
	 * @throws com.hardcode.gdbms.engine.data.driver.DriverException
260
	 * @throws DriverLoadException
261
	 */
262
	public void restoreDataSource()
263
			throws com.hardcode.gdbms.engine.data.driver.DriverException,
264
			DriverLoadException {
265
		// FJP:
266
		// Si la tabla proviene de un layer, cambiamos su recordset
267
		if (associatedTable != null) {
268
			if (associatedTable instanceof FLyrVect) {
269
				// Miramos si la leyenda que est? usando es una
270
				// leyenda basada en un campo de los de la uni?n.
271
				// Si lo es, no dejamos pegarle el cambiazo al recordset
272
				FLyrVect lyr = ((FLyrVect) associatedTable);
273
				if (lyr.getLegend() instanceof ClassifiedLegend) {
274
					ClassifiedLegend legend = (ClassifiedLegend) lyr
275
							.getLegend();
276
					VectorialLegend aux = (VectorialLegend) legend;
277
					String fieldName = legend.getFieldName();
278
					int idField = original.getRecordset().getFieldIndexByName(
279
							fieldName);
280
					int idLabelField = -2;
281
					if (aux.getLabelField() != null) {
282
						idLabelField = original.getRecordset()
283
								.getFieldIndexByName(aux.getLabelField());
284
					}
285
					if ((idField == -1) || (idLabelField == -1)) {
286
						// No se ha encontrado ese campo, o se est? etiquetando
287
						// por ese campo
288
						JOptionPane.showMessageDialog(null, PluginServices
289
								.getText(this, "leyenda_campo_unido"));
271 290

  
272
                        return;
273
                    }
274
                }
291
						return;
292
					}
293
				}
275 294

  
295
				lyr
296
						.setRecordset((SelectableDataSource) original
297
								.getRecordset());
276 298

  
277
                lyr.setRecordset((SelectableDataSource)original.getRecordset());
299
				lyr.setIsJoined(false);
300
			}
301
		}
278 302

  
279
                lyr.setIsJoined(false);
280
            }
281
        }
303
		esModel = original;
304
		original = null;
305
		createAlias();
282 306

  
307
		change.firePropertyChange("model", original, esModel);
308
	}
283 309

  
284
        esModel = original;
285
        original = null;
286
        createAlias();
310
	/**
311
	 * DOCUMENT ME!
312
	 * 
313
	 * @return DOCUMENT ME!
314
	 * @throws SaveException
315
	 * 
316
	 * @throws XMLException
317
	 */
318
	public XMLEntity getXMLEntity() throws SaveException {
319
		XMLEntity xml = super.getXMLEntity();
320
		try {
321
			// xml.putProperty("nameClass", this.getClass().getName());
322
			xml.putProperty("numTables", numTables);
287 323

  
324
			if (getLinkTable() != null) {
325
				xml.putProperty("linkTable", linkTable);
326
				xml.putProperty("field1", field1);
327
				xml.putProperty("field2", field2);
328
			}
288 329

  
289
        change.firePropertyChange("model", original, esModel);
290
    }
330
			if (getOriginal() != null) {
331
				xml.addChild(getOriginal().getRecordset().getXMLEntity());
332
			}
291 333

  
292
    /**
293
     * DOCUMENT ME!
294
     *
295
     * @return DOCUMENT ME!
296
     * @throws SaveException
297
     *
298
     * @throws XMLException
299
     */
300
    public XMLEntity getXMLEntity() throws SaveException {
301
        XMLEntity xml = super.getXMLEntity();
302
        try {
303
        //xml.putProperty("nameClass", this.getClass().getName());
304
        xml.putProperty("numTables", numTables);
334
			xml.addChild(esModel.getRecordset().getXMLEntity());
305 335

  
306
        if (getLinkTable() != null) {
307
            xml.putProperty("linkTable", linkTable);
308
            xml.putProperty("field1", field1);
309
            xml.putProperty("field2", field2);
310
        }
336
			Object di = LayerFactory.getDataSourceFactory().getDriverInfo(
337
					esModel.getRecordset().getName());
311 338

  
312
        if (getOriginal() != null) {
313
            xml.addChild(getOriginal().getRecordset().getXMLEntity());
314
        }
339
			if (associatedTable != null) {
340
				xml.putProperty("layerName", ((FLayer) associatedTable)
341
						.getName());
342
				xml.putProperty("viewName", project
343
						.getView((FLayer) associatedTable));
344
			}
315 345

  
316
        xml.addChild(esModel.getRecordset().getXMLEntity());
346
			xml.putProperty("mapping", mapping);
347
			xml.putProperty("aliases", alias);
348
		} catch (Exception e) {
349
			throw new SaveException(e, this.getClass().getName());
350
		}
351
		return xml;
352
	}
317 353

  
318
        Object di = LayerFactory.getDataSourceFactory().getDriverInfo(esModel.getRecordset().getName());
354
	/**
355
	 * DOCUMENT ME!
356
	 * 
357
	 * @param xml
358
	 *            DOCUMENT ME!
359
	 * @param p
360
	 *            DOCUMENT ME!
361
	 * 
362
	 * @throws XMLException
363
	 * @throws DriverException
364
	 * 
365
	 * @see com.iver.cit.gvsig.project.ProjectElement#setXMLEntity(com.iver.utiles.XMLEntity)
366
	 */
367
	public void setXMLEntity03(XMLEntity xml, Project p) throws XMLException,
368
			DriverException {
369
		numTables = xml.getIntProperty("numTables");
319 370

  
320
        if (associatedTable != null) {
321
            xml.putProperty("layerName", ((FLayer) associatedTable).getName());
322
            xml.putProperty("viewName",
323
                project.getView((FLayer) associatedTable));
324
        }
371
		if (xml.getStringProperty("type").equals("otherDriverFile")) {
372
			LayerFactory.getDataSourceFactory().addFileDataSource(
373
					xml.getStringProperty("driverName"),
374
					xml.getStringProperty("gdbmsname"),
375
					xml.getStringProperty("file"));
325 376

  
326
        xml.putProperty("mapping", mapping);
327
        xml.putProperty("aliases", alias);
328
        }catch (Exception e) {
329
			throw new SaveException(e,this.getClass().getName());
330
		}
331
        return xml;
332
    }
377
			setSelectableDataSource03(xml);
378
		} else if (xml.getStringProperty("type").equals("sameDriverFile")) {
379
			String layerName = xml.getStringProperty("layerName");
333 380

  
334
    /**
335
     * DOCUMENT ME!
336
     *
337
     * @param xml DOCUMENT ME!
338
     * @param p DOCUMENT ME!
339
     *
340
     * @throws XMLException
341
     * @throws DriverException
342
     *
343
     * @see com.iver.cit.gvsig.project.ProjectElement#setXMLEntity(com.iver.utiles.XMLEntity)
344
     */
345
    public void setXMLEntity03(XMLEntity xml, Project p)
346
        throws XMLException, DriverException {
347
        numTables = xml.getIntProperty("numTables");
381
			ProjectView vista = project.getViewByName(xml
382
					.getStringProperty("viewName"));
383
			FLayer layer = vista.getMapContext().getLayers()
384
					.getLayer(layerName);
348 385

  
349
        if (xml.getStringProperty("type").equals("otherDriverFile")) {
350
            LayerFactory.getDataSourceFactory().addFileDataSource(xml.getStringProperty(
351
                    "driverName"), xml.getStringProperty("gdbmsname"),
352
                xml.getStringProperty("file"));
386
			esModel = (VectorialEditableAdapter) ((FLyrVect) layer).getSource();
387
			associatedTable = (AlphanumericData) layer;
353 388

  
354
            setSelectableDataSource03(xml);
355
        } else if (xml.getStringProperty("type").equals("sameDriverFile")) {
356
            String layerName = xml.getStringProperty("layerName");
389
			LayerFactory.getDataSourceFactory().addDataSource(
390
					(ObjectDriver) ((SingleLayer) layer).getSource()
391
							.getDriver(), xml.getStringProperty("gdbmsname"));
392
		} else if (xml.getStringProperty("type").equals("db")) {
393
			LayerFactory.getDataSourceFactory().addDBDataSourceByTable(
394
					xml.getStringProperty("gdbmsname"),
395
					xml.getStringProperty("host"), xml.getIntProperty("port"),
396
					xml.getStringProperty("user"),
397
					xml.getStringProperty("password"),
398
					xml.getStringProperty("dbName"),
399
					xml.getStringProperty("tableName"),
400
					xml.getStringProperty("driverInfo"));
357 401

  
358
            ProjectView vista = project.getViewByName(xml.getStringProperty(
359
                        "viewName"));
360
            FLayer layer = vista.getMapContext().getLayers().getLayer(layerName);
402
			setSelectableDataSource03(xml);
403
		}
361 404

  
362
            esModel = (VectorialEditableAdapter)((FLyrVect) layer).getSource();
363
            associatedTable = (AlphanumericData) layer;
405
		setName(xml.getStringProperty("name"));
406
	}
364 407

  
365
            LayerFactory.getDataSourceFactory().addDataSource((ObjectDriver) ((SingleLayer) layer).getSource()
366
                                                                              .getDriver(),
367
                xml.getStringProperty("gdbmsname"));
368
        } else if (xml.getStringProperty("type").equals("db")) {
369
            LayerFactory.getDataSourceFactory().addDBDataSourceByTable(xml.getStringProperty(
370
                    "gdbmsname"), xml.getStringProperty("host"),
371
                xml.getIntProperty("port"), xml.getStringProperty("user"),
372
                xml.getStringProperty("password"),
373
                xml.getStringProperty("dbName"),
374
                xml.getStringProperty("tableName"),
375
                xml.getStringProperty("driverInfo"));
408
	/**
409
	 * DOCUMENT ME!
410
	 * 
411
	 * @param xml
412
	 *            DOCUMENT ME!
413
	 * @param p
414
	 *            DOCUMENT ME!
415
	 * 
416
	 * @throws XMLException
417
	 * @throws DriverException
418
	 * @throws OpenException
419
	 * 
420
	 * @see com.iver.cit.gvsig.project.ProjectElement#setXMLEntity(com.iver.utiles.XMLEntity)
421
	 */
422
	public void setXMLEntity(XMLEntity xml, Project p) throws XMLException,
423
			DriverException, OpenException {
424
		try {
425
			setName(xml.getStringProperty("name"));
426
			numTables = xml.getIntProperty("numTables");
376 427

  
377
            setSelectableDataSource03(xml);
378
        }
428
			setSelectableDataSource(xml);
379 429

  
380
        setName(xml.getStringProperty("name"));
381
    }
430
			/*
431
			 * if (xml.getStringProperty("type").equals("otherDriverFile")) { }
432
			 * else if (xml.getStringProperty("type").equals("sameDriverFile")) {
433
			 * String layerName = xml.getStringProperty("layerName");
434
			 * ProjectView vista = project.getViewByName(xml.getStringProperty(
435
			 * "viewName")); FLayer layer =
436
			 * vista.getMapContext().getLayers().getLayer(layerName);
437
			 * 
438
			 * modelo = ((AlphanumericData) layer).getRecordset();
439
			 * associatedTable = (AlphanumericData) layer; } else if
440
			 * (xml.getStringProperty("type").equals("db")) {
441
			 * setSelectableDataSource(xml); }
442
			 */
443
			setName(xml.getStringProperty("name"));
382 444

  
383
    /**
384
     * DOCUMENT ME!
385
     *
386
     * @param xml DOCUMENT ME!
387
     * @param p DOCUMENT ME!
388
     *
389
     * @throws XMLException
390
     * @throws DriverException
391
     * @throws OpenException
392
     *
393
     * @see com.iver.cit.gvsig.project.ProjectElement#setXMLEntity(com.iver.utiles.XMLEntity)
394
     */
395
    public void setXMLEntity(XMLEntity xml, Project p)
396
        throws XMLException, DriverException, OpenException {
397
        try{
398
    	setName(xml.getStringProperty("name"));
399
        numTables = xml.getIntProperty("numTables");
445
			if (xml.contains("linkTable")) {
446
				setLinkTable(xml.getStringProperty("linkTable"), xml
447
						.getStringProperty("field1"), xml
448
						.getStringProperty("field2"));
449
			}
400 450

  
401
        setSelectableDataSource(xml);
451
			if (xml.contains("mapping")) {
452
				mapping = (int[]) xml.getIntArrayProperty("mapping");
453
				alias = (String[]) xml.getStringArrayProperty("aliases");
454
			} else {
455
				try {
456
					createAlias();
457
				} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
458
					throw new XMLException(e);
459
				}
460
			}
461
		} catch (Exception e) {
462
			throw new OpenException(e, this.getClass().getName());
463
		}
464
	}
402 465

  
403
        /*
404
           if (xml.getStringProperty("type").equals("otherDriverFile")) {
405
           } else if (xml.getStringProperty("type").equals("sameDriverFile")) {
406
                   String layerName = xml.getStringProperty("layerName");
407
                   ProjectView vista = project.getViewByName(xml.getStringProperty(
408
                   "viewName"));
409
                   FLayer layer = vista.getMapContext().getLayers().getLayer(layerName);
466
	/**
467
	 * DOCUMENT ME!
468
	 * 
469
	 * @param xml
470
	 *            DOCUMENT ME!
471
	 * 
472
	 * @throws XMLException
473
	 *             DOCUMENT ME!
474
	 * @throws DriverException
475
	 *             DOCUMENT ME!
476
	 */
477
	private void setSelectableDataSource03(XMLEntity xml) throws XMLException,
478
			DriverException {
479
		String layerName = null;
410 480

  
411
                   modelo = ((AlphanumericData) layer).getRecordset();
412
                   associatedTable = (AlphanumericData) layer;
413
           } else if (xml.getStringProperty("type").equals("db")) {
414
                   setSelectableDataSource(xml);
415
           }
416
         */
417
        setName(xml.getStringProperty("name"));
481
		if (xml.contains("layerName")) {
482
			layerName = xml.getStringProperty("layerName");
483
		}
418 484

  
419
        if (xml.contains("linkTable")) {
420
            setLinkTable(xml.getStringProperty("linkTable"),
421
                xml.getStringProperty("field1"), xml.getStringProperty("field2"));
422
        }
485
		if (layerName == null) {
486
			DataSource dataSource;
423 487

  
424
        if (xml.contains("mapping")){
425
            mapping = (int[]) xml.getIntArrayProperty("mapping");
426
            alias = (String[]) xml.getStringArrayProperty("aliases");
427
        }else{
428
            try {
429
                createAlias();
430
            } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
431
                throw new XMLException(e);
432
            }
433
        }
434
        }catch (Exception e) {
435
			throw new OpenException(e,this.getClass().getName());
436
		}
437
    }
488
			try {
489
				dataSource = LayerFactory.getDataSourceFactory()
490
						.createRandomDataSource(
491
								xml.getStringProperty("gdbmsname"),
492
								DataSourceFactory.AUTOMATIC_OPENING);
438 493

  
439
    /**
440
     * DOCUMENT ME!
441
     *
442
     * @param xml DOCUMENT ME!
443
     *
444
     * @throws XMLException DOCUMENT ME!
445
     * @throws DriverException DOCUMENT ME!
446
     */
447
    private void setSelectableDataSource03(XMLEntity xml)
448
        throws XMLException, DriverException {
449
        String layerName = null;
494
				SelectableDataSource sds = new SelectableDataSource(dataSource);
450 495

  
451
        if (xml.contains("layerName")) {
452
            layerName = xml.getStringProperty("layerName");
453
        }
496
				sds.setXMLEntity03(xml.getChild(0));
497
				EditableAdapter auxea = new EditableAdapter();
498
				auxea.setOriginalDataSource(sds);
499
				setDataSource(auxea);
500
			} catch (NoSuchTableException e) {
501
				throw new XMLException(e);
502
			} catch (DriverLoadException e) {
503
				throw new XMLException(e);
504
			} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
505
				throw new XMLException(e);
506
			}
454 507

  
455
        if (layerName == null) {
456
            DataSource dataSource;
508
		} else {
509
			ProjectView vista = project.getViewByName(xml
510
					.getStringProperty("viewName"));
511
			FLayer layer = vista.getMapContext().getLayers()
512
					.getLayer(layerName);
457 513

  
458
            try {
459
                dataSource = LayerFactory.getDataSourceFactory()
460
                                         .createRandomDataSource(xml.getStringProperty(
461
                            "gdbmsname"),
462
                        DataSourceFactory.AUTOMATIC_OPENING);
514
			esModel = (VectorialEditableAdapter) ((FLyrVect) layer).getSource();
515
			associatedTable = (AlphanumericData) layer;
516
		}
517
	}
463 518

  
464
                SelectableDataSource sds = new SelectableDataSource(dataSource);
519
	/**
520
	 * DOCUMENT ME!
521
	 * 
522
	 * @param xml
523
	 *            DOCUMENT ME!
524
	 * 
525
	 * @throws XMLException
526
	 *             DOCUMENT ME!
527
	 * @throws DriverException
528
	 *             DOCUMENT ME!
529
	 */
530
	private void setSelectableDataSource(XMLEntity xml) throws XMLException,
531
			DriverException {
532
		String layerName = null;
533
		boolean bNeedToReplace = false;
534
		XMLEntity xmlAux = null;
465 535

  
466
                sds.setXMLEntity03(xml.getChild(0));
467
                EditableAdapter auxea=new EditableAdapter();
468
            	auxea.setOriginalDataSource(sds);
469
                setDataSource(auxea);
470
            } catch (NoSuchTableException e) {
471
                throw new XMLException(e);
472
            } catch (DriverLoadException e) {
473
                throw new XMLException(e);
474
            } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
475
                throw new XMLException(e);
476
            }
536
		try {
537
			EditableAdapter es;
477 538

  
478
        } else {
479
            ProjectView vista = project.getViewByName(xml.getStringProperty(
480
                        "viewName"));
481
            FLayer layer = vista.getMapContext().getLayers().getLayer(layerName);
539
			if (xml.contains("layerName")) {
540
				layerName = xml.getStringProperty("layerName");
482 541

  
483
            esModel = (VectorialEditableAdapter)((FLyrVect) layer).getSource();
484
            associatedTable = (AlphanumericData) layer;
485
        }
486
    }
542
				ProjectView vista = project.getViewByName(xml
543
						.getStringProperty("viewName"));
544
				FLayer layer = getLayer(vista.getMapContext().getLayers(),
545
						layerName);
546
				EditableAdapter ea = new EditableAdapter();
547
				SelectableDataSource sds = ((FLyrVect) layer).getRecordset();
548
				// sds.setSelectionSupport(((FLyrVect)
549
				// layer).getSelectionSupport());
550
				ea.setOriginalDataSource(sds);
487 551

  
488
    /**
489
     * DOCUMENT ME!
490
     *
491
     * @param xml DOCUMENT ME!
492
     *
493
     * @throws XMLException DOCUMENT ME!
494
     * @throws DriverException DOCUMENT ME!
495
     */
496
    private void setSelectableDataSource(XMLEntity xml)
497
        throws XMLException, DriverException {
498
        String layerName = null;
499
        boolean bNeedToReplace = false;
500
        XMLEntity xmlAux = null;
552
				es = ea;
553
			} else {
554
				es = new EditableAdapter();
555
				es.setOriginalDataSource(SelectableDataSource
556
						.createSelectableDataSource(xml.getChild(0)));
557
			}
501 558

  
502
        try {
503
            EditableAdapter es;
559
			setDataSource(es);
504 560

  
505
            if (xml.contains("layerName")) {
506
                layerName = xml.getStringProperty("layerName");
561
			if (xml.getNumChild() == 2) {
562
				bNeedToReplace = true;
563
				xmlAux = xml.getChild(1);
564
				es = new EditableAdapter();
565
				// es.setRecordSet(SelectableDataSource.createSelectableDataSource(xmlAux));
507 566

  
508
                ProjectView vista = project.getViewByName(xml.getStringProperty(
509
                            "viewName"));
510
               	FLayer layer=getLayer(vista.getMapContext().getLayers(),layerName);
511
               	EditableAdapter ea=new EditableAdapter();
512
               	SelectableDataSource sds=((FLyrVect) layer).getRecordset();
513
               	//sds.setSelectionSupport(((FLyrVect) layer).getSelectionSupport());
514
               	ea.setOriginalDataSource(sds);
567
				// replaceDataSource(SelectableDataSource.createSelectableDataSource(xml.getChild(1)));
568
			}
515 569

  
516
               	es = ea;
517
            } else {
518
                es= new EditableAdapter();
519
                es.setOriginalDataSource(SelectableDataSource.createSelectableDataSource(xml.getChild(
520
                            0)));
521
            }
570
			if (bNeedToReplace) {
571
				if (layerName != null) {
572
					ProjectView vista = project.getViewByName(xml
573
							.getStringProperty("viewName"));
574
					FLayer layer = getLayer(vista.getMapContext().getLayers(),
575
							layerName);
522 576

  
523
            setDataSource(es);
577
					// modelo = ((AlphanumericData) layer).getRecordset();
578
					associatedTable = (AlphanumericData) layer;
579
				}
524 580

  
525
            if (xml.getNumChild() == 2) {
526
                bNeedToReplace = true;
527
                xmlAux = xml.getChild(1);
528
                // replaceDataSource(SelectableDataSource.createSelectableDataSource(xml.getChild(1)));
529
            }
530
        } catch (NoSuchTableException e) {
531
            throw new XMLException(e);
532
        } catch (ParseException e) {
533
            throw new XMLException(e);
534
        } catch (DriverLoadException e) {
535
            throw new XMLException(e);
536
        } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
537
            throw new XMLException(e);
538
        } catch (SemanticException e) {
539
            throw new XMLException(e);
540
        } catch (IOException e) {
541
            throw new XMLException(e);
542
        }
581
				EditableAdapter auxea = new EditableAdapter();
582
				auxea.setOriginalDataSource(SelectableDataSource
583
						.createSelectableDataSource(xmlAux));
584
				replaceDataSource(auxea);
585
			}
586
		} catch (DriverLoadException e) {
587
			// TODO Auto-generated catch block
588
			e.printStackTrace();
589
		} catch (NoSuchTableException e) {
590
			// TODO Auto-generated catch block
591
			e.printStackTrace();
592
		} catch (ParseException e) {
593
			// TODO Auto-generated catch block
594
			e.printStackTrace();
595
		} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
596
			// TODO Auto-generated catch block
597
			e.printStackTrace();
598
		} catch (SemanticException e) {
599
			// TODO Auto-generated catch block
600
			e.printStackTrace();
601
		} catch (IOException e) {
602
			// TODO Auto-generated catch block
603
			e.printStackTrace();
604
		} catch (XMLException e) {
605
			// TODO Auto-generated catch block
606
			e.printStackTrace();
607
		}
608
	}
543 609

  
544
        if (layerName != null) {
545
            ProjectView vista = project.getViewByName(xml.getStringProperty(
546
                        "viewName"));
547
        	FLayer layer=getLayer(vista.getMapContext().getLayers(),layerName);
610
	private FLayer getLayer(FLayers layers, String name) {
611
		for (int i = 0; i < layers.getLayersCount(); i++) {
612
			if (layers.getLayer(i) instanceof FLayers) {
613
				return getLayer((FLayers) layers.getLayer(i), name);
614
			} else if (layers.getLayer(i).getName().equals(name)) {
615
				return layers.getLayer(i);
616
			}
617
		}
618
		return null;
619
	}
548 620

  
549
            //			modelo = ((AlphanumericData) layer).getRecordset();
550
            associatedTable = (AlphanumericData) layer;
621
	/**
622
	 * DOCUMENT ME!
623
	 * 
624
	 * @return DOCUMENT ME!
625
	 */
626
	public AlphanumericData getAssociatedTable() {
627
		return associatedTable;
628
	}
551 629

  
552
            if (bNeedToReplace)
553
            {
554
                try {
555
                	EditableAdapter auxea=new EditableAdapter();
556
                	auxea.setOriginalDataSource(SelectableDataSource.createSelectableDataSource(xmlAux));
557
                    replaceDataSource(auxea);
558
                } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
559
                    // TODO Auto-generated catch block
560
                    e.printStackTrace();
561
                } catch (NoSuchTableException e) {
562
                    // TODO Auto-generated catch block
563
                    e.printStackTrace();
564
                } catch (ParseException e) {
565
                    // TODO Auto-generated catch block
566
                    e.printStackTrace();
567
                } catch (DriverLoadException e) {
568
                    // TODO Auto-generated catch block
569
                    e.printStackTrace();
570
                } catch (SemanticException e) {
571
                    // TODO Auto-generated catch block
572
                    e.printStackTrace();
573
                } catch (IOException e) {
574
                    // TODO Auto-generated catch block
575
                    e.printStackTrace();
576
                } catch (XMLException e) {
577
                    // TODO Auto-generated catch block
578
                    e.printStackTrace();
579
                }
580
            }
581
        }
582
    }
583
    private FLayer getLayer(FLayers layers,String name){
584
    	for (int i=0;i<layers.getLayersCount();i++){
585
    		if (layers.getLayer(i) instanceof FLayers){
586
    			return getLayer((FLayers)layers.getLayer(i),name);
587
    		}else if (layers.getLayer(i).getName().equals(name)){
588
    			return layers.getLayer(i);
589
    		}
590
    	}
591
    return null;
592
    }
593
    /**
594
     * DOCUMENT ME!
595
     *
596
     * @return DOCUMENT ME!
597
     */
598
    public AlphanumericData getAssociatedTable() {
599
        return associatedTable;
600
    }
630
	/**
631
	 * DOCUMENT ME!
632
	 * 
633
	 * @param associatedTable
634
	 *            DOCUMENT ME!
635
	 */
636
	public void setAssociatedTable(AlphanumericData associatedTable) {
637
		this.associatedTable = associatedTable;
638
	}
601 639

  
602
    /**
603
     * DOCUMENT ME!
604
     *
605
     * @param associatedTable DOCUMENT ME!
606
     */
607
    public void setAssociatedTable(AlphanumericData associatedTable) {
608
        this.associatedTable = associatedTable;
609
    }
640
	/**
641
	 * Obtiene la fuente de datos original de la tabla si se ha invocado
642
	 * replaceDataSource. Si no se invoc? este m?todo o se invoc? posteriormente
643
	 * restoreDataSource se devuelve null
644
	 * 
645
	 * @return Returns the original.
646
	 */
647
	public IEditableSource getOriginal() {
648
		return original;
649
	}
610 650

  
611
    /**
612
     * Obtiene la fuente de datos original de la tabla si se ha invocado
613
     * replaceDataSource. Si no se invoc? este m?todo o se invoc?
614
     * posteriormente restoreDataSource se devuelve null
615
     *
616
     * @return Returns the original.
617
     */
618
    public IEditableSource getOriginal() {
619
       	return original;
651
	/**
652
	 * Devuelve el identificador de la tabla que contiene el link.
653
	 * 
654
	 * @return identificador ?nico de la tabla.
655
	 */
656
	public String getLinkTable() {
657
		return linkTable;
620 658
	}
621 659

  
622
    /**
623
     * Devuelve el identificador de la tabla que contiene el link.
624
     *
625
     * @return identificador ?nico de la tabla.
626
     */
627
    public String getLinkTable() {
628
        return linkTable;
629
    }
660
	/**
661
	 * Devuelve el nombre del campo de la tabla a enlazar.
662
	 * 
663
	 * @return Nombre del campo de la tabla a enlazar.
664
	 */
665
	public String getField1() {
666
		return field1;
667
	}
630 668

  
631
    /**
632
     * Devuelve el nombre del campo de la tabla a enlazar.
633
     *
634
     * @return Nombre del campo de la tabla a enlazar.
635
     */
636
    public String getField1() {
637
        return field1;
638
    }
669
	/**
670
	 * Devuelve el nombre del campo de la tabla enlazada.
671
	 * 
672
	 * @return Nombre del campo de la tabla enlazada.
673
	 */
674
	public String getField2() {
675
		return field2;
676
	}
639 677

  
640
    /**
641
     * Devuelve el nombre del campo de la tabla enlazada.
642
     *
643
     * @return Nombre del campo de la tabla enlazada.
644
     */
645
    public String getField2() {
646
        return field2;
647
    }
678
	/**
679
	 * Inserta el identificador de la tabla, el campo de la primera tabla y el
680
	 * campo de la segunda tabla.
681
	 * 
682
	 * @param lt
683
	 *            identificado de la tabla.
684
	 * @param f1
685
	 *            nombre del campo de la primera tabla.
686
	 * @param f2
687
	 *            nombre del campo de la segunda tabla.
688
	 */
689
	public void setLinkTable(String lt, String f1, String f2) {
690
		linkTable = lt;
691
		field1 = f1;
692
		field2 = f2;
693
	}
648 694

  
649
    /**
650
     * Inserta el identificador de la tabla, el campo de la primera tabla y el
651
     * campo de la segunda tabla.
652
     *
653
     * @param lt identificado de la tabla.
654
     * @param f1 nombre del campo de la primera tabla.
655
     * @param f2 nombre del campo de la segunda tabla.
656
     */
657
    public void setLinkTable(String lt, String f1, String f2) {
658
        linkTable = lt;
659
        field1 = f1;
660
        field2 = f2;
661
    }
662

  
663
    /**
664
     * Borra el identificador de la tabla y elimina del array de listener los
665
     * listener que sean del tipo: LinkSelectionListenr
666
     */
667
    public void removeLinkTable() {
668
        linkTable = null;
669
        try {
670
        	((SelectableDataSource)getModelo().getRecordset()).removeLinksSelectionListener();
695
	/**
696
	 * Borra el identificador de la tabla y elimina del array de listener los
697
	 * listener que sean del tipo: LinkSelectionListenr
698
	 */
699
	public void removeLinkTable() {
700
		linkTable = null;
701
		try {
702
			((SelectableDataSource) getModelo().getRecordset())
703
					.removeLinksSelectionListener();
671 704
		} catch (DriverLoadException e) {
672 705
			// TODO Auto-generated catch block
673 706
			e.printStackTrace();
674 707
		}
675
    }
676
    public String[] getAliases() {
677
        return alias;
678
    }
679
    public void setAliases(String[] alias) {
680
        this.alias = alias;
681
    }
682
    public int[] getMapping() {
683
        return mapping;
684
    }
685
    public void setMapping(int[] mapping) {
686
        this.mapping = mapping;
687
    }
688
    public void setModel(IEditableSource ies){
689
    	esModel=ies;
690
    }
708
	}
709

  
710
	public String[] getAliases() {
711
		return alias;
712
	}
713

  
714
	public void setAliases(String[] alias) {
715
		this.alias = alias;
716
	}
717

  
718
	public int[] getMapping() {
719
		return mapping;
720
	}
721

  
722
	public void setMapping(int[] mapping) {
723
		this.mapping = mapping;
724
	}
725

  
726
	public void setModel(IEditableSource ies) {
727
		esModel = ies;
728
	}
691 729
}

Also available in: Unified diff