Revision 6212

View differences:

trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/DefaultRow.java
100 100
	public void setID(String ID) {
101 101
		id = ID;
102 102
	}
103

  
104
	public void setAttributes(Value[] att) {
105
		this.attributes = att;
106
	}
103 107
    
104 108
}
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/IRow.java
16 16
	public Value getAttribute(int fieldIndex);
17 17

  
18 18
	public Value[] getAttributes();
19
	
20
	public void setAttributes(Value[] att);
19 21

  
20 22
	public IRow cloneRow();
21 23
	
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/FieldDescription.java
43 43
 */
44 44
package com.iver.cit.gvsig.fmap.drivers;
45 45

  
46
import com.hardcode.gdbms.engine.values.NullValue;
47
import com.hardcode.gdbms.engine.values.Value;
48

  
46 49
public class FieldDescription {
47 50
    /**
48 51
     * Internal field name.
......
50 53
    private String fieldName;
51 54
    private String fieldAlias;
52 55
    private int fieldType;
56
    private Value defaultValue = new NullValue();
53 57
    /**
54 58
     * En campos num?ricos, numero de d?gitos a la izquierda del punto
55 59
     * En campos de texto, numero de caracteres.
......
135 139
		return resul;
136 140
	}
137 141

  
142
	public Value getDefaultValue() {
143
		return defaultValue;
144
	}
145

  
146
	public void setDefaultValue(Value defaultValue) {
147
		this.defaultValue = defaultValue;
148
	}
149

  
138 150
}
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/edition/EditableAdapter.java
2 2

  
3 3
import java.io.IOException;
4 4
import java.util.ArrayList;
5
import java.util.Collection;
5 6
import java.util.HashMap;
7
import java.util.Hashtable;
8
import java.util.Iterator;
9
import java.util.TreeMap;
6 10

  
11
import sun.print.PSPrinterJob.PluginPrinter;
12

  
7 13
import com.hardcode.driverManager.Driver;
8 14
import com.hardcode.driverManager.DriverLoadException;
9 15
import com.hardcode.gdbms.engine.data.DataSourceFactory;
......
12 18
import com.hardcode.gdbms.engine.data.driver.ObjectDriver;
13 19
import com.hardcode.gdbms.engine.data.edition.DataWare;
14 20
import com.hardcode.gdbms.engine.values.Value;
21
import com.hardcode.gdbms.engine.values.ValueFactory;
15 22
import com.iver.cit.gvsig.fmap.MapControl.CancelDraw;
16 23
import com.iver.cit.gvsig.fmap.core.DefaultRow;
17 24
import com.iver.cit.gvsig.fmap.core.IRow;
18 25
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
26
import com.iver.cit.gvsig.fmap.drivers.FieldDescription;
19 27
import com.iver.cit.gvsig.fmap.drivers.ITableDefinition;
20 28
import com.iver.cit.gvsig.fmap.drivers.TableDefinition;
29
import com.iver.cit.gvsig.fmap.edition.commands.AddFieldCommand;
21 30
import com.iver.cit.gvsig.fmap.edition.commands.AddRowCommand;
22 31
import com.iver.cit.gvsig.fmap.edition.commands.Command;
23 32
import com.iver.cit.gvsig.fmap.edition.commands.CommandCollection;
24 33
import com.iver.cit.gvsig.fmap.edition.commands.CommandRecord;
25 34
import com.iver.cit.gvsig.fmap.edition.commands.MemoryCommandRecord;
26 35
import com.iver.cit.gvsig.fmap.edition.commands.ModifyRowCommand;
36
import com.iver.cit.gvsig.fmap.edition.commands.RemoveFieldCommand;
27 37
import com.iver.cit.gvsig.fmap.edition.commands.RemoveRowCommand;
38
import com.iver.cit.gvsig.fmap.edition.commands.RenameFieldCommand;
39
import com.iver.cit.gvsig.fmap.edition.fieldmanagers.AbstractFieldManager;
28 40
import com.iver.cit.gvsig.fmap.edition.rules.IRule;
29 41
import com.iver.cit.gvsig.fmap.layers.FBitSet;
30 42
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
......
33 45

  
34 46
/**
35 47
 * DOCUMENT ME!
36
 *
48
 * 
37 49
 * @author Vicente Caballero Navarro
38 50
 */
39 51
public class EditableAdapter implements IEditableSource, IWriteable {
......
44 56
	protected FBitSet delRows = new FBitSet();
45 57

  
46 58
	private CommandRecord cr;
59

  
47 60
	protected IWriter writer;
48 61

  
49 62
	/**
......
54 67

  
55 68
	private CommandCollection commands = null;
56 69

  
70
	protected ArrayList listFields = new ArrayList();
71

  
72
	protected ArrayList listInternalFields = new ArrayList();
73

  
74
	/**
75
	 * La clave ser? el fieldIndex. Para buscar si un value de una row ha de ser
76
	 * rellenado con defaultValue o con lo que venga del expansion file,
77
	 * miraremos si existe en este hash. Si existe, usamos el value del
78
	 * expansion file. Si no existe, usamos el defaultValue del campo busc?ndolo
79
	 * en la lista internalFields. Por cierto, en listInternalFields NO se
80
	 * borran campos. Solo se marcan como borrados.
81
	 */
82
	protected TreeMap actualFields; // la clave ser? el fieldIndex.
83

  
84
	protected class MyFieldManager extends AbstractFieldManager {
85

  
86
		public boolean alterTable() throws EditionException {
87
			return getFieldManager().alterTable();
88
		}
89

  
90
		public void addField(FieldDescription fieldDesc) {
91
			super.addField(fieldDesc);
92
		}
93

  
94
		public FieldDescription removeField(String fieldName) {
95
			// TODO Auto-generated method stub
96
			return super.removeField(fieldName);
97
		}
98

  
99
		public void renameField(String antName, String newName) {
100
			// TODO Auto-generated method stub
101
			super.renameField(antName, newName);
102
		}
103

  
104
	}
105

  
57 106
	/*
58 107
	 * Establece una relaci?n entre los ?ndices de las geometr?as en el
59 108
	 * EditableFeatureSource y los ?ndices en el fichero de expansi?n FJP:
......
85 134

  
86 135
	private ArrayList rules = new ArrayList();
87 136

  
137
	protected int actualIndexFields;
138

  
88 139
	/**
89 140
	 * Crea un nuevo EditableAdapter.
90 141
	 */
91 142
	public EditableAdapter() {
92
		expansionFile = new MemoryExpansionFile();
143
		expansionFile = new MemoryExpansionFile(this);
93 144
		cr = new MemoryCommandRecord();
94 145
	}
95 146

  
96 147
	/**
97 148
	 * DOCUMENT ME!
98
	 *
149
	 * 
99 150
	 * @param ds
100 151
	 *            DOCUMENT ME!
152
	 * @throws DriverException 
101 153
	 */
102
	public void setOriginalDataSource(SelectableDataSource ds) {
154
	public void setOriginalDataSource(SelectableDataSource ds) throws DriverException {
103 155
		this.ods = ds;
156
		FieldDescription[] fields = ds.getFieldsDescription();
157
		actualFields = new TreeMap();
158
		for (int i=0; i < fields.length; i++)
159
		{
160
			InternalField field = new InternalField(fields[i], InternalField.ORIGINAL, new Integer(i));
161
			listFields.add(field);
162
			actualFields.put(field.getFieldId(), field);
163
		}
164
		fieldsChanged();
165
		
104 166
	}
105 167

  
168
	private void fieldsChanged() {
169
		listInternalFields.add(actualFields);
170
		actualIndexFields = listInternalFields.size()-1;
171
	}
172

  
106 173
	/**
107 174
	 * DOCUMENT ME!
108
	 *
175
	 * 
109 176
	 * @throws EditionException
110 177
	 *             DOCUMENT ME!
111 178
	 */
112 179
	public void startEdition(int sourceType) throws EditionException {
113 180
		isEditing = true;
114 181
		// Obtenemos el driver y vemos si implementa IWriter.
115
		/* DataWare dataWare = ods.getDataWare(DataSourceFactory.DATA_WARE_DIRECT_MODE);
116
		dataWare.get */
182
		/*
183
		 * DataWare dataWare =
184
		 * ods.getDataWare(DataSourceFactory.DATA_WARE_DIRECT_MODE);
185
		 * dataWare.get
186
		 */
117 187
		Driver drv = ods.getDriver();
118
		if (drv instanceof IWriteable)
119
		{
188
		if (drv instanceof IWriteable) {
120 189
			setWriter(((IWriteable) drv).getWriter());
121 190
		}
122 191

  
123 192
		fireStartEditionEvent(sourceType);
124 193
	}
125 194

  
126

  
127 195
	/**
128 196
	 * Se ejecuta preProcess() del IWriter, luego se itera por los registros
129 197
	 * borrados por si el IWriter los quiere borrar (solo ser? necesario cuando
130 198
	 * escribimos sobre la misma tabla) y luego se itera por los nuevos
131 199
	 * registros llamando a process con el registro correcto. (A?adidos,
132 200
	 * modificados). Para finalizar, se ejecuta PostProcess
133
	 *
201
	 * 
134 202
	 * @param writer
135 203
	 *            IWriter que recibir? las llamadas.
136
	 *
204
	 * 
137 205
	 * @throws EditionException
138 206
	 *             DOCUMENT ME!
139 207
	 */
140
	public void stopEdition(IWriter writer, int sourceType) throws EditionException {
208
	public void stopEdition(IWriter writer, int sourceType)
209
			throws EditionException {
141 210

  
211
		saveEdits(writer, sourceType);
212
		fireStopEditionEvent(sourceType);
213
	}
214

  
215
	public void saveEdits(IWriter writer, int sourceType)
216
			throws EditionException {
142 217
		writer.preProcess();
143 218

  
144 219
		try {
......
147 222
			// Cuando se genere un tema nuevo, no se les debe hacer caso
148 223
			// a estos registros
149 224

  
150
			for (int i = delRows.nextSetBit(0); i >= 0; i = delRows.nextSetBit(i + 1)) {
225
			for (int i = delRows.nextSetBit(0); i >= 0; i = delRows
226
					.nextSetBit(i + 1)) {
151 227
				int calculatedIndex = i;
152 228
				Integer integer = new Integer(calculatedIndex);
153 229
				// Si no est? en el fichero de expansi?n, es de los originales
......
165 241
					IRowEdited rowFromExpansion = expansionFile.getRow(num);
166 242
					// ?Habr?a que hacer aqu? setID(index + "")?
167 243
					edRow = new DefaultRowEdited(rowFromExpansion
168
							.getLinkedRow().cloneRow(), DefaultRowEdited.STATUS_DELETED
169
							, calculatedIndex);
244
							.getLinkedRow().cloneRow(),
245
							DefaultRowEdited.STATUS_DELETED, calculatedIndex);
170 246
					writer.process(edRow);
171 247
				}
172 248

  
......
196 272
			throw new EditionException(e);
197 273
		}
198 274

  
199
		fireStopEditionEvent(sourceType);
200 275
	}
201 276

  
202 277
	/**
203 278
	 * DOCUMENT ME!
204
	 *
279
	 * 
205 280
	 * @throws IOException
206 281
	 *             DOCUMENT ME!
207 282
	 */
......
213 288

  
214 289
	/*
215 290
	 * (non-Javadoc)
216
	 *
291
	 * 
217 292
	 * @see com.iver.cit.gvsig.fmap.edition.IEditableSource#getRow(int)
218 293
	 */
219 294
	public IRowEdited getRow(int index) throws DriverIOException, IOException {
......
250 325

  
251 326
	/**
252 327
	 * DOCUMENT ME!
253
	 *
328
	 * 
254 329
	 * @return DOCUMENT ME!
255
	 *
330
	 * 
256 331
	 * @throws DriverIOException
257 332
	 *             DOCUMENT ME!
258 333
	 * @throws IOException
......
261 336
	public int getRowCount() throws DriverIOException, IOException {
262 337
		try {
263 338
			return (int) (ods.getRowCount() + numAdd) - delRows.cardinality();// -
264
																				// expansionFile.getInvalidRows().cardinality();
339
			// expansionFile.getInvalidRows().cardinality();
265 340
		} catch (DriverException e) {
266 341
			throw new DriverIOException(e);
267 342
		}
268 343

  
269 344
	}
270 345

  
271
	/* (non-Javadoc)
272
	 * @see com.iver.cit.gvsig.fmap.edition.IEditableSource#addRow(com.iver.cit.gvsig.fmap.core.IRow, java.lang.String)
346
	/*
347
	 * (non-Javadoc)
348
	 * 
349
	 * @see com.iver.cit.gvsig.fmap.edition.IEditableSource#addRow(com.iver.cit.gvsig.fmap.core.IRow,
350
	 *      java.lang.String)
273 351
	 */
274
	public int addRow(IRow row, String descrip, int sourceType) throws DriverIOException,
275
			IOException {
352
	public int addRow(IRow row, String descrip, int sourceType)
353
			throws DriverIOException, IOException {
276 354

  
277 355
		try {
278 356
			validateRow(row);
......
282 360
		}
283 361

  
284 362
		int calculatedIndex = doAddRow(row, sourceType);
285
		Command command = new AddRowCommand(this, row, calculatedIndex, sourceType);
363
		Command command = new AddRowCommand(this, row, calculatedIndex,
364
				sourceType);
286 365
		command.setDescription(descrip);
287 366
		if (complex) {
288 367
			commands.add(command);
......
293 372
		return calculatedIndex;
294 373
	}
295 374

  
296

  
297

  
298 375
	/**
299 376
	 * DOCUMENT ME!
300
	 *
377
	 * 
301 378
	 * @throws DriverIOException
302 379
	 *             DOCUMENT ME!
303 380
	 * @throws IOException
......
312 389

  
313 390
	/**
314 391
	 * DOCUMENT ME!
315
	 *
392
	 * 
316 393
	 * @throws DriverIOException
317 394
	 *             DOCUMENT ME!
318 395
	 * @throws IOException
......
325 402
		}
326 403
	}
327 404

  
328
		/*
405
	/*
329 406
	 * (non-Javadoc)
330
	 *
407
	 * 
331 408
	 * @see com.iver.cit.gvsig.fmap.edition.IEditableSource#removeRow(int)
332 409
	 */
333
	public void removeRow(int index, String descrip, int sourceType) throws IOException,
334
			DriverIOException {
410
	public void removeRow(int index, String descrip, int sourceType)
411
			throws IOException, DriverIOException {
335 412

  
336 413
		int calculatedIndex = getCalculatedIndex(index);
337
		Command command = new RemoveRowCommand(this, calculatedIndex, sourceType);
414
		Command command = new RemoveRowCommand(this, calculatedIndex,
415
				sourceType);
338 416
		command.setDescription(descrip);
339 417
		if (complex) {
340 418
			commands.add(command);
......
347 425

  
348 426
	/*
349 427
	 * (non-Javadoc)
350
	 *
428
	 * 
351 429
	 * @see com.iver.cit.gvsig.fmap.edition.IEditableSource#modifyRow(int,
352 430
	 *      com.iver.cit.gvsig.fmap.core.IRow)
353 431
	 */
......
363 441

  
364 442
		int calculatedIndex = getCalculatedIndex(index);
365 443
		int pos = doModifyRow(calculatedIndex, row, sourceType);
366
		Command command = new ModifyRowCommand(this, calculatedIndex, pos, row,sourceType);
444
		Command command = new ModifyRowCommand(this, calculatedIndex, pos, row,
445
				sourceType);
367 446
		command.setDescription(descrip);
368 447
		if (complex) {
369 448
			commands.add(command);
......
391 470

  
392 471
	/**
393 472
	 * DOCUMENT ME!
394
	 *
473
	 * 
395 474
	 * @throws IOException
396 475
	 *             DOCUMENT ME!
397 476
	 * @throws DriverIOException
398 477
	 *             DOCUMENT ME!
399 478
	 */
400
	public void endComplexRow(String description) throws IOException, DriverIOException {
479
	public void endComplexRow(String description) throws IOException,
480
			DriverIOException {
401 481
		commands.setDescription(description);
402 482
		cr.pushCommand(commands);
403 483
		complex = false;
......
409 489
	 * fuera una modificaci?n de una geometr?a que estuviese en el fichero de
410 490
	 * expansi?n antes de ser modificada y se pone el puntero de escritura del
411 491
	 * expansion file a justo despues de la penultima geometr?a
412
	 *
492
	 * 
413 493
	 * @param geometryIndex
414 494
	 *            ?ndice de la geometr?a que se quiere deshacer su modificaci?n
415 495
	 * @param previousExpansionFileIndex
......
417 497
	 *            vale -1 quiere decir que es una modificaci?n de una geometr?a
418 498
	 *            original y por tanto no hay que actualizar el mapa de indices
419 499
	 *            sino eliminar su entrada.
420
	 *
500
	 * 
421 501
	 * @throws IOException
422 502
	 * @throws DriverIOException
423 503
	 */
424
	public void undoModifyRow(int geometryIndex, int previousExpansionFileIndex, int sourceType)
425
			throws IOException, DriverIOException {
504
	public void undoModifyRow(int geometryIndex,
505
			int previousExpansionFileIndex, int sourceType) throws IOException,
506
			DriverIOException {
426 507

  
427 508
		if (previousExpansionFileIndex == -1) {
428
			DefaultRowEdited edRow=null;
509
			DefaultRowEdited edRow = null;
429 510
			try {
430 511
				edRow = new DefaultRowEdited(new DefaultRow(ods
431 512
						.getRow(geometryIndex)),
432
						DefaultRowEdited.STATUS_ORIGINAL,geometryIndex);
513
						DefaultRowEdited.STATUS_ORIGINAL, geometryIndex);
433 514
			} catch (DriverException e) {
434 515
				e.printStackTrace();
435 516
			}
436
			boolean cancel = fireBeforeModifyRow(edRow,geometryIndex,sourceType);
517
			boolean cancel = fireBeforeModifyRow(edRow, geometryIndex,
518
					sourceType);
437 519
			if (cancel)
438 520
				return;
439 521
			// Se elimina de las relaciones y del fichero de expansi?n
440 522
			relations.remove(new Integer(geometryIndex));
441 523
			expansionFile.deleteLastRow();
442 524
		} else {
443
			boolean cancel = fireBeforeModifyRow(expansionFile.getRow(previousExpansionFileIndex),geometryIndex,sourceType);
525
			boolean cancel = fireBeforeModifyRow(expansionFile
526
					.getRow(previousExpansionFileIndex), geometryIndex,
527
					sourceType);
444 528
			if (cancel)
445 529
				return;
446 530
			// Se actualiza la relaci?n de ?ndices
447 531
			relations.put(new Integer(geometryIndex), new Integer(
448 532
					previousExpansionFileIndex));
449 533
		}
450
		fireAfterModifyRow(geometryIndex,sourceType);
534
		fireAfterModifyRow(geometryIndex, sourceType);
451 535
	}
452 536

  
453 537
	/**
......
455 539
	 * se marca como eliminada (haya sido modificada o no). Si es una geometr?a
456 540
	 * a?adida posteriormente se invalida en el fichero de expansi?n, para que
457 541
	 * una futura compactaci?n termine con ella.
458
	 *
542
	 * 
459 543
	 * @param index
460 544
	 *            ?ndice de la geometr?a.
461
	 *
545
	 * 
462 546
	 * @throws DriverIOException
463 547
	 * @throws IOException
464 548
	 */
465
	public IRow doRemoveRow(int index, int sourceType) throws DriverIOException, IOException {
549
	public IRow doRemoveRow(int index, int sourceType)
550
			throws DriverIOException, IOException {
466 551
		boolean cancel = fireBeforeRemoveRow(index, sourceType);
467 552
		if (cancel)
468 553
			return null;
......
482 567
	 * fichero de expansi?n (por ser nueva o original pero modificada) se invoca
483 568
	 * el m?todo modifyGeometry y se actualiza el ?ndice de la geometria en el
484 569
	 * fichero.
485
	 *
570
	 * 
486 571
	 * @param index
487 572
	 *            DOCUMENT ME!
488 573
	 * @param feat
489 574
	 *            DOCUMENT ME!
490
	 *
575
	 * 
491 576
	 * @return DOCUMENT ME!
492
	 *
577
	 * 
493 578
	 * @throws IOException
494 579
	 * @throws DriverIOException
495 580
	 */
496
	public int doModifyRow(int index, IRow feat, int sourceType) throws IOException,
497
			DriverIOException {
498
		boolean cancel = fireBeforeModifyRow(feat,index, sourceType);
581
	public int doModifyRow(int index, IRow feat, int sourceType)
582
			throws IOException, DriverIOException {
583
		boolean cancel = fireBeforeModifyRow(feat, index, sourceType);
499 584
		if (cancel)
500 585
			return -1;
501 586

  
......
504 589
		System.err.println("Modifica una Row en la posici?n: " + index);
505 590
		// Si la geometr?a no ha sido modificada
506 591
		if (!relations.containsKey(integer)) {
507
			int expansionIndex = expansionFile.addRow(feat, IRowEdited.STATUS_MODIFIED);
592
			int expansionIndex = expansionFile.addRow(feat,
593
					IRowEdited.STATUS_MODIFIED, actualIndexFields);
508 594
			relations.put(integer, new Integer(expansionIndex));
509 595
		} else {
510 596
			// Obtenemos el ?ndice en el fichero de expansi?n
......
516 602
			 * fichero de expansi?n en el que se encuentra la geometr?a
517 603
			 * modificada
518 604
			 */
519
			num = expansionFile.modifyRow(num, feat);
605
			num = expansionFile.modifyRow(num, feat, actualIndexFields);
520 606

  
521 607
			/*
522 608
			 * Actualiza la relaci?n del ?ndice de la geometr?a al ?ndice en el
......
531 617
	/**
532 618
	 * A?ade una geometria al fichero de expansi?n y guarda la correspondencia
533 619
	 * en la tabla relations.
534
	 *
620
	 * 
535 621
	 * @param feat
536 622
	 *            geometr?a a guardar.
537
	 *
623
	 * 
538 624
	 * @return calculatedIndex
539
	 *
625
	 * 
540 626
	 * @throws DriverIOException
541 627
	 * @throws IOException
542 628
	 */
543
	public int doAddRow(IRow feat,int sourceType) throws DriverIOException, IOException {
629
	public int doAddRow(IRow feat, int sourceType) throws DriverIOException,
630
			IOException {
544 631
		boolean cancel = fireBeforeRowAdded(sourceType);
545 632
		if (cancel)
546 633
			return -1;
......
556 643
			throw new DriverIOException(e);
557 644
		}
558 645

  
559
		int pos = expansionFile.addRow(feat, IRowEdited.STATUS_ADDED);
646
		int pos = expansionFile.addRow(feat, IRowEdited.STATUS_ADDED, actualIndexFields);
560 647
		relations.put(new Integer(calculatedIndex), new Integer(pos));
561 648
		numAdd++;
562 649
		System.err.println("A?ade una Row en la posici?n: " + calculatedIndex);
......
567 654
	/**
568 655
	 * Se desmarca como invalidada en el fichero de expansion o como eliminada
569 656
	 * en el fichero original
570
	 *
657
	 * 
571 658
	 * @param index
572 659
	 *            DOCUMENT ME!
573
	 *
660
	 * 
574 661
	 * @throws IOException
575 662
	 * @throws DriverIOException
576 663
	 */
577
	public void undoRemoveRow(int index, int sourceType) throws IOException, DriverIOException {
664
	public void undoRemoveRow(int index, int sourceType) throws IOException,
665
			DriverIOException {
578 666
		boolean cancel = fireBeforeRowAdded(sourceType);
579 667
		if (cancel)
580 668
			return;
......
586 674
	 * Se elimina del final del fichero de expansi?n poniendo el puntero de
587 675
	 * escritura apuntando al final de la pen?ltima geometr?a. Deber? quitar la
588 676
	 * relaci?n del mapa de relaciones
589
	 *
677
	 * 
590 678
	 * @param index
591 679
	 *            ?ndice de la geometr?a que se a?adi?
592
	 *
680
	 * 
593 681
	 * @throws DriverIOException
594 682
	 * @throws IOException
595 683
	 */
596
	public void undoAddRow(int calculatedIndex,int sourceType) throws DriverIOException,
597
			IOException {
598
		boolean cancel = fireBeforeRemoveRow(calculatedIndex,sourceType);
684
	public void undoAddRow(int calculatedIndex, int sourceType)
685
			throws DriverIOException, IOException {
686
		boolean cancel = fireBeforeRemoveRow(calculatedIndex, sourceType);
599 687
		if (cancel)
600 688
			return;
601 689
		expansionFile.deleteLastRow();
602 690
		relations.remove(new Integer(calculatedIndex));
603 691
		numAdd--;
604
		fireAfterRemoveRow(calculatedIndex,sourceType);
692
		fireAfterRemoveRow(calculatedIndex, sourceType);
605 693
	}
606 694

  
607 695
	/*
608 696
	 * (non-Javadoc)
609
	 *
697
	 * 
610 698
	 * @see com.iver.cit.gvsig.fmap.layers.VectorialAdapter#getRecordset()
611 699
	 */
612 700
	public SelectableDataSource getRecordset() throws DriverLoadException {
......
634 722
		}
635 723
	}
636 724

  
637
	/**
638
	 * DOCUMENT ME!
639
	 *
640
	 * @param sds
641
	 *            DOCUMENT ME!
642
	 */
643
	public void setRecordSet(SelectableDataSource sds) {
644
		this.ods = sds;
645
	}
646 725

  
647 726
	/**
648 727
	 * DOCUMENT ME!
649
	 *
728
	 * 
650 729
	 * @return
651 730
	 */
652 731
	public FBitSet getSelection() {
......
669 748

  
670 749
	/**
671 750
	 * DOCUMENT ME!
672
	 *
751
	 * 
673 752
	 * @return DOCUMENT ME!
674 753
	 */
675 754
	public boolean isEditing() {
......
702 781

  
703 782
	/**
704 783
	 * DOCUMENT ME!
705
	 *
784
	 * 
706 785
	 * @param rowIndex
707 786
	 *            DOCUMENT ME!
708
	 *
787
	 * 
709 788
	 * @return DOCUMENT ME!
710 789
	 */
711 790
	public int getCalculatedIndex(long rowIndex) {
......
734 813

  
735 814
	/**
736 815
	 * DOCUMENT ME!
737
	 *
816
	 * 
738 817
	 * @author Vicente Caballero Navarro
739 818
	 */
740 819
	private class myObjectDriver implements ObjectDriver {
741 820
		/*
742 821
		 * (non-Javadoc)
743
		 *
822
		 * 
744 823
		 * @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#getPrimaryKeys()
745 824
		 */
746 825
		public int[] getPrimaryKeys() throws DriverException {
......
755 834

  
756 835
		/*
757 836
		 * (non-Javadoc)
758
		 *
837
		 * 
759 838
		 * @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#write(com.hardcode.gdbms.engine.data.edition.DataWare)
760 839
		 */
761 840
		public void write(DataWare dataWare) throws DriverException {
......
766 845

  
767 846
		/*
768 847
		 * (non-Javadoc)
769
		 *
848
		 * 
770 849
		 * @see com.hardcode.gdbms.engine.data.driver.GDBMSDriver#setDataSourceFactory(com.hardcode.gdbms.engine.data.DataSourceFactory)
771 850
		 */
772 851
		public void setDataSourceFactory(DataSourceFactory dsf) {
......
775 854

  
776 855
		/*
777 856
		 * (non-Javadoc)
778
		 *
857
		 * 
779 858
		 * @see com.hardcode.driverManager.Driver#getName()
780 859
		 */
781 860
		public String getName() {
......
784 863

  
785 864
		/*
786 865
		 * (non-Javadoc)
787
		 *
866
		 * 
788 867
		 * @see com.hardcode.gdbms.engine.data.driver.ReadAccess#getFieldValue(long,
789 868
		 *      int)
790 869
		 */
......
831 910

  
832 911
		/*
833 912
		 * (non-Javadoc)
834
		 *
913
		 * 
835 914
		 * @see com.hardcode.gdbms.engine.data.driver.ReadAccess#getFieldCount()
836 915
		 */
837 916
		public int getFieldCount() throws DriverException {
......
841 920

  
842 921
		/*
843 922
		 * (non-Javadoc)
844
		 *
923
		 * 
845 924
		 * @see com.hardcode.gdbms.engine.data.driver.ReadAccess#getFieldName(int)
846 925
		 */
847 926
		public String getFieldName(int fieldId) throws DriverException {
......
850 929

  
851 930
		/*
852 931
		 * (non-Javadoc)
853
		 *
932
		 * 
854 933
		 * @see com.hardcode.gdbms.engine.data.driver.ReadAccess#getRowCount()
855 934
		 */
856 935
		public long getRowCount() {
857 936
			try {
858 937
				return (int) (ods.getRowCount() + numAdd)
859 938
						- delRows.cardinality();// -
860
												// expansionFile.getInvalidRows().cardinality();
939
				// expansionFile.getInvalidRows().cardinality();
861 940
			} catch (DriverException e) {
862 941
				// TODO Auto-generated catch block
863 942
				e.printStackTrace();
......
868 947

  
869 948
		/*
870 949
		 * (non-Javadoc)
871
		 *
950
		 * 
872 951
		 * @see com.hardcode.gdbms.engine.data.driver.ReadAccess#getFieldType(int)
873 952
		 */
874 953
		public int getFieldType(int i) throws DriverException {
......
884 963
		return cr;
885 964
	}
886 965

  
887
	protected void fireAfterRemoveRow(int index,int sourceType) {
888
		AfterRowEditEvent event = new AfterRowEditEvent(this, index, EditionEvent.CHANGE_TYPE_DELETE, sourceType);
889
		for (int i=0; i < editionListeners.size(); i++)
890
		{
891
			IEditionListener listener = (IEditionListener) editionListeners.get(i);
966
	protected void fireAfterRemoveRow(int index, int sourceType) {
967
		AfterRowEditEvent event = new AfterRowEditEvent(this, index,
968
				EditionEvent.CHANGE_TYPE_DELETE, sourceType);
969
		for (int i = 0; i < editionListeners.size(); i++) {
970
			IEditionListener listener = (IEditionListener) editionListeners
971
					.get(i);
892 972
			listener.afterRowEditEvent(event);
893 973
		}
894 974

  
895 975
	}
896 976

  
897
	protected boolean fireBeforeRemoveRow(int index,int sourceType) {
977
	protected boolean fireBeforeRemoveRow(int index, int sourceType) {
898 978
		Cancel cancel = new Cancel();
899
		BeforeRowEditEvent event = new BeforeRowEditEvent(this, index, EditionEvent.CHANGE_TYPE_DELETE, cancel, sourceType);
900
		for (int i=0; i < editionListeners.size(); i++)
901
		{
902
			IEditionListener listener = (IEditionListener) editionListeners.get(i);
903
			listener.beforeRowEditEvent(null,event);
979
		BeforeRowEditEvent event = new BeforeRowEditEvent(this, index,
980
				EditionEvent.CHANGE_TYPE_DELETE, cancel, sourceType);
981
		for (int i = 0; i < editionListeners.size(); i++) {
982
			IEditionListener listener = (IEditionListener) editionListeners
983
					.get(i);
984
			listener.beforeRowEditEvent(null, event);
904 985
			if (cancel.isCanceled())
905 986
				return true;
906 987
		}
907 988
		return false;
908 989
	}
909 990

  
910
	protected void fireAfterRowAdded(int calculatedIndex,int sourceType) {
911
		AfterRowEditEvent event = new AfterRowEditEvent(this, calculatedIndex, EditionEvent.CHANGE_TYPE_ADD, sourceType);
912
		for (int i=0; i < editionListeners.size(); i++)
913
		{
914
			IEditionListener listener = (IEditionListener) editionListeners.get(i);
991
	protected void fireAfterRowAdded(int calculatedIndex, int sourceType) {
992
		AfterRowEditEvent event = new AfterRowEditEvent(this, calculatedIndex,
993
				EditionEvent.CHANGE_TYPE_ADD, sourceType);
994
		for (int i = 0; i < editionListeners.size(); i++) {
995
			IEditionListener listener = (IEditionListener) editionListeners
996
					.get(i);
915 997
			listener.afterRowEditEvent(event);
916 998
		}
917 999
	}
918 1000

  
919
	protected boolean fireBeforeRowAdded(int sourceType) throws DriverIOException, IOException {
1001
	protected boolean fireBeforeRowAdded(int sourceType)
1002
			throws DriverIOException, IOException {
920 1003
		Cancel cancel = new Cancel();
921
		BeforeRowEditEvent event = new BeforeRowEditEvent(this, getRowCount(), EditionEvent.CHANGE_TYPE_ADD, cancel, sourceType);
922
		for (int i=0; i < editionListeners.size(); i++)
923
		{
924
			IEditionListener listener = (IEditionListener) editionListeners.get(i);
925
			listener.beforeRowEditEvent(null,event);
1004
		BeforeRowEditEvent event = new BeforeRowEditEvent(this, getRowCount(),
1005
				EditionEvent.CHANGE_TYPE_ADD, cancel, sourceType);
1006
		for (int i = 0; i < editionListeners.size(); i++) {
1007
			IEditionListener listener = (IEditionListener) editionListeners
1008
					.get(i);
1009
			listener.beforeRowEditEvent(null, event);
926 1010
			if (cancel.isCanceled())
927 1011
				return true;
928 1012
		}
929 1013
		return false;
930 1014
	}
931 1015

  
932
	protected boolean fireBeforeModifyRow(IRow feat,int index, int sourceType) {
1016
	protected boolean fireBeforeModifyRow(IRow feat, int index, int sourceType) {
933 1017
		Cancel cancel = new Cancel();
934
		BeforeRowEditEvent event = new BeforeRowEditEvent(this, index, EditionEvent.CHANGE_TYPE_MODIFY, cancel,sourceType);
935
		for (int i=0; i < editionListeners.size(); i++)
936
		{
937
			IEditionListener listener = (IEditionListener) editionListeners.get(i);
1018
		BeforeRowEditEvent event = new BeforeRowEditEvent(this, index,
1019
				EditionEvent.CHANGE_TYPE_MODIFY, cancel, sourceType);
1020
		for (int i = 0; i < editionListeners.size(); i++) {
1021
			IEditionListener listener = (IEditionListener) editionListeners
1022
					.get(i);
938 1023
			listener.beforeRowEditEvent(feat, event);
939 1024
			if (cancel.isCanceled())
940 1025
				return true;
......
942 1027
		return false;
943 1028
	}
944 1029

  
945
	protected void fireAfterModifyRow(int index,int sourceType) {
946
		AfterRowEditEvent event = new AfterRowEditEvent(this, index, EditionEvent.CHANGE_TYPE_MODIFY,sourceType);
947
		for (int i=0; i < editionListeners.size(); i++)
948
		{
949
			IEditionListener listener = (IEditionListener) editionListeners.get(i);
1030
	protected void fireAfterModifyRow(int index, int sourceType) {
1031
		AfterRowEditEvent event = new AfterRowEditEvent(this, index,
1032
				EditionEvent.CHANGE_TYPE_MODIFY, sourceType);
1033
		for (int i = 0; i < editionListeners.size(); i++) {
1034
			IEditionListener listener = (IEditionListener) editionListeners
1035
					.get(i);
950 1036
			listener.afterRowEditEvent(event);
951 1037
		}
952 1038

  
953

  
954 1039
	}
955 1040

  
956 1041
	protected void fireStartEditionEvent(int sourceType) {
957
		EditionEvent ev = new EditionEvent(this, EditionEvent.START_EDITION, sourceType);
958
		for (int i=0; i < editionListeners.size(); i++)
959
		{
960
			IEditionListener listener = (IEditionListener) editionListeners.get(i);
1042
		EditionEvent ev = new EditionEvent(this, EditionEvent.START_EDITION,
1043
				sourceType);
1044
		for (int i = 0; i < editionListeners.size(); i++) {
1045
			IEditionListener listener = (IEditionListener) editionListeners
1046
					.get(i);
961 1047
			listener.processEvent(ev);
962 1048
		}
963 1049

  
964 1050
	}
965 1051

  
966 1052
	protected void fireStopEditionEvent(int sourceType) {
967
		EditionEvent ev = new EditionEvent(this, EditionEvent.STOP_EDITION, sourceType);
968
		for (int i=0; i < editionListeners.size(); i++)
969
		{
970
			IEditionListener listener = (IEditionListener) editionListeners.get(i);
1053
		EditionEvent ev = new EditionEvent(this, EditionEvent.STOP_EDITION,
1054
				sourceType);
1055
		for (int i = 0; i < editionListeners.size(); i++) {
1056
			IEditionListener listener = (IEditionListener) editionListeners
1057
					.get(i);
971 1058
			listener.processEvent(ev);
972 1059
		}
973 1060

  
974 1061
	}
975 1062

  
976 1063
	protected void fireCancelEditionEvent(int sourceType) {
977
		EditionEvent ev = new EditionEvent(this, EditionEvent.CANCEL_EDITION, sourceType);
978
		for (int i=0; i < editionListeners.size(); i++)
979
		{
980
			IEditionListener listener = (IEditionListener) editionListeners.get(i);
1064
		EditionEvent ev = new EditionEvent(this, EditionEvent.CANCEL_EDITION,
1065
				sourceType);
1066
		for (int i = 0; i < editionListeners.size(); i++) {
1067
			IEditionListener listener = (IEditionListener) editionListeners
1068
					.get(i);
981 1069
			listener.processEvent(ev);
982 1070
		}
983 1071

  
984 1072
	}
985 1073

  
986

  
987
	public void addEditionListener(IEditionListener listener){
1074
	public void addEditionListener(IEditionListener listener) {
988 1075
		if (!editionListeners.contains(listener))
989 1076
			editionListeners.add(listener);
990 1077
	}
991 1078

  
992
	public void removeEditionListener(IEditionListener listener)
993
	{
1079
	public void removeEditionListener(IEditionListener listener) {
994 1080
		editionListeners.remove(listener);
995 1081
	}
996 1082

  
......
998 1084
		return writer;
999 1085
	}
1000 1086

  
1001
	public void setWriter(IWriter writer) {
1087
	protected void setWriter(IWriter writer) {
1002 1088
		this.writer = writer;
1003 1089

  
1004 1090
	}
1005 1091

  
1006
	public ITableDefinition getTableDefinition() throws DriverLoadException, DriverException {
1092
	public ITableDefinition getTableDefinition() throws DriverLoadException,
1093
			DriverException {
1007 1094
		TableDefinition tableDef = new TableDefinition();
1008 1095
		tableDef.setFieldsDesc(getRecordset().getFieldsDescription());
1009 1096
		tableDef.setName(getRecordset().getSourceInfo().name);
......
1011 1098
	}
1012 1099

  
1013 1100
	public void validateRow(IRow row) throws EditionException {
1014
		for (int i=0; i< rules.size(); i++)
1015
		{
1101
		for (int i = 0; i < rules.size(); i++) {
1016 1102
			IRule rule = (IRule) rules.get(i);
1017 1103
			boolean bAux = rule.validate(row);
1018
			if (bAux == false)
1019
			{
1020
				EditionException ex = new EditionException("NOT follow the rule: " + rule.getDescription());
1104
			if (bAux == false) {
1105
				EditionException ex = new EditionException(
1106
						"NOT follow the rule: " + rule.getDescription());
1021 1107
				// TODO: Lanzar una RuleException con datos como el registro
1022 1108
				// que no cumple, la regla que no lo ha cumplido, etc.
1023 1109
				throw ex;
......
1032 1118
	public void setRules(ArrayList rules) {
1033 1119
		this.rules = rules;
1034 1120
	}
1035
	
1036
	private void clean() throws IOException
1037
	{
1121

  
1122
	private void clean() throws IOException {
1038 1123
		expansionFile.close();
1039 1124
		relations.clear();
1040 1125
		numAdd = 0;
1041 1126
		delRows.clear();
1042 1127
	}
1043 1128

  
1129
	/*
1130
	 * (non-Javadoc)
1131
	 * 
1132
	 * @see com.iver.cit.gvsig.fmap.edition.IEditableSource#getFieldManager()
1133
	 */
1134
	public IFieldManager getFieldManager() {
1135
		if (ods.getDriver() instanceof IFieldManager)
1136
			return (IFieldManager) ods.getDriver();
1137
		return null;
1138
	}
1139

  
1140
	/**
1141
	 * Tiene en cuenta los campos actuales para formatear una row con ellos. Le
1142
	 * pasamos los campos que hab?a en el momento en que se cre? esa row.
1143
	 * 
1144
	 * @param edRow
1145
	 * @param indexInternalFields
1146
	 * @return
1147
	 */
1148
	public IRowEdited createExternalRow(IRowEdited edRow,
1149
			int indexInternalFields) {
1150
		Value[] att = edRow.getAttributes();
1151
		TreeMap ancientFields = (TreeMap) listInternalFields
1152
				.get(indexInternalFields);
1153
		Value[] newAtt = new Value[actualFields.size()];
1154
		Collection aux = actualFields.values();
1155
		Iterator it = aux.iterator();
1156
		int i = 0;
1157
		Value val = null;
1158
		while (it.hasNext()) {
1159
			InternalField fld = (InternalField) it.next();
1160
			if (ancientFields.containsKey(fld.getFieldId())) {
1161
				InternalField ancientField = (InternalField) ancientFields
1162
						.get(fld.getFieldId());
1163
				val = att[ancientField.getFieldIndex()];
1164
			} else
1165
				val = fld.getFieldDesc().getDefaultValue();
1166
			newAtt[i] = val;
1167
		}
1168
		IRowEdited newRow = (IRowEdited) edRow.cloneRow();
1169
		newRow.setAttributes(newAtt);
1170
		return newRow;
1171
	}
1172

  
1173
	public void removeField(String fieldName) throws EditionException {
1174

  
1175
		InternalField fld = findFieldByName(fieldName);
1176
		Command command = new RemoveFieldCommand(this, fld);
1177
		if (complex) {
1178
			commands.add(command);
1179
		} else {
1180
			cr.pushCommand(command);
1181
		}
1182
		doRemoveField(fld);
1183

  
1184
	}
1185

  
1186
	private InternalField findFieldByName(String fieldName) {
1187
		Collection aux = actualFields.values();
1188
		Iterator it = aux.iterator();
1189
		while (it.hasNext()) {
1190
			InternalField fld = (InternalField) it.next();
1191
			if (fld.getFieldDesc().getFieldName().compareToIgnoreCase(fieldName) == 0)
1192
				return fld;
1193
		}
1194
		
1195
		return null;
1196
	}
1197

  
1198
	public void undoRemoveField(InternalField field) {
1199
		field.setDeleted(false);
1200
		actualFields.put(field.getFieldId(), field);
1201
		fieldsChanged();
1202
	}
1203

  
1204
	public void doRemoveField(InternalField field) {
1205
		field.setDeleted(true);
1206
		actualFields.remove(field.getFieldId());
1207
		fieldsChanged();
1208
	}
1209

  
1210
	public void renameField(String antName, String newName) throws EditionException {
1211

  
1212
		InternalField fld = findFieldByName(antName);
1213
		Command command = new RenameFieldCommand(this, fld, newName);
1214
		if (complex) {
1215
			commands.add(command);
1216
		} else {
1217
			cr.pushCommand(command);
1218
		}
1219
		doRenameField(fld, newName);
1220

  
1221
	}
1222
	
1223
	public void undoRenameField(InternalField field, String antName) {
1224
		field.getFieldDesc().setFieldAlias(antName);
1225
	}
1226

  
1227
	public void doRenameField(InternalField field, String newName) {
1228
		field.getFieldDesc().setFieldAlias(newName);
1229
	}
1230

  
1231

  
1232
	public void addField(FieldDescription field) throws EditionException {
1233

  
1234
		InternalField fld = new InternalField(field, InternalField.ADDED, new Integer(listFields.size()));
1235
		Command command = new AddFieldCommand(this, fld);
1236
		if (complex) {
1237
			commands.add(command);
1238
		} else {
1239
			cr.pushCommand(command);
1240
		}
1241
		listFields.add(fld);
1242
		doAddField(fld);
1243

  
1244
	}
1245

  
1246
	public void undoAddField(InternalField field) {
1247
		field.setDeleted(true);
1248
		field.setFieldIndex(actualFields.size());
1249
		actualFields.put(field.getFieldId(), field);
1250
		fieldsChanged();
1251
		
1252
	}
1253

  
1254
	public void doAddField(InternalField field) {
1255
		field.setDeleted(false);
1256
		actualFields.remove(field.getFieldId());
1257
		fieldsChanged();
1258
		
1259
	}
1260
	
1044 1261
}
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/edition/writers/dbf/DbfWriter.java
34 34

  
35 35
	private Object[] record;
36 36

  
37
	private ArrayList fieldCommands = new ArrayList();
38

  
37 39
	// private FLyrVect lyrVect;
38 40
	private FBitSet selection = null;
39 41

  
......
70 72
		// de las cabeceras. Luego en el postprocess los escribiremos
71 73
		// correctamente, con el fullExtent y el numero de
72 74
		// registros que tocan.
75
		alterTable();
73 76
		if (selection == null) {
74 77

  
75 78
			try {
......
89 92

  
90 93
	public void process(IRowEdited row) throws EditionException {
91 94
		IRow rowEdit = (IRow) row.getLinkedRow();
92
		System.err.println("DBFWriter: " + row.getStatus() + " numRows = " + numRows);
93
		switch (row.getStatus())
94
		{
95
		System.err.println("DBFWriter: " + row.getStatus() + " numRows = "
96
				+ numRows);
97
		switch (row.getStatus()) {
95 98
		case IRowEdited.STATUS_ADDED:
96 99
		case IRowEdited.STATUS_ORIGINAL:
97 100
		case IRowEdited.STATUS_MODIFIED:
98 101
			try {
99
				
102

  
100 103
				for (int i = 0; i < record.length; i++)
101 104
					record[i] = rowEdit.getAttribute(i);
102 105
				dbfWrite.write(record);
......
106 109
				e.printStackTrace();
107 110
				throw new EditionException(e);
108 111
			}
109
			
112

  
110 113
		}
111 114

  
112

  
113 115
	}
114 116

  
115 117
	public void postProcess() throws EditionException {
......
118 120
			dbfWrite = new DbaseFileWriterNIO(myHeader,
119 121
					(FileChannel) getWriteChannel(dbfPath));
120 122

  
121
			
122 123
		} catch (IOException e) {
123 124
			e.printStackTrace();
124 125
			throw new EditionException(e);
......
146 147
		case Types.CHAR:
147 148
		case Types.LONGVARCHAR:
148 149
			return true; // TODO: Revisar esto, porque no creo que admita
149
							// campos muy grandes
150
		// campos muy grandes
150 151

  
151 152
		}
152 153

  
......
169 170
		return originalFields;
170 171
	}
171 172

  
172
public void alterTable(FieldCommand[] fieldCommands) throws EditionException {
173
	public boolean alterTable() throws EditionException {
173 174
		ArrayList fields = new ArrayList();
174 175
		boolean bNeedRewrite = false;
175
		for (int i=0; i < fieldCommands.length; i++)
176
		{
177
			if (fieldCommands[i] instanceof AddFieldCommand)
178
			{
179
				AddFieldCommand addFC = (AddFieldCommand) fieldCommands[i];
176
		for (int i = 0; i < fieldCommands.size(); i++) {
177
			FieldCommand fc = (FieldCommand) fieldCommands.get(i);
178
			if (fc instanceof AddFieldCommand) {
179
				AddFieldCommand addFC = (AddFieldCommand) fc;
180 180
				bNeedRewrite = true;
181 181
				fields.add(addFC.getFieldDesc());
182 182
			}
183
			if (fieldCommands[i] instanceof RemoveFieldCommand)
184
			{
183
			if (fc instanceof RemoveFieldCommand) {
185 184
				bNeedRewrite = true;
186
				RemoveFieldCommand deleteFC = (RemoveFieldCommand) fieldCommands[i];
187
//				for (int j=0; j < myHeader.getNumFields(); j++)
188
//				{
189
//					if (myHeader.getFieldName(j).compareTo(deleteFC.getFieldName()) == 0)
190
//					{
191
						myHeader.removeColumn(deleteFC.getFieldName());
192
//						break;
193
//					}
194
//				}
195
				
185
				RemoveFieldCommand deleteFC = (RemoveFieldCommand) fc;
186
				// for (int j=0; j < myHeader.getNumFields(); j++)
187
				// {
188
				// if
189
				// (myHeader.getFieldName(j).compareTo(deleteFC.getFieldName())
190
				// == 0)
191
				// {
192
				myHeader.removeColumn(deleteFC.getFieldName());
193
				// break;
194
				// }
195
				// }
196

  
196 197
			}
197
			if (fieldCommands[i] instanceof RenameFieldCommand)
198
			{
199
				RenameFieldCommand renFC = (RenameFieldCommand) fieldCommands[i];
200
				for (int j=0; j < myHeader.getNumFields(); j++)
201
				{
202
					if (myHeader.getFieldName(j).compareTo(renFC.getAntName()) == 0)
203
					{
198
			if (fc instanceof RenameFieldCommand) {
199
				RenameFieldCommand renFC = (RenameFieldCommand) fc;
200
				for (int j = 0; j < myHeader.getNumFields(); j++) {
201
					if (myHeader.getFieldName(j).compareTo(renFC.getAntName()) == 0) {
204 202
						myHeader.setFieldName(j, renFC.getNewName());
205 203
						break;
206 204
					}
207 205
				}
208
			}			
209
			
206
			}
207

  
210 208
		}
211
		FieldDescription[] fieldsDesc = (FieldDescription[]) fields.toArray(new FieldDescription[0]);
212
		
209
		FieldDescription[] fieldsDesc = (FieldDescription[]) fields
210
				.toArray(new FieldDescription[0]);
211

  
213 212
		myHeader = DbaseFileHeaderNIO.createDbaseHeader(fieldsDesc);
214 213
		try {
215 214
			dbfWrite = new DbaseFileWriterNIO(myHeader,
216 215
					(FileChannel) getWriteChannel(dbfPath));
217
			if (bNeedRewrite)
218
			{
219
				int aux = (int)(Math.random() * 1000);
220
				File fTemp = new File(System.getProperty("java.io.tmpdir") + "/tmpDbf" + aux + ".dbf");
221
				
222
				// TODO: TERMINAR!!
223
				
224
			}
216
//			if (bNeedRewrite) {
217
//				int aux = (int) (Math.random() * 1000);
218
//				File fTemp = new File(System.getProperty("java.io.tmpdir")
219
//						+ "/tmpDbf" + aux + ".dbf");
220
//
221
//				// TODO: TERMINAR!!
222
//
223
//			}
225 224
		} catch (IOException e) {
226 225
			throw new EditionException(e);
227 226
		}
228
	
229
	}}
227
		return bNeedRewrite;
228
	}
229

  
230
	public void addField(FieldDescription fieldDesc) {
231
		AddFieldCommand c = new AddFieldCommand(fieldDesc);
232
		fieldCommands.add(c);
233
	}
234

  
235
	public FieldDescription removeField(String fieldName) {
236
		RemoveFieldCommand c = new RemoveFieldCommand(fieldName);
237
		FieldDescription[] act = getFields();
238
		FieldDescription found = null;
239
		for (int i=0; i < act.length; i++)
240
		{
241
			if (act[i].getFieldAlias().compareToIgnoreCase(fieldName) == 0)
242
			{
243
				found = act[i];
244
				break;
245
			}
246
		}
247
		fieldCommands.add(c);
248
		return found;
249
	}
250

  
251
	public void renameField(String antName, String newName) {
252
		RenameFieldCommand c = new RenameFieldCommand(antName, newName);
253
		fieldCommands.add(c);
254
		
255
	}
256

  
257
	public FieldDescription[] getFields() {
258
		ArrayList aux = new ArrayList();
259
		for (int i=0; i < aux.size(); i++)
260
		{
261
			aux.add(getOriginalFields()[i]);
262
		}
263
		// procesamos comandos para devolver los campos reales.
264
		for (int j=0; j < fieldCommands.size(); j++)
265
		{
266
			FieldCommand fc = (FieldCommand) fieldCommands.get(j);
267
			if (fc instanceof AddFieldCommand)
268
			{
269
				AddFieldCommand ac = (AddFieldCommand) fc;
270
				aux.add(ac.getFieldDesc());
271
			}
272
			if (fc instanceof RemoveFieldCommand)
273
			{
274
				RemoveFieldCommand rc = (RemoveFieldCommand) fc;
275
				for (int k = 0; k < aux.size(); k++) {
276
					FieldDescription fAux = (FieldDescription) aux.get(k);
277
					if (fAux.getFieldAlias().compareTo(rc.getFieldName()) == 0) {
278
						aux.remove(k);
279
						break;
280
					}
281
				}
282
			}
283
			if (fc instanceof RenameFieldCommand)
284
			{
285
				RenameFieldCommand renc = (RenameFieldCommand) fc;
286
				for (int k = 0; k < aux.size(); k++) {
287
					FieldDescription fAux = (FieldDescription) aux.get(k);
288
					if (fAux.getFieldAlias().compareTo(renc.getAntName()) == 0) {
289
						fAux.setFieldAlias(renc.getNewName());
290
						break;
291
					}
292
				}
293

  
294
			}			
295
			
296
		}
297
		return (FieldDescription[]) aux.toArray(new FieldDescription[0]);
298
	}
299

  
300
}
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/edition/InternalField.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package com.iver.cit.gvsig.fmap.edition;
42

  
43
import com.iver.cit.gvsig.fmap.drivers.FieldDescription;
44

  
45
public class InternalField {
46
	public final static int ORIGINAL = 0;
47

  
48
	public final static int DELETED = 2;
49

  
50
	public final static int ADDED = 3;
51

  
52
	private int fieldType = -1;
53

  
54
	private Integer fieldId;
55

  
56
	private boolean isDeleted = false;
57

  
58
	private FieldDescription fieldDesc = null;
59
	
60
	private int fieldIndex;
61

  
62
	public boolean isDeleted() {
63
		return isDeleted;
64
	}
65

  
66
	public void setDeleted(boolean isDeleted) {
67
		this.isDeleted = isDeleted;
68
	}
69

  
70
	public FieldDescription getFieldDesc() {
71
		return fieldDesc;
72
	}
73

  
74
	/**
75
	 * Possible values: InternalField.ORIGINAL, InternalField.DELETED, ADDED
76
	 * 
77
	 * @return
78
	 */
79
	public int getFieldType() {
80
		return fieldType;
81
	}
82

  
83
	public InternalField(FieldDescription fieldDesc, int fieldType, Integer fieldId) {
84
		this.fieldDesc = fieldDesc;		
85
		this.fieldType  =fieldType;
86
		this.fieldId = fieldId;
87
	}
88

  
89
	/**
90
	 * All fields are created and stored in fieldList. Every field has a unique
91
	 * fieldId. This fieldId is useful to find the field that was used to
92
	 * generate a row. De esta forma, si nos interesa saber si un campo actual
93
	 * es el mismo que aqu?l con el que fue generado la row correspondiente,
94
	 * miramos si coincide su fieldIndex.
95
	 * 
96
	 * @return
97
	 */
98
	public Integer getFieldId() {
99
		return fieldId;
100
	}
101

  
102
	public int getFieldIndex() {
103
		return fieldIndex;
104
	}
105

  
106
	public void setFieldIndex(int i) {
107
		fieldIndex = i;
108
		
109
	}
110

  
111
}
0 112

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff