use of org.jkiss.dbeaver.model.runtime.AbstractJob in project dbeaver by serge-rider.
the class PostgresRolePrivilegesEditor method createPartControl.
@Override
public void createPartControl(Composite parent) {
this.boldFont = UIUtils.makeBoldFont(parent.getFont());
parent.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
UIUtils.dispose(boldFont);
}
});
this.pageControl = new PageControl(parent);
this.pageControl.createOrSubstituteProgressPanel(getSite());
this.pageControl.setDoubleClickHandler(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
final ISelection selection = pageControl.getSelectionProvider().getSelection();
if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
final PostgrePermission element = (PostgrePermission) ((IStructuredSelection) selection).getFirstElement();
new AbstractJob("Open target object") {
@Override
protected IStatus run(DBRProgressMonitor monitor) {
try {
final PostgreObject targetObject = element.getTargetObject(monitor);
if (targetObject != null) {
DBeaverUI.syncExec(new Runnable() {
@Override
public void run() {
NavigatorHandlerObjectOpen.openEntityEditor(targetObject);
}
});
}
} catch (DBException e) {
return GeneralUtils.makeExceptionStatus(e);
}
return Status.OK_STATUS;
}
}.schedule();
}
}
});
}
use of org.jkiss.dbeaver.model.runtime.AbstractJob in project dbeaver by serge-rider.
the class RuntimeUtils method runTask.
public static boolean runTask(final DBRRunnableWithProgress task, String taskName, final long waitTime) {
final MonitoringTask monitoringTask = new MonitoringTask(task);
Job monitorJob = new AbstractJob(taskName) {
@Override
protected IStatus run(DBRProgressMonitor monitor) {
try {
monitoringTask.run(monitor);
} catch (InvocationTargetException e) {
log.error(getName() + " - error", e.getTargetException());
return Status.OK_STATUS;
} catch (InterruptedException e) {
// do nothing
}
return Status.OK_STATUS;
}
};
monitorJob.schedule();
// Wait for job to finish
long startTime = System.currentTimeMillis();
if (waitTime > 0) {
while (!monitoringTask.finished && System.currentTimeMillis() - startTime < waitTime) {
try {
Thread.sleep(50);
} catch (InterruptedException e) {
break;
}
}
}
return monitoringTask.finished;
}
use of org.jkiss.dbeaver.model.runtime.AbstractJob in project dbeaver by serge-rider.
the class SQLEditor method runPostExecuteActions.
private void runPostExecuteActions(@Nullable SQLQueryResult result) {
final DBCExecutionContext executionContext = getExecutionContext();
if (executionContext != null) {
final DBPDataSource dataSource = executionContext.getDataSource();
// Dump server output
DBCServerOutputReader outputReader = DBUtils.getAdapter(DBCServerOutputReader.class, dataSource);
if (outputReader == null && result != null) {
outputReader = new DefaultServerOutputReader(result);
}
if (outputReader != null && outputReader.isServerOutputEnabled()) {
dumpServerOutput(executionContext, outputReader);
}
// Refresh active object
if (result == null || !result.hasError() && getActivePreferenceStore().getBoolean(SQLPreferenceConstants.REFRESH_DEFAULTS_AFTER_EXECUTE)) {
final DBSObjectSelector objectSelector = DBUtils.getAdapter(DBSObjectSelector.class, dataSource);
if (objectSelector != null) {
new AbstractJob("Refresh default object") {
@Override
protected IStatus run(DBRProgressMonitor monitor) {
try (DBCSession session = executionContext.openSession(monitor, DBCExecutionPurpose.UTIL, "Refresh default object")) {
objectSelector.refreshDefaultObject(session);
} catch (Exception e) {
log.error(e);
}
return Status.OK_STATUS;
}
}.schedule();
}
}
}
}
Aggregations