Revision 31228

View differences:

trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/layers/SelectableDataSource.java
123 123
		}
124 124

  
125 125
		mapping = new int[numExternalFields];
126

  
126
		
127 127
		int j=0;
128 128
		for (int i=0; i < fieldCount; i++)
129 129
		{
......
133 133
			}
134 134

  
135 135
		}
136

  
136
		
137 137
//		this.dataSource.stop();
138 138
	}
139 139

  
......
218 218
	 */
219 219
	public int getFieldIndexByName(String arg0)
220 220
		throws ReadDriverException {
221
		int internal = dataSource.getFieldIndexByName(arg0);
222
		for (int i=0; i < mapping.length; i++)
223
		{
224
			if (mapping[i] == internal)
221
//		int internal = dataSource.getFieldIndexByName(arg0);
222
//		for (int i=0; i < mapping.length; i++)
223
//		{
224
//			if (mapping[i] == internal)
225
//				return i;
226
//		}
227
//		//OJO Parche para rodear poblema de gdbms + FileDriver
228
//		// Cuando en le fichero existe un campo de nombre 'PK'
229
//		if (arg0.equalsIgnoreCase("pk")){
230
//			for (int i=0; i < mapping.length; i++)
231
//			{
232
//				if (dataSource.getFieldName(mapping[i]).equalsIgnoreCase(arg0)){
233
//					return i;
234
//				}
235
//			}
236
//
237
//		}
238
		for (int i=0; i < getFieldCount(); i++) {
239
			// Buscamos en los alias. Si no hay alias, cada alias es igual al fieldname
240
			if (getFieldAlias(i).compareTo(arg0) == 0)
225 241
				return i;
226 242
		}
227
		//OJO Parche para rodear poblema de gdbms + FileDriver
228
		// Cuando en le fichero existe un campo de nombre 'PK'
229
		if (arg0.equalsIgnoreCase("pk")){
230
			for (int i=0; i < mapping.length; i++)
231
			{
232
				if (dataSource.getFieldName(mapping[i]).equalsIgnoreCase(arg0)){
233
					return i;
234
				}
235
			}
236

  
243
		for (int i=0; i < getFieldCount(); i++) {
244
			// Por compatibilidad con posibles leyendas guardadas 
245
			if (getFieldName(i).compareTo(arg0) == 0)
246
				return i;
237 247
		}
248
		
238 249
		return -1;
239 250
	}
240 251

  
......
531 542
     * @see com.hardcode.gdbms.engine.data.DataSource#getFieldNames()
532 543
     */
533 544
    public String[] getFieldNames() throws ReadDriverException {
534
    	String[] fieldNames = new String[getFieldCount()];
535
		int j=0;
536
		int fieldCount=dataSource.getFieldCount();
545
    	int fieldCount=getFieldCount();
546
    	String[] fieldNames = new String[fieldCount];
547
//		int j=0;
548
//		int fieldCount=dataSource.getFieldCount();
549
//		for (int i=0; i < fieldCount; i++)
550
//		{
551
//			if (!dataSource.isVirtualField(i))
552
//				fieldNames[j++] = dataSource.getFieldName(i);
553
//
554
//		}
537 555
		for (int i=0; i < fieldCount; i++)
538 556
		{
539
			if (!dataSource.isVirtualField(i))
540
				fieldNames[j++] = dataSource.getFieldName(i);
557
			fieldNames[i] = getFieldAlias(i);
541 558

  
542 559
		}
543
        // return dataSource.getFieldNames();
560
    	
544 561
    	return fieldNames;
545 562
    }
546 563

  
......
587 604
			fieldsDescrip[i].setFieldType(type);
588 605
			fieldsDescrip[i].setFieldName(getFieldName(i));
589 606
			fieldsDescrip[i].setFieldLength(getFieldWidth(i));
590
			try{
591
				fieldsDescrip[i].setFieldAlias(getFieldAlias(i));
592
			}catch (Exception e) {
593
				fieldsDescrip[i].setFieldAlias(getFieldName(i));
594
			}
607
			fieldsDescrip[i].setFieldAlias(getFieldAlias(i));
595 608
			if (NumberUtilities.isNumeric(type))
596 609
			{
597 610
				if (!NumberUtilities.isNumericInteger(type))
......
612 625
	public void setFieldAlias(int idField, String aliasName) {
613 626
		alias[idField] = aliasName;
614 627
	}
628
	
615 629

  
616

  
617 630
	public Driver getDriver() {
618 631
		return this.dataSource.getDriver();
619 632
	}
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/layers/FLyrVect.java
374 374
    				aux = ((IClassifiedVectorLegend) legend).getClassifyingFieldNames();
375 375
    				if (aux!=null) {
376 376
    					for (int i = 0; i < aux.length; i++) {
377
    							fieldList.add(aux[i]);
377
    						// check fields exists
378
    						if (sds.getFieldIndexByName(aux[i]) == -1) {
379
    							logger.warn("Error en leyenda de " + getName() +
380
    									". El campo " + aux[i] + " no est?.");
381
    							legend = LegendFactory.createSingleSymbolLegend(getShapeType());
382
    							break; 
383
    						}
384
    						fieldList.add(aux[i]);
378 385
    					}
379 386
    				}
380 387
    			}
......
1097 1104
         * por campos que pertenec?an a la tabla y no s?lo a la capa.
1098 1105
         *
1099 1106
         */
1100
		if(r instanceof IClassifiedVectorLegend){
1101
			IClassifiedVectorLegend classifiedLegend = (IClassifiedVectorLegend)r;
1102
			String[] fieldNames = classifiedLegend.getClassifyingFieldNames();
1103

  
1104
			for (int i = 0; i < fieldNames.length; i++) {
1105
				try {
1106
					if(this.getRecordset().getFieldIndexByName(fieldNames[i]) == -1){
1107
//					if(this.getSource().getRecordset().getFieldIndexByName(fieldNames[i]) == -1){
1108
						logger.warn("Some fields of the classification of the legend doesn't belong with the source of the layer.");
1109
						if (this.legend == null){
1110
							r = LegendFactory.createSingleSymbolLegend(this.getShapeType());
1111
						} else {
1112
							return;
1113
						}
1114
					}
1115
				} catch (ReadDriverException e1) {
1116
					throw new LegendLayerException(getName(),e1);
1117
				}
1118
			}
1119
		}
1107
//		if(r instanceof IClassifiedVectorLegend){
1108
//			IClassifiedVectorLegend classifiedLegend = (IClassifiedVectorLegend)r;
1109
//			String[] fieldNames = classifiedLegend.getClassifyingFieldNames();
1110
//
1111
//			for (int i = 0; i < fieldNames.length; i++) {
1112
//				try {
1113
//					if(this.getRecordset().getFieldIndexByName(fieldNames[i]) == -1){
1114
////					if(this.getSource().getRecordset().getFieldIndexByName(fieldNames[i]) == -1){
1115
//						logger.warn("Some fields of the classification of the legend doesn't belong with the source of the layer.");
1116
//						if (this.legend == null){
1117
//							r = LegendFactory.createSingleSymbolLegend(this.getShapeType());
1118
//						} else {
1119
//							return;
1120
//						}
1121
//					}
1122
//				} catch (ReadDriverException e1) {
1123
//					throw new LegendLayerException(getName(),e1);
1124
//				}
1125
//			}
1126
//		}
1120 1127
		/* Fin del parche */
1121 1128

  
1122 1129
		legend = r;
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/layers/layerOperations/VectorialXMLItem.java
8 8

  
9 9
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
10 10
import com.hardcode.gdbms.engine.data.DataSource;
11
import com.iver.cit.gvsig.fmap.drivers.FieldDescription;
11 12
import com.iver.cit.gvsig.fmap.layers.FLayer;
13
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
12 14

  
13 15

  
14 16
public class VectorialXMLItem implements XMLItem {
......
32 34
		handler.startElement("", "", ((FLayer) layer).getName(), aii);
33 35
		try {
34 36

  
35
			DataSource ds = ((AlphanumericData) layer).getRecordset();
37
			SelectableDataSource ds = ((AlphanumericData) layer).getRecordset();		
36 38
			ds.start();
39
			FieldDescription[] fields = ds.getFieldsDescription();
37 40

  
38 41
			for (int j = bitset.nextSetBit(0); j >= 0; j = bitset
39 42
					.nextSetBit(j + 1)) {
40 43
				AttributesImpl ai = new AttributesImpl();
41 44

  
42 45
				for (int k = 0; k < ds.getFieldCount(); k++) {
43
					ai.addAttribute("", ds.getFieldName(k), ds.getFieldName(k),
46
					System.out.println("fieldName:" + ds.getFieldName(k) + " fieldAlias:" + fields[k].getFieldAlias());
47
					ai.addAttribute("", ds.getFieldAlias(k), ds.getFieldAlias(k),
44 48
							"xs:string", ds.getFieldValue(j, k).toString());
45 49
				}
46 50
				handler.startElement("", "", String.valueOf(j), ai);
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/rendering/AbstractIntervalLegend.java
213 213
		String[] fieldNames = getClassifyingFieldNames();
214 214

  
215 215

  
216
		for (int i = 0; i < recordSet.getFieldCount(); i++) {
217
			String nomAux = recordSet.getFieldName(i).trim();
216
		idField = recordSet.getFieldIndexByName(fieldNames[0]);
218 217

  
219
			if (fieldNames[0].compareToIgnoreCase(nomAux) == 0) {
220
				idField = i;
221

  
222
				break;
223
			}
224
		}
225

  
218
		
226 219
		if (idField == -1) {
227 220
			logger.error("Campo no reconocido " + fieldNames);
228 221

  
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/rendering/styling/labeling/AttrInTableLabelingStrategy.java
119 119
				FBitSet bs = layer.queryByRect(viewPort.getAdjustedExtent());
120 120

  
121 121
				ReadableVectorial source = layer.getSource();
122
				SelectableDataSource recordSet = source.getRecordset();
122
				SelectableDataSource recordSet = layer.getRecordset();
123 123
				boolean reproject=layer.getProjection()!=null && !layer.getProjection().getAbrev().equals(
124 124
						layer.getMapContext().getViewPort().getProjection().getAbrev()) &&
125 125
						(layer.getCoordTrans()!=null);
126
				
127
				
128
				if ((idTextField == -1) || (idTextField >= recordSet.getFieldCount())) {
129
					System.err.println("Ha habido un error. Se ha perdido el campo de etiquetado. Probablemente por quitar un join o edici?n externa.");
130
					return;
131
				}
132

  
126 133
				for(int i=bs.nextSetBit(0); i>=0 && !cancel.isCanceled(); i=bs.nextSetBit(i+1)) {
127 134
					Value[] vv = recordSet.getRow(i);
128 135
					double size;
......
298 305

  
299 306
	public String getTextField() throws ReadDriverException {
300 307
		if (idTextField == -1) return null;
301
		return ((SelectableDataSource) layer.getRecordset())
302
				.getFieldName(idTextField);
308
		try {
309
			String fieldName = ((SelectableDataSource) layer.getRecordset()).getFieldAlias(idTextField); 
310
			return fieldName;
311
		}
312
		catch (ArrayIndexOutOfBoundsException e) {
313
			// Probablmente hemos quitado un join y la leyenda se basaba en un campo de la segunda tabla
314
			e.printStackTrace();
315
			return null;
316
		}
303 317
	}
304 318

  
305 319
	public int getTextFieldId() {
......
313 327
	public String getHeightField() throws ReadDriverException {
314 328
		if (idHeightField == -1) return null;
315 329
		return ((SelectableDataSource) layer.getRecordset())
316
				.getFieldName(idHeightField);
330
				.getFieldAlias(idHeightField);
317 331
	}
318 332

  
319 333
	public int getHeightFieldId() {
......
327 341
	public String getColorField() throws ReadDriverException {
328 342
		if (idColorField == -1) return null;
329 343
		return ((SelectableDataSource) layer.getRecordset())
330
				.getFieldName(idColorField);
344
				.getFieldAlias(idColorField);
331 345
	}
332 346

  
333 347
	public int getColorFieldId() {

Also available in: Unified diff