@Override
protected Component getComponentForProperty(String id, IModel itemModel,
Property<LayerSummary> property) {
final LayerSummary layerSummary = (LayerSummary) itemModel.getObject();
final CatalogIconFactory icons = CatalogIconFactory.get();
LayerInfo layer = layerSummary.getLayer();
if(property == LAYER) {
Fragment f = new Fragment(id, "edit", ImportSummaryPage.this);
Link editLink = editLink(layerSummary);
editLink.setEnabled(layer != null);
f.add(editLink);
return f;
} else if(property == STATUS) {
ResourceReference icon = layerSummary.getStatus().successful() ?
icons.getEnabledIcon() : icons.getDisabledIcon();
Fragment f = new Fragment(id, "iconFragment", ImportSummaryPage.this);
f.add(new Image("icon", icon));
return f;
} else if(property == TYPE) {
if(layer != null) {
ResourceReference icon = icons.getSpecificLayerIcon(layer);
Fragment f = new Fragment(id, "iconFragment", ImportSummaryPage.this);
Image image = new Image("icon", icon);
image.add(new AttributeModifier("title", true, new Model(getTypeTooltip(layer))));
f.add(image);
return f;
} else {
return new Label(id, "");
}
} else if(property == COMMANDS) {
Fragment f = new Fragment(id, "preview", ImportSummaryPage.this);
ExternalLink link = new ExternalLink("preview", "#");
if(layerSummary.getStatus().successful()) {
// TODO: move the preview link generation ability to some utility object
PreviewLayer preview = new PreviewLayer(layer);
String url = "window.open(\"" + preview.getWmsLink() + "&format=application/openlayers\")";
link.add(new AttributeAppender("onclick", new Model(url), ";"));
} else {
link.setEnabled(false);
}
f.add(link);
return f;
}
return null;
}
};
table.setOutputMarkupId(true);
table.setFilterable(false);
add(table);
// the rollback command
add(new ConfirmationAjaxLink("rollback", null,
new ParamResourceModel("rollback", this),
new ParamResourceModel("confirmRollback", this)) {
@Override
protected void onClick(AjaxRequestTarget target) {
Catalog catalog = getCatalog();
CascadeDeleteVisitor deleteVisitor = new CascadeDeleteVisitor(catalog);
String project = summary.getProject();
if(summary.isWorkspaceNew()) {
WorkspaceInfo ws = catalog.getWorkspaceByName(project);
if(ws != null)
ws.accept(deleteVisitor);
} else if(summary.isStoreNew()) {
StoreInfo si = catalog.getStoreByName(project, project, StoreInfo.class);
if(si != null)
si.accept(deleteVisitor);
} else {
// just remove the layers we created
for (LayerSummary layer : summary.getLayers()) {
catalog.remove(layer.getLayer());
catalog.remove(layer.getLayer().getResource());
}
}
setResponsePage(ImportPage.class, new PageParameters("afterCleanup=true"));
}
});