use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project dbeaver by serge-rider.
the class ClientHomesSelector method populateHomes.
public void populateHomes(DBPDriver driver, String currentHome, boolean selectDefault) {
this.driver = driver;
this.currentHomeId = currentHome;
this.homesCombo.removeAll();
this.homeIds.clear();
Map<String, DBPNativeClientLocation> homes = new LinkedHashMap<>();
AbstractJob hlJob = new AbstractJob("Find native client homes") {
@Override
protected IStatus run(DBRProgressMonitor monitor) {
for (DBPNativeClientLocation ncl : driver.getNativeClientLocations()) {
homes.put(ncl.getName(), ncl);
}
DBPNativeClientLocationManager clientManager = driver.getNativeClientManager();
if (clientManager != null) {
for (DBPNativeClientLocation location : clientManager.findLocalClientLocations()) {
homes.putIfAbsent(location.getName(), location);
}
}
return Status.OK_STATUS;
}
};
hlJob.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
UIUtils.syncExec(() -> {
for (DBPNativeClientLocation location : homes.values()) {
homesCombo.add(location.getDisplayName());
homeIds.add(location.getName());
if (currentHomeId != null && location.getName().equals(currentHomeId)) {
homesCombo.select(homesCombo.getItemCount() - 1);
}
}
if (homesCombo.getItemCount() == 0) {
homesCombo.add(UIConnectionMessages.controls_client_home_selector_missing);
homeIds.add(null);
}
if (selectDefault && homesCombo.getSelectionIndex() == -1) {
homesCombo.select(0);
currentHomeId = homeIds.get(0);
}
homesCombo.add(UIConnectionMessages.controls_client_home_selector_browse);
displayClientVersion();
homesCombo.setEnabled(true);
});
super.done(event);
}
});
hlJob.schedule();
}
use of org.eclipse.core.runtime.jobs.IJobChangeEvent 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) {
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 serge-rider.
the class ExasolBaseTableToolDialog method executeSQL.
@Override
protected void executeSQL() {
final String jobName = getShell().getText();
final SQLScriptProgressListener<ExasolTableBase> scriptListener = getScriptListener();
final List<ExasolTableBase> objects = getCheckedObjects();
final Map<ExasolTableBase, List<String>> objectsSQL = new LinkedHashMap<>();
for (ExasolTableBase object : objects) {
final List<String> lines = new ArrayList<>();
generateObjectCommand(lines, object);
objectsSQL.put(object, lines);
}
final DataSourceJob job = new DataSourceJob(jobName, getExecutionContext()) {
Exception objectProcessingError;
@SuppressWarnings("rawtypes")
@Override
protected IStatus run(final DBRProgressMonitor monitor) {
final DataSourceJob curJob = this;
UIUtils.asyncExec(() -> scriptListener.beginScriptProcessing(curJob, objects));
monitor.beginTask(jobName, objects.size());
try (DBCSession session = getExecutionContext().openSession(monitor, DBCExecutionPurpose.UTIL, jobName)) {
for (int i = 0; i < objects.size(); i++) {
if (monitor.isCanceled()) {
break;
}
final int objectNumber = i;
final ExasolTableBase object = objects.get(i);
monitor.subTask("Process " + DBUtils.getObjectFullName(object, DBPEvaluationContext.UI));
objectProcessingError = null;
UIUtils.asyncExec(() -> scriptListener.beginObjectProcessing(object, objectNumber));
try {
final List<String> lines = objectsSQL.get(object);
for (String line : lines) {
try (final Statement statement = ((JDBCSession) session).getOriginal().createStatement()) {
int affectedRows = statement.executeUpdate(line);
Integer[] resultSetData = new Integer[] { affectedRows };
final LocalResultSet resultSet = new LocalResultSet<>(session, new JDBCStatementImpl<>((JDBCSession) session, statement, true));
resultSet.addColumn("ROWS_AFFECTED", DBPDataKind.NUMERIC);
resultSet.addRow((Object[]) resultSetData);
// Run in sync because we need result set
UIUtils.syncExec(() -> {
try {
scriptListener.processObjectResults(object, null, resultSet);
} catch (DBCException e) {
objectProcessingError = e;
}
});
if (objectProcessingError != null) {
break;
}
}
}
} catch (Exception e) {
objectProcessingError = e;
} finally {
UIUtils.asyncExec(() -> scriptListener.endObjectProcessing(object, objectProcessingError));
}
monitor.worked(1);
}
} finally {
monitor.done();
UIUtils.asyncExec(scriptListener::endScriptProcessing);
}
return Status.OK_STATUS;
}
};
job.setUser(false);
job.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
}
});
job.schedule();
}
use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project dbeaver by serge-rider.
the class DBGJDBCSession method runAsync.
/**
* Start thread for SQL command
*/
protected void runAsync(String commandSQL, String name, DBGEvent begin, DBGEvent end) throws DBGException {
workerJob = new DBGJDBCWorker(this, name, commandSQL, begin, end);
workerJob.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
workerJob = null;
}
});
workerJob.schedule();
}
use of org.eclipse.core.runtime.jobs.IJobChangeEvent in project dbeaver by serge-rider.
the class PropertySourceAbstract method getPropertyValue.
@Override
public Object getPropertyValue(@Nullable DBRProgressMonitor monitor, final Object object, final ObjectPropertyDescriptor prop, boolean formatValue) {
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 = DBWorkbench.getPlatformUI().createLoadingService(new PropertyValueLoadService(), new PropertyValueLoadVisualizer());
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, formatValue);
}
} 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