use of org.jkiss.dbeaver.model.runtime.DBRRunnableWithResult in project dbeaver by serge-rider.
the class DatabaseNavigatorTree method expandNodeOnLoad.
private void expandNodeOnLoad(final DBNNode node) {
if (node instanceof DBNDataSource && DBWorkbench.getPlatform().getPreferenceStore().getBoolean(NavigatorPreferences.NAVIGATOR_EXPAND_ON_CONNECT)) {
try {
DBRRunnableWithResult<DBNNode> runnable = new DBRRunnableWithResult<DBNNode>() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException {
try {
result = findActiveNode(monitor, node);
} catch (DBException e) {
throw new InvocationTargetException(e);
}
}
};
UIUtils.runInProgressService(runnable);
if (runnable.getResult() != null && !treeViewer.getTree().isDisposed()) {
showNode(runnable.getResult());
treeViewer.expandToLevel(runnable.getResult(), 1);
/*
// TODO: it is a bug in Eclipse Photon.
try {
treeViewer.expandToLevel(runnable.getResult(), 1, true);
} catch (Throwable e) {
treeViewer.expandToLevel(runnable.getResult(), 1);
}
*/
}
} catch (InvocationTargetException e) {
log.error("Can't expand node", e.getTargetException());
} catch (InterruptedException e) {
// skip it
}
}
}
use of org.jkiss.dbeaver.model.runtime.DBRRunnableWithResult in project dbeaver by serge-rider.
the class DBUtils method createNewAttributeValue.
public static <T> T createNewAttributeValue(DBCExecutionContext context, DBDValueHandler valueHandler, DBSTypedObject valueType, Class<T> targetType) throws DBCException {
DBRRunnableWithResult<Object> runnable = new DBRRunnableWithResult<Object>() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException {
try (DBCSession session = context.openSession(monitor, DBCExecutionPurpose.UTIL, "Create new object")) {
result = valueHandler.createNewValueObject(session, valueType);
} catch (DBCException e) {
throw new InvocationTargetException(e);
}
}
};
try {
DBWorkbench.getPlatformUI().executeWithProgress(runnable);
// UIUtils.runInProgressService(runnable);
} catch (InvocationTargetException e) {
throw new DBCException(e.getTargetException(), context);
} catch (InterruptedException e) {
throw new DBCException(e, context);
}
Object result = runnable.getResult();
if (result == null) {
throw new DBCException("Internal error - null object created");
}
if (!targetType.isInstance(result)) {
throw new DBCException("Internal error - wrong object type '" + result.getClass().getName() + "' while '" + targetType.getName() + "' was expected");
}
return targetType.cast(result);
}
Aggregations