protected static Layer createTitleArea(Map map, Rectangle location, IProgressMonitor monitor) {
try {
ICatalog localCatalog = CatalogPlugin.getDefault().getLocalCatalog();
List<Layer> layersInternal = map.getLayersInternal();
LayerFactory layerFactory = map.getLayerFactory();
Iterator layerIterator = layersInternal.iterator();
Layer farmParcelLayer = null;
while (layerIterator.hasNext()) {
Layer layer = (Layer)layerIterator.next();
if (layer.getName().equals("SDE.DATE_PRIMARE")) {
farmParcelLayer = layer;
}
}
if (farmParcelLayer == null) {
throw new IllegalStateException("cannot find farm layer");
}
//get title from selected feature of farm layer
Filter farmParcelFilter = farmParcelLayer.getFilter();
Query query = new DefaultQuery(farmParcelLayer.getSchema().getTypeName(),
farmParcelFilter,
new String[0] ); //{"nume_com", "fbid"}
FeatureSource<SimpleFeatureType, SimpleFeature> featureSource =
farmParcelLayer.getResource(FeatureSource.class,
new SubProgressMonitor(monitor, 1));
FeatureCollection<SimpleFeatureType, SimpleFeature> features = featureSource.getFeatures(query);
FeatureIterator<SimpleFeature> featureIterator = features.features();
if (!featureIterator.hasNext()) {
throw new IllegalStateException("At least one feature must be selected in the farm layer. "+features.size()+ " found.");
}
SimpleFeature selectedFarmFeature = featureIterator.next();
String prov = (String)selectedFarmFeature.getAttribute(0);
String id = (String)selectedFarmFeature.getAttribute(1);
//put layer info on the mapgraphic's style blackboard
URL detailsResId = new URL(null, "mapgraphic://localhost/mapgraphic#org.locationtech.udig.tutorial.mapgraphic.TitleArea", CorePlugin.RELAXED_HANDLER);
IGeoResource detailsRes = localCatalog.getById(IGeoResource.class, new ID(detailsResId), new NullProgressMonitor());
Layer titleAreaLayer = layerFactory.createLayer(detailsRes);
titleAreaLayer.getStyleBlackboard().put(LocationStyleContent.ID, location);
XMLMemento selectedFeatureMemento = XMLMemento.createWriteRoot("style");
selectedFeatureMemento.putString(FEATURE_ID_KEY, id);
titleAreaLayer.getStyleBlackboard().put(DialogSettingsStyleContent.EXTENSION_ID, selectedFeatureMemento);
return titleAreaLayer;