com.datastax.data.dataset.provider.SaveTask Maven / Gradle / Ivy
The newest version!
package com.datastax.data.dataset.provider;
import com.datastax.data.dataset.DataTable;
import javax.swing.*;
import java.util.Arrays;
import java.util.logging.Level;
import java.util.logging.Logger;
public abstract class SaveTask extends AbstractTask {
private static final Logger LOG = Logger.getLogger(SaveTask.class.getName());
private DataTable[] tables;
public SaveTask(DataTable[] tables) {
this.tables = tables == null ? new DataTable[0] : tables;
}
public void run() {
setIndeterminate(true);
try {
saveData(tables);
setProgress(getMaximum());
} catch (Exception e) {
final Throwable error = e;
LOG.log(Level.WARNING, "Failed to save data from tables {0}", Arrays.asList(tables));
LOG.log(Level.WARNING, e.getMessage(), e);
setProgress(getMaximum());
}
}
protected abstract void saveData(DataTable[] tables) throws Exception;
public String getDescription() {
return "Saving data
";
}
public Icon getIcon() {
return null;
}
public String getMessage() {
return "Saving item " + (getProgress() + 1) + " of " + getMaximum();
}
public boolean cancel() throws Exception {
return false;
}
}