Revision 31226

View differences:

trunk/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/table/ProjectTable.java
40 40
 */
41 41
package com.iver.cit.gvsig.project.documents.table;
42 42

  
43
import java.io.FileNotFoundException;
43 44
import java.text.DateFormat;
44 45
import java.util.ArrayList;
45 46
import java.util.Date;
46 47

  
48
import javax.swing.JOptionPane;
49

  
47 50
import com.hardcode.driverManager.DriverLoadException;
48 51
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
49 52
import com.hardcode.gdbms.engine.data.DataSource;
......
51 54
import com.hardcode.gdbms.engine.data.NoSuchTableException;
52 55
import com.hardcode.gdbms.engine.data.driver.DriverException;
53 56
import com.hardcode.gdbms.engine.data.driver.ObjectDriver;
57
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException;
54 58
import com.iver.andami.PluginServices;
55 59
import com.iver.andami.messages.NotificationManager;
56 60
import com.iver.andami.ui.mdiManager.IWindow;
61
import com.iver.cit.gvsig.exceptions.layers.LegendLayerException;
57 62
import com.iver.cit.gvsig.fmap.edition.EditableAdapter;
58 63
import com.iver.cit.gvsig.fmap.edition.IEditableSource;
59 64
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter;
......
67 72
import com.iver.cit.gvsig.fmap.layers.layerOperations.SingleLayer;
68 73
import com.iver.cit.gvsig.fmap.rendering.IClassifiedVectorLegend;
69 74
import com.iver.cit.gvsig.fmap.rendering.IVectorLegend;
75
import com.iver.cit.gvsig.fmap.rendering.LegendFactory;
76
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.AttrInTableLabelingStrategy;
77
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.ILabelingStrategy;
78
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.LabelingFactory;
70 79
import com.iver.cit.gvsig.project.Project;
71 80
import com.iver.cit.gvsig.project.documents.ProjectDocument;
72 81
import com.iver.cit.gvsig.project.documents.exceptions.OpenException;
......
80 89

  
81 90
/**
82 91
 * Tabla del proyecto
83
 *
92
 * 
84 93
 * @author Fernando Gonz?lez Cort?s
85 94
 */
86 95
public class ProjectTable extends ProjectDocument {
87
	//public static int numTables = 0;
96
	// public static int numTables = 0;
88 97

  
89 98
	private IEditableSource esModel;
90 99

  
......
106 115
	private String[] alias = null;
107 116

  
108 117
	private Columns columns = new Columns();
118

  
109 119
	private long[] orderIndexes = null;
110 120

  
111
	private XMLEntity backupXMLEntity= null;
121
	private XMLEntity backupXMLEntity = null;
112 122

  
113 123
	/**
114 124
	 * Establece a true el bit index-?simo del bitmap de campos visibles. Los
115 125
	 * campos cuyos bits est?n a true se considerar?n visibles y viceversa
116
	 *
126
	 * 
117 127
	 * @param index
118 128
	 *            indice del bit que se quiere establecer a true
119 129
	 */
......
126 136

  
127 137
	/**
128 138
	 * Obtiene el valor del bit index-?simo del bitmap de campos visibles
129
	 *
139
	 * 
130 140
	 * @param index
131 141
	 *            indice del bit que se quiere obtener
132
	 *
142
	 * 
133 143
	 * @return devuelve true si el campo index-?simo es visible y false en caso
134 144
	 *         contrario
135 145
	 */
......
142 152
	/**
143 153
	 * Obtiene el modelo de la Tabla. Es decir, una clase con capacidad para
144 154
	 * leer la informaci?n de la tabla
145
	 *
155
	 * 
146 156
	 * @return
147 157
	 */
148 158
	public IEditableSource getModelo() {
......
151 161

  
152 162
	/**
153 163
	 * Establece el valor del bit index-?simo al valor 'value'
154
	 *
164
	 * 
155 165
	 * @param bitIndex
156 166
	 *            indice del bit que se quiere tocar
157 167
	 * @param value
......
163 173
		change.firePropertyChange("visibles", value, value);
164 174
	}
165 175

  
166

  
167

  
168 176
	public void createAlias() throws ReadDriverException {
169 177
		SelectableDataSource sds = esModel.getRecordset();
170
		int fieldCount=sds.getFieldCount();
178
		int fieldCount = sds.getFieldCount();
171 179
		mapping = new int[fieldCount];
172 180
		alias = new String[fieldCount];
173 181
		for (int i = 0; i < fieldCount; i++) {
174
			mapping[i]=i;
175
			alias[i]=sds.getFieldName(i);
182
			mapping[i] = i;
183
			alias[i] = sds.getFieldName(i);
176 184
		}
177 185
		recalculateColumnsFromAliases();
178 186

  
179 187
	}
180 188

  
181
	public void recalculateColumnsFromAliases()
182
	{
183
		ArrayList columnsAux=new ArrayList();
189
	public void recalculateColumnsFromAliases() {
190
		ArrayList columnsAux = new ArrayList();
184 191
		columnsAux.addAll(columns);
185 192
		columns.clear();
186 193
		int aliasLength = getAliases().length;
187 194
		for (int i = 0; i < aliasLength; i++) {
188
			if (columnsAux.size()>i) {
195
			if (columnsAux.size() > i) {
189 196
				columns.add(columnsAux.get(i));
190
			}else {
197
			} else {
191 198
				addColumn(new Column());
192 199
			}
193 200
		}
......
196 203

  
197 204
	/**
198 205
	 * DOCUMENT ME!
199
	 *
206
	 * 
200 207
	 * @param sds
201 208
	 *            DOCUMENT ME!
202 209
	 * @throws DriverLoadException
203 210
	 * @throws ReadDriverException
204 211
	 */
205
	public void setDataSource(IEditableSource es) throws DriverLoadException, ReadDriverException {
212
	public void setDataSource(IEditableSource es) throws DriverLoadException,
213
			ReadDriverException {
206 214
		setModel(es);
207 215

  
208 216
		setName(esModel.getRecordset().getName());
......
212 220

  
213 221
	/**
214 222
	 * DOCUMENT ME!
215
	 *
223
	 * 
216 224
	 * @param ds
217 225
	 *            DOCUMENT ME!
218 226
	 * @throws ReadDriverException
219 227
	 * @throws com.hardcode.gdbms.engine.data.driver.DriverException
220 228
	 */
221
	public void replaceDataSource(IEditableSource es) throws ReadDriverException {
229
	public void replaceDataSource(IEditableSource es)
230
			throws ReadDriverException {
222 231
		if (original == null) {
223 232
			original = esModel;
224 233
		}
225 234
		setModel(es);
226
		 es.getRecordset().setSelectionSupport((original
227
							.getRecordset()).getSelectionSupport());
235
		es.getRecordset().setSelectionSupport(
236
				(original.getRecordset()).getSelectionSupport());
228 237

  
229
			createAlias();
238
		createAlias();
230 239
		// FJP:
231 240
		// Si la tabla proviene de un layer, cambiamos su recordset
232 241
		if (associatedTable != null) {
......
244 253

  
245 254
	/**
246 255
	 * DOCUMENT ME!
247
	 *
256
	 * 
248 257
	 * @throws com.hardcode.gdbms.engine.data.driver.DriverException
249 258
	 * @throws DriverLoadException
250 259
	 */
251
	public void restoreDataSource()
252
			throws ReadDriverException,
260
	public void restoreDataSource() throws ReadDriverException,
253 261
			DriverLoadException {
254 262
		// FJP:
255 263
		// Si la tabla proviene de un layer, cambiamos su recordset
......
257 265
			if (associatedTable instanceof FLyrVect) {
258 266
				// Miramos si la leyenda que est? usando es una
259 267
				// leyenda basada en un campo de los de la uni?n.
260
				// Si lo es, no dejamos pegarle el cambiazo al recordset
268
				// Si lo es, avisamos al usuario de que ponemos una leyenda por
269
				// defecto.
270
				// Si los campos son de los originales, les ponemos el nombre
271
				// correcto en la leyenda
272

  
261 273
				FLyrVect lyr = ((FLyrVect) associatedTable);
274
				SelectableDataSource sdsOrig = original.getRecordset();
275
				SelectableDataSource sdsJoined = lyr.getRecordset();
276

  
262 277
				if (lyr.getLegend() instanceof IClassifiedVectorLegend) {
263 278
					IClassifiedVectorLegend legend = (IClassifiedVectorLegend) lyr
264 279
							.getLegend();
265
					IVectorLegend aux = (IVectorLegend) legend;
266
					int idField = original.getRecordset().getFieldIndexByName(
267
							legend.getClassifyingFieldNames()[0]);
268
					int idLabelField = -2;
280
					String[] legendFields = legend.getClassifyingFieldNames();
281
					boolean bUsingJoinedField = false;
282
					for (int i = 0; i < legendFields.length; i++) {
283
						int idField = sdsJoined
284
								.getFieldIndexByName(legendFields[i]);
285
						String fieldName = sdsJoined.getFieldName(idField);
286
						int idOriginal = sdsOrig.getFieldIndexByName(fieldName);
287
						if (idOriginal == -1) {
288
							bUsingJoinedField = true;
289
							break;
290
						} else {
291
							legendFields[i] = fieldName;
292
						}
293
					}
269 294

  
270
					// TODO
271
					NotificationManager.addWarning("Piece of code remains unrefactored in methdo com.iver.cit.gvsig.project.documents.table.ProjectTable.restoreDataSource()", null);
272
					// TODO
273
//					if (aux.getLabelField() != null) {
274
//						idLabelField = original.getRecordset()
275
//								.getFieldIndexByName(aux.getLabelField());
276
//					}
277
//					if ((idField == -1) || (idLabelField == -1)) {
278
//						// No se ha encontrado ese campo, o se est? etiquetando
279
//						// por ese campo
280
//						JOptionPane.showMessageDialog(null, PluginServices
281
//								.getText(this, "leyenda_campo_unido"));
282
//
283
//						return;
284
//					}
285
				}
295
					if (bUsingJoinedField) {
296
						JOptionPane.showMessageDialog(null, PluginServices.getText(null,
297
								"legend_using_joined_field"));
298
						try {
299
							lyr.setLegend(LegendFactory
300
									.createSingleSymbolLegend(lyr
301
											.getShapeType()));
302
						} catch (LegendLayerException e) {
303
							// TODO Auto-generated catch block
304
							e.printStackTrace();
305
							NotificationManager
306
									.addWarning(
307
											"Error in com.iver.cit.gvsig.project.documents.table.ProjectTable.restoreDataSource()",
308
											null);
309
							return;
310
						}
311
					} else {
312
						legend.setClassifyingFieldNames(legendFields);
313
						try {
314
							legend.setDataSource(original.getRecordset());
315
						} catch (FieldNotFoundException e) {
316
							// TODO Auto-generated catch block
317
							e.printStackTrace();
318
							NotificationManager
319
									.addWarning(
320
											"Error in com.iver.cit.gvsig.project.documents.table.ProjectTable.restoreDataSource()",
321
											null);
322
						}
323
							
324
					}
325
				} // ClassifiedVectorLegend
326
				checkLabelling(lyr, sdsOrig, sdsJoined);
286 327

  
287 328
				lyr.setRecordset(original.getRecordset());
288 329

  
......
298 339
		change.firePropertyChange("model", original, esModel);
299 340
	}
300 341

  
342
	private void checkLabelling(FLyrVect lyr, SelectableDataSource sdsOrig,
343
			SelectableDataSource sdsJoined) throws ReadDriverException {
344
		boolean bLabelingWithJoin = false;
345
		if (lyr.getLabelingStrategy() != null) {
346
			if (lyr.getLabelingStrategy() instanceof AttrInTableLabelingStrategy) {
347
				AttrInTableLabelingStrategy labelStrategy = (AttrInTableLabelingStrategy) lyr
348
						.getLabelingStrategy();
349
				String alias = labelStrategy.getTextField();
350
				if (alias != null) {
351
					int idField = sdsJoined.getFieldIndexByName(alias);
352
					String fieldName = sdsJoined.getFieldName(idField);
353
					int idOriginal = sdsOrig.getFieldIndexByName(fieldName);
354
					if (idOriginal == -1) {
355
						bLabelingWithJoin = true;
356
					} else {
357
						labelStrategy.setTextField(fieldName);
358
					}
359
				}
360

  
361
				alias = labelStrategy.getRotationField();
362
				if (alias != null) {
363
					int idField = sdsJoined.getFieldIndexByName(alias);
364
					String fieldName = sdsJoined.getFieldName(idField);
365
					int idOriginal = sdsOrig.getFieldIndexByName(fieldName);
366
					if (idOriginal == -1) {
367
						bLabelingWithJoin = true;
368
					} else {
369
						labelStrategy.setRotationField(fieldName);
370
					}
371
				}
372

  
373
				if (alias != null) {
374
					alias = labelStrategy.getColorField();
375
					int idField = sdsJoined.getFieldIndexByName(alias);
376
					String fieldName = sdsJoined.getFieldName(idField);
377
					int idOriginal = sdsOrig.getFieldIndexByName(fieldName);
378
					if (idOriginal == -1) {
379
						bLabelingWithJoin = true;
380
					} else {
381
						labelStrategy.setColorField(fieldName);
382
					}
383
				}
384

  
385
				if (alias != null) {
386
					alias = labelStrategy.getHeightField();
387
					int idField = sdsJoined.getFieldIndexByName(alias);
388
					String fieldName = sdsJoined.getFieldName(idField);
389
					int idOriginal = sdsOrig.getFieldIndexByName(fieldName);
390
					if (idOriginal == -1) {
391
						bLabelingWithJoin = true;
392
					} else {
393
						labelStrategy.setHeightField(fieldName);
394
					}
395
				}
396
			}
397
		}
398

  
399
		if (bLabelingWithJoin) {
400
			JOptionPane.showMessageDialog(null, PluginServices.getText(null,
401
					"labelling_using_joined_field"));
402
			
403
			lyr.setLabelingStrategy(LabelingFactory.createDefaultStrategy(lyr));
404
			lyr.setIsLabeled(false);
405
		}
406
	}
407

  
301 408
	/**
302 409
	 * DOCUMENT ME!
303
	 *
410
	 * 
304 411
	 * @return DOCUMENT ME!
305 412
	 * @throws SaveException
306
	 *
413
	 * 
307 414
	 * @throws XMLException
308 415
	 */
309 416
	public XMLEntity getXMLEntity() throws SaveException {
310 417
		XMLEntity xml = super.getXMLEntity();
311 418
		try {
312 419
			// xml.putProperty("nameClass", this.getClass().getName());
313
			int numTables=((Integer)ProjectDocument.NUMS.get(ProjectTableFactory.registerName)).intValue();
420
			int numTables = ((Integer) ProjectDocument.NUMS
421
					.get(ProjectTableFactory.registerName)).intValue();
314 422

  
315 423
			xml.putProperty("numTables", numTables);
316 424

  
317
			if (this.getModelo() == null){
318
				if (this.backupXMLEntity == null){
425
			if (this.getModelo() == null) {
426
				if (this.backupXMLEntity == null) {
319 427
					return xml;
320
				} else{
428
				} else {
321 429
					return this.backupXMLEntity;
322 430
				}
323 431
			}
......
328 436
				xml.putProperty("field2", field2);
329 437
			}
330 438

  
331
			if (getJoinedTables()!=null) {
439
			if (getJoinedTables() != null) {
332 440
				xml.putProperty("joinedTableNames", getJoinedTables());
333 441
			}
334 442

  
......
337 445
			}
338 446
			xml.addChild(esModel.getRecordset().getXMLEntity());
339 447

  
340
//			Object di = LayerFactory.getDataSourceFactory().getDriverInfo(
341
//					esModel.getRecordset().getName());
448
			// Object di = LayerFactory.getDataSourceFactory().getDriverInfo(
449
			// esModel.getRecordset().getName());
342 450

  
343 451
			if (associatedTable != null) {
344 452
				xml.putProperty("layerName", ((FLayer) associatedTable)
......
364 472

  
365 473
	/**
366 474
	 * DOCUMENT ME!
367
	 *
475
	 * 
368 476
	 * @param xml
369 477
	 *            DOCUMENT ME!
370 478
	 * @param p
371 479
	 *            DOCUMENT ME!
372
	 *
480
	 * 
373 481
	 * @throws XMLException
374 482
	 * @throws ReadDriverException
375 483
	 * @throws DriverException
376
	 *
484
	 * 
377 485
	 * @see com.iver.cit.gvsig.project.documents.ProjectDocument#setXMLEntity(com.iver.utiles.XMLEntity)
378 486
	 */
379
	public void setXMLEntity03(XMLEntity xml)
380
		throws XMLException, ReadDriverException{
487
	public void setXMLEntity03(XMLEntity xml) throws XMLException,
488
			ReadDriverException {
381 489
		super.setXMLEntity03(xml);
382 490
		int numTables = xml.getIntProperty("numTables");
383
		ProjectDocument.NUMS.put(ProjectTableFactory.registerName,new Integer(numTables));
491
		ProjectDocument.NUMS.put(ProjectTableFactory.registerName, new Integer(
492
				numTables));
384 493

  
385 494
		if (xml.getStringProperty("type").equals("otherDriverFile")) {
386 495
			LayerFactory.getDataSourceFactory().addFileDataSource(
......
392 501
		} else if (xml.getStringProperty("type").equals("sameDriverFile")) {
393 502
			String layerName = xml.getStringProperty("layerName");
394 503

  
395
			ProjectView vista =(ProjectView) project.getProjectDocumentByName(xml
396
					.getStringProperty("viewName"), ProjectViewFactory.registerName);
504
			ProjectView vista = (ProjectView) project.getProjectDocumentByName(
505
					xml.getStringProperty("viewName"),
506
					ProjectViewFactory.registerName);
397 507
			FLayer layer = vista.getMapContext().getLayers()
398 508
					.getLayer(layerName);
399 509

  
400
			setTheModel((VectorialEditableAdapter) ((FLyrVect) layer).getSource());
510
			setTheModel((VectorialEditableAdapter) ((FLyrVect) layer)
511
					.getSource());
401 512
			associatedTable = (AlphanumericData) layer;
402 513

  
403 514
			LayerFactory.getDataSourceFactory().addDataSource(
......
419 530
		setName(xml.getStringProperty("name"));
420 531
	}
421 532

  
422
	private void fillAsEmpty(){
533
	private void fillAsEmpty() {
423 534
		this.esModel = null;
424 535
		mapping = new int[0];
425 536
		alias = new String[0];
......
428 539

  
429 540
	/**
430 541
	 * DOCUMENT ME!
431
	 *
542
	 * 
432 543
	 * @param xml
433 544
	 *            DOCUMENT ME!
434 545
	 * @param p
435 546
	 *            DOCUMENT ME!
436
	 *
547
	 * 
437 548
	 * @throws XMLException
438 549
	 * @throws DriverException
439 550
	 * @throws OpenException
440
	 *
551
	 * 
441 552
	 * @see com.iver.cit.gvsig.project.documents.ProjectDocument#setXMLEntity(com.iver.utiles.XMLEntity)
442 553
	 */
443 554
	public void setXMLEntity(XMLEntity xml) throws XMLException,
......
448 559

  
449 560
			setName(xml.getStringProperty("name"));
450 561
			int numTables = xml.getIntProperty("numTables");
451
			ProjectDocument.NUMS.put(ProjectTableFactory.registerName,new Integer(numTables));
562
			ProjectDocument.NUMS.put(ProjectTableFactory.registerName,
563
					new Integer(numTables));
452 564

  
453
			if (xml.getChildrenCount() == 0){
565
			if (xml.getChildrenCount() == 0) {
454 566
				fillAsEmpty();
455 567
				return;
456 568

  
457 569
			}
458
			try{
570
			try {
459 571
				setSelectableDataSource(xml);
460
			} catch (ReadDriverException e){
572
			} catch (ReadDriverException e) {
461 573
				fillAsEmpty();
462 574
				throw e;
463 575
			}
......
469 581
			 * ProjectView vista = project.getViewByName(xml.getStringProperty(
470 582
			 * "viewName")); FLayer layer =
471 583
			 * vista.getMapContext().getLayers().getLayer(layerName);
472
			 *
584
			 * 
473 585
			 * modelo = ((AlphanumericData) layer).getRecordset();
474 586
			 * associatedTable = (AlphanumericData) layer; } else if
475 587
			 * (xml.getStringProperty("type").equals("db")) {
......
490 602
			if (xml.contains("mapping")) {
491 603
				mapping = xml.getIntArrayProperty("mapping");
492 604
				alias = xml.getStringArrayProperty("aliases");
493
				// we check if all fields are real there (may be some external program has changed them.
605
				// we check if all fields are real there (may be some external
606
				// program has changed them.
494 607
				// If we detect any change, we discard all mapping and aliases.
495
				if (mapping.length != getModelo().getRecordset().getFieldCount())
496
				{
608
				SelectableDataSource sds = getModelo().getRecordset();
609
				if (mapping.length != sds.getFieldCount()) {
497 610
					createAlias();
498
//					columns.clear();
499
//					for (int i = 0; i < esModel.getRecordset().getFieldCount(); i++) {
500
//						addColumn(new Column());
501
//					}
611
					// columns.clear();
612
					// for (int i = 0; i <
613
					// esModel.getRecordset().getFieldCount(); i++) {
614
					// addColumn(new Column());
615
					// }
502 616
					return;
503 617

  
618
				} else {
619
					for (int i = 0; i < alias.length; i++) {
620
						sds.setFieldAlias(i, alias[i]);
621
					}
504 622
				}
505 623

  
506 624
			} else {
......
519 637
		// }
520 638
		if (xml.contains("columns")) {
521 639
			columns.clear();
522
			columns = Columns
523
					.createColumns(xml.getChild(xml.getChildrenCount() - 1));
640
			columns = Columns.createColumns(xml
641
					.getChild(xml.getChildrenCount() - 1));
524 642
		}
525 643

  
526

  
527 644
	}
528 645

  
529 646
	/**
530 647
	 * DOCUMENT ME!
531
	 *
648
	 * 
532 649
	 * @param xml
533 650
	 *            DOCUMENT ME!
534
	 *
651
	 * 
535 652
	 * @throws XMLException
536 653
	 *             DOCUMENT ME!
537 654
	 * @throws DriverException
......
568 685
			}
569 686

  
570 687
		} else {
571
			ProjectView vista = (ProjectView) project.getProjectDocumentByName(xml
572
					.getStringProperty("viewName"), ProjectViewFactory.registerName);
688
			ProjectView vista = (ProjectView) project.getProjectDocumentByName(
689
					xml.getStringProperty("viewName"),
690
					ProjectViewFactory.registerName);
573 691
			FLayer layer = vista.getMapContext().getLayers()
574 692
					.getLayer(layerName);
575 693

  
576
			setTheModel((VectorialEditableAdapter) ((FLyrVect) layer).getSource());
694
			setTheModel((VectorialEditableAdapter) ((FLyrVect) layer)
695
					.getSource());
577 696
			associatedTable = (AlphanumericData) layer;
578 697
		}
579 698
	}
580 699

  
581 700
	/**
582 701
	 * DOCUMENT ME!
583
	 *
702
	 * 
584 703
	 * @param xml
585 704
	 *            DOCUMENT ME!
586
	 *
705
	 * 
587 706
	 * @throws XMLException
588 707
	 *             DOCUMENT ME!
589 708
	 * @throws DriverException
590 709
	 *             DOCUMENT ME!
591 710
	 */
592
	private void setSelectableDataSource(XMLEntity xml) throws ReadDriverException {
711
	private void setSelectableDataSource(XMLEntity xml)
712
			throws ReadDriverException {
593 713
		String layerName = null;
594 714
		boolean bNeedToReplace = false;
595 715
		XMLEntity xmlAux = null;
......
600 720
			if (xml.contains("layerName")) {
601 721
				layerName = xml.getStringProperty("layerName");
602 722

  
603
				ProjectView vista = (ProjectView) project.getProjectDocumentByName(xml
604
						.getStringProperty("viewName"), ProjectViewFactory.registerName);
723
				ProjectView vista = (ProjectView) project
724
						.getProjectDocumentByName(xml
725
								.getStringProperty("viewName"),
726
								ProjectViewFactory.registerName);
605 727
				FLayer layer = getLayer(vista.getMapContext().getLayers(),
606 728
						layerName);
607 729
				EditableAdapter ea = new EditableAdapter();
......
620 742

  
621 743
			setDataSource(es);
622 744

  
623
			if (xml.getChildrenCount() == 2 && !(xml.contains("columns"))
745
			if (xml.getChildrenCount() == 2
746
					&& !(xml.contains("columns"))
624 747
					|| (xml.contains("columns") && (xml.getChildrenCount() == 3))) {
625 748
				bNeedToReplace = true;
626 749
				xmlAux = xml.getChild(1);
......
632 755

  
633 756
			if (bNeedToReplace) {
634 757
				if (layerName != null) {
635
					ProjectView vista = (ProjectView) project.getProjectDocumentByName(xml
636
							.getStringProperty("viewName"), ProjectViewFactory.registerName);
758
					ProjectView vista = (ProjectView) project
759
							.getProjectDocumentByName(xml
760
									.getStringProperty("viewName"),
761
									ProjectViewFactory.registerName);
637 762
					FLayer layer = getLayer(vista.getMapContext().getLayers(),
638 763
							layerName);
639 764

  
......
647 772
				replaceDataSource(auxea);
648 773
			}
649 774
		} catch (DriverLoadException e) {
650
			throw new ReadDriverException(getName(),e);
775
			throw new ReadDriverException(getName(), e);
651 776
		} catch (XMLException e) {
652
			throw new ReadDriverException(getName(),e);
777
			throw new ReadDriverException(getName(), e);
653 778
		}
654 779
	}
655 780

  
......
658 783
		for (int i = 0; i < layers.getLayersCount(); i++) {
659 784
			if (layers.getLayer(i) instanceof FLayers) {
660 785
				aux = getLayer((FLayers) layers.getLayer(i), name);
661
				if (aux != null){
786
				if (aux != null) {
662 787
					return aux;
663 788
				}
664 789
			} else if (layers.getLayer(i).getName().equals(name)) {
......
670 795

  
671 796
	/**
672 797
	 * DOCUMENT ME!
673
	 *
798
	 * 
674 799
	 * @return DOCUMENT ME!
675 800
	 */
676 801
	public AlphanumericData getAssociatedTable() {
......
679 804

  
680 805
	/**
681 806
	 * DOCUMENT ME!
682
	 *
807
	 * 
683 808
	 * @param associatedTable
684 809
	 *            DOCUMENT ME!
685 810
	 */
......
691 816
	 * Obtiene la fuente de datos original de la tabla si se ha invocado
692 817
	 * replaceDataSource. Si no se invoc? este m?todo o se invoc? posteriormente
693 818
	 * restoreDataSource se devuelve null
694
	 *
819
	 * 
695 820
	 * @return Returns the original.
696 821
	 */
697 822
	public IEditableSource getOriginal() {
......
700 825

  
701 826
	/**
702 827
	 * Devuelve el identificador de la tabla que contiene el link.
703
	 *
828
	 * 
704 829
	 * @return identificador ?nico de la tabla.
705 830
	 */
706 831
	public String getLinkTable() {
......
708 833
	}
709 834

  
710 835
	/**
711
	 * Returns the name of the table(s) which have been joined to this
712
	 * table (using the JOIN operation from TableOperations).
713
	 *
836
	 * Returns the name of the table(s) which have been joined to this table
837
	 * (using the JOIN operation from TableOperations).
838
	 * 
714 839
	 * @return The name of the joined table(s), if any, or null otherwise.
715 840
	 */
716 841
	public String[] getJoinedTables() {
......
718 843
	}
719 844

  
720 845
	/**
721
	 * Sets the name of the table(s) which have been joined to this
722
	 * table (using the JOIN operation from TableOperations).
723
	 *
846
	 * Sets the name of the table(s) which have been joined to this table (using
847
	 * the JOIN operation from TableOperations).
848
	 * 
724 849
	 * @return The name of the joined table(s), if any, or null otherwise.
725 850
	 */
726 851
	public void setJoinTable(String[] tables) {
......
729 854

  
730 855
	/**
731 856
	 * Devuelve el nombre del campo de la tabla a enlazar.
732
	 *
857
	 * 
733 858
	 * @return Nombre del campo de la tabla a enlazar.
734 859
	 */
735 860
	public String getField1() {
......
738 863

  
739 864
	/**
740 865
	 * Devuelve el nombre del campo de la tabla enlazada.
741
	 *
866
	 * 
742 867
	 * @return Nombre del campo de la tabla enlazada.
743 868
	 */
744 869
	public String getField2() {
......
748 873
	/**
749 874
	 * Inserta el identificador de la tabla, el campo de la primera tabla y el
750 875
	 * campo de la segunda tabla.
751
	 *
876
	 * 
752 877
	 * @param lt
753 878
	 *            identificado de la tabla.
754 879
	 * @param f1
......
769 894
	public void removeLinkTable() {
770 895
		linkTable = null;
771 896
		try {
772
			getModelo().getRecordset()
773
					.removeLinksSelectionListener();
897
			getModelo().getRecordset().removeLinksSelectionListener();
774 898
		} catch (ReadDriverException e) {
775 899
			e.printStackTrace();
776 900
		}
777 901
	}
778 902

  
779 903
	public String[] getAliases() {
780
		if (alias==null) {
904
		if (alias == null) {
781 905
			try {
782 906
				createAlias();
783 907
			} catch (ReadDriverException e) {
784
				PluginServices.getLogger().error("Error creating the field aliases", e);
908
				PluginServices.getLogger().error(
909
						"Error creating the field aliases", e);
785 910
			}
786 911
		}
787 912
		return alias;
......
816 941
	}
817 942

  
818 943
	public Column getColumn(int i) {
819
//		if (i==0){
820
//			Column column=new Column();
821
//			column.setWidth(45);
822
//			return column;
823
//		}
824
//		i--;
825
			return (Column) columns.get(getMapping()[i]);
944
		// if (i==0){
945
		// Column column=new Column();
946
		// column.setWidth(45);
947
		// return column;
948
		// }
949
		// i--;
950
		return (Column) columns.get(getMapping()[i]);
826 951
	}
827 952

  
828 953
	public void addColumn(Column column) {
......
841 966
		callCreateWindow(table);
842 967
		return table;
843 968
	}
969

  
844 970
	public IWindow getProperties() {
845 971
		return new TableProperties(this);
846 972
	}
......
860 986

  
861 987
	}
862 988

  
863
	public void exportToXML(XMLEntity root, Project project)  throws SaveException {
864
		XMLEntity tableRoot = project.getExportXMLTypeRootNode(root,ProjectTableFactory.registerName);
989
	public void exportToXML(XMLEntity root, Project project)
990
			throws SaveException {
991
		XMLEntity tableRoot = project.getExportXMLTypeRootNode(root,
992
				ProjectTableFactory.registerName);
865 993
		try {
866
			project.exportToXMLDataSource(root,this.getModelo().getRecordset().getName());
994
			project.exportToXMLDataSource(root, this.getModelo().getRecordset()
995
					.getName());
867 996
		} catch (ReadDriverException e) {
868 997
			throw new SaveException();
869 998
		}
870 999
		tableRoot.addChild(this.getXMLEntity());
871 1000
	}
872 1001

  
873
	public void importFromXML(XMLEntity root, XMLEntity typeRoot,int elementIndex ,Project project, boolean removeDocumentsFromRoot) throws XMLException, ReadDriverException, OpenException {
1002
	public void importFromXML(XMLEntity root, XMLEntity typeRoot,
1003
			int elementIndex, Project project, boolean removeDocumentsFromRoot)
1004
			throws XMLException, ReadDriverException, OpenException {
874 1005
		XMLEntity element = typeRoot.getChild(elementIndex);
875 1006
		this.setXMLEntity(element);
876 1007
		if (removeDocumentsFromRoot) {
......
888 1019
		this.orderIndexes = orderIndexes;
889 1020
	}
890 1021

  
891
//	public int computeSignature() {
892
//		int result = 17;
893
//
894
//		Class clazz = getClass();
895
//		Field[] fields = clazz.getDeclaredFields();
896
//		for (int i = 0; i < fields.length; i++) {
897
//			try {
898
//				String type = fields[i].getType().getName();
899
//				if (type.equals("boolean")) {
900
//					result += 37 + ((fields[i].getBoolean(this)) ? 1 : 0);
901
//				} else if (type.equals("java.lang.String")) {
902
//					Object v = fields[i].get(this);
903
//					if (v == null) {
904
//						result += 37;
905
//						continue;
906
//					}
907
//					char[] chars = ((String) v).toCharArray();
908
//					for (int j = 0; j < chars.length; j++) {
909
//						result += 37 + (int) chars[i];
910
//					}
911
//				} else if (type.equals("byte")) {
912
//					result += 37 + (int) fields[i].getByte(this);
913
//				} else if (type.equals("char")) {
914
//					result += 37 + (int) fields[i].getChar(this);
915
//				} else if (type.equals("short")) {
916
//					result += 37 + (int) fields[i].getShort(this);
917
//				} else if (type.equals("int")) {
918
//					result += 37 + fields[i].getInt(this);
919
//				} else if (type.equals("long")) {
920
//					long f = fields[i].getLong(this) ;
921
//					result += 37 + (f ^ (f >>> 32));
922
//				} else if (type.equals("float")) {
923
//					result += 37 + Float.floatToIntBits(fields[i].getFloat(this));
924
//				} else if (type.equals("double")) {
925
//					long f = Double.doubleToLongBits(fields[i].getDouble(this));
926
//					result += 37 + (f ^ (f >>> 32));
927
//				} else {
928
//					Object obj = fields[i].get(this);
929
//					result += 37 + ((obj != null)? obj.hashCode() : 0);
930
//				}
931
//			} catch (Exception e) { e.printStackTrace(); }
932
//
933
//		}
934
//		return result;
935
//	}
1022
	// public int computeSignature() {
1023
	// int result = 17;
1024
	//
1025
	// Class clazz = getClass();
1026
	// Field[] fields = clazz.getDeclaredFields();
1027
	// for (int i = 0; i < fields.length; i++) {
1028
	// try {
1029
	// String type = fields[i].getType().getName();
1030
	// if (type.equals("boolean")) {
1031
	// result += 37 + ((fields[i].getBoolean(this)) ? 1 : 0);
1032
	// } else if (type.equals("java.lang.String")) {
1033
	// Object v = fields[i].get(this);
1034
	// if (v == null) {
1035
	// result += 37;
1036
	// continue;
1037
	// }
1038
	// char[] chars = ((String) v).toCharArray();
1039
	// for (int j = 0; j < chars.length; j++) {
1040
	// result += 37 + (int) chars[i];
1041
	// }
1042
	// } else if (type.equals("byte")) {
1043
	// result += 37 + (int) fields[i].getByte(this);
1044
	// } else if (type.equals("char")) {
1045
	// result += 37 + (int) fields[i].getChar(this);
1046
	// } else if (type.equals("short")) {
1047
	// result += 37 + (int) fields[i].getShort(this);
1048
	// } else if (type.equals("int")) {
1049
	// result += 37 + fields[i].getInt(this);
1050
	// } else if (type.equals("long")) {
1051
	// long f = fields[i].getLong(this) ;
1052
	// result += 37 + (f ^ (f >>> 32));
1053
	// } else if (type.equals("float")) {
1054
	// result += 37 + Float.floatToIntBits(fields[i].getFloat(this));
1055
	// } else if (type.equals("double")) {
1056
	// long f = Double.doubleToLongBits(fields[i].getDouble(this));
1057
	// result += 37 + (f ^ (f >>> 32));
1058
	// } else {
1059
	// Object obj = fields[i].get(this);
1060
	// result += 37 + ((obj != null)? obj.hashCode() : 0);
1061
	// }
1062
	// } catch (Exception e) { e.printStackTrace(); }
1063
	//
1064
	// }
1065
	// return result;
1066
	// }
936 1067
}
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/view/legend/gui/VectorialInterval.java
584 584
	}
585 585

  
586 586
	protected void fillFieldNames() {
587
		DataSource rs = null;
587
		SelectableDataSource rs = null;
588 588
		ArrayList nomFields = null;
589 589

  
590 590
		try {
......
607 607
						(type == Types.DOUBLE) ||
608 608
						(type == Types.FLOAT) ||
609 609
						(type == Types.BIGINT)) {
610
					nomFields.add(rs.getFieldName(i).trim());
610
					nomFields.add(rs.getFieldAlias(i));
611 611
				}
612 612
			}
613 613

  
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/view/legend/gui/VectorialUniqueValue.java
76 76
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
77 77
import com.iver.cit.gvsig.fmap.layers.FLayer;
78 78
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
79
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
79 80
import com.iver.cit.gvsig.fmap.layers.XMLException;
80 81
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData;
81 82
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial;
......
428 429
	 * DOCUMENT ME!
429 430
	 */
430 431
	private void fillFieldNames() {
431
		DataSource rs;
432
		SelectableDataSource rs;
432 433

  
433 434
		try {
434 435
			// rs = ((FLyrVect) layer).getSource().getRecordset();
......
439 440
			String[] nomFields = new String[fieldCount];
440 441

  
441 442
			for (int i = 0; i < fieldCount; i++) {
442
				nomFields[i] = rs.getFieldName(i).trim();
443
				nomFields[i] = rs.getFieldAlias(i);
443 444
			}
444 445

  
445 446
			rs.stop();
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/TableOperations.java
54 54
import com.iver.andami.messages.NotificationManager;
55 55
import com.iver.andami.plugins.Extension;
56 56
import com.iver.andami.ui.mdiManager.IWindow;
57
import com.iver.cit.gvsig.fmap.drivers.FieldDescription;
57 58
import com.iver.cit.gvsig.fmap.edition.EditableAdapter;
58 59
import com.iver.cit.gvsig.fmap.layers.FBitSet;
59 60
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
......
480 481
			DataSource ds2, String prefix2) {
481 482
		try {
482 483
			SelectableDataSource sds = targetPt.getModelo().getRecordset();
484
			FieldDescription[] fields = sds.getFieldsDescription();
483 485
			String[] aliases = new String[sds.getFieldCount()];
484 486
			int i=0;
485 487
			while (i<aliases.length && i<ds1.getFieldCount()){
486
				if (!prefix1.equals(""))
487
					aliases[i] = prefix1+"_"+sds.getFieldName(i);
488
				else
489
					aliases[i] = sds.getFieldName(i);
488
				aliases[i] = prefix1+"_"+sds.getFieldName(i);
489
				sds.setFieldAlias(i, aliases[i]);
490 490
				i++;
491 491
			}
492 492
			while (i<aliases.length) {
493
				if (!prefix2.equals(""))
494
					aliases[i] = prefix2 + "_" + sds.getFieldName(i).substring(ArcJoinDataSource.prefix.length());
495
				else
496
					aliases[i] = sds.getFieldName(i).substring(ArcJoinDataSource.prefix.length());
493
				aliases[i] = prefix2 + "_" + sds.getFieldName(i).substring(ArcJoinDataSource.prefix.length());
494
				sds.setFieldAlias(i,aliases[i]);
497 495
				i++;
498 496
			}
499 497
			targetPt.setAliases(aliases);
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/gui/filter/FilterDialog.java
212 212
							fillValues(row);
213 213
							break;
214 214
						case 2:
215
							putSymbol(jtreeRoot.getChildAt(row).toString());
215
							String alias = jtreeRoot.getChildAt(row).toString();
216
							String name;
217
							try {
218
								name = model.getFieldName(row);
219
								putSymbol(name);
220
							} catch (FilterException e1) {
221
								e1.printStackTrace();
222
							}
223
							
216 224
							break;
217 225
					}
218 226
				}
......
319 327

  
320 328
        try {
321 329
			for (int i = 0; i < model.getFieldCount(); i++) {
322
				Object field = model.getFieldName(i);
330
				Object field = model.getFieldAlias(i);
323 331

  
324 332
				if (field != null) {
325 333
					jtreeRoot.add(new DefaultMutableTreeNode(field.toString()));
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/gui/filter/ExpressionDataSource.java
82 82
	 * @throws FilterException DOCUMENT ME!
83 83
	 */
84 84
	public String getFieldName(int idField) throws FilterException;
85
	
86
	
87
	// FJP: Mantengo esta clase por si acaso, pero lo correcto seria
88
	// no usarla y trabajar directamente con SelectableDataSource
89
	public String getFieldAlias(int idField) throws FilterException;
85 90

  
86 91
	/**
87 92
	 * DOCUMENT ME!
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/gui/filter/DefaultExpressionDataSource.java
78 78
     * @return
79 79
     * @throws FilterException
80 80
     */
81
    public String getFieldName(int idField) throws FilterException {
81
    public String getFieldName(int idField) throws FilterException { 
82 82
        try {
83
			return tabla.getFieldName(idField);
83
    		return tabla.getFieldName(idField);
84 84
		} catch (ReadDriverException e) {
85 85
			throw new FilterException();
86 86
		}
87
		
87 88
    }
88 89

  
89 90
    /**
......
134 135
	public String getDataSourceName() {
135 136
		return tabla.getName();
136 137
	}
138
	public String getFieldAlias(int idField) throws FilterException {
139
		return tabla.getFieldAlias(idField);
140
	}
137 141
}
trunk/applications/appgvSIG/config/text_en.properties
623 623
label_text_in_the_TOC=Label text that will appear in the TOC
624 624
labeling=Labeling
625 625
labeling_field=Labeling field
626
labelling_using_joined_field=Labelling using a field from join. The labelling will be lost.
626 627
layer=Layer
627 628
layer_geometry_and_legend_types_are_incompatible=
628 629
Layer_loading_order=Layer loading order
......
638 639
legend_exception=Legend exception
639 640
legend_format_not_yet_supported=
640 641
legend_type_not_yet_supported=
642
legend_using_joined_field=Legend using joined field. A SingleSymbolLegend will be used.
641 643
leyenda=Legend
642 644
Leyenda=Legend
643 645
leyenda_campo_unido=You are using a field of the union either in the legend or in the labelling. Please, change the legend before removing the union.
trunk/applications/appgvSIG/config/text.properties
640 640
label_text_in_the_TOC=Etiqueta que aparecer\u00e1 en el TOC
641 641
labeling=Etiquetado
642 642
labeling_field=Campo de etiquetado
643
labelling_using_joined_field=El etiquetado usa un campo de la uni\u00f3n. Se va a quitar el etiquetado.
643 644
layer=Capa
644 645
layer_geometry_and_legend_types_are_incompatible=
645 646
Layer_loading_order=Orden de carga de capas
......
655 656
legend_exception=Excepci\u00f3n de leyenda
656 657
legend_format_not_yet_supported=
657 658
legend_type_not_yet_supported=
659
legend_using_joined_field=Leyenda con un campo de la uni\u00f3n. Se va a cambiar por una leyenda simple.
658 660
leyenda=Leyenda
659 661
Leyenda=Leyenda
660 662
leyenda_campo_unido=Se est\u00e1 utilizando un campo de la uni\u00f3n en la leyenda (y/o etiquetado). Cambie la leyenda antes de quitar la uni\u00f3n, por favor.

Also available in: Unified diff