// track objects that could not be removed
Map<CatalogInfo, StringResourceModel> notRemoved = new HashMap();
// collect the objects that will be removed (besides the roots)
Catalog catalog = GeoServerApplication.get().getCatalog();
CascadeRemovalReporter visitor = new CascadeRemovalReporter(catalog);
for (Iterator<CatalogInfo> i = (Iterator<CatalogInfo>) roots.iterator(); i.hasNext();) {
CatalogInfo root = i.next();
StringResourceModel reason = canRemove(root);
if ( reason != null ) {
notRemoved.put(root, reason);
i.remove();
}
else {
root.accept(visitor);
}
}
visitor.removeAll(roots);
// add roots
WebMarkupContainer root = new WebMarkupContainer("rootObjects");
root.add(new Label("rootObjectNames", names(roots)));
root.setVisible( !roots.isEmpty() );
add(root);
// objects that could not be removed
WebMarkupContainer nr = new WebMarkupContainer("notRemovedObjects");
nr.setVisible( !notRemoved.isEmpty() );
nr.add( notRemovedList(notRemoved));
add(nr);
// removed objects root (we show it if any removed object is on the list)
WebMarkupContainer removed = new WebMarkupContainer("removedObjects");
List<CatalogInfo> cascaded = visitor.getObjects(CatalogInfo.class, DELETE);
// remove the resources, they are cascaded, but won't be show in the UI
for (Iterator it = cascaded.iterator(); it.hasNext();) {
CatalogInfo catalogInfo = (CatalogInfo) it.next();
if(catalogInfo instanceof ResourceInfo)
it.remove();
}
removed.setVisible(cascaded.size() > 0);
add(removed);
// removed workspaces
WebMarkupContainer wsr = new WebMarkupContainer("workspacesRemoved");
removed.add(wsr);
List<WorkspaceInfo> workspaces = visitor.getObjects(WorkspaceInfo.class);
if(workspaces.size() == 0)
wsr.setVisible(false);
wsr.add(new Label("workspaces", names(workspaces)));
// removed stores
WebMarkupContainer str = new WebMarkupContainer("storesRemoved");
removed.add(str);
List<StoreInfo> stores = visitor.getObjects(StoreInfo.class);
if(stores.size() == 0)
str.setVisible(false);
str.add(new Label("stores", names(stores)));
// removed layers
WebMarkupContainer lar = new WebMarkupContainer("layersRemoved");
removed.add(lar);
List<LayerInfo> layers = visitor.getObjects(LayerInfo.class, DELETE);
if(layers.size() == 0)
lar.setVisible(false);
lar.add(new Label("layers", names(layers)));
// removed groups
WebMarkupContainer grr = new WebMarkupContainer("groupsRemoved");
removed.add(grr);
List<LayerGroupInfo> groups = visitor.getObjects(LayerGroupInfo.class, DELETE);
if(groups.size() == 0)
grr.setVisible(false);
grr.add(new Label("groups", names(groups)));
// modified objects root (we show it if any modified object is on the list)
WebMarkupContainer modified = new WebMarkupContainer("modifiedObjects");
modified.setVisible(visitor.getObjects(null, EXTRA_STYLE_REMOVED, GROUP_CHANGED, STYLE_RESET).size() > 0);
add(modified);
// layers modified
WebMarkupContainer lam = new WebMarkupContainer("layersModified");
modified.add(lam);
layers = visitor.getObjects(LayerInfo.class,
STYLE_RESET, EXTRA_STYLE_REMOVED);
if(layers.size() == 0)
lam.setVisible(false);
lam.add(new Label("layers", names(layers)));
// groups modified
WebMarkupContainer grm = new WebMarkupContainer("groupsModified");
modified.add(grm);
groups = visitor.getObjects(LayerGroupInfo.class, GROUP_CHANGED);
if(groups.size() == 0)
grm.setVisible(false);
grm.add(new Label("groups", names(groups)));
}