* @param folder
* @param layer
* @return true if removed, otherwise false
*/
private boolean removeLayerLegendItem(Folder folder, Layer layer) {
Folder flaggedFolder = null;
LayerLegendItem flaggedLayerItem = null;
for (ILegendItem item : folder.getItems()) {
if (item instanceof Folder) {
final boolean isRemoved = removeLayerLegendItem((Folder) item, layer);
if (isRemoved) {
return true;
}
} else if (item instanceof LayerLegendItem) {
final LayerLegendItem layerItem = (LayerLegendItem) item;
if (layer == layerItem.getLayer()) {
flaggedFolder = folder;
flaggedLayerItem = layerItem;
break;
}
}
}
if (flaggedLayerItem != null) {
flaggedFolder.getItems().remove(flaggedLayerItem);
return true;
}
return false;
}