}
cancel.setDefaultModelObject(jobid);
this.add(new AbstractAjaxTimerBehavior(Duration.seconds(3)) {
protected void onTimer(AjaxRequestTarget target) {
Importer importer = ImporterWebUtils.importer();
Task<ImportContext> t = importer.getTask(jobid);
if (t.isDone()) {
try {
if (t.getError() != null) {
error(t.getError());
}
else if (t.isCancelled()) {
//do nothing
}
else {
ImportContext imp = t.get();
//check the import for actual things to do
boolean proceed = !imp.getTasks().isEmpty();
if (proceed) {
imp.setArchive(false);
importer.changed(imp);
PageParameters pp = new PageParameters();
pp.put("id", imp.getId());
setResponsePage(ImportPage.class, pp);
}
else {
info("No data to import was found");
importer.delete(imp);
}
}
}
catch(Exception e) {
error(e);
LOGGER.log(Level.WARNING, "", e);
}
finally {
stop();
//update the button back to original state
resetButtons(form, target);
target.addComponent(feedbackPanel);
}
return;
}
ProgressMonitor m = t.getMonitor();
String msg = m.getTask() != null ? m.getTask().toString() : "Working";
statusLabel.setDefaultModelObject(msg);
target.addComponent(statusLabel);
};
});
}
});
form.add(new AjaxLink<Long>("cancel", new Model<Long>()) {
protected void disableLink(ComponentTag tag) {
super.disableLink(tag);
ImporterWebUtils.disableLink(tag);
};
@Override
public void onClick(AjaxRequestTarget target) {
Importer importer = ImporterWebUtils.importer();
Long jobid = getModelObject();
Task<ImportContext> task = importer.getTask(jobid);
if (task != null && !task.isDone() && !task.isCancelled()) {
task.getMonitor().setCanceled(true);
task.cancel(false);
try {
task.get();
}
catch(Exception e) {
}
}
setEnabled(false);
Component next = getParent().get("next");
next.setEnabled(true);
target.addComponent(this);
target.addComponent(next);
}
}.setOutputMarkupId(true).setEnabled(false));
importTable = new ImportContextTable("imports", new ImportContextProvider(true) {
@Override
protected List<org.geoserver.web.wicket.GeoServerDataProvider.Property<ImportContext>> getProperties() {
return Arrays.asList(ID, STATE, UPDATED);
}
}, true) {
protected void onSelectionUpdate(AjaxRequestTarget target) {
removeImportLink.setEnabled(!getSelection().isEmpty());
target.addComponent(removeImportLink);
};
};
importTable.setOutputMarkupId(true);
importTable.setFilterable(false);
importTable.setSortable(false);
form.add(importTable);
form.add(removeImportLink = new AjaxLink("remove") {
@Override
public void onClick(AjaxRequestTarget target) {
Importer importer = ImporterWebUtils.importer();
for (ImportContext c : importTable.getSelection()) {
try {
importer.delete(c);
} catch (IOException e) {
LOGGER.log(Level.WARNING, "Error deleting context", c);
}
}
importTable.clearSelection();