monitor.beginTask(Messages.ReshapeOperation_task, 100 );
List<Definition> transform = dialog.getTransform();
TransformProcess process = new TransformProcess();
DefaultTransaction transaction = new DefaultTransaction("Processing "+source.getName() ); //$NON-NLS-1$
try {
SimpleFeatureCollection collection = source.getFeatures();
SimpleFeatureCollection output = process.executeList(collection, transform);
final SimpleFeatureType featureType = output.getSchema();
IGeoResource scratch = CatalogPlugin.getDefault().getLocalCatalog().createTemporaryResource( featureType );
final SimpleFeatureStore store = scratch.resolve(SimpleFeatureStore.class, SubMonitor.convert(monitor,Messages.ReshapeOperation_createTempSpaceTask, 10));
store.setTransaction( transaction );
ProgressListener progessListener = GeoToolsAdapters.progress( SubMonitor.convert(monitor,"processing "+source.getName(), 90)); //$NON-NLS-1$
output.accepts(new FeatureVisitor(){
boolean warning = true;
public void visit( Feature rawFeature ) {
SimpleFeature feature = (SimpleFeature) rawFeature;
String fid = feature.getID();
try {
store.addFeatures(DataUtilities.collection(feature));
} catch (Throwable t) {
if (warning) {
System.out.println( "Process "+fid+":"+t);
t.printStackTrace();
warning = false;
}
}
}
}, progessListener );
transaction.commit();
// TODO: we need to show our new scratch feature in the catalog view?
return scratch;
}
catch (RuntimeException huh){
transaction.rollback();
huh.printStackTrace();
}
finally {
monitor.done();
}