for (ILegendItem item : legendItems) {
if (item instanceof Folder) {
final Folder folder = (Folder) item;
for (ILegendItem folderItem : folder.getItems()) {
if (folderItem instanceof LayerLegendItem) {
final LayerLegendItem layerItem = (LayerLegendItem) folderItem;
final Layer layer = layerItem.getLayer();
if (isGridLayer(layer)) {
layers.add(layer);
}
}
}
} else if (item instanceof LayerLegendItem) {
final LayerLegendItem layerItem = (LayerLegendItem) item;
final Layer layer = layerItem.getLayer();
if (isGridLayer(layer)) {
layers.add(layer);
}
}
}