Revision 4447 trunk/extensions/extGeoProcessing/src/com/iver/gvsig/geoprocessing/impl/dissolve/DissolveGeoprocess.java

View differences:

DissolveGeoprocess.java
45 45
*
46 46
* $Id$
47 47
* $Log$
48
* Revision 1.5  2006-03-14 18:32:46  fjp
48
* Revision 1.6  2006-03-15 18:33:24  azabala
49
* *** empty log message ***
50
*
51
* Revision 1.5  2006/03/14 18:32:46  fjp
49 52
* Cambio con LayerDefinition para que sea compatible con la definici?n de tablas tambi?n.
50 53
*
51 54
* Revision 1.4  2006/03/07 21:01:33  azabala
......
69 72
import java.util.Map;
70 73

  
71 74
import com.iver.cit.gvsig.fmap.DriverException;
75
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
72 76
import com.iver.cit.gvsig.fmap.drivers.FieldDescription;
73 77
import com.iver.cit.gvsig.fmap.drivers.ILayerDefinition;
74 78
import com.iver.cit.gvsig.fmap.drivers.LayerDefinition;
75 79
import com.iver.cit.gvsig.fmap.drivers.SHPLayerDefinition;
80
import com.iver.cit.gvsig.fmap.edition.EditionException;
76 81
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
82
import com.iver.cit.gvsig.fmap.operations.CancellableMonitorable;
83
import com.iver.cit.gvsig.fmap.operations.DefaultCancellableMonitorable;
77 84
import com.iver.cit.gvsig.fmap.operations.strategies.Strategy;
78 85
import com.iver.cit.gvsig.fmap.operations.strategies.StrategyManager;
79 86
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException;
......
83 90
import com.iver.gvsig.geoprocessing.model.IOneLayerGeoprocess;
84 91
import com.iver.gvsig.geoprocessing.model.SummarizationFunction;
85 92
import com.iver.gvsig.geoprocessing.schemabuilder.XTypes;
93
import com.iver.utiles.swing.threads.IMonitorableTask;
86 94
/**
87 95
 * Processes each geometry of a polygonal vectorial layer, looking for
88 96
 * its adjacent polygons. If this adjacent polygons has the same specified 
......
135 143
			throw new GeoprocessException("Buffer con capa de entrada a null");
136 144
		if(this.writer == null || 
137 145
		   this.schemaManager == null){
138
			throw new GeoprocessException("Operacion de buffer sin especificar capa de resultados");
146
			throw new GeoprocessException("Operacion de dissolve sin especificar capa de resultados");
139 147
		}
140 148
		if(this.dissolveField == null)
141 149
			throw new GeoprocessException("No se ha proporcionado el campo para dissolver");
......
168 176
	
169 177

  
170 178
	public void cancel() {
171
		// TODO Auto-generated method stub
172

  
179
		try {
180
			schemaManager.drop();
181
		} catch (EditionException e) {
182
			// TODO Auto-generated catch block
183
			e.printStackTrace();
184
		}
173 185
	}
174 186
	
175 187
	public ILayerDefinition createLayerDefinition() {
......
214 226
		return resultLayerDefinition;
215 227
	}
216 228

  
229
	public IMonitorableTask createTask() {
230
		try {
231
			return new DissolveMonitorableTask();
232
		} catch (DriverIOException e) {
233
			return null;
234
		}
235
	}
236
	
237
	/**
238
	 * IMonitorableTask that allows to run diff geoprocess in background,
239
	 * with cancelation requests.
240
	 * 
241
	 * @author azabala
242
	 * 
243
	 */
244
	class DissolveMonitorableTask implements IMonitorableTask {
245
		private CancellableMonitorable cancelMonitor = null;
246

  
247
		// FIXME INTERNACIONALIZAR ESTO
248
		String DISSOLVE_MESSAGE = "Computing dissolve: ";
249

  
250
		private boolean finished = false;
251

  
252
		DissolveMonitorableTask() throws DriverIOException {
253
			initialize();
254
		}
255
		void initialize() throws DriverIOException{
256
			cancelMonitor = createCancelMonitor();
257
		}
258

  
259
		private CancellableMonitorable createCancelMonitor() throws DriverIOException{
260
			DefaultCancellableMonitorable monitor = new 
261
							DefaultCancellableMonitorable();
262
			monitor.setInitialStep(0);
263
			//monitor.setDeterminatedProcess(false);
264
			monitor.setFinalStep(firstLayer.getSource().getShapeCount());
265
			monitor.setDeterminatedProcess(true);
266
			return monitor;
267
		}
268

  
269
		public int getInitialStep() {
270
			return cancelMonitor.getInitialStep();
271
		}
272

  
273
		public int getFinishStep() {
274
			return cancelMonitor.getFinalStep();
275
		}
276

  
277
		public int getCurrentStep() {
278
			//return cancelMonitor.getCurrentStep();
279
			if(visitor == null)
280
				return getInitialStep();
281
			else
282
				return visitor.getNumProcessedGeometries();
283
		}
284

  
285
		public String getStatusMessage() {
286
			// FIXME Cambiar esto por un mecanismo de eventos,
287
			// de forma que la tarea lo que tenga sea un escuchador
288
			// que cambie el mensaje de estado segun los eventos
289
			// de tareas que se est?n realizando
290
			return "Dissolve Geoprocess...";
291
		}
292

  
293
		public String getNote() {
294
			// FIXME Cambiar esto por un mecanismo de eventos,
295
			// de forma que la tarea lo que tenga sea un escuchador
296
			// que cambie el mensaje de estado segun los eventos
297
			// de tareas que se est?n realizando
298
			return DISSOLVE_MESSAGE + getCurrentStep() + " of " +
299
													getFinishStep();
300
		}
301

  
302
		public void cancel() {
303
			((DefaultCancellableMonitorable) cancelMonitor).setCanceled(true);
304
		}
305

  
306
		public void run() throws GeoprocessException {
307

  
308
			try {
309

  
310
				FeaturePersisterProcessor2 processor =
311
					new FeaturePersisterProcessor2(writer);
312
				visitor = new DissolveVisitor(dissolveField, processor);
313
				visitor.setDissolvedAttributesInfo(fields_functions);
314
				Strategy strategy =
315
					StrategyManager.getStrategy(firstLayer);
316
				visitor.setStrategy(strategy);
317
				if(dissolveOnlySelection){
318
					strategy.process(visitor, firstLayer.
319
												   getRecordset().
320
												   getSelection(),
321
												   cancelMonitor);
322
				}else{
323
					strategy.process(visitor, cancelMonitor);
324
				}
325
			} catch (DriverException e) {
326
				throw new GeoprocessException("Error accediendo a los datos durante un dissolve");
327
			} catch (VisitException e) {
328
				throw new GeoprocessException("Error al procesar los elementos de la capa de entrada durante un dissolve");
329
			} finally{
330
				finished = true;
331
			}
332
		}
333

  
334
		public boolean isDefined() {
335
			return cancelMonitor.isDeterminatedProcess();
336
		}
337

  
338
		public boolean isCanceled() {
339
			return cancelMonitor.isCanceled();
340
		}
341

  
342
		public boolean isFinished() {
343
			return finished;
344
		}
345
	}
346

  
217 347
}
218 348

  

Also available in: Unified diff