private void prepareDraw( IProgressMonitor monitor ) throws IOException, SchemaException {
// check for style information on the blackboard
ILayer layer = getContext().getLayer();
StyleBlackboard styleBlackboard = (StyleBlackboard) layer.getStyleBlackboard();
SimpleFeatureSource featureSource;
featureSource = layer.getResource(SimpleFeatureStore.class, new SubProgressMonitor(monitor, 0));
if (featureSource == null) {
featureSource = layer.getResource(SimpleFeatureSource.class, new SubProgressMonitor(monitor,
0));
}
Style style = getStyle(styleBlackboard, featureSource);
layers = new Layer[1];
CoordinateReferenceSystem layerCRS = layer.getCRS();
SimpleFeatureType schema = featureSource.getSchema();
// Original Query provided by Layer.getFilter() as adjusted by selection and edit filter
Query query = getContext().getFeatureQuery();
if( styleBlackboard.contains(ProjectBlackboardConstants.LAYER__STYLE_FILTER)){
if( query == null ){
query = new Query( schema.getTypeName() );
}
// Additional Filter provided as Style used to reduce onscreen clutter
FilterStyle filterStyle = (FilterStyle) styleBlackboard.get(ProjectBlackboardConstants.LAYER__STYLE_FILTER);
Filter styleFilter = filterStyle.toFilter(schema);
if( styleFilter != Filter.INCLUDE ){
Filter queryFilter = query.getFilter();
if( queryFilter == Filter.INCLUDE ){
query.setFilter( styleFilter );
}
else {
FilterFactory ff = CommonFactoryFinder.getFilterFactory();
Filter combinedFilter = ff.and(styleFilter, queryFilter);
query.setFilter( combinedFilter );
}
}
}
CoordinateReferenceSystem dataCRS = schema.getCoordinateReferenceSystem();
if (!layerCRS.equals(dataCRS)) {
// need to force the coordinate reference system to match the layer definition
FeatureLayer featureLayer = new FeatureLayer(featureSource, style, layer.getName()); //$NON-NLS-1$
if( query == null ){
query = new Query(schema.getTypeName());
}
query.setCoordinateSystem(layerCRS);
featureLayer.setQuery(query);
// double check the implementation is respecting our layer CRS
FeatureCollection<SimpleFeatureType, SimpleFeature> features = featureSource.getFeatures( query );
CoordinateReferenceSystem queryCRS = features.getSchema().getCoordinateReferenceSystem();
if(queryCRS.equals(layerCRS)){
layers[0] = featureLayer;
} else {