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 |
}
|