use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project dbeaver by dbeaver.
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) {
DBUserInterface.getInstance().showError("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;
}
}
// Check for dirty editor (some local changes) and ask for confirmation
if (node instanceof DBNDatabaseFolder && !(node.getParentNode() instanceof DBNDatabaseFolder) && node.getParentNode() instanceof DBNDatabaseNode) {
// USe parent if this node is a folder
node = node.getParentNode();
}
IEditorPart nodeEditor = NavigatorHandlerObjectOpen.findEntityEditor(DBeaverUI.getActiveWorkbenchWindow(), node);
if (nodeEditor != null && nodeEditor.isDirty()) {
if (!new UIConfirmation() {
@Override
protected Boolean runTask() {
return ConfirmationDialog.showConfirmDialog(null, DBeaverPreferences.CONFIRM_ENTITY_REVERT, ConfirmationDialog.QUESTION, nodeEditor.getTitle()) == IDialogConstants.YES_ID;
}
}.execute()) {
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.IJobChangeEvent in project dbeaver by dbeaver.
the class GenerateSQLDialog method executeSQL.
protected void executeSQL() {
final String jobName = getShell().getText();
final String[] scriptLines = generateSQLScript();
DataSourceJob job = new DataSourceJob(jobName, executionContext) {
@Override
protected IStatus run(DBRProgressMonitor monitor) {
try (DBCSession session = getExecutionContext().openSession(monitor, DBCExecutionPurpose.UTIL, jobName)) {
for (String line : scriptLines) {
DBCStatement statement = DBUtils.makeStatement(session, line, false);
try {
statement.executeStatement();
} finally {
statement.close();
}
}
} catch (DBCException e) {
return GeneralUtils.makeExceptionStatus(e);
}
return Status.OK_STATUS;
}
};
job.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
if (event.getResult().isOK()) {
if (onSuccess != null) {
onSuccess.run();
}
}
}
});
job.schedule();
}
use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project dbeaver by dbeaver.
the class ObjectListControl method loadData.
public void loadData(boolean lazy) {
if (this.loadingJob != null) {
int dataLoadUpdatePeriod = 200;
int dataLoadTimes = getDataLoadTimeout() / dataLoadUpdatePeriod;
try {
for (int i = 0; i < dataLoadTimes; i++) {
Thread.sleep(dataLoadUpdatePeriod);
if (this.loadingJob == null) {
break;
}
}
} catch (InterruptedException e) {
// interrupted
}
if (loadingJob != null) {
UIUtils.showMessageBox(getShell(), "Load", "Service is busy", SWT.ICON_WARNING);
return;
}
return;
}
getListPropertySource();
clearLazyCache();
this.lazyLoadCanceled = false;
if (lazy) {
// start loading service
synchronized (this) {
this.loadingJob = createLoadService();
if (this.loadingJob != null) {
this.loadingJob.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
loadingJob = null;
}
});
this.loadingJob.schedule(LAZY_LOAD_DELAY);
}
}
} else {
// Load data synchronously
final LoadingJob<Collection<OBJECT_TYPE>> loadService = createLoadService();
if (loadService != null) {
loadService.syncRun();
}
}
}
use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project yamcs-studio by yamcs.
the class PreloadingRepositoryHandler method doExecuteAndLoad.
void doExecuteAndLoad() {
if (preloadRepositories()) {
// cancel any load that is already running
Job.getJobManager().cancel(LoadMetadataRepositoryJob.LOAD_FAMILY);
final LoadMetadataRepositoryJob loadJob = new LoadMetadataRepositoryJob(getProvisioningUI());
setLoadJobProperties(loadJob);
if (waitForPreload()) {
loadJob.addJobChangeListener(new JobChangeAdapter() {
public void done(IJobChangeEvent event) {
if (PlatformUI.isWorkbenchRunning())
if (event.getResult().isOK()) {
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
public void run() {
doExecute(loadJob);
}
});
}
}
});
loadJob.setUser(true);
loadJob.schedule();
} else {
loadJob.setSystem(true);
loadJob.setUser(false);
loadJob.schedule();
doExecute(null);
}
} else {
doExecute(null);
}
}
use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project dbeaver by dbeaver.
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