root / branches / v10 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / edition / EditableAdapter.java @ 12132
History | View | Annotate | Download (48.4 KB)
1 | 3940 | caballero | package com.iver.cit.gvsig.fmap.edition; |
---|---|---|---|
2 | |||
3 | 4061 | caballero | import java.io.IOException; |
4 | 12132 | caballero | import java.rmi.server.UID; |
5 | 4832 | fjp | import java.util.ArrayList; |
6 | 6212 | fjp | import java.util.Collection; |
7 | 4061 | caballero | import java.util.HashMap; |
8 | 6212 | fjp | import java.util.Iterator; |
9 | import java.util.TreeMap; |
||
10 | 3940 | caballero | |
11 | 5569 | jmvivo | import com.hardcode.driverManager.Driver; |
12 | 4061 | caballero | import com.hardcode.driverManager.DriverLoadException; |
13 | 3940 | caballero | import com.hardcode.gdbms.engine.data.DataSourceFactory; |
14 | import com.hardcode.gdbms.engine.data.NoSuchTableException; |
||
15 | 9887 | fjp | import com.hardcode.gdbms.engine.data.driver.AlphanumericDBDriver; |
16 | 3940 | caballero | import com.hardcode.gdbms.engine.data.driver.DriverException; |
17 | import com.hardcode.gdbms.engine.data.driver.ObjectDriver; |
||
18 | import com.hardcode.gdbms.engine.data.edition.DataWare; |
||
19 | import com.hardcode.gdbms.engine.values.Value; |
||
20 | 4026 | caballero | import com.iver.cit.gvsig.fmap.core.DefaultRow; |
21 | 3940 | caballero | import com.iver.cit.gvsig.fmap.core.IRow; |
22 | import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
||
23 | 6212 | fjp | import com.iver.cit.gvsig.fmap.drivers.FieldDescription; |
24 | 5558 | fjp | import com.iver.cit.gvsig.fmap.drivers.ITableDefinition; |
25 | import com.iver.cit.gvsig.fmap.drivers.TableDefinition; |
||
26 | 6212 | fjp | import com.iver.cit.gvsig.fmap.edition.commands.AddFieldCommand; |
27 | 3940 | caballero | import com.iver.cit.gvsig.fmap.edition.commands.AddRowCommand; |
28 | 4120 | caballero | import com.iver.cit.gvsig.fmap.edition.commands.Command; |
29 | 3940 | caballero | import com.iver.cit.gvsig.fmap.edition.commands.CommandCollection; |
30 | import com.iver.cit.gvsig.fmap.edition.commands.CommandRecord; |
||
31 | import com.iver.cit.gvsig.fmap.edition.commands.MemoryCommandRecord; |
||
32 | import com.iver.cit.gvsig.fmap.edition.commands.ModifyRowCommand; |
||
33 | 6212 | fjp | import com.iver.cit.gvsig.fmap.edition.commands.RemoveFieldCommand; |
34 | 3940 | caballero | import com.iver.cit.gvsig.fmap.edition.commands.RemoveRowCommand; |
35 | 6212 | fjp | import com.iver.cit.gvsig.fmap.edition.commands.RenameFieldCommand; |
36 | import com.iver.cit.gvsig.fmap.edition.fieldmanagers.AbstractFieldManager; |
||
37 | 5886 | fjp | import com.iver.cit.gvsig.fmap.edition.rules.IRule; |
38 | 3940 | caballero | import com.iver.cit.gvsig.fmap.layers.FBitSet; |
39 | import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
||
40 | import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
||
41 | 4832 | fjp | import com.iver.cit.gvsig.fmap.operations.Cancel; |
42 | 3940 | caballero | |
43 | /**
|
||
44 | * DOCUMENT ME!
|
||
45 | 7272 | jaume | *
|
46 | 3940 | caballero | * @author Vicente Caballero Navarro
|
47 | */
|
||
48 | 5595 | fjp | public class EditableAdapter implements IEditableSource, IWriteable { |
49 | 4792 | fjp | protected boolean isEditing = false; |
50 | 3996 | caballero | |
51 | 4792 | fjp | private SelectableDataSource ds = null; |
52 | 3940 | caballero | |
53 | 4792 | fjp | protected FBitSet delRows = new FBitSet(); |
54 | 3940 | caballero | |
55 | 4792 | fjp | private CommandRecord cr;
|
56 | 6212 | fjp | |
57 | 5549 | fjp | protected IWriter writer;
|
58 | 3940 | caballero | |
59 | 4792 | fjp | /**
|
60 | * Flag que indica que hay que tomar las siguientes operaciones como una
|
||
61 | * operaci?n at?mica
|
||
62 | */
|
||
63 | private boolean complex = false; |
||
64 | 3940 | caballero | |
65 | 4792 | fjp | private CommandCollection commands = null; |
66 | 3940 | caballero | |
67 | 6212 | fjp | protected ArrayList listFields = new ArrayList(); |
68 | |||
69 | protected ArrayList listInternalFields = new ArrayList(); |
||
70 | 7272 | jaume | |
71 | 6483 | fjp | protected boolean bFieldsHasBeenChanged = false; |
72 | 6212 | fjp | |
73 | /**
|
||
74 | 6483 | fjp | * La clave ser? el fieldId. Para buscar si un value de una row ha de ser
|
75 | 6212 | fjp | * rellenado con defaultValue o con lo que venga del expansion file,
|
76 | * miraremos si existe en este hash. Si existe, usamos el value del
|
||
77 | * expansion file. Si no existe, usamos el defaultValue del campo busc?ndolo
|
||
78 | * en la lista internalFields. Por cierto, en listInternalFields NO se
|
||
79 | 6483 | fjp | * borran campos. Solo se van a?adiendo nuevos actualFields.
|
80 | 6212 | fjp | */
|
81 | 6483 | fjp | protected TreeMap actualFields; // la clave ser? el fieldId. |
82 | 7272 | jaume | |
83 | 6483 | fjp | protected ArrayList fastAccessFields = new ArrayList(); |
84 | 6212 | fjp | |
85 | protected class MyFieldManager extends AbstractFieldManager { |
||
86 | |||
87 | public boolean alterTable() throws EditionException { |
||
88 | return getFieldManager().alterTable();
|
||
89 | } |
||
90 | |||
91 | public void addField(FieldDescription fieldDesc) { |
||
92 | super.addField(fieldDesc);
|
||
93 | } |
||
94 | |||
95 | public FieldDescription removeField(String fieldName) { |
||
96 | // TODO Auto-generated method stub
|
||
97 | return super.removeField(fieldName); |
||
98 | } |
||
99 | |||
100 | public void renameField(String antName, String newName) { |
||
101 | // TODO Auto-generated method stub
|
||
102 | super.renameField(antName, newName);
|
||
103 | } |
||
104 | |||
105 | } |
||
106 | |||
107 | 4792 | fjp | /*
|
108 | * Establece una relaci?n entre los ?ndices de las geometr?as en el
|
||
109 | * EditableFeatureSource y los ?ndices en el fichero de expansi?n FJP:
|
||
110 | * CAMBIO: NECESITAMOS TRABAJAR CON FEATURE Y FEATUREITERATOR PARA IR
|
||
111 | * PREPARANDO EL CAMINO, GUARDAMOS EL FEATUREID (STRING) COMO CLAVE, Y COMO
|
||
112 | * VALOR, EL INDICE DENTRO DEL FICHERO DE EXPANSION (Integer). Lo de que
|
||
113 | * FeatureId sea un String es por compatibilidad con OGC. Seg?n OGC, una
|
||
114 | * Feature tiene que tener un Id string En el caso de los randomaccess,
|
||
115 | * ser?n el id de registro En los casos de base de datos espaciales, supongo
|
||
116 | * que siempre ser? num?rico tambi?n, pero lo tendremos que convertir a
|
||
117 | * string. Lo que est? claro es que NO se puede confiar nunca en que sea
|
||
118 | * algo correlativo (1, 2, 3, 4, 5, ... => FALSO!!)
|
||
119 | */
|
||
120 | protected HashMap relations = new HashMap(); |
||
121 | 3940 | caballero | |
122 | 4792 | fjp | /*
|
123 | * Fichero en el que se guardan las nuevas geometr?as, producto de adiciones
|
||
124 | * o de modificaciones
|
||
125 | */
|
||
126 | protected ExpansionFile expansionFile;
|
||
127 | 3940 | caballero | |
128 | 4792 | fjp | protected int numAdd = 0; |
129 | 3940 | caballero | |
130 | 4792 | fjp | private ObjectDriver editingDriver = new myObjectDriver(); |
131 | 3996 | caballero | |
132 | 4792 | fjp | private SelectableDataSource ods;
|
133 | 4954 | caballero | |
134 | 4832 | fjp | private ArrayList editionListeners = new ArrayList(); |
135 | 3940 | caballero | |
136 | 5886 | fjp | private ArrayList rules = new ArrayList(); |
137 | |||
138 | 6212 | fjp | protected int actualIndexFields; |
139 | |||
140 | 7272 | jaume | protected boolean isFullExtentDirty = false; |
141 | |||
142 | 10333 | caballero | private ArrayList fieldEvents=new ArrayList(); |
143 | private ArrayList rowEvents=new ArrayList(); |
||
144 | 10234 | caballero | |
145 | 4792 | fjp | /**
|
146 | * Crea un nuevo EditableAdapter.
|
||
147 | */
|
||
148 | public EditableAdapter() {
|
||
149 | 6212 | fjp | expansionFile = new MemoryExpansionFile(this); |
150 | 4792 | fjp | cr = new MemoryCommandRecord();
|
151 | } |
||
152 | 3940 | caballero | |
153 | 4792 | fjp | /**
|
154 | * DOCUMENT ME!
|
||
155 | 7272 | jaume | *
|
156 | 4792 | fjp | * @param ds
|
157 | * DOCUMENT ME!
|
||
158 | 7272 | jaume | * @throws DriverException
|
159 | 4792 | fjp | */
|
160 | 6212 | fjp | public void setOriginalDataSource(SelectableDataSource ds) throws DriverException { |
161 | 4792 | fjp | this.ods = ds;
|
162 | 6313 | fjp | initalizeFields(ds); |
163 | 6856 | fjp | Driver drv = ods.getDriver();
|
164 | if (drv instanceof IWriteable) { |
||
165 | setWriter(((IWriteable) drv).getWriter()); |
||
166 | } |
||
167 | |||
168 | 7272 | jaume | |
169 | 6313 | fjp | } |
170 | |||
171 | /**
|
||
172 | * @param ds
|
||
173 | * @throws DriverException
|
||
174 | */
|
||
175 | private void initalizeFields(SelectableDataSource ds) throws DriverException { |
||
176 | 6212 | fjp | FieldDescription[] fields = ds.getFieldsDescription();
|
177 | 6313 | fjp | listInternalFields.clear(); |
178 | 6326 | fjp | actualIndexFields = 0;
|
179 | 6212 | fjp | actualFields = new TreeMap(); |
180 | 6483 | fjp | // fastAccessFields = new ArrayList();
|
181 | 6212 | fjp | for (int i=0; i < fields.length; i++) |
182 | { |
||
183 | InternalField field = new InternalField(fields[i], InternalField.ORIGINAL, new Integer(i)); |
||
184 | listFields.add(field); |
||
185 | 6384 | fjp | // field.setFieldIndex(i);
|
186 | 6212 | fjp | actualFields.put(field.getFieldId(), field); |
187 | 6483 | fjp | // fastAccessFields.add(fields[i]);
|
188 | 6326 | fjp | System.out.println("INITIALIZEFIELDS: FIELD " + field.getFieldDesc().getFieldAlias()); |
189 | 6212 | fjp | } |
190 | 6259 | fjp | try {
|
191 | fieldsChanged(); |
||
192 | 6483 | fjp | bFieldsHasBeenChanged = false;
|
193 | 6259 | fjp | } catch (EditionException e) {
|
194 | e.printStackTrace(); |
||
195 | throw new DriverException(e); |
||
196 | } |
||
197 | 4792 | fjp | } |
198 | 3940 | caballero | |
199 | 6839 | fjp | private TreeMap deepCloneInternalFields(TreeMap col) |
200 | { |
||
201 | TreeMap clonedFields = new TreeMap(); |
||
202 | for (Iterator iter = col.values().iterator(); iter.hasNext();) { |
||
203 | InternalField fld = (InternalField) iter.next(); |
||
204 | InternalField clonedField = fld.cloneInternalField(); |
||
205 | clonedFields.put(clonedField.getFieldId(), clonedField); |
||
206 | } |
||
207 | 7272 | jaume | |
208 | 6839 | fjp | return clonedFields;
|
209 | } |
||
210 | 6259 | fjp | private void fieldsChanged() throws EditionException { |
211 | 6483 | fjp | fastAccessFields= new ArrayList(); |
212 | 6839 | fjp | int index = 0; |
213 | 6483 | fjp | for (Iterator iter = actualFields.values().iterator(); iter.hasNext();) { |
214 | InternalField fld = (InternalField) iter.next(); |
||
215 | fastAccessFields.add(fld.getFieldDesc()); |
||
216 | 6839 | fjp | fld.setFieldIndex(index++); |
217 | 6483 | fjp | } |
218 | 6384 | fjp | |
219 | 6839 | fjp | listInternalFields.add(deepCloneInternalFields(actualFields)); |
220 | 6212 | fjp | actualIndexFields = listInternalFields.size()-1;
|
221 | 6259 | fjp | try {
|
222 | 6365 | fjp | ds = null;
|
223 | 6259 | fjp | getRecordset().mapExternalFields(); |
224 | 6483 | fjp | bFieldsHasBeenChanged = true;
|
225 | 6259 | fjp | } catch (DriverLoadException e) {
|
226 | e.printStackTrace(); |
||
227 | throw new EditionException(e); |
||
228 | } catch (DriverException e) {
|
||
229 | e.printStackTrace(); |
||
230 | throw new EditionException(e); |
||
231 | } |
||
232 | 6212 | fjp | } |
233 | |||
234 | 4792 | fjp | /**
|
235 | * DOCUMENT ME!
|
||
236 | 7272 | jaume | *
|
237 | 4792 | fjp | * @throws EditionException
|
238 | * DOCUMENT ME!
|
||
239 | */
|
||
240 | 5184 | caballero | public void startEdition(int sourceType) throws EditionException { |
241 | 4792 | fjp | isEditing = true;
|
242 | 5986 | caballero | |
243 | 5184 | caballero | fireStartEditionEvent(sourceType); |
244 | 4792 | fjp | } |
245 | 3996 | caballero | |
246 | 4792 | fjp | /**
|
247 | * Se ejecuta preProcess() del IWriter, luego se itera por los registros
|
||
248 | * borrados por si el IWriter los quiere borrar (solo ser? necesario cuando
|
||
249 | * escribimos sobre la misma tabla) y luego se itera por los nuevos
|
||
250 | * registros llamando a process con el registro correcto. (A?adidos,
|
||
251 | * modificados). Para finalizar, se ejecuta PostProcess
|
||
252 | 7272 | jaume | *
|
253 | 4792 | fjp | * @param writer
|
254 | * IWriter que recibir? las llamadas.
|
||
255 | 7272 | jaume | *
|
256 | 4792 | fjp | * @throws EditionException
|
257 | * DOCUMENT ME!
|
||
258 | 7272 | jaume | *
|
259 | 4792 | fjp | */
|
260 | 6212 | fjp | public void stopEdition(IWriter writer, int sourceType) |
261 | throws EditionException {
|
||
262 | saveEdits(writer, sourceType); |
||
263 | 6227 | fjp | isEditing = false;
|
264 | 6356 | fjp | cr.clearAll(); |
265 | 6212 | fjp | fireStopEditionEvent(sourceType); |
266 | } |
||
267 | |||
268 | public void saveEdits(IWriter writer, int sourceType) |
||
269 | throws EditionException {
|
||
270 | 7272 | jaume | |
271 | 6579 | fjp | // TODO: ARREGLAR ESTO PARA QUE CUANDO HA HABIDO CAMBIOS
|
272 | // EN LOS CAMPOS, PODAMOS CAMBIAR LO QUE TOQUE (A SER POSIBLE
|
||
273 | // SIN TENER QUE REESCRIBIR TODA LA TABLA CON POSTGIS)
|
||
274 | if (bFieldsHasBeenChanged)
|
||
275 | { |
||
276 | 7272 | jaume | // Para cada campo de los originales, miramos si no est? en
|
277 | 6579 | fjp | // los actuales. Si no est?, le decimos al fieldManager
|
278 | // que lo borre. Si est?, pero le hemos cambiado el nombre
|
||
279 | // le pedimos al fieldManager que le cambie el nombre.
|
||
280 | // Luego recorremos los campos actuales para ver cuales
|
||
281 | // son nuevos, y los a?adimos.
|
||
282 | 7272 | jaume | |
283 | 6579 | fjp | TreeMap ancientFields = (TreeMap) listInternalFields |
284 | .get(0);
|
||
285 | Collection aux = ancientFields.values();
|
||
286 | Iterator it = aux.iterator();
|
||
287 | while (it.hasNext()) {
|
||
288 | InternalField fld = (InternalField) it.next(); |
||
289 | // System.err.println("fld = " + fld.getFieldDesc().getFieldAlias() + " id=" + fld.getFieldId());
|
||
290 | if (actualFields.containsKey(fld.getFieldId())) {
|
||
291 | // Es un original
|
||
292 | String f1 = fld.getFieldDesc().getFieldName();
|
||
293 | String f2 = fld.getFieldDesc().getFieldAlias();
|
||
294 | if (f1.compareTo(f2) != 0) |
||
295 | { |
||
296 | getFieldManager().renameField(f1, f2); |
||
297 | 7272 | jaume | } |
298 | 6579 | fjp | } |
299 | else
|
||
300 | { // No est?, hay que borrarlo
|
||
301 | getFieldManager().removeField(fld.getFieldDesc().getFieldAlias()); |
||
302 | } |
||
303 | } |
||
304 | Collection aux2= actualFields.values();
|
||
305 | Iterator it2 = aux2.iterator();
|
||
306 | while (it2.hasNext()) {
|
||
307 | InternalField fld = (InternalField) it2.next(); |
||
308 | // System.err.println("fld = " + fld.getFieldDesc().getFieldAlias() + " id=" + fld.getFieldId());
|
||
309 | if (!ancientFields.containsKey(fld.getFieldId())) {
|
||
310 | // Es uno a?adido
|
||
311 | getFieldManager().addField(fld.getFieldDesc()); |
||
312 | } |
||
313 | } |
||
314 | // getFieldManager().alterTable(); // Se llama dentro del preprocess()
|
||
315 | } |
||
316 | 7272 | jaume | |
317 | 4792 | fjp | writer.preProcess(); |
318 | 4368 | caballero | |
319 | 4792 | fjp | try {
|
320 | 3940 | caballero | |
321 | 4792 | fjp | // Procesamos primero los borrados.
|
322 | // Cuando se genere un tema nuevo, no se les debe hacer caso
|
||
323 | // a estos registros
|
||
324 | 3996 | caballero | |
325 | 6212 | fjp | for (int i = delRows.nextSetBit(0); i >= 0; i = delRows |
326 | .nextSetBit(i + 1)) {
|
||
327 | 4792 | fjp | int calculatedIndex = i;
|
328 | Integer integer = new Integer(calculatedIndex); |
||
329 | // Si no est? en el fichero de expansi?n, es de los originales
|
||
330 | // y hay que borrarlo
|
||
331 | DefaultRowEdited edRow = null;
|
||
332 | if (!relations.containsKey(integer)) {
|
||
333 | edRow = new DefaultRowEdited(new DefaultRow(ods |
||
334 | .getRow(calculatedIndex)), |
||
335 | DefaultRowEdited.STATUS_DELETED, calculatedIndex); |
||
336 | writer.process(edRow); |
||
337 | } else {
|
||
338 | int num = ((Integer) relations.get(integer)).intValue(); |
||
339 | 4061 | caballero | |
340 | 4792 | fjp | // return expansionFile.getRow(num);
|
341 | IRowEdited rowFromExpansion = expansionFile.getRow(num); |
||
342 | // ?Habr?a que hacer aqu? setID(index + "")?
|
||
343 | edRow = new DefaultRowEdited(rowFromExpansion
|
||
344 | 6212 | fjp | .getLinkedRow().cloneRow(), |
345 | DefaultRowEdited.STATUS_DELETED, calculatedIndex); |
||
346 | 4792 | fjp | writer.process(edRow); |
347 | } |
||
348 | 3940 | caballero | |
349 | 4792 | fjp | } |
350 | 3940 | caballero | |
351 | 4792 | fjp | int rowCount = getRowCount();
|
352 | 8913 | fjp | if (writer.isWriteAll())
|
353 | { |
||
354 | for (int i = 0; i < rowCount; i++) { |
||
355 | IRowEdited rowEdited = getRow(i); |
||
356 | 10333 | caballero | |
357 | 8913 | fjp | if (rowEdited != null) { |
358 | writer.process(rowEdited); |
||
359 | } |
||
360 | } |
||
361 | } |
||
362 | else
|
||
363 | { |
||
364 | // Escribimos solo aquellos registros que han cambiado
|
||
365 | for (int i = 0; i < rowCount; i++) { |
||
366 | int calculatedIndex = getCalculatedIndex(i);
|
||
367 | Integer integer = new Integer(calculatedIndex); |
||
368 | DefaultRowEdited edRow = null;
|
||
369 | // Si est? en el fichero de expansi?n hay que modificar
|
||
370 | if (relations.containsKey(integer)) {
|
||
371 | int num = ((Integer) relations.get(integer)).intValue(); |
||
372 | 3940 | caballero | |
373 | 8913 | fjp | // return expansionFile.getRow(num);
|
374 | // ExpansionFile ya entrega el registro formateado como debe
|
||
375 | IRowEdited rowFromExpansion = expansionFile.getRow(num); |
||
376 | // ?Habr?a que hacer aqu? setID(index + "")?
|
||
377 | edRow = new DefaultRowEdited(rowFromExpansion.getLinkedRow()
|
||
378 | .cloneRow(), rowFromExpansion.getStatus(), i); |
||
379 | writer.process(edRow); |
||
380 | } |
||
381 | 4792 | fjp | } |
382 | } |
||
383 | 5668 | fjp | writer.postProcess(); |
384 | 5986 | caballero | |
385 | 6580 | fjp | // Hacemos que el escritor se entere de los nuevos campos
|
386 | // que tiene. El escritor debe guardar una referencia
|
||
387 | // a los campos con los que trabaja el drier, de forma
|
||
388 | // que al recargar la capa (por ejemplo en el caso de
|
||
389 | // PostGIS, se haga un setData con los campos que se hayan
|
||
390 | // a?adido, borrado o renombrado).
|
||
391 | writer.getTableDefinition().setFieldsDesc(getRecordset().getFieldsDescription()); |
||
392 | |||
393 | 6323 | fjp | ods.reload(); |
394 | 6326 | fjp | ds = null;
|
395 | clean(); |
||
396 | 7272 | jaume | |
397 | 4792 | fjp | } catch (DriverIOException e) {
|
398 | e.printStackTrace(); |
||
399 | throw new EditionException(e); |
||
400 | } catch (IOException e) { |
||
401 | e.printStackTrace(); |
||
402 | throw new EditionException(e); |
||
403 | } catch (DriverException e) {
|
||
404 | e.printStackTrace(); |
||
405 | throw new EditionException(e); |
||
406 | } |
||
407 | 3940 | caballero | |
408 | 4792 | fjp | } |
409 | 3940 | caballero | |
410 | 4792 | fjp | /**
|
411 | * DOCUMENT ME!
|
||
412 | 7272 | jaume | *
|
413 | 4792 | fjp | * @throws IOException
|
414 | * DOCUMENT ME!
|
||
415 | */
|
||
416 | 5184 | caballero | public void cancelEdition(int sourceType) throws IOException { |
417 | 4792 | fjp | isEditing = false;
|
418 | 6313 | fjp | try {
|
419 | 6341 | fjp | ds= null;
|
420 | 6313 | fjp | clean(); |
421 | 6356 | fjp | cr.clearAll(); |
422 | 6313 | fjp | } catch (DriverException e) {
|
423 | e.printStackTrace(); |
||
424 | throw new IOException("Error: " + e.getMessage()); |
||
425 | } |
||
426 | 5184 | caballero | fireCancelEditionEvent(sourceType); |
427 | 4792 | fjp | } |
428 | 3940 | caballero | |
429 | 4792 | fjp | /*
|
430 | * (non-Javadoc)
|
||
431 | 7272 | jaume | *
|
432 | 4792 | fjp | * @see com.iver.cit.gvsig.fmap.edition.IEditableSource#getRow(int)
|
433 | */
|
||
434 | public IRowEdited getRow(int index) throws DriverIOException, IOException { |
||
435 | int calculatedIndex = getCalculatedIndex(index);
|
||
436 | Integer integer = new Integer(calculatedIndex); |
||
437 | DefaultRowEdited edRow = null;
|
||
438 | // Si no est? en el fichero de expansi?n
|
||
439 | if (!relations.containsKey(integer)) {
|
||
440 | try {
|
||
441 | /*
|
||
442 | * edRow = new DefaultRowEdited(new
|
||
443 | * DefaultRow(ods.getRow(calculatedIndex), "" + index),
|
||
444 | * DefaultRowEdited.STATUS_ORIGINAL, index);
|
||
445 | */
|
||
446 | 6313 | fjp | DefaultRow auxR = new DefaultRow(ods.getRow(calculatedIndex));
|
447 | edRow = new DefaultRowEdited(auxR,
|
||
448 | 4792 | fjp | DefaultRowEdited.STATUS_ORIGINAL, index); |
449 | 6313 | fjp | return createExternalRow(edRow, 0); |
450 | // edRow = new DefaultRowEdited(new DefaultRow(ods
|
||
451 | // .getRow(calculatedIndex)),
|
||
452 | // DefaultRowEdited.STATUS_ORIGINAL, index);
|
||
453 | 4792 | fjp | } catch (DriverException e) {
|
454 | throw new DriverIOException(e); |
||
455 | } |
||
456 | } else {
|
||
457 | int num = ((Integer) relations.get(integer)).intValue(); |
||
458 | 3940 | caballero | |
459 | 4792 | fjp | // return expansionFile.getRow(num);
|
460 | 6313 | fjp | // ExpansionFile ya entrega el registro formateado como debe
|
461 | 4792 | fjp | IRowEdited rowFromExpansion = expansionFile.getRow(num); |
462 | // ?Habr?a que hacer aqu? setID(index + "")?
|
||
463 | edRow = new DefaultRowEdited(rowFromExpansion.getLinkedRow()
|
||
464 | .cloneRow(), rowFromExpansion.getStatus(), index); |
||
465 | return edRow;
|
||
466 | } |
||
467 | 6313 | fjp | |
468 | 7272 | jaume | |
469 | |||
470 | 4792 | fjp | } |
471 | 3940 | caballero | |
472 | 4792 | fjp | /**
|
473 | * DOCUMENT ME!
|
||
474 | 7272 | jaume | *
|
475 | 4792 | fjp | * @return DOCUMENT ME!
|
476 | 7272 | jaume | *
|
477 | 4792 | fjp | * @throws DriverIOException
|
478 | * DOCUMENT ME!
|
||
479 | * @throws IOException
|
||
480 | * DOCUMENT ME!
|
||
481 | */
|
||
482 | public int getRowCount() throws DriverIOException, IOException { |
||
483 | try {
|
||
484 | return (int) (ods.getRowCount() + numAdd) - delRows.cardinality();// - |
||
485 | 6212 | fjp | // expansionFile.getInvalidRows().cardinality();
|
486 | 4792 | fjp | } catch (DriverException e) {
|
487 | throw new DriverIOException(e); |
||
488 | } |
||
489 | |||
490 | 4637 | caballero | } |
491 | 12132 | caballero | public String getNewFID() { |
492 | return "fid-" + (new UID()).toString(); |
||
493 | 12040 | caballero | } |
494 | 6212 | fjp | /*
|
495 | * (non-Javadoc)
|
||
496 | 7272 | jaume | *
|
497 | 6212 | fjp | * @see com.iver.cit.gvsig.fmap.edition.IEditableSource#addRow(com.iver.cit.gvsig.fmap.core.IRow,
|
498 | * java.lang.String)
|
||
499 | 4792 | fjp | */
|
500 | 6212 | fjp | public int addRow(IRow row, String descrip, int sourceType) |
501 | throws DriverIOException, IOException { |
||
502 | 6071 | caballero | |
503 | 6002 | fjp | try {
|
504 | 10234 | caballero | validateRow(row,sourceType); |
505 | 6002 | fjp | } catch (EditionException e) {
|
506 | e.printStackTrace(); |
||
507 | throw new IOException(e.getMessage()); |
||
508 | 5886 | fjp | } |
509 | 5077 | caballero | |
510 | 5184 | caballero | int calculatedIndex = doAddRow(row, sourceType);
|
511 | 6212 | fjp | Command command = new AddRowCommand(this, row, calculatedIndex, |
512 | sourceType); |
||
513 | 4792 | fjp | command.setDescription(descrip); |
514 | if (complex) {
|
||
515 | commands.add(command); |
||
516 | } else {
|
||
517 | cr.pushCommand(command); |
||
518 | } |
||
519 | 5077 | caballero | |
520 | 4792 | fjp | return calculatedIndex;
|
521 | } |
||
522 | 3940 | caballero | |
523 | 4792 | fjp | /**
|
524 | * DOCUMENT ME!
|
||
525 | 7272 | jaume | *
|
526 | 4792 | fjp | * @throws DriverIOException
|
527 | * DOCUMENT ME!
|
||
528 | * @throws IOException
|
||
529 | * DOCUMENT ME!
|
||
530 | */
|
||
531 | public void undo() throws DriverIOException, IOException { |
||
532 | // seleccion.clear();
|
||
533 | 6127 | fjp | if (cr.moreUndoCommands()) {
|
534 | 4792 | fjp | cr.undoCommand(); |
535 | } |
||
536 | } |
||
537 | 3940 | caballero | |
538 | 4792 | fjp | /**
|
539 | * DOCUMENT ME!
|
||
540 | 7272 | jaume | *
|
541 | 4792 | fjp | * @throws DriverIOException
|
542 | * DOCUMENT ME!
|
||
543 | * @throws IOException
|
||
544 | * DOCUMENT ME!
|
||
545 | */
|
||
546 | public void redo() throws DriverIOException, IOException { |
||
547 | // seleccion.clear();
|
||
548 | 6127 | fjp | if (cr.moreRedoCommands()) {
|
549 | 4792 | fjp | cr.redoCommand(); |
550 | } |
||
551 | } |
||
552 | 3940 | caballero | |
553 | 6212 | fjp | /*
|
554 | 4792 | fjp | * (non-Javadoc)
|
555 | 7272 | jaume | *
|
556 | 4792 | fjp | * @see com.iver.cit.gvsig.fmap.edition.IEditableSource#removeRow(int)
|
557 | */
|
||
558 | 6212 | fjp | public void removeRow(int index, String descrip, int sourceType) |
559 | throws IOException, DriverIOException { |
||
560 | 5077 | caballero | |
561 | 4792 | fjp | int calculatedIndex = getCalculatedIndex(index);
|
562 | 6212 | fjp | Command command = new RemoveRowCommand(this, calculatedIndex, |
563 | sourceType); |
||
564 | 4792 | fjp | command.setDescription(descrip); |
565 | if (complex) {
|
||
566 | commands.add(command); |
||
567 | } else {
|
||
568 | cr.pushCommand(command); |
||
569 | } |
||
570 | 5184 | caballero | doRemoveRow(calculatedIndex, sourceType); |
571 | 5077 | caballero | |
572 | 4792 | fjp | } |
573 | 3940 | caballero | |
574 | 4792 | fjp | /*
|
575 | * (non-Javadoc)
|
||
576 | 7272 | jaume | *
|
577 | 4792 | fjp | * @see com.iver.cit.gvsig.fmap.edition.IEditableSource#modifyRow(int,
|
578 | * com.iver.cit.gvsig.fmap.core.IRow)
|
||
579 | */
|
||
580 | 5184 | caballero | public int modifyRow(int index, IRow row, String descrip, int sourceType) |
581 | 4792 | fjp | throws IOException, DriverIOException { |
582 | 4954 | caballero | |
583 | 6002 | fjp | try {
|
584 | 10234 | caballero | validateRow(row,sourceType); |
585 | 6002 | fjp | } catch (EditionException e) {
|
586 | e.printStackTrace(); |
||
587 | throw new IOException(e.getMessage()); |
||
588 | 5886 | fjp | } |
589 | |||
590 | 4792 | fjp | int calculatedIndex = getCalculatedIndex(index);
|
591 | 5184 | caballero | int pos = doModifyRow(calculatedIndex, row, sourceType);
|
592 | 6212 | fjp | Command command = new ModifyRowCommand(this, calculatedIndex, pos, row, |
593 | sourceType); |
||
594 | 4792 | fjp | command.setDescription(descrip); |
595 | if (complex) {
|
||
596 | commands.add(command); |
||
597 | } else {
|
||
598 | cr.pushCommand(command); |
||
599 | } |
||
600 | 5077 | caballero | |
601 | 4792 | fjp | return pos;
|
602 | } |
||
603 | 3940 | caballero | |
604 | 4792 | fjp | /**
|
605 | * DOCUMENT ME!
|
||
606 | */
|
||
607 | public void compact() { |
||
608 | expansionFile.compact(relations); |
||
609 | } |
||
610 | 3996 | caballero | |
611 | 4792 | fjp | /**
|
612 | * DOCUMENT ME!
|
||
613 | */
|
||
614 | public void startComplexRow() { |
||
615 | complex = true;
|
||
616 | commands = new CommandCollection();
|
||
617 | } |
||
618 | 3996 | caballero | |
619 | 4792 | fjp | /**
|
620 | * DOCUMENT ME!
|
||
621 | 7272 | jaume | *
|
622 | 4792 | fjp | * @throws IOException
|
623 | * DOCUMENT ME!
|
||
624 | * @throws DriverIOException
|
||
625 | * DOCUMENT ME!
|
||
626 | */
|
||
627 | 6212 | fjp | public void endComplexRow(String description) throws IOException, |
628 | DriverIOException { |
||
629 | 6071 | caballero | commands.setDescription(description); |
630 | 4792 | fjp | cr.pushCommand(commands); |
631 | complex = false;
|
||
632 | 10377 | caballero | for (int j = 0; j < editionListeners.size(); j++) { |
633 | for (int i = 0; i < fieldEvents.size(); i++) { |
||
634 | IEditionListener listener = (IEditionListener) editionListeners |
||
635 | .get(j); |
||
636 | listener.afterFieldEditEvent((AfterFieldEditEvent)fieldEvents.get(i)); |
||
637 | } |
||
638 | for (int i = 0; i < rowEvents.size(); i++) { |
||
639 | IEditionListener listener = (IEditionListener) editionListeners |
||
640 | .get(j); |
||
641 | listener.afterRowEditEvent(null,(AfterRowEditEvent)rowEvents.get(i));
|
||
642 | } |
||
643 | 10234 | caballero | } |
644 | 10333 | caballero | fieldEvents.clear(); |
645 | rowEvents.clear(); |
||
646 | 4792 | fjp | } |
647 | 3940 | caballero | |
648 | 4792 | fjp | /**
|
649 | * Actualiza en el mapa de ?ndices, la posici?n en la que estaba la
|
||
650 | * geometr?a antes de ser modificada. Se marca como v?lida, en caso de que
|
||
651 | * fuera una modificaci?n de una geometr?a que estuviese en el fichero de
|
||
652 | * expansi?n antes de ser modificada y se pone el puntero de escritura del
|
||
653 | * expansion file a justo despues de la penultima geometr?a
|
||
654 | 7272 | jaume | *
|
655 | 4792 | fjp | * @param geometryIndex
|
656 | * ?ndice de la geometr?a que se quiere deshacer su modificaci?n
|
||
657 | * @param previousExpansionFileIndex
|
||
658 | * ?ndice que ten?a antes la geometr?a en el expansionFile. Si
|
||
659 | * vale -1 quiere decir que es una modificaci?n de una geometr?a
|
||
660 | * original y por tanto no hay que actualizar el mapa de indices
|
||
661 | * sino eliminar su entrada.
|
||
662 | 7272 | jaume | *
|
663 | 4792 | fjp | * @throws IOException
|
664 | * @throws DriverIOException
|
||
665 | */
|
||
666 | 6212 | fjp | public void undoModifyRow(int geometryIndex, |
667 | int previousExpansionFileIndex, int sourceType) throws IOException, |
||
668 | DriverIOException { |
||
669 | 5197 | caballero | |
670 | 4792 | fjp | if (previousExpansionFileIndex == -1) { |
671 | 6212 | fjp | DefaultRowEdited edRow = null;
|
672 | 5197 | caballero | try {
|
673 | edRow = new DefaultRowEdited(new DefaultRow(ods |
||
674 | .getRow(geometryIndex)), |
||
675 | 6212 | fjp | DefaultRowEdited.STATUS_ORIGINAL, geometryIndex); |
676 | 5197 | caballero | } catch (DriverException e) {
|
677 | e.printStackTrace(); |
||
678 | } |
||
679 | 6212 | fjp | boolean cancel = fireBeforeModifyRow(edRow, geometryIndex,
|
680 | sourceType); |
||
681 | 5197 | caballero | if (cancel)
|
682 | return;
|
||
683 | 4792 | fjp | // Se elimina de las relaciones y del fichero de expansi?n
|
684 | relations.remove(new Integer(geometryIndex)); |
||
685 | expansionFile.deleteLastRow(); |
||
686 | } else {
|
||
687 | 6212 | fjp | boolean cancel = fireBeforeModifyRow(expansionFile
|
688 | .getRow(previousExpansionFileIndex), geometryIndex, |
||
689 | sourceType); |
||
690 | 5197 | caballero | if (cancel)
|
691 | return;
|
||
692 | 4792 | fjp | // Se actualiza la relaci?n de ?ndices
|
693 | relations.put(new Integer(geometryIndex), new Integer( |
||
694 | previousExpansionFileIndex)); |
||
695 | } |
||
696 | 10292 | caballero | //fireAfterModifyRow(geometryIndex, sourceType);
|
697 | 4792 | fjp | } |
698 | 3940 | caballero | |
699 | 4792 | fjp | /**
|
700 | * Elimina una geometria. Si es una geometr?a original de la capa en edici?n
|
||
701 | * se marca como eliminada (haya sido modificada o no). Si es una geometr?a
|
||
702 | * a?adida posteriormente se invalida en el fichero de expansi?n, para que
|
||
703 | * una futura compactaci?n termine con ella.
|
||
704 | 7272 | jaume | *
|
705 | 4792 | fjp | * @param index
|
706 | * ?ndice de la geometr?a.
|
||
707 | 7272 | jaume | *
|
708 | 4792 | fjp | * @throws DriverIOException
|
709 | * @throws IOException
|
||
710 | */
|
||
711 | 6212 | fjp | public IRow doRemoveRow(int index, int sourceType) |
712 | throws DriverIOException, IOException { |
||
713 | 5184 | caballero | boolean cancel = fireBeforeRemoveRow(index, sourceType);
|
714 | 5077 | caballero | if (cancel)
|
715 | return null; |
||
716 | 4792 | fjp | // Llega un calculatedIndex
|
717 | delRows.set(index, true);
|
||
718 | System.err.println("Elimina una Row en la posici?n: " + index); |
||
719 | // TODO: Con tablas no es necesario devolver la anterior feature. Por
|
||
720 | // ahora.
|
||
721 | 7272 | jaume | isFullExtentDirty = true;
|
722 | 5184 | caballero | fireAfterRemoveRow(index, sourceType); |
723 | 4792 | fjp | return null; |
724 | } |
||
725 | 3940 | caballero | |
726 | 4792 | fjp | /**
|
727 | 9887 | fjp | ** Si se intenta modificar una geometr?a original de la capa en edici?n se
|
728 | 4792 | fjp | * a?ade al fichero de expansi?n y se registra la posici?n en la que se
|
729 | * a?adi?. Si se intenta modificar una geometria que se encuentra en el
|
||
730 | 9887 | fjp | * fichero de expansi?n, ?sta puede estar ah? (en el ExpansionFile
|
731 | * por haber sido a?adida o modificada. Si ha sido a?adida, entonces hay
|
||
732 | * que respetar su estatus para que los writers puedan saber que es
|
||
733 | * un registro NUEVO).
|
||
734 | 7272 | jaume | *
|
735 | 4792 | fjp | * @param index
|
736 | * DOCUMENT ME!
|
||
737 | * @param feat
|
||
738 | * DOCUMENT ME!
|
||
739 | 7272 | jaume | *
|
740 | 4792 | fjp | * @return DOCUMENT ME!
|
741 | 7272 | jaume | *
|
742 | 4792 | fjp | * @throws IOException
|
743 | * @throws DriverIOException
|
||
744 | */
|
||
745 | 6212 | fjp | public int doModifyRow(int index, IRow feat, int sourceType) |
746 | throws IOException, DriverIOException { |
||
747 | boolean cancel = fireBeforeModifyRow(feat, index, sourceType);
|
||
748 | 5077 | caballero | if (cancel)
|
749 | return -1; |
||
750 | |||
751 | 4792 | fjp | int pos = -1; |
752 | Integer integer = new Integer(index); |
||
753 | 10234 | caballero | // System.err.println("Modifica una Row en la posici?n: " + index);
|
754 | 4792 | fjp | // Si la geometr?a no ha sido modificada
|
755 | if (!relations.containsKey(integer)) {
|
||
756 | 6212 | fjp | int expansionIndex = expansionFile.addRow(feat,
|
757 | IRowEdited.STATUS_MODIFIED, actualIndexFields); |
||
758 | 4792 | fjp | relations.put(integer, new Integer(expansionIndex)); |
759 | } else {
|
||
760 | // Obtenemos el ?ndice en el fichero de expansi?n
|
||
761 | int num = ((Integer) relations.get(integer)).intValue(); |
||
762 | pos = num; |
||
763 | 3940 | caballero | |
764 | 4792 | fjp | /*
|
765 | * Se modifica la geometr?a y nos guardamos el ?ndice dentro del
|
||
766 | * fichero de expansi?n en el que se encuentra la geometr?a
|
||
767 | * modificada
|
||
768 | */
|
||
769 | 6212 | fjp | num = expansionFile.modifyRow(num, feat, actualIndexFields); |
770 | 3940 | caballero | |
771 | 4792 | fjp | /*
|
772 | * Actualiza la relaci?n del ?ndice de la geometr?a al ?ndice en el
|
||
773 | * fichero de expansi?n.
|
||
774 | */
|
||
775 | relations.put(integer, new Integer(num)); |
||
776 | } |
||
777 | 7272 | jaume | isFullExtentDirty = true;
|
778 | 10292 | caballero | //fireAfterModifyRow(index, sourceType);
|
779 | 4792 | fjp | return pos;
|
780 | } |
||
781 | 3940 | caballero | |
782 | 4792 | fjp | /**
|
783 | * A?ade una geometria al fichero de expansi?n y guarda la correspondencia
|
||
784 | * en la tabla relations.
|
||
785 | 7272 | jaume | *
|
786 | 4792 | fjp | * @param feat
|
787 | * geometr?a a guardar.
|
||
788 | 7272 | jaume | *
|
789 | 4792 | fjp | * @return calculatedIndex
|
790 | 7272 | jaume | *
|
791 | 4792 | fjp | * @throws DriverIOException
|
792 | * @throws IOException
|
||
793 | */
|
||
794 | 6212 | fjp | public int doAddRow(IRow feat, int sourceType) throws DriverIOException, |
795 | IOException {
|
||
796 | 12132 | caballero | |
797 | boolean cancel = fireBeforeRowAdded(sourceType,feat.getID());
|
||
798 | 5077 | caballero | if (cancel)
|
799 | return -1; |
||
800 | 4792 | fjp | // A?ade la geometr?a
|
801 | // int virtualIndex = 0;
|
||
802 | int calculatedIndex = -1; |
||
803 | |||
804 | try {
|
||
805 | calculatedIndex = (int) ods.getRowCount() + numAdd;
|
||
806 | // int externalIndex = getRowCount();
|
||
807 | // calculatedIndex = getCalculatedIndex(externalIndex);
|
||
808 | } catch (DriverException e) {
|
||
809 | throw new DriverIOException(e); |
||
810 | 4368 | caballero | } |
811 | 4792 | fjp | |
812 | 6212 | fjp | int pos = expansionFile.addRow(feat, IRowEdited.STATUS_ADDED, actualIndexFields);
|
813 | 4792 | fjp | relations.put(new Integer(calculatedIndex), new Integer(pos)); |
814 | numAdd++; |
||
815 | System.err.println("A?ade una Row en la posici?n: " + calculatedIndex); |
||
816 | 8765 | jjdelcerro | isFullExtentDirty = true;
|
817 | fireAfterRowAdded(feat,calculatedIndex, sourceType); |
||
818 | 4792 | fjp | return calculatedIndex;
|
819 | 4061 | caballero | } |
820 | 3996 | caballero | |
821 | 4792 | fjp | /**
|
822 | * Se desmarca como invalidada en el fichero de expansion o como eliminada
|
||
823 | * en el fichero original
|
||
824 | 7272 | jaume | *
|
825 | 4792 | fjp | * @param index
|
826 | * DOCUMENT ME!
|
||
827 | 7272 | jaume | *
|
828 | 4792 | fjp | * @throws IOException
|
829 | * @throws DriverIOException
|
||
830 | */
|
||
831 | 6212 | fjp | public void undoRemoveRow(int index, int sourceType) throws IOException, |
832 | DriverIOException { |
||
833 | 12132 | caballero | delRows.set(index, false);
|
834 | String fid=getRow(index).getID();
|
||
835 | boolean cancel = fireBeforeRowAdded(sourceType,fid);
|
||
836 | if (cancel){
|
||
837 | delRows.set(index,true);
|
||
838 | 5077 | caballero | return;
|
839 | 12132 | caballero | } |
840 | |||
841 | 8765 | jjdelcerro | fireAfterRowAdded(null,index, sourceType);
|
842 | 4792 | fjp | } |
843 | 3996 | caballero | |
844 | 4792 | fjp | /**
|
845 | * Se elimina del final del fichero de expansi?n poniendo el puntero de
|
||
846 | * escritura apuntando al final de la pen?ltima geometr?a. Deber? quitar la
|
||
847 | * relaci?n del mapa de relaciones
|
||
848 | 7272 | jaume | *
|
849 | 4792 | fjp | * @param index
|
850 | * ?ndice de la geometr?a que se a?adi?
|
||
851 | 7272 | jaume | *
|
852 | 4792 | fjp | * @throws DriverIOException
|
853 | * @throws IOException
|
||
854 | */
|
||
855 | 6212 | fjp | public void undoAddRow(int calculatedIndex, int sourceType) |
856 | throws DriverIOException, IOException { |
||
857 | boolean cancel = fireBeforeRemoveRow(calculatedIndex, sourceType);
|
||
858 | 5077 | caballero | if (cancel)
|
859 | return;
|
||
860 | 4792 | fjp | expansionFile.deleteLastRow(); |
861 | relations.remove(new Integer(calculatedIndex)); |
||
862 | numAdd--; |
||
863 | 6212 | fjp | fireAfterRemoveRow(calculatedIndex, sourceType); |
864 | 4792 | fjp | } |
865 | 3996 | caballero | |
866 | 4792 | fjp | /*
|
867 | * (non-Javadoc)
|
||
868 | 7272 | jaume | *
|
869 | 4792 | fjp | * @see com.iver.cit.gvsig.fmap.layers.VectorialAdapter#getRecordset()
|
870 | */
|
||
871 | public SelectableDataSource getRecordset() throws DriverLoadException { |
||
872 | if (isEditing) {
|
||
873 | if (ds == null) { |
||
874 | String name = LayerFactory.getDataSourceFactory()
|
||
875 | .addDataSource((ObjectDriver) editingDriver); |
||
876 | 3996 | caballero | |
877 | 4792 | fjp | try {
|
878 | 7272 | jaume | |
879 | 11008 | jmvivo | /*
|
880 | 4792 | fjp | ds = new SelectableDataSource(LayerFactory
|
881 | .getDataSourceFactory().createRandomDataSource(
|
||
882 | 6313 | fjp | name, DataSourceFactory.MANUAL_OPENING));
|
883 | 11008 | jmvivo | */
|
884 | // CHEMA: AUTOMATIC DATA SOURCE
|
||
885 | ds = new SelectableDataSource(LayerFactory
|
||
886 | .getDataSourceFactory().createRandomDataSource( |
||
887 | name, DataSourceFactory.AUTOMATIC_OPENING)); |
||
888 | 6313 | fjp | ds.start(); |
889 | 4792 | fjp | ds.setSelectionSupport(ods.getSelectionSupport()); |
890 | 3940 | caballero | |
891 | 4792 | fjp | } catch (NoSuchTableException e) {
|
892 | throw new RuntimeException(e); |
||
893 | } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
||
894 | throw new RuntimeException(e); |
||
895 | } |
||
896 | } |
||
897 | 3940 | caballero | |
898 | 4792 | fjp | return ds;
|
899 | } else {
|
||
900 | return ods;
|
||
901 | } |
||
902 | } |
||
903 | 10333 | caballero | |
904 | 9887 | fjp | /**
|
905 | * Return always the original recordset (even when is editing,
|
||
906 | * nor the getRecorset() method)
|
||
907 | 10333 | caballero | *
|
908 | 9887 | fjp | * */
|
909 | public SelectableDataSource getOriginalRecordset(){
|
||
910 | return ods;
|
||
911 | } |
||
912 | 3940 | caballero | |
913 | |||
914 | 4792 | fjp | /**
|
915 | * DOCUMENT ME!
|
||
916 | 7272 | jaume | *
|
917 | 4792 | fjp | * @return
|
918 | */
|
||
919 | public FBitSet getSelection() {
|
||
920 | /*
|
||
921 | * try { return getRecordset().getSelection(); } catch
|
||
922 | * (DriverLoadException e) { // TODO Auto-generated catch block
|
||
923 | * e.printStackTrace(); } return null;
|
||
924 | */
|
||
925 | return getRecordset().getSelection();
|
||
926 | } |
||
927 | 3940 | caballero | |
928 | 4792 | fjp | public void setSelection(FBitSet selection) { |
929 | /*
|
||
930 | * try { getRecordset().setSelection(selection); } catch
|
||
931 | * (DriverLoadException e) { // TODO Auto-generated catch block
|
||
932 | * e.printStackTrace(); }
|
||
933 | */
|
||
934 | getRecordset().setSelection(selection); |
||
935 | } |
||
936 | 3940 | caballero | |
937 | 4792 | fjp | /**
|
938 | * DOCUMENT ME!
|
||
939 | 7272 | jaume | *
|
940 | 4792 | fjp | * @return DOCUMENT ME!
|
941 | */
|
||
942 | public boolean isEditing() { |
||
943 | return isEditing;
|
||
944 | } |
||
945 | 3996 | caballero | |
946 | 5986 | caballero | public int getInversedIndex(long rowIndex) { |
947 | 4792 | fjp | int intervalNotDeleted = 0; |
948 | int antDeleted = -1; |
||
949 | int idPedido = (int) rowIndex; |
||
950 | int numNotDeleted = 0; |
||
951 | int numBorradosAnt = 0; |
||
952 | 3996 | caballero | |
953 | 4792 | fjp | for (int i = delRows.nextSetBit(0); i >= 0; i = delRows |
954 | .nextSetBit(i + 1)) {
|
||
955 | intervalNotDeleted = i - antDeleted - 1;
|
||
956 | numNotDeleted += intervalNotDeleted; |
||
957 | if (i > idPedido) {
|
||
958 | numNotDeleted = numNotDeleted + (i - idPedido); |
||
959 | break;
|
||
960 | } |
||
961 | numBorradosAnt++; |
||
962 | antDeleted = i; |
||
963 | } |
||
964 | numNotDeleted = idPedido - numBorradosAnt; |
||
965 | // System.out.println("Piden Viejo : "+ rowIndex + " y devuelvo como
|
||
966 | // nuevo " + (numNotDeleted));
|
||
967 | return numNotDeleted;
|
||
968 | } |
||
969 | 3940 | caballero | |
970 | 4792 | fjp | /**
|
971 | * DOCUMENT ME!
|
||
972 | 7272 | jaume | *
|
973 | 4792 | fjp | * @param rowIndex
|
974 | * DOCUMENT ME!
|
||
975 | 7272 | jaume | *
|
976 | 4792 | fjp | * @return DOCUMENT ME!
|
977 | */
|
||
978 | 4954 | caballero | public int getCalculatedIndex(long rowIndex) { |
979 | 4792 | fjp | int numNotDeleted = 0; |
980 | int intervalNotDeleted = 0; |
||
981 | int antDeleted = -1; |
||
982 | int calculatedIndex;
|
||
983 | int idPedido = (int) rowIndex; |
||
984 | int numBorradosAnt = 0; |
||
985 | 3940 | caballero | |
986 | 4792 | fjp | for (int i = delRows.nextSetBit(0); i >= 0; i = delRows |
987 | .nextSetBit(i + 1)) {
|
||
988 | intervalNotDeleted = i - antDeleted - 1;
|
||
989 | numNotDeleted += intervalNotDeleted; |
||
990 | if (numNotDeleted > idPedido) {
|
||
991 | break;
|
||
992 | } |
||
993 | numBorradosAnt++; |
||
994 | antDeleted = i; |
||
995 | } |
||
996 | calculatedIndex = numBorradosAnt + idPedido; |
||
997 | // System.out.println("Piden Registro : "+ rowIndex + " y devuelvo el "
|
||
998 | // + (calculatedIndex));
|
||
999 | return calculatedIndex;
|
||
1000 | } |
||
1001 | 3940 | caballero | |
1002 | 4792 | fjp | /**
|
1003 | * DOCUMENT ME!
|
||
1004 | 7272 | jaume | *
|
1005 | 4792 | fjp | * @author Vicente Caballero Navarro
|
1006 | */
|
||
1007 | private class myObjectDriver implements ObjectDriver { |
||
1008 | /*
|
||
1009 | * (non-Javadoc)
|
||
1010 | 7272 | jaume | *
|
1011 | 4792 | fjp | * @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#getPrimaryKeys()
|
1012 | */
|
||
1013 | public int[] getPrimaryKeys() throws DriverException { |
||
1014 | return ods.getPrimaryKeys();
|
||
1015 | // int[] pk=new int[1];
|
||
1016 | /*
|
||
1017 | * for (int i=0;i<getRowCount();i++){ pk[i]=i; }
|
||
1018 | */
|
||
1019 | // pk[0]=1;
|
||
1020 | // return pk;
|
||
1021 | } |
||
1022 | 3996 | caballero | |
1023 | 4792 | fjp | /*
|
1024 | * (non-Javadoc)
|
||
1025 | 7272 | jaume | *
|
1026 | 4792 | fjp | * @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#write(com.hardcode.gdbms.engine.data.edition.DataWare)
|
1027 | */
|
||
1028 | public void write(DataWare dataWare) throws DriverException { |
||
1029 | DataWare dataWareOrig = ods |
||
1030 | .getDataWare(DataSourceFactory.DATA_WARE_DIRECT_MODE); |
||
1031 | dataWareOrig.commitTrans(); |
||
1032 | } |
||
1033 | 3940 | caballero | |
1034 | 4792 | fjp | /*
|
1035 | * (non-Javadoc)
|
||
1036 | 7272 | jaume | *
|
1037 | 4792 | fjp | * @see com.hardcode.gdbms.engine.data.driver.GDBMSDriver#setDataSourceFactory(com.hardcode.gdbms.engine.data.DataSourceFactory)
|
1038 | */
|
||
1039 | public void setDataSourceFactory(DataSourceFactory dsf) { |
||
1040 | ods.setDataSourceFactory(dsf); |
||
1041 | } |
||
1042 | |||
1043 | /*
|
||
1044 | * (non-Javadoc)
|
||
1045 | 7272 | jaume | *
|
1046 | 4792 | fjp | * @see com.hardcode.driverManager.Driver#getName()
|
1047 | */
|
||
1048 | public String getName() { |
||
1049 | return ods.getName();
|
||
1050 | } |
||
1051 | |||
1052 | /*
|
||
1053 | * (non-Javadoc)
|
||
1054 | 7272 | jaume | *
|
1055 | 4792 | fjp | * @see com.hardcode.gdbms.engine.data.driver.ReadAccess#getFieldValue(long,
|
1056 | * int)
|
||
1057 | */
|
||
1058 | public Value getFieldValue(long rowIndex, int fieldId) |
||
1059 | throws DriverException {
|
||
1060 | // Si no est? en el fichero de expansi?n
|
||
1061 | 6259 | fjp | // Integer integer = new Integer(getCalculatedIndex(rowIndex));
|
1062 | 4792 | fjp | |
1063 | 6259 | fjp | |
1064 | 4792 | fjp | try {
|
1065 | 6259 | fjp | IRow row = getRow((int)rowIndex);
|
1066 | return row.getAttribute(fieldId);
|
||
1067 | // if (!relations.containsKey(integer)) {
|
||
1068 | // return ods.getFieldValue(rowIndex, fieldId);
|
||
1069 | // } else {
|
||
1070 | // int num = ((Integer) relations.get(integer)).intValue();
|
||
1071 | // DefaultRowEdited feat = (DefaultRowEdited) expansionFile
|
||
1072 | // .getRow(num);
|
||
1073 | //
|
||
1074 | // if (feat == null) {
|
||
1075 | // return null;
|
||
1076 | // }
|
||
1077 | //
|
||
1078 | // return feat.getAttribute(fieldId);
|
||
1079 | // }
|
||
1080 | // } catch (DriverException e) {
|
||
1081 | // e.printStackTrace();
|
||
1082 | // throw new DriverException(e);
|
||
1083 | } catch (IOException e) { |
||
1084 | 4792 | fjp | e.printStackTrace(); |
1085 | throw new DriverException(e); |
||
1086 | 6259 | fjp | } catch (DriverIOException e) {
|
1087 | 4792 | fjp | e.printStackTrace(); |
1088 | throw new DriverException(e); |
||
1089 | } |
||
1090 | |||
1091 | /**
|
||
1092 | * try { if (!relations.containsKey(integer)) { // Si ha sido
|
||
1093 | * eliminada if (delRows.get(integer.intValue())) { return null; }
|
||
1094 | * else { return ods.getFieldValue(rowIndex, fieldId); }} else { int
|
||
1095 | * num = ((Integer) relations.get(integer)).intValue();
|
||
1096 | * DefaultRowEdited feat = (DefaultRowEdited)
|
||
1097 | * expansionFile.getRow(num); if (feat==null)return null; return
|
||
1098 | * feat.getAttribute(fieldId); }} catch (DriverException e) {
|
||
1099 | * e.printStackTrace(); throw new DriverException(e); } catch
|
||
1100 | * (IOException e) { e.printStackTrace(); throw new
|
||
1101 | * DriverException(e); }
|
||
1102 | */
|
||
1103 | } |
||
1104 | |||
1105 | /*
|
||
1106 | * (non-Javadoc)
|
||
1107 | 7272 | jaume | *
|
1108 | 4792 | fjp | * @see com.hardcode.gdbms.engine.data.driver.ReadAccess#getFieldCount()
|
1109 | */
|
||
1110 | public int getFieldCount() throws DriverException { |
||
1111 | 6483 | fjp | return fastAccessFields.size();
|
1112 | 4792 | fjp | } |
1113 | |||
1114 | /*
|
||
1115 | * (non-Javadoc)
|
||
1116 | 7272 | jaume | *
|
1117 | 4792 | fjp | * @see com.hardcode.gdbms.engine.data.driver.ReadAccess#getFieldName(int)
|
1118 | */
|
||
1119 | public String getFieldName(int fieldId) throws DriverException { |
||
1120 | 6483 | fjp | // int i=0;
|
1121 | // for (Iterator iter = actualFields.values().iterator(); iter.hasNext();) {
|
||
1122 | // InternalField fld = (InternalField) iter.next();
|
||
1123 | // if (i == fieldId)
|
||
1124 | 6384 | fjp | // return fld.getFieldDesc().getFieldAlias();
|
1125 | 6483 | fjp | // i++;
|
1126 | 7272 | jaume | //
|
1127 | 6483 | fjp | // }
|
1128 | // throw new DriverException("FieldId " + fieldId + " not found ");
|
||
1129 | FieldDescription aux = (FieldDescription) fastAccessFields.get(fieldId); |
||
1130 | return aux.getFieldAlias();
|
||
1131 | 6259 | fjp | // return null;
|
1132 | // return ods.getFieldName(fieldId);
|
||
1133 | 4792 | fjp | } |
1134 | |||
1135 | /*
|
||
1136 | * (non-Javadoc)
|
||
1137 | 7272 | jaume | *
|
1138 | 4792 | fjp | * @see com.hardcode.gdbms.engine.data.driver.ReadAccess#getRowCount()
|
1139 | */
|
||
1140 | public long getRowCount() { |
||
1141 | try {
|
||
1142 | return (int) (ods.getRowCount() + numAdd) |
||
1143 | - delRows.cardinality();// -
|
||
1144 | 6212 | fjp | // expansionFile.getInvalidRows().cardinality();
|
1145 | 4792 | fjp | } catch (DriverException e) {
|
1146 | // TODO Auto-generated catch block
|
||
1147 | e.printStackTrace(); |
||
1148 | } |
||
1149 | |||
1150 | return 0; |
||
1151 | } |
||
1152 | |||
1153 | /*
|
||
1154 | * (non-Javadoc)
|
||
1155 | 7272 | jaume | *
|
1156 | 4792 | fjp | * @see com.hardcode.gdbms.engine.data.driver.ReadAccess#getFieldType(int)
|
1157 | */
|
||
1158 | 6384 | fjp | public int getFieldType(int fieldId) throws DriverException { |
1159 | 6483 | fjp | // int i=0;
|
1160 | // for (Iterator iter = actualFields.values().iterator(); iter.hasNext();) {
|
||
1161 | // InternalField fld = (InternalField) iter.next();
|
||
1162 | // if (i == fieldId)
|
||
1163 | 6384 | fjp | // return fld.getFieldDesc().getFieldType();
|
1164 | 6483 | fjp | // i++;
|
1165 | 7272 | jaume | //
|
1166 | 6483 | fjp | // }
|
1167 | FieldDescription aux = (FieldDescription) fastAccessFields.get(fieldId); |
||
1168 | return aux.getFieldType();
|
||
1169 | 7272 | jaume | |
1170 | 6483 | fjp | // return ods.getFieldType(i);
|
1171 | 4792 | fjp | } |
1172 | 4863 | fjp | |
1173 | 6384 | fjp | public int getFieldWidth(int fieldId) throws DriverException { |
1174 | 6483 | fjp | // int i=0;
|
1175 | 7272 | jaume | // for (Iterator iter = actualFields.values().iterator(); iter.hasNext();) {
|
1176 | 6483 | fjp | // InternalField fld = (InternalField) iter.next();
|
1177 | //// if (fld.getFieldIndex() == i)
|
||
1178 | //// return fld.getFieldDesc().getFieldLength();
|
||
1179 | // if (i == fieldId)
|
||
1180 | 6384 | fjp | // return fld.getFieldDesc().getFieldLength();
|
1181 | 6483 | fjp | // i++;
|
1182 | 7272 | jaume | //
|
1183 | 6483 | fjp | // }
|
1184 | //
|
||
1185 | // return ods.getFieldWidth(i);
|
||
1186 | FieldDescription aux = (FieldDescription) fastAccessFields.get(fieldId); |
||
1187 | return aux.getFieldLength();
|
||
1188 | 6259 | fjp | |
1189 | 4863 | fjp | } |
1190 | 6323 | fjp | |
1191 | public void reload() throws IOException, DriverException { |
||
1192 | ods.reload(); |
||
1193 | 7272 | jaume | |
1194 | 6323 | fjp | } |
1195 | 4792 | fjp | } |
1196 | |||
1197 | public CommandRecord getCommandRecord() {
|
||
1198 | return cr;
|
||
1199 | } |
||
1200 | 4832 | fjp | |
1201 | 6212 | fjp | protected void fireAfterRemoveRow(int index, int sourceType) { |
1202 | AfterRowEditEvent event = new AfterRowEditEvent(this, index, |
||
1203 | EditionEvent.CHANGE_TYPE_DELETE, sourceType); |
||
1204 | 10333 | caballero | if (complex){
|
1205 | rowEvents.add(event); |
||
1206 | 10234 | caballero | return;
|
1207 | } |
||
1208 | 6212 | fjp | for (int i = 0; i < editionListeners.size(); i++) { |
1209 | IEditionListener listener = (IEditionListener) editionListeners |
||
1210 | .get(i); |
||
1211 | 6689 | caballero | listener.afterRowEditEvent(null, event);
|
1212 | 4832 | fjp | } |
1213 | 4954 | caballero | |
1214 | 4832 | fjp | } |
1215 | |||
1216 | 6212 | fjp | protected boolean fireBeforeRemoveRow(int index, int sourceType) { |
1217 | 4832 | fjp | Cancel cancel = new Cancel();
|
1218 | 12132 | caballero | String fid=null; |
1219 | try {
|
||
1220 | fid = getRow(index).getID(); |
||
1221 | } catch (DriverIOException e) {
|
||
1222 | e.printStackTrace(); |
||
1223 | } catch (IOException e) { |
||
1224 | e.printStackTrace(); |
||
1225 | } |
||
1226 | BeforeRowEditEvent event = new BeforeRowEditEvent(this, fid, |
||
1227 | 6212 | fjp | EditionEvent.CHANGE_TYPE_DELETE, cancel, sourceType); |
1228 | for (int i = 0; i < editionListeners.size(); i++) { |
||
1229 | IEditionListener listener = (IEditionListener) editionListeners |
||
1230 | .get(i); |
||
1231 | listener.beforeRowEditEvent(null, event);
|
||
1232 | 4832 | fjp | if (cancel.isCanceled())
|
1233 | return true; |
||
1234 | } |
||
1235 | return false; |
||
1236 | } |
||
1237 | |||
1238 | 8765 | jjdelcerro | protected void fireAfterRowAdded(IRow feat,int calculatedIndex, int sourceType) { |
1239 | 6212 | fjp | AfterRowEditEvent event = new AfterRowEditEvent(this, calculatedIndex, |
1240 | EditionEvent.CHANGE_TYPE_ADD, sourceType); |
||
1241 | 10333 | caballero | if (complex){
|
1242 | rowEvents.add(event); |
||
1243 | 10234 | caballero | return;
|
1244 | } |
||
1245 | 6212 | fjp | for (int i = 0; i < editionListeners.size(); i++) { |
1246 | IEditionListener listener = (IEditionListener) editionListeners |
||
1247 | .get(i); |
||
1248 | 8765 | jjdelcerro | listener.afterRowEditEvent(feat, event); |
1249 | 4954 | caballero | } |
1250 | 4832 | fjp | } |
1251 | |||
1252 | 6335 | fjp | protected void fireAfterFieldAdded(FieldDescription field) { |
1253 | AfterFieldEditEvent event = new AfterFieldEditEvent(this,field, |
||
1254 | EditionEvent.CHANGE_TYPE_ADD); |
||
1255 | 10234 | caballero | if (complex) {
|
1256 | 10333 | caballero | fieldEvents.add(event); |
1257 | 10234 | caballero | return;
|
1258 | } |
||
1259 | 6335 | fjp | for (int i = 0; i < editionListeners.size(); i++) { |
1260 | IEditionListener listener = (IEditionListener) editionListeners |
||
1261 | .get(i); |
||
1262 | listener.afterFieldEditEvent(event); |
||
1263 | 10234 | caballero | |
1264 | 6335 | fjp | } |
1265 | } |
||
1266 | |||
1267 | protected void fireAfterFieldRemoved(FieldDescription field) { |
||
1268 | AfterFieldEditEvent event = new AfterFieldEditEvent(this,field, |
||
1269 | EditionEvent.CHANGE_TYPE_DELETE); |
||
1270 | 10234 | caballero | if (complex) {
|
1271 | 10333 | caballero | fieldEvents.add(event); |
1272 | 10234 | caballero | return;
|
1273 | } |
||
1274 | 6335 | fjp | for (int i = 0; i < editionListeners.size(); i++) { |
1275 | IEditionListener listener = (IEditionListener) editionListeners |
||
1276 | .get(i); |
||
1277 | listener.afterFieldEditEvent(event); |
||
1278 | } |
||
1279 | } |
||
1280 | |||
1281 | 6399 | fjp | protected void fireAfterFieldModified(FieldDescription field) { |
1282 | AfterFieldEditEvent event = new AfterFieldEditEvent(this,field, |
||
1283 | EditionEvent.CHANGE_TYPE_MODIFY); |
||
1284 | 10234 | caballero | if (complex) {
|
1285 | 10333 | caballero | fieldEvents.add(event); |
1286 | 10234 | caballero | return;
|
1287 | } |
||
1288 | 6399 | fjp | for (int i = 0; i < editionListeners.size(); i++) { |
1289 | IEditionListener listener = (IEditionListener) editionListeners |
||
1290 | .get(i); |
||
1291 | listener.afterFieldEditEvent(event); |
||
1292 | } |
||
1293 | } |
||
1294 | 7272 | jaume | |
1295 | |||
1296 | 12132 | caballero | protected boolean fireBeforeRowAdded(int sourceType,String newFID) |
1297 | 6212 | fjp | throws DriverIOException, IOException { |
1298 | 4832 | fjp | Cancel cancel = new Cancel();
|
1299 | 12040 | caballero | BeforeRowEditEvent event; |
1300 | 12132 | caballero | event = new BeforeRowEditEvent(this, newFID, |
1301 | EditionEvent.CHANGE_TYPE_ADD, cancel, sourceType); |
||
1302 | 6212 | fjp | for (int i = 0; i < editionListeners.size(); i++) { |
1303 | IEditionListener listener = (IEditionListener) editionListeners |
||
1304 | .get(i); |
||
1305 | listener.beforeRowEditEvent(null, event);
|
||
1306 | 4832 | fjp | if (cancel.isCanceled())
|
1307 | return true; |
||
1308 | } |
||
1309 | return false; |
||
1310 | } |
||
1311 | |||
1312 | 6335 | fjp | protected boolean fireBeforeFieldAdded(FieldDescription field) |
1313 | throws EditionException {
|
||
1314 | Cancel cancel = new Cancel();
|
||
1315 | BeforeFieldEditEvent event = new BeforeFieldEditEvent(this, field, |
||
1316 | EditionEvent.CHANGE_TYPE_ADD, cancel); |
||
1317 | for (int i = 0; i < editionListeners.size(); i++) { |
||
1318 | IEditionListener listener = (IEditionListener) editionListeners |
||
1319 | .get(i); |
||
1320 | listener.beforeFieldEditEvent(event); |
||
1321 | if (cancel.isCanceled())
|
||
1322 | return true; |
||
1323 | } |
||
1324 | return false; |
||
1325 | } |
||
1326 | |||
1327 | protected boolean fireBeforeRemoveField(FieldDescription field) |
||
1328 | throws EditionException {
|
||
1329 | Cancel cancel = new Cancel();
|
||
1330 | BeforeFieldEditEvent event = new BeforeFieldEditEvent(this, field, |
||
1331 | EditionEvent.CHANGE_TYPE_DELETE, cancel); |
||
1332 | for (int i = 0; i < editionListeners.size(); i++) { |
||
1333 | IEditionListener listener = (IEditionListener) editionListeners |
||
1334 | .get(i); |
||
1335 | listener.beforeFieldEditEvent(event); |
||
1336 | if (cancel.isCanceled())
|
||
1337 | return true; |
||
1338 | } |
||
1339 | return false; |
||
1340 | } |
||
1341 | |||
1342 | 7272 | jaume | |
1343 | 6212 | fjp | protected boolean fireBeforeModifyRow(IRow feat, int index, int sourceType) { |
1344 | 4832 | fjp | Cancel cancel = new Cancel();
|
1345 | 12132 | caballero | String fid=null; |
1346 | try {
|
||
1347 | fid = getRow(index).getID(); |
||
1348 | } catch (DriverIOException e) {
|
||
1349 | e.printStackTrace(); |
||
1350 | } catch (IOException e) { |
||
1351 | e.printStackTrace(); |
||
1352 | } |
||
1353 | BeforeRowEditEvent event = new BeforeRowEditEvent(this, fid, |
||
1354 | 6212 | fjp | EditionEvent.CHANGE_TYPE_MODIFY, cancel, sourceType); |
1355 | for (int i = 0; i < editionListeners.size(); i++) { |
||
1356 | IEditionListener listener = (IEditionListener) editionListeners |
||
1357 | .get(i); |
||
1358 | 5197 | caballero | listener.beforeRowEditEvent(feat, event); |
1359 | 4832 | fjp | if (cancel.isCanceled())
|
1360 | return true; |
||
1361 | } |
||
1362 | return false; |
||
1363 | } |
||
1364 | |||
1365 | 6212 | fjp | protected void fireAfterModifyRow(int index, int sourceType) { |
1366 | AfterRowEditEvent event = new AfterRowEditEvent(this, index, |
||
1367 | EditionEvent.CHANGE_TYPE_MODIFY, sourceType); |
||
1368 | 10333 | caballero | if (complex){
|
1369 | rowEvents.add(event); |
||
1370 | return;
|
||
1371 | } |
||
1372 | 6212 | fjp | for (int i = 0; i < editionListeners.size(); i++) { |
1373 | IEditionListener listener = (IEditionListener) editionListeners |
||
1374 | .get(i); |
||
1375 | 6689 | caballero | listener.afterRowEditEvent(null, event);
|
1376 | 4954 | caballero | } |
1377 | 4832 | fjp | |
1378 | } |
||
1379 | |||
1380 | 5184 | caballero | protected void fireStartEditionEvent(int sourceType) { |
1381 | 6212 | fjp | EditionEvent ev = new EditionEvent(this, EditionEvent.START_EDITION, |
1382 | sourceType); |
||
1383 | for (int i = 0; i < editionListeners.size(); i++) { |
||
1384 | IEditionListener listener = (IEditionListener) editionListeners |
||
1385 | .get(i); |
||
1386 | 4832 | fjp | listener.processEvent(ev); |
1387 | 4954 | caballero | } |
1388 | |||
1389 | 4832 | fjp | } |
1390 | |||
1391 | 5184 | caballero | protected void fireStopEditionEvent(int sourceType) { |
1392 | 6212 | fjp | EditionEvent ev = new EditionEvent(this, EditionEvent.STOP_EDITION, |
1393 | sourceType); |
||
1394 | for (int i = 0; i < editionListeners.size(); i++) { |
||
1395 | IEditionListener listener = (IEditionListener) editionListeners |
||
1396 | .get(i); |
||
1397 | 4832 | fjp | listener.processEvent(ev); |
1398 | 4954 | caballero | } |
1399 | |||
1400 | 4832 | fjp | } |
1401 | |||
1402 | 5184 | caballero | protected void fireCancelEditionEvent(int sourceType) { |
1403 | 6212 | fjp | EditionEvent ev = new EditionEvent(this, EditionEvent.CANCEL_EDITION, |
1404 | sourceType); |
||
1405 | for (int i = 0; i < editionListeners.size(); i++) { |
||
1406 | IEditionListener listener = (IEditionListener) editionListeners |
||
1407 | .get(i); |
||
1408 | 4832 | fjp | listener.processEvent(ev); |
1409 | 4954 | caballero | } |
1410 | |||
1411 | 4832 | fjp | } |
1412 | 4954 | caballero | |
1413 | 6212 | fjp | public void addEditionListener(IEditionListener listener) { |
1414 | 5111 | caballero | if (!editionListeners.contains(listener))
|
1415 | editionListeners.add(listener); |
||
1416 | 4832 | fjp | } |
1417 | |||
1418 | 6212 | fjp | public void removeEditionListener(IEditionListener listener) { |
1419 | 4832 | fjp | editionListeners.remove(listener); |
1420 | } |
||
1421 | 4954 | caballero | |
1422 | 5549 | fjp | public IWriter getWriter() {
|
1423 | return writer;
|
||
1424 | } |
||
1425 | |||
1426 | 6212 | fjp | protected void setWriter(IWriter writer) { |
1427 | 5549 | fjp | this.writer = writer;
|
1428 | 5986 | caballero | |
1429 | 5549 | fjp | } |
1430 | 9887 | fjp | /*
|
1431 | * azabala: esto funciona para todos los drivers gdbms
|
||
1432 | * salvo para MySQL, que necesita que el ITableDefinition
|
||
1433 | * contenga el nombre de la tabla (y por tanto requiere
|
||
1434 | * DBLayerDefinition-en realidad hace falta DBTableDefinition)
|
||
1435 | * TODO REVISAR LA ARQUITECTURA DE ESTO
|
||
1436 | 10333 | caballero | *
|
1437 | 9887 | fjp | * */
|
1438 | 6212 | fjp | public ITableDefinition getTableDefinition() throws DriverLoadException, |
1439 | DriverException { |
||
1440 | 9887 | fjp | Driver originalDriver = getOriginalDriver();
|
1441 | 10052 | fjp | // if(! (originalDriver instanceof AlphanumericDBDriver)){
|
1442 | 9887 | fjp | TableDefinition tableDef = new TableDefinition();
|
1443 | tableDef.setFieldsDesc(getRecordset().getFieldsDescription()); |
||
1444 | tableDef.setName(getRecordset().getSourceInfo().name); |
||
1445 | return tableDef;
|
||
1446 | 10052 | fjp | // }else{
|
1447 | // AlphanumericDBDriver dbDriver = (AlphanumericDBDriver)originalDriver;
|
||
1448 | // return dbDriver.getTableDefinition();
|
||
1449 | 10333 | caballero | //
|
1450 | 10052 | fjp | // }
|
1451 | 10333 | caballero | |
1452 | |||
1453 | 5558 | fjp | } |
1454 | |||
1455 | 10234 | caballero | public void validateRow(IRow row,int sourceType) throws EditionException { |
1456 | 6212 | fjp | for (int i = 0; i < rules.size(); i++) { |
1457 | 5886 | fjp | IRule rule = (IRule) rules.get(i); |
1458 | 10234 | caballero | boolean bAux = rule.validate(row,sourceType);
|
1459 | 6212 | fjp | if (bAux == false) { |
1460 | EditionException ex = new EditionException(
|
||
1461 | "NOT follow the rule: " + rule.getDescription());
|
||
1462 | 6002 | fjp | // TODO: Lanzar una RuleException con datos como el registro
|
1463 | // que no cumple, la regla que no lo ha cumplido, etc.
|
||
1464 | 6071 | caballero | throw ex;
|
1465 | 6002 | fjp | } |
1466 | 5886 | fjp | } |
1467 | } |
||
1468 | |||
1469 | public ArrayList getRules() { |
||
1470 | return rules;
|
||
1471 | } |
||
1472 | |||
1473 | public void setRules(ArrayList rules) { |
||
1474 | this.rules = rules;
|
||
1475 | } |
||
1476 | 6212 | fjp | |
1477 | 6313 | fjp | private void clean() throws IOException, DriverException { |
1478 | 6127 | fjp | expansionFile.close(); |
1479 | relations.clear(); |
||
1480 | numAdd = 0;
|
||
1481 | delRows.clear(); |
||
1482 | 6313 | fjp | // TODO: Es muy probable que necesitemos un reload de los datasources, al
|
1483 | // igual que lo tenemos en las capas. Por ahora, basta con retocar
|
||
1484 | // listInternalFields, pero casi seguro que lo correcto ser?a hacer un
|
||
1485 | // reload completo.
|
||
1486 | initalizeFields(ods); |
||
1487 | 7272 | jaume | |
1488 | 6313 | fjp | // listInternalFields.clear();
|
1489 | // listInternalFields.add(actualFields);
|
||
1490 | 6127 | fjp | } |
1491 | 5886 | fjp | |
1492 | 6212 | fjp | /*
|
1493 | * (non-Javadoc)
|
||
1494 | 7272 | jaume | *
|
1495 | 6212 | fjp | * @see com.iver.cit.gvsig.fmap.edition.IEditableSource#getFieldManager()
|
1496 | */
|
||
1497 | public IFieldManager getFieldManager() {
|
||
1498 | 6356 | fjp | if (ods.getDriver() instanceof IWriteable) |
1499 | { |
||
1500 | IWriter writer = ((IWriteable)ods.getDriver()).getWriter(); |
||
1501 | if ((writer != null) && (writer instanceof IFieldManager)) |
||
1502 | { |
||
1503 | 6628 | fjp | IFieldManager fldManager = (IFieldManager) writer; |
1504 | return fldManager;
|
||
1505 | 6356 | fjp | } |
1506 | } |
||
1507 | 6212 | fjp | return null; |
1508 | } |
||
1509 | |||
1510 | /**
|
||
1511 | * Tiene en cuenta los campos actuales para formatear una row con ellos. Le
|
||
1512 | * pasamos los campos que hab?a en el momento en que se cre? esa row.
|
||
1513 | 7272 | jaume | *
|
1514 | 6212 | fjp | * @param edRow
|
1515 | * @param indexInternalFields
|
||
1516 | * @return
|
||
1517 | */
|
||
1518 | public IRowEdited createExternalRow(IRowEdited edRow,
|
||
1519 | int indexInternalFields) {
|
||
1520 | 7272 | jaume | |
1521 | 6483 | fjp | // para acelerar
|
1522 | if (bFieldsHasBeenChanged == false) |
||
1523 | return edRow;
|
||
1524 | 7272 | jaume | |
1525 | 6212 | fjp | Value[] att = edRow.getAttributes();
|
1526 | TreeMap ancientFields = (TreeMap) listInternalFields |
||
1527 | .get(indexInternalFields); |
||
1528 | Value[] newAtt = new Value[actualFields.size()]; |
||
1529 | Collection aux = actualFields.values();
|
||
1530 | Iterator it = aux.iterator();
|
||
1531 | int i = 0; |
||
1532 | Value val = null;
|
||
1533 | while (it.hasNext()) {
|
||
1534 | 6384 | fjp | // Para cada campo de los actuales, miramos si ya estaba cuando
|
1535 | 7272 | jaume | // el registro estaba guardado.
|
1536 | 6384 | fjp | // Si estaba, cogemos el valor de ese campo en el registro
|
1537 | // guardado. Si no estaba, ha sido a?adido despu?s y ponemos
|
||
1538 | // su valor por defecto.
|
||
1539 | // Nota importante: fieldIndex es el ?ndice del campo cuando
|
||
1540 | // se guard?. NO es el ?ndice actual dentro de actualFields.
|
||
1541 | // Se usa SOLO para recuperar el valor de los atributos
|
||
1542 | // antiguos. Por eso no nos preocupamos de mantener actuallizados
|
||
1543 | // el resto de campos cuando se borra o a?ade un nuevo campo.
|
||
1544 | 6212 | fjp | InternalField fld = (InternalField) it.next(); |
1545 | 6483 | fjp | // System.err.println("fld = " + fld.getFieldDesc().getFieldAlias() + " id=" + fld.getFieldId());
|
1546 | 6212 | fjp | if (ancientFields.containsKey(fld.getFieldId())) {
|
1547 | InternalField ancientField = (InternalField) ancientFields |
||
1548 | .get(fld.getFieldId()); |
||
1549 | 6839 | fjp | val = att[ancientField.getFieldIndex()]; |
1550 | // val = att[ancientField.getFieldId().intValue()];
|
||
1551 | 6483 | fjp | // System.out.println("fld: " + fld.getFieldDesc().getFieldAlias() + " ancient:" + " val" + val);
|
1552 | 6212 | fjp | } else
|
1553 | val = fld.getFieldDesc().getDefaultValue(); |
||
1554 | 6227 | fjp | newAtt[i++] = val; |
1555 | 6212 | fjp | } |
1556 | IRowEdited newRow = (IRowEdited) edRow.cloneRow(); |
||
1557 | newRow.setAttributes(newAtt); |
||
1558 | return newRow;
|
||
1559 | } |
||
1560 | |||
1561 | public void removeField(String fieldName) throws EditionException { |
||
1562 | |||
1563 | InternalField fld = findFieldByName(fieldName); |
||
1564 | 6259 | fjp | if (fld == null) |
1565 | throw new EditionException("Field " + fieldName + " not found when removing field"); |
||
1566 | 6212 | fjp | Command command = new RemoveFieldCommand(this, fld); |
1567 | if (complex) {
|
||
1568 | commands.add(command); |
||
1569 | } else {
|
||
1570 | cr.pushCommand(command); |
||
1571 | } |
||
1572 | doRemoveField(fld); |
||
1573 | |||
1574 | } |
||
1575 | |||
1576 | private InternalField findFieldByName(String fieldName) { |
||
1577 | Collection aux = actualFields.values();
|
||
1578 | Iterator it = aux.iterator();
|
||
1579 | while (it.hasNext()) {
|
||
1580 | InternalField fld = (InternalField) it.next(); |
||
1581 | 6399 | fjp | if (fld.getFieldDesc().getFieldAlias().compareToIgnoreCase(fieldName) == 0) |
1582 | 6212 | fjp | return fld;
|
1583 | } |
||
1584 | 7272 | jaume | |
1585 | 6212 | fjp | return null; |
1586 | } |
||
1587 | |||
1588 | 6259 | fjp | public void undoRemoveField(InternalField field) throws EditionException { |
1589 | 6384 | fjp | // field.setDeleted(false);
|
1590 | // field.setFieldIndex(actualFields.size());
|
||
1591 | 6212 | fjp | actualFields.put(field.getFieldId(), field); |
1592 | fieldsChanged(); |
||
1593 | 6356 | fjp | fireAfterFieldAdded(field.getFieldDesc()); |
1594 | 6212 | fjp | } |
1595 | |||
1596 | 6259 | fjp | public void doRemoveField(InternalField field) throws EditionException { |
1597 | 6335 | fjp | boolean cancel = fireBeforeRemoveField(field.getFieldDesc());
|
1598 | if (cancel) return; |
||
1599 | 6212 | fjp | actualFields.remove(field.getFieldId()); |
1600 | fieldsChanged(); |
||
1601 | 6335 | fjp | fireAfterFieldRemoved(field.getFieldDesc()); |
1602 | 6212 | fjp | } |
1603 | |||
1604 | public void renameField(String antName, String newName) throws EditionException { |
||
1605 | |||
1606 | InternalField fld = findFieldByName(antName); |
||
1607 | Command command = new RenameFieldCommand(this, fld, newName); |
||
1608 | if (complex) {
|
||
1609 | commands.add(command); |
||
1610 | } else {
|
||
1611 | cr.pushCommand(command); |
||
1612 | } |
||
1613 | doRenameField(fld, newName); |
||
1614 | |||
1615 | } |
||
1616 | 7272 | jaume | |
1617 | 6399 | fjp | public void undoRenameField(InternalField field, String antName) throws EditionException { |
1618 | 6621 | fjp | field.getFieldDesc().setFieldAlias(antName); |
1619 | 6399 | fjp | fieldsChanged(); |
1620 | fireAfterFieldModified(field.getFieldDesc()); |
||
1621 | |||
1622 | 6212 | fjp | } |
1623 | |||
1624 | 6399 | fjp | public void doRenameField(InternalField field, String newName) throws EditionException { |
1625 | 6621 | fjp | field.getFieldDesc().setFieldAlias(newName); |
1626 | 6399 | fjp | fieldsChanged(); |
1627 | fireAfterFieldModified(field.getFieldDesc()); |
||
1628 | |||
1629 | 6212 | fjp | } |
1630 | |||
1631 | |||
1632 | public void addField(FieldDescription field) throws EditionException { |
||
1633 | |||
1634 | InternalField fld = new InternalField(field, InternalField.ADDED, new Integer(listFields.size())); |
||
1635 | Command command = new AddFieldCommand(this, fld); |
||
1636 | if (complex) {
|
||
1637 | commands.add(command); |
||
1638 | } else {
|
||
1639 | cr.pushCommand(command); |
||
1640 | } |
||
1641 | listFields.add(fld); |
||
1642 | doAddField(fld); |
||
1643 | |||
1644 | } |
||
1645 | |||
1646 | 6259 | fjp | public void undoAddField(InternalField field) throws EditionException { |
1647 | 6335 | fjp | boolean cancel = fireBeforeRemoveField(field.getFieldDesc());
|
1648 | if (cancel)
|
||
1649 | return;
|
||
1650 | |||
1651 | 6384 | fjp | // field.setDeleted(true);
|
1652 | 6227 | fjp | actualFields.remove(field.getFieldId()); |
1653 | 6212 | fjp | fieldsChanged(); |
1654 | 6335 | fjp | fireAfterFieldRemoved(field.getFieldDesc()); |
1655 | 7272 | jaume | |
1656 | 6212 | fjp | } |
1657 | |||
1658 | 6335 | fjp | public int doAddField(InternalField field) throws EditionException { |
1659 | boolean cancel;
|
||
1660 | cancel = fireBeforeFieldAdded(field.getFieldDesc()); |
||
1661 | if (cancel)
|
||
1662 | return -1; |
||
1663 | |||
1664 | 6384 | fjp | // field.setDeleted(false);
|
1665 | // field.setFieldIndex(actualFields.size());
|
||
1666 | 6227 | fjp | actualFields.put(field.getFieldId(), field); |
1667 | 6212 | fjp | fieldsChanged(); |
1668 | 6335 | fjp | fireAfterFieldAdded(field.getFieldDesc()); |
1669 | 6384 | fjp | // return field.getFieldIndex();
|
1670 | return field.getFieldId().intValue();
|
||
1671 | 6212 | fjp | } |
1672 | 7272 | jaume | |
1673 | 6365 | fjp | public Driver getOriginalDriver() |
1674 | 6356 | fjp | { |
1675 | return ods.getDriver();
|
||
1676 | } |
||
1677 | 7272 | jaume | |
1678 | 6478 | fjp | /**
|
1679 | * Use it to be sure the recordset will have the right fields. It forces a new SelectableDataSource
|
||
1680 | * to be created next time it is needed
|
||
1681 | */
|
||
1682 | public void cleanSelectableDatasource() { |
||
1683 | ds = null;
|
||
1684 | } |
||
1685 | |||
1686 | 6628 | fjp | public FieldDescription[] getFieldsDescription() { |
1687 | return (FieldDescription[]) fastAccessFields.toArray(new FieldDescription[0]); |
||
1688 | } |
||
1689 | |||
1690 | 7272 | jaume | |
1691 | 6384 | fjp | // private InternalField getInternalFieldByIndex(int fieldId)
|
1692 | // {
|
||
1693 | // for (Iterator iter = actualFields.values().iterator(); iter.hasNext();) {
|
||
1694 | // InternalField fld = (InternalField) iter.next();
|
||
1695 | // if (fld.getFieldIndex() == fieldId)
|
||
1696 | // return fld;
|
||
1697 | // }
|
||
1698 | // return null;
|
||
1699 | // }
|
||
1700 | 7272 | jaume | |
1701 | 3940 | caballero | } |