use of eu.esdihumboldt.hale.common.core.io.ProgressMonitorIndicator in project hale by halestudio.
the class ProjectResourcesUtil method executeProvider.
/**
* Execute the given I/O provider with the given I/O advisor.
*
* @param provider the I/O provider
* @param advisor the I/O advisor
* @param publishReport if the report should be published
* @param cacheCallback call back that is notified on cache changes for the
* I/O provider, may be <code>null</code>
* @return the future yielding the report on success
*/
public static ListenableFuture<IOReport> executeProvider(final IOProvider provider, @SuppressWarnings("rawtypes") final IOAdvisor advisor, final boolean publishReport, final CacheCallback cacheCallback) {
final SettableFuture<IOReport> result = SettableFuture.create();
IRunnableWithProgress op = new IRunnableWithProgress() {
@SuppressWarnings("unchecked")
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
if (cacheCallback != null && provider instanceof CachingImportProvider) {
// enable cache generation
((CachingImportProvider) provider).setProvideCache();
}
IOReporter reporter = provider.createReporter();
ATransaction trans = log.begin(reporter.getTaskName());
try {
// use advisor to configure provider
advisor.prepareProvider(provider);
advisor.updateConfiguration(provider);
// execute
IOReport report = provider.execute(new ProgressMonitorIndicator(monitor));
if (publishReport) {
// publish report
ReportService rs = PlatformUI.getWorkbench().getService(ReportService.class);
rs.addReport(report);
}
// handle cache update
if (cacheCallback != null && provider instanceof CachingImportProvider) {
CachingImportProvider cip = (CachingImportProvider) provider;
if (cip.isCacheUpdate()) {
Value cache = cip.getCache();
cacheCallback.update(cache);
}
}
// handle results
if (report.isSuccess()) {
advisor.handleResults(provider);
}
result.set(report);
} catch (Exception e) {
log.error("Error executing an I/O provider.", e);
result.setException(e);
} finally {
trans.end();
}
}
};
try {
ThreadProgressMonitor.runWithProgressDialog(op, provider.isCancelable());
} catch (Exception e) {
log.error("Error executing an I/O provider.", e);
result.setException(e);
}
return result;
}
Aggregations