Revision 4447 trunk/extensions/extGeoProcessing/src/com/iver/gvsig/geoprocessing/impl/spatialjoin/SpatialJoinGeoprocess.java

View differences:

SpatialJoinGeoprocess.java
45 45
 *
46 46
 * $Id$
47 47
 * $Log$
48
 * Revision 1.4  2006-03-14 18:32:46  fjp
48
 * Revision 1.5  2006-03-15 18:34:31  azabala
49
 * *** empty log message ***
50
 *
51
 * Revision 1.4  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.3  2006/03/07 21:01:33  azabala
......
64 67
import java.util.Map;
65 68

  
66 69
import com.iver.cit.gvsig.fmap.DriverException;
70
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
67 71
import com.iver.cit.gvsig.fmap.drivers.ILayerDefinition;
68
import com.iver.cit.gvsig.fmap.drivers.ITableDefinition;
72
import com.iver.cit.gvsig.fmap.edition.EditionException;
73
import com.iver.cit.gvsig.fmap.layers.FBitSet;
69 74
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
75
import com.iver.cit.gvsig.fmap.operations.CancellableMonitorable;
76
import com.iver.cit.gvsig.fmap.operations.DefaultCancellableMonitorable;
70 77
import com.iver.cit.gvsig.fmap.operations.strategies.Strategy;
71 78
import com.iver.cit.gvsig.fmap.operations.strategies.StrategyManager;
72 79
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException;
73 80
import com.iver.gvsig.geoprocessing.impl.AbstractGeoprocess;
81
import com.iver.gvsig.geoprocessing.impl.difference.DifferenceVisitor;
82
import com.iver.gvsig.geoprocessing.impl.intersection.IntersectVisitor;
83
import com.iver.gvsig.geoprocessing.impl.jtsprocessors.DeferredFeaturePersisterProcessor;
74 84
import com.iver.gvsig.geoprocessing.impl.jtsprocessors.FeaturePersisterProcessor2;
75 85
import com.iver.gvsig.geoprocessing.model.GeoprocessException;
76 86
import com.iver.gvsig.geoprocessing.model.ITwoLayersGeoprocess;
77 87
import com.iver.gvsig.geoprocessing.schemabuilder.XTypes;
88
import com.iver.utiles.swing.threads.IMonitorableTask;
78 89

  
79 90
public class SpatialJoinGeoprocess extends AbstractGeoprocess
80 91
								implements ITwoLayersGeoprocess {
......
247 258
		this.fields_sumFunctions = fields_sumFunctions;
248 259
	}
249 260

  
261
	public IMonitorableTask createTask() {
262
		try {
263
			return new SpatialJoinMonitorableTask();
264
		} catch (DriverIOException e) {
265
			return null;
266
		}
267
	}
268
	
269
	class SpatialJoinMonitorableTask implements IMonitorableTask {
270
		private CancellableMonitorable cancelMonitor = null;
271
		private boolean finished = false;
272

  
273
		SpatialJoinMonitorableTask() throws DriverIOException {
274
			initialize();
275
		}
276
		void initialize() throws DriverIOException {
277
			cancelMonitor = createCancelMonitor();
278
		}
279

  
280
		private CancellableMonitorable createCancelMonitor()
281
				throws DriverIOException {
282
			DefaultCancellableMonitorable monitor = new 
283
							DefaultCancellableMonitorable();
284
			monitor.setInitialStep(0);
285
			monitor.setDeterminatedProcess(true);
286
			int numSteps = 0;
287
			if (onlyFirstLayerSelection) {
288
				FBitSet selection = firstLayer.getRecordset().getSelection();
289
				numSteps += (2 * selection.cardinality());
290
			} else {
291
				numSteps += 2 * firstLayer.getSource().getShapeCount();
292
			}
293
			monitor.setFinalStep(numSteps);
294
			return monitor;
295
		}
296

  
297
		public int getInitialStep() {
298
			return cancelMonitor.getInitialStep();
299
		}
300

  
301
		public int getFinishStep() {
302
			return cancelMonitor.getFinalStep();
303
		}
304

  
305
		public int getCurrentStep() {
306
			return cancelMonitor.getCurrentStep();
307
		}
308

  
309
		public String getStatusMessage() {
310
			// FIXME Cambiar esto por un mecanismo de eventos,
311
			// de forma que la tarea lo que tenga sea un escuchador
312
			// que cambie el mensaje de estado segun los eventos
313
			// de tareas que se est?n realizando
314
			return "Spatial Join Geoprocess...";
315
		}
316

  
317
		public String getNote() {
318
			// FIXME Cambiar esto por un mecanismo de eventos,
319
			// de forma que la tarea lo que tenga sea un escuchador
320
			// que cambie el mensaje de estado segun los eventos
321
			// de tareas que se est?n realizando
322
			return "Joining " + getCurrentStep() + " of " + getFinishStep();
323
		}
324

  
325
		public void cancel() {
326
			((DefaultCancellableMonitorable) cancelMonitor).setCanceled(true);
327
		}
328

  
329
		public void run() throws GeoprocessException {
330

  
331
			Strategy strategy =
332
				StrategyManager.getStrategy(firstLayer);
333
			Strategy secondLyrStrategy =
334
				StrategyManager.getStrategy(secondLayer);
335
			visitor.setCancelableStrategy(secondLyrStrategy);
336
			visitor.setOnlySecondLyrSelection(onlySecondLayerSelection);
337
			try {
338
				if(onlyFirstLayerSelection){
339
					strategy.process(visitor, 
340
							firstLayer.getRecordset().
341
							getSelection(),
342
							cancelMonitor);
343
					
344
				}else{
345
					strategy.process(visitor, cancelMonitor);
346
				}
347
				
348
			} catch (DriverException e) {
349
				throw new GeoprocessException("Error al acceder a los datos durante un spatial join");
350
			} catch (VisitException e) {
351
				throw new GeoprocessException("Error al procesar los datos durante un spatial join");
352
			}
353
			finally{
354
				finished = true;
355
			}
356
		}
357

  
358
		public boolean isDefined() {
359
			return cancelMonitor.isDeterminatedProcess();
360
		}
361

  
362
		public boolean isCanceled() {
363
			return cancelMonitor.isCanceled();
364
		}
365

  
366
		public boolean isFinished() {
367
			return finished;
368
		}
369
	}
370
	
371

  
250 372
}

Also available in: Unified diff