use of de.fhg.igd.slf4jplus.ATransaction in project hale by halestudio.
the class ActionProjectFile method executeProvider.
private <P extends IOProvider> void executeProvider(P provider, IOAdvisor<P> advisor) throws Exception {
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 LogProgressIndicator());
// handle results
if (report.isSuccess()) {
advisor.handleResults(provider);
} else {
// TODO propagate report errors somehow?
throw new IOException("Project file action was not successful");
}
} finally {
trans.end();
}
}
use of de.fhg.igd.slf4jplus.ATransaction in project hale by halestudio.
the class IOWizard method execute.
/**
* Execute the given provider
*
* @param provider the I/O provider
* @param defaultReporter the default reporter that is used if the provider
* doesn't supply a report
* @return the execution report, if null it will not give feedback to the
* user and the advisor's handleResult method won't be called either
*/
protected IOReport execute(final IOProvider provider, final IOReporter defaultReporter) {
// execute provider
final AtomicReference<IOReport> report = new AtomicReference<IOReport>(defaultReporter);
defaultReporter.setSuccess(false);
try {
getContainer().run(true, provider.isCancelable(), new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
ATransaction trans = log.begin(defaultReporter.getTaskName());
try {
IOReport result = provider.execute(new ProgressMonitorIndicator(monitor));
if (result != null) {
report.set(result);
} else {
defaultReporter.setSuccess(true);
}
} catch (Throwable e) {
defaultReporter.error(new IOMessageImpl(e.getLocalizedMessage(), e));
} finally {
trans.end();
}
}
});
} catch (Throwable e) {
defaultReporter.error(new IOMessageImpl(e.getLocalizedMessage(), e));
}
return report.get();
}
use of de.fhg.igd.slf4jplus.ATransaction 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;
}
use of de.fhg.igd.slf4jplus.ATransaction in project hale by halestudio.
the class ProjectServiceImpl method internalClean.
private boolean internalClean() {
if (!changeCheck()) {
return false;
}
// reset current session descriptor
ReportService repService = PlatformUI.getWorkbench().getService(ReportService.class);
repService.updateCurrentSessionDescription();
// clean
final IRunnableWithProgress op = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
ATransaction trans = log.begin("Clean project");
CleanupService cs = HalePlatform.getService(CleanupService.class);
if (cs != null) {
cs.triggerProjectCleanup();
}
monitor.beginTask("Clean project", IProgressMonitor.UNKNOWN);
try {
synchronized (this) {
main = createDefaultProject();
projectFile = null;
projectLocation = null;
changed = false;
projectLoadContentType = null;
temporarySettings.clear();
}
updateWindowTitle();
notifyClean();
// schemas aren't valid anymore, clear property resolver
// cache
PropertyResolver.clearCache();
} finally {
monitor.done();
trans.end();
}
// clean workbench history AFTER other cleans since they can
// create operations
IWorkbenchOperationSupport os = PlatformUI.getWorkbench().getOperationSupport();
os.getOperationHistory().dispose(os.getUndoContext(), true, true, false);
// suppress the status being set to changed by the clean
synchronized (ProjectServiceImpl.this) {
changed = false;
}
updateWindowTitle();
}
};
try {
ThreadProgressMonitor.runWithProgressDialog(op, false);
} catch (Exception e) {
log.error("Error cleaning the project.", e);
}
return true;
}
Aggregations