use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project dbeaver by serge-rider.
the class ObjectEditorPageControl method runService.
public synchronized <OBJECT_TYPE> void runService(LoadingJob<OBJECT_TYPE> service) {
curService = service;
service.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
synchronized (ObjectEditorPageControl.this) {
curService = null;
}
}
});
service.schedule();
}
use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project gfm_viewer by satyagraha.
the class SchedulerDefault method scheduleTransformation.
@Override
public void scheduleTransformation(final File mdFile, final File htFile, final Callback<File> onDone) {
final String jobName = "Transforming: " + mdFile.getName();
Job job = new Job(jobName) {
@Override
protected IStatus run(IProgressMonitor monitor) {
IStatus status = Status.OK_STATUS;
try {
transformer.transformMarkdownFile(mdFile, htFile);
} catch (IOException e) {
status = new Status(Status.ERROR, pluginId, jobName, e);
}
return status;
}
};
job.setUser(false);
job.setSystem(false);
job.setPriority(Job.SHORT);
job.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
// refreshFile(htFile);
if (event.getResult().isOK()) {
if (onDone != null) {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
onDone.onComplete(htFile);
}
});
}
} else {
// normal reporting has occurred
if (onDone != null) {
final Throwable exception = event.getResult().getException();
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
onDone.onError(htFile, exception);
}
});
}
}
}
});
job.schedule();
}
use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project snow-owl by b2ihealthcare.
the class ValidationThreadPool method submit.
public Promise<Object> submit(CheckType checkType, Runnable runnable) {
final Job job = new ValidationJob(checkType.getName(), runnable);
final String uniqueRuleId = UUID.randomUUID().toString();
final ISchedulingRule schedulingRule = new ValidationRuleSchedulingRule(checkType, maxValidationThreadCount, maxConcurrentExpensiveJobs, maxConcurrentNormalJobs, uniqueRuleId);
final Promise<Object> promise = new Promise<>();
job.setSystem(true);
job.setRule(schedulingRule);
job.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
if (event.getResult().isOK()) {
promise.resolve(Boolean.TRUE);
} else {
promise.reject(new ValidationException(String.format("Validation job failed with status %s.", event.getResult())));
}
}
});
job.schedule();
return promise;
}
use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project dbeaver by dbeaver.
the class ERDEditorStandalone method loadDiagram.
/*
protected void createActions()
{
super.createActions();
//addEditorAction(new SaveAction(this));
}
*/
@Override
protected synchronized void loadDiagram(boolean refreshMetadata) {
if (diagramLoadingJob != null) {
// Do not start new one while old is running
return;
}
diagramLoadingJob = LoadingJob.createService(new AbstractLoadService<EntityDiagram>("Load diagram '" + getEditorInput().getName() + "'") {
@Override
public EntityDiagram evaluate(DBRProgressMonitor monitor) {
try {
return loadContentFromFile(monitor);
} catch (DBException e) {
log.error(e);
}
return null;
}
@Override
public Object getFamily() {
return ERDEditorStandalone.this;
}
}, progressControl.createLoadVisualizer());
diagramLoadingJob.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
diagramLoadingJob = null;
}
});
diagramLoadingJob.schedule();
setPartName(getEditorInput().getName());
}
use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project dbeaver by dbeaver.
the class DataSourceHandler method disconnectDataSource.
public static void disconnectDataSource(DBPDataSourceContainer dataSourceContainer, @Nullable final Runnable onFinish) {
// Save users
for (DBPDataSourceTask user : dataSourceContainer.getTasks()) {
if (user instanceof ISaveablePart) {
if (!SaveChangesHandler.validateAndSave(new VoidProgressMonitor(), (ISaveablePart) user)) {
return;
}
}
}
if (!checkAndCloseActiveTransaction(dataSourceContainer)) {
return;
}
if (dataSourceContainer instanceof DataSourceDescriptor && dataSourceContainer.isConnected()) {
final DataSourceDescriptor dataSourceDescriptor = (DataSourceDescriptor) dataSourceContainer;
if (!ArrayUtils.isEmpty(Job.getJobManager().find(dataSourceDescriptor))) {
// Already connecting/disconnecting - just return
return;
}
final DisconnectJob disconnectJob = new DisconnectJob(dataSourceDescriptor);
disconnectJob.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
IStatus result = disconnectJob.getConnectStatus();
if (onFinish != null) {
onFinish.run();
} else if (!result.isOK()) {
DBWorkbench.getPlatformUI().showError(disconnectJob.getName(), null, result);
}
DataSourcePropertyTester.firePropertyChange(DataSourcePropertyTester.PROP_CONNECTED);
}
});
disconnectJob.schedule();
}
}
Aggregations