List<EditGeom> geoms = bb.getGeoms();
monitor.beginTask(Messages.EditBlackboardUtil_updating_selected_features, geoms.size());
PrimitiveShape shape = (PrimitiveShape) layer.getMap().getBlackboard().get(
EditToolHandler.CURRENT_SHAPE);
EditManager editManager = (EditManager) layer.getMap().getEditManager();
FilterFactory factory = CommonFactoryFinder.getFilterFactory(GeoTools.getDefaultHints());
Set<Identifier> ids = new HashSet<Identifier>();
for( EditGeom geom : geoms ) {
ids.add(factory.featureId(geom.getFeatureIDRef().get()));
}
Id fidFilter = factory.id(ids);
Filter filter =factory.and(fidFilter, layer.createBBoxFilter(dirtyArea, new NullProgressMonitor()));
try {
FeatureSource<SimpleFeatureType, SimpleFeature> fs = layer.getResource(FeatureSource.class, monitor);
FeatureCollection<SimpleFeatureType, SimpleFeature> results = fs.getFeatures(filter);
FeatureIterator<SimpleFeature> reader = results.features();
try {
int read = 0;
boolean selectedFound = false;
List<EditGeom> toRemove = new ArrayList<EditGeom>();
while( reader.hasNext() ) {
int count = geoms.size() - read;
monitor.setTaskName(MessageFormat.format(Messages.EditBlackboardUtil_count_remaining, new Object[] {count}));
read++;
SimpleFeature feature = reader.next();
for( EditGeom geom : geoms ) {
if (feature.getID().equals(geom.getFeatureIDRef().get())) {
toRemove.add(geom);
}
}
Map<Geometry, EditGeom> mapping = bb.addGeometry((Geometry) feature.getDefaultGeometry(),
feature.getID());
if (feature.getID().equals(shape.getEditGeom().getFeatureIDRef().get())) {
editManager.setEditFeature(feature, (Layer) layer);
layer.getMap().getBlackboard().put(EditToolHandler.CURRENT_SHAPE,
mapping.values().iterator().next().getShell());
selectedFound = true;
}
monitor.worked(1);
}
if (!selectedFound) {
layer.getMap().getBlackboard().put(EditToolHandler.CURRENT_SHAPE, null);
editManager.setEditFeature(null, null);
}
bb.removeGeometries(toRemove);
} finally {
reader.close();
monitor.done();