use of org.eclipse.core.runtime.jobs.JobChangeAdapter 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.JobChangeAdapter in project dbeaver by serge-rider.
the class NavigatorHandlerRefresh method refreshNavigator.
public static void refreshNavigator(final Collection<? extends DBNNode> refreshObjects) {
Job refreshJob = new AbstractJob("Refresh navigator object(s)") {
public Throwable error;
@Override
protected IStatus run(DBRProgressMonitor monitor) {
addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
if (error != null) {
UIUtils.showErrorDialog(null, "Refresh", "Error refreshing node", error);
}
}
});
Set<DBNNode> refreshedSet = new HashSet<>();
for (DBNNode node : refreshObjects) {
if (node.isDisposed() || node.isLocked()) {
// Skip locked nodes
continue;
}
// Check this node was already refreshed
if (!refreshedSet.isEmpty()) {
boolean skip = false;
for (DBNNode refreshed : refreshedSet) {
if (node == refreshed || node.isChildOf(refreshed)) {
skip = true;
break;
}
}
if (skip) {
continue;
}
}
setName("Refresh '" + node.getNodeName() + "'...");
try {
DBNNode refreshed = node.refreshNode(monitor, DBNEvent.FORCE_REFRESH);
if (refreshed != null) {
refreshedSet.add(refreshed);
}
} catch (Throwable ex) {
error = ex;
}
}
return Status.OK_STATUS;
}
};
refreshJob.setUser(true);
refreshJob.schedule();
}
use of org.eclipse.core.runtime.jobs.JobChangeAdapter in project dbeaver by serge-rider.
the class DataSourceHandler method connectToDataSource.
/**
* Connects datasource
* @param monitor progress monitor or null. If nul then new job will be started
* @param dataSourceContainer container to connect
* @param onFinish finish handler
*/
public static void connectToDataSource(@Nullable DBRProgressMonitor monitor, @NotNull DBPDataSourceContainer dataSourceContainer, @Nullable final DBRProgressListener onFinish) {
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 ConnectJob connectJob = new ConnectJob(dataSourceDescriptor);
final JobChangeAdapter jobChangeAdapter = new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
IStatus result = connectJob.getConnectStatus();
if (result.isOK()) {
if (!dataSourceDescriptor.isSavePassword()) {
// Rest password back to null
// TODO: to be correct we need to reset password info.
// but we need a password to open isolated contexts (e.g. for data export)
// Currently it is not possible to ask for password from isolation context opening
// procedure. We need to do something here...
//dataSourceDescriptor.getConnectionConfiguration().setUserName(oldName);
//dataSourceDescriptor.getConnectionConfiguration().setUserPassword(oldPassword);
}
}
if (onFinish != null) {
onFinish.onTaskFinished(result);
} else if (!result.isOK()) {
DBUserInterface.getInstance().showError(connectJob.getName(), //NLS.bind(CoreMessages.runtime_jobs_connect_status_error, dataSourceContainer.getName()),
null, result);
}
}
};
if (monitor != null) {
connectJob.runSync(monitor);
jobChangeAdapter.done(new IJobChangeEvent() {
@Override
public long getDelay() {
return 0;
}
@Override
public Job getJob() {
return connectJob;
}
@Override
public IStatus getResult() {
return connectJob.getConnectStatus();
}
public IStatus getJobGroupResult() {
return null;
}
});
} else {
connectJob.addJobChangeListener(jobChangeAdapter);
// Schedule in UI because connect may be initiated during application startup
// and UI is still not initiated. In this case no progress dialog will appear
// to be sure run in UI async
DBeaverUI.asyncExec(new Runnable() {
@Override
public void run() {
connectJob.schedule();
}
});
}
}
}
use of org.eclipse.core.runtime.jobs.JobChangeAdapter in project dbeaver by serge-rider.
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) throws InvocationTargetException, InterruptedException {
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.JobChangeAdapter in project dbeaver by serge-rider.
the class PropertySourceAbstract method getPropertyValue.
@Override
public Object getPropertyValue(@Nullable DBRProgressMonitor monitor, final Object object, final ObjectPropertyDescriptor prop) {
try {
if (monitor == null && prop.isLazy(object, true) && !prop.supportsPreview()) {
final Object value = lazyValues.get(prop.getId());
if (value != null) {
return value;
}
if (lazyValues.containsKey(prop.getId())) {
// Some lazy props has null value
return null;
}
if (!loadLazyProps) {
return null;
} else {
synchronized (lazyProps) {
lazyProps.add(prop);
if (lazyLoadJob == null) {
// We assume that it can be called ONLY by properties viewer
// So, start lazy loading job to update it after value will be loaded
lazyLoadJob = LoadingJob.createService(new PropertySheetLoadService(), new PropertySheetLoadVisualizer());
lazyLoadJob.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
synchronized (lazyProps) {
if (!lazyProps.isEmpty()) {
lazyLoadJob.schedule(100);
} else {
lazyLoadJob = null;
}
}
}
});
lazyLoadJob.schedule(100);
}
}
// Return dummy string for now
lazyValues.put(prop.getId(), null);
return null;
}
} else {
return prop.readValue(object, monitor);
}
} catch (Throwable e) {
if (e instanceof InvocationTargetException) {
e = ((InvocationTargetException) e).getTargetException();
}
log.error("Error reading property '" + prop.getId() + "' from " + object, e);
return e.getMessage();
}
}
Aggregations