headerTable.setOutputMarkupId(true);
headerTable.setFilterable(false);
headerTable.setPageable(false);
add(headerTable);
final ImportContext imp = model.getObject();
boolean selectable = imp.getState() != ImportContext.State.COMPLETE;
final ImportTaskTable taskTable = new ImportTaskTable("tasks",
new ImportTaskProvider(model), selectable) {
@Override
protected void onSelectionUpdate(AjaxRequestTarget target) {
updateImportLink((AjaxLink) ImportPage.this.get("import"), this, target);
}
}.setFeedbackPanel(feedbackPanel);
taskTable.setOutputMarkupId(true);
taskTable.setFilterable(false);
add(taskTable);
final AjaxLink<Long> importLink = new AjaxLink<Long>("import",
new Model<Long>()) {
@Override
protected void disableLink(ComponentTag tag) {
super.disableLink(tag);
ImporterWebUtils.disableLink(tag);
}
@Override
public void onClick(AjaxRequestTarget target) {
ImportContext imp = model.getObject();
BasicImportFilter filter = new BasicImportFilter();
for (ImportTask t : taskTable.getSelection()) {
filter.add(t);
}
//set running flag and update cancel link
running.set(true);
target.addComponent(cancelLink(this));
final Long jobid = importer().runAsync(imp, filter);
setDefaultModelObject(jobid);
final AjaxLink self = this;
// create a timer to update the table and reload the page when
// necessary
taskTable.add(new AbstractAjaxTimerBehavior(Duration.milliseconds(500)) {
@Override
protected void onTimer(AjaxRequestTarget target) {
Task<ImportContext> job = importer().getTask(jobid);
if (job == null || job.isDone()) {
// remove the timer
stop();
self.setEnabled(true);
target.addComponent(self);
running.set(false);
target.addComponent(cancelLink(self));
/*ImportContext imp = model.getObject();
if (imp.getState() == ImportContext.State.COMPLETE) {
// enable cancel, which will not be "done"
setLinkEnabled(cancelLink(self), true, target);
} else {
// disable cancel, import is not longer running, but
// also
// not complete
setLinkEnabled(cancelLink(self), false, target);
}*/
}
// update the table
target.addComponent(taskTable);
target.addComponent(headerTable);
}
});
target.addComponent(taskTable);
// disable import button
setLinkEnabled(this, false, target);
// enable cancel button
//setLinkEnabled(cancelLink(this), true, target);
}
};
importLink.setOutputMarkupId(true);
importLink.setEnabled(doSelectReady(imp, taskTable, null));
add(importLink);
final AjaxLink cancelLink = new AjaxLink("cancel") {
@Override
protected void disableLink(ComponentTag tag) {
super.disableLink(tag);
ImporterWebUtils.disableLink(tag);
}
@Override
public void onClick(AjaxRequestTarget target) {
ImportContext imp = model.getObject();
if (!running.get()) {
//if (imp.getState() == ImportContext.State.COMPLETE) {
setResponsePage(ImportDataPage.class);
return;
}
Long jobid = importLink.getModelObject();
if (jobid == null) {
return;
}
Task<ImportContext> task = importer().getTask(jobid);
if (task == null || task.isDone()) {
return;
}
task.getMonitor().setCanceled(true);
task.cancel(false);
try {
task.get();
} catch (Exception e) {
}
// enable import button
setLinkEnabled(importLink, true, target);
// disable cancel button
//setLinkEnabled(cancelLink(importLink), false, target);
}
};
//cancelLink.setEnabled(imp.getState() == ImportContext.State.COMPLETE);
cancelLink.add(new Label("text", new CancelTitleModel()));
add(cancelLink);
WebMarkupContainer selectPanel = new WebMarkupContainer("select");
selectPanel.add(new AjaxLink<ImportContext>("select-all", model) {
@Override
public void onClick(AjaxRequestTarget target) {
taskTable.selectAll();
target.addComponent(taskTable);
updateImportLink(importLink, taskTable, target);
}
});
selectPanel.add(new AjaxLink<ImportContext>("select-none", model) {
@Override
public void onClick(AjaxRequestTarget target) {
taskTable.clearSelection();
target.addComponent(taskTable);
updateImportLink(importLink, taskTable, target);
}
});
selectPanel.add(new AjaxLink<ImportContext>("select-ready", model) {
@Override
public void onClick(AjaxRequestTarget target) {
doSelectReady(getModelObject(), taskTable, target);
target.addComponent(taskTable);
updateImportLink(importLink, taskTable, target);
}
});
add(selectPanel);
add(new Icon("icon",new DataIconModel(imp.getData())));
add(new Label("title", new DataTitleModel(imp))
.add(new AttributeModifier("title", new DataTitleModel(imp, false))));
add(dialog = new GeoServerDialog("dialog"));
}