use of org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress in project dbeaver by dbeaver.
the class NavigatorHandlerObjectOpen method refreshDatabaseNode.
private static void refreshDatabaseNode(@NotNull DBNDatabaseNode selectedNode) throws InvocationTargetException, InterruptedException {
final DBNDatabaseNode nodeToRefresh = selectedNode;
DBeaverUI.runInProgressService(new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
nodeToRefresh.refreshNode(monitor, nodeToRefresh);
} catch (DBException e) {
log.error("Error refreshing database object", e);
}
}
});
}
use of org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress in project dbeaver by dbeaver.
the class DialogUtils method loadFromFile.
public static boolean loadFromFile(final IValueController controller) {
if (!(controller.getValue() instanceof DBDContent)) {
log.error(CoreMessages.model_jdbc_bad_content_value_ + controller.getValue());
return false;
}
Shell shell = UIUtils.getShell(controller.getValueSite());
final File openFile = openFile(shell);
if (openFile == null) {
return false;
}
final DBDContent value = (DBDContent) controller.getValue();
DBeaverUI.runInUI(PlatformUI.getWorkbench().getActiveWorkbenchWindow(), new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
DBDContentStorage storage;
if (ContentUtils.isTextContent(value)) {
storage = new ExternalContentStorage(DBeaverCore.getInstance(), openFile, GeneralUtils.UTF8_ENCODING);
} else {
storage = new ExternalContentStorage(DBeaverCore.getInstance(), openFile);
}
value.updateContents(monitor, storage);
controller.updateValue(value, true);
} catch (Exception e) {
throw new InvocationTargetException(e);
}
}
});
return true;
}
use of org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress in project dbeaver by dbeaver.
the class DialogUtils method saveToFile.
public static void saveToFile(IValueController controller) {
if (!(controller.getValue() instanceof DBDContent)) {
log.error(CoreMessages.model_jdbc_bad_content_value_ + controller.getValue());
return;
}
Shell shell = UIUtils.getShell(controller.getValueSite());
final File saveFile = selectFileForSave(shell, controller.getValueName());
if (saveFile == null) {
return;
}
final DBDContent value = (DBDContent) controller.getValue();
try {
DBeaverUI.runInProgressService(new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
DBDContentStorage storage = value.getContents(monitor);
if (ContentUtils.isTextContent(value)) {
try (Reader cr = storage.getContentReader()) {
ContentUtils.saveContentToFile(cr, saveFile, GeneralUtils.UTF8_ENCODING, monitor);
}
} else {
try (InputStream cs = storage.getContentStream()) {
ContentUtils.saveContentToFile(cs, saveFile, monitor);
}
}
} catch (Exception e) {
throw new InvocationTargetException(e);
}
}
});
} catch (InvocationTargetException e) {
DBUserInterface.getInstance().showError(CoreMessages.model_jdbc_could_not_save_content, // $NON-NLS-2$
CoreMessages.model_jdbc_could_not_save_content_to_file_ + saveFile.getAbsolutePath() + "'", e.getTargetException());
} catch (InterruptedException e) {
// do nothing
}
}
use of org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress in project dbeaver by dbeaver.
the class ContentPanelEditor method primeEditorValue.
@Override
public void primeEditorValue(@Nullable final Object value) throws DBException {
final DBDContent content = (DBDContent) valueController.getValue();
if (content == null) {
valueController.showMessage("NULL content value. Must be DBDContent.", DBPMessageType.ERROR);
return;
}
if (streamEditor == null) {
valueController.showMessage("NULL content editor.", DBPMessageType.ERROR);
return;
}
DBeaverUI.runInUI(valueController.getValueSite().getWorkbenchWindow(), new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
streamEditor.primeEditorValue(monitor, control, content);
} catch (Throwable e) {
log.debug(e);
valueController.showMessage(e.getMessage(), DBPMessageType.ERROR);
}
}
});
}
use of org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress in project dbeaver by dbeaver.
the class DriverDescriptor method validateFilesPresence.
@NotNull
private List<File> validateFilesPresence(boolean resetVersions) {
boolean localLibsExists = false;
final List<DBPDriverLibrary> downloadCandidates = new ArrayList<>();
for (DBPDriverLibrary library : libraries) {
if (library.isDisabled()) {
// Nothing we can do about it
continue;
}
if (!library.matchesCurrentPlatform()) {
// Wrong OS or architecture
continue;
}
if (library.isDownloadable()) {
boolean allExists = true;
if (resetVersions) {
allExists = false;
} else {
List<DriverFileInfo> files = resolvedFiles.get(library);
if (files == null) {
allExists = false;
} else {
for (DriverFileInfo file : files) {
if (file.file == null || !file.file.exists()) {
allExists = false;
break;
}
}
}
}
if (!allExists) {
downloadCandidates.add(library);
}
} else {
localLibsExists = true;
}
}
// if (!CommonUtils.isEmpty(fileSources)) {
// for (DriverFileSource source : fileSources) {
// for (DriverFileSource.FileInfo fileInfo : source.getFiles()) {
// DriverLibraryLocal libraryLocal = new DriverLibraryLocal(this, DBPDriverLibrary.FileType.jar, fileInfo.getName());
// final File localFile = libraryLocal.getLocalFile();
// }
// }
// }
boolean downloaded = false;
if (!downloadCandidates.isEmpty() || (!localLibsExists && !fileSources.isEmpty())) {
final DriverDependencies dependencies = new DriverDependencies(downloadCandidates);
boolean downloadOk = new UITask<Boolean>() {
@Override
protected Boolean runTask() {
return DriverDownloadDialog.downloadDriverFiles(null, DriverDescriptor.this, dependencies);
}
}.execute();
if (!downloadOk) {
return Collections.emptyList();
}
if (resetVersions) {
resetDriverInstance();
/*
for (DBPDriverLibrary library : libraries) {
if (!library.isDisabled()) {
library.resetVersion();
}
}
*/
}
downloaded = true;
for (DBPDriverDependencies.DependencyNode node : dependencies.getLibraryMap()) {
List<DriverFileInfo> info = new ArrayList<>();
resolvedFiles.put(node.library, info);
collectLibraryFiles(node, info);
}
providerDescriptor.getRegistry().saveDrivers();
}
List<File> result = new ArrayList<>();
for (DBPDriverLibrary library : libraries) {
if (library.isDisabled() || !library.matchesCurrentPlatform()) {
// Wrong OS or architecture
continue;
}
if (library.isDownloadable()) {
List<DriverFileInfo> files = resolvedFiles.get(library);
if (files != null) {
for (DriverFileInfo file : files) {
result.add(file.file);
}
}
} else {
result.add(library.getLocalFile());
}
}
// Now check driver version
if (DBeaverCore.getGlobalPreferenceStore().getBoolean(DBeaverPreferences.UI_DRIVERS_VERSION_UPDATE) && !downloaded) {
// TODO: implement new version check
if (false) {
try {
DBeaverUI.runInProgressService(new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
checkDriverVersion(monitor);
} catch (IOException e) {
throw new InvocationTargetException(e);
}
}
});
} catch (InvocationTargetException e) {
log.error(e.getTargetException());
} catch (InterruptedException e) {
// ignore
}
}
}
return result;
}
Aggregations