Search in sources :

Example 6 with ProgressMonitorIndicator

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;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IOReporter(eu.esdihumboldt.hale.common.core.io.report.IOReporter) ReportService(eu.esdihumboldt.hale.ui.service.report.ReportService) ProgressMonitorIndicator(eu.esdihumboldt.hale.common.core.io.ProgressMonitorIndicator) CachingImportProvider(eu.esdihumboldt.hale.common.core.io.CachingImportProvider) ATransaction(de.fhg.igd.slf4jplus.ATransaction) Value(eu.esdihumboldt.hale.common.core.io.Value) IOReport(eu.esdihumboldt.hale.common.core.io.report.IOReport) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Aggregations

ProgressMonitorIndicator (eu.esdihumboldt.hale.common.core.io.ProgressMonitorIndicator)6 ATransaction (de.fhg.igd.slf4jplus.ATransaction)5 IOReport (eu.esdihumboldt.hale.common.core.io.report.IOReport)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 IOReporter (eu.esdihumboldt.hale.common.core.io.report.IOReporter)3 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)3 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)3 Cell (eu.esdihumboldt.hale.common.align.model.Cell)2 TransformationReport (eu.esdihumboldt.hale.common.align.transformation.report.TransformationReport)2 TransformationService (eu.esdihumboldt.hale.common.align.transformation.service.TransformationService)2 InstanceCollection (eu.esdihumboldt.hale.common.instance.model.InstanceCollection)2 FilteredInstanceCollection (eu.esdihumboldt.hale.common.instance.model.impl.FilteredInstanceCollection)2 BrowseOrientInstanceCollection (eu.esdihumboldt.hale.common.instance.orient.storage.BrowseOrientInstanceCollection)2 ReportService (eu.esdihumboldt.hale.ui.service.report.ReportService)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Alignment (eu.esdihumboldt.hale.common.align.model.Alignment)1 CachingImportProvider (eu.esdihumboldt.hale.common.core.io.CachingImportProvider)1 Value (eu.esdihumboldt.hale.common.core.io.Value)1 Locatable (eu.esdihumboldt.hale.common.core.io.supplier.Locatable)1 InstanceIndexService (eu.esdihumboldt.hale.common.instance.index.InstanceIndexService)1