Revision 6313 trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/edition/EditableAdapter.java

View differences:

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

  
11
import sun.print.PSPrinterJob.PluginPrinter;
12

  
13 10
import com.hardcode.driverManager.Driver;
14 11
import com.hardcode.driverManager.DriverLoadException;
15 12
import com.hardcode.gdbms.engine.data.DataSourceFactory;
......
18 15
import com.hardcode.gdbms.engine.data.driver.ObjectDriver;
19 16
import com.hardcode.gdbms.engine.data.edition.DataWare;
20 17
import com.hardcode.gdbms.engine.values.Value;
21
import com.hardcode.gdbms.engine.values.ValueFactory;
22
import com.iver.cit.gvsig.fmap.MapControl.CancelDraw;
23 18
import com.iver.cit.gvsig.fmap.core.DefaultRow;
24 19
import com.iver.cit.gvsig.fmap.core.IRow;
25 20
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
......
153 148
	 */
154 149
	public void setOriginalDataSource(SelectableDataSource ds) throws DriverException {
155 150
		this.ods = ds;
151
		initalizeFields(ds);
152
		
153
	}
154

  
155
	/**
156
	 * @param ds
157
	 * @throws DriverException
158
	 */
159
	private void initalizeFields(SelectableDataSource ds) throws DriverException {
160
		boolean bReallyClosed = false;
161
		while (!bReallyClosed)
162
		{
163
			try {
164
				ds.stop();
165
			}
166
			catch (RuntimeException e) {
167
				bReallyClosed = true;
168
				ds.start();
169
			}
170
		}
171
		
172
		
156 173
		FieldDescription[] fields = ds.getFieldsDescription();
174
		listInternalFields.clear();
157 175
		actualFields = new TreeMap();
158 176
		for (int i=0; i < fields.length; i++)
159 177
		{
......
168 186
			e.printStackTrace();
169 187
			throw new DriverException(e);
170 188
		}
171
		
172 189
	}
173 190

  
174 191
	private void fieldsChanged() throws EditionException {
175
		listInternalFields.add(actualFields);
192
		listInternalFields.add(actualFields.clone());
176 193
		actualIndexFields = listInternalFields.size()-1;
177 194
		try {
178 195
			getRecordset().mapExternalFields();
......
298 315
	 */
299 316
	public void cancelEdition(int sourceType) throws IOException {
300 317
		isEditing = false;
301
		clean();
318
		try {
319
			clean();
320
		} catch (DriverException e) {
321
			e.printStackTrace();
322
			throw new IOException("Error: " + e.getMessage());
323
		}
302 324
		fireCancelEditionEvent(sourceType);
303 325
	}
304 326

  
......
319 341
				 * DefaultRow(ods.getRow(calculatedIndex), "" + index),
320 342
				 * DefaultRowEdited.STATUS_ORIGINAL, index);
321 343
				 */
322
				edRow = new DefaultRowEdited(new DefaultRow(ods
323
						.getRow(calculatedIndex)),
344
				DefaultRow auxR = new DefaultRow(ods.getRow(calculatedIndex));
345
				edRow = new DefaultRowEdited(auxR,
324 346
						DefaultRowEdited.STATUS_ORIGINAL, index);
347
				return createExternalRow(edRow, 0);
348
//				edRow = new DefaultRowEdited(new DefaultRow(ods
349
//						.getRow(calculatedIndex)),
350
//						DefaultRowEdited.STATUS_ORIGINAL, index);
325 351
			} catch (DriverException e) {
326 352
				throw new DriverIOException(e);
327 353
			}
328

  
329
			return edRow;
330 354
		} else {
331 355
			int num = ((Integer) relations.get(integer)).intValue();
332 356

  
333 357
			// return expansionFile.getRow(num);
358
			// ExpansionFile ya entrega el registro formateado como debe
334 359
			IRowEdited rowFromExpansion = expansionFile.getRow(num);
335 360
			// ?Habr?a que hacer aqu? setID(index + "")?
336 361
			edRow = new DefaultRowEdited(rowFromExpansion.getLinkedRow()
337 362
					.cloneRow(), rowFromExpansion.getStatus(), index);
338 363
			return edRow;
339 364
		}
365
		
366
		
367

  
340 368
	}
341 369

  
342 370
	/**
......
722 750
				try {
723 751
					ds = new SelectableDataSource(LayerFactory
724 752
							.getDataSourceFactory().createRandomDataSource(
725
									name, DataSourceFactory.AUTOMATIC_OPENING));
753
									name, DataSourceFactory.MANUAL_OPENING));
754
					ds.start();
726 755
					ds.setSelectionSupport(ods.getSelectionSupport());
727 756

  
728 757
				} catch (NoSuchTableException e) {
......
1163 1192
		this.rules = rules;
1164 1193
	}
1165 1194

  
1166
	private void clean() throws IOException {
1195
	private void clean() throws IOException, DriverException {
1167 1196
		expansionFile.close();
1168 1197
		relations.clear();
1169 1198
		numAdd = 0;
1170 1199
		delRows.clear();
1200
		// TODO: Es muy probable que necesitemos un reload de los datasources, al
1201
		// igual que lo tenemos en las capas. Por ahora, basta con retocar
1202
		// listInternalFields, pero casi seguro que lo correcto ser?a hacer un
1203
		// reload completo.
1204
		initalizeFields(ods);
1205
		
1206
//		listInternalFields.clear();
1207
//		listInternalFields.add(actualFields);
1171 1208
	}
1172 1209

  
1173 1210
	/*
......
1201 1238
		Value val = null;
1202 1239
		while (it.hasNext()) {
1203 1240
			InternalField fld = (InternalField) it.next();
1241
			System.err.println("fld = " + fld.getFieldDesc().getFieldAlias() + " index=" + fld.getFieldIndex() + " id=" + fld.getFieldId());
1204 1242
			if (ancientFields.containsKey(fld.getFieldId())) {
1205 1243
				InternalField ancientField = (InternalField) ancientFields
1206 1244
						.get(fld.getFieldId());

Also available in: Unified diff