use of org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress in project dbeaver by dbeaver.
the class DriverPropertiesDialogPage method setVisible.
@Override
public void setVisible(boolean visible) {
super.setVisible(visible);
// Set props model
if (visible && propsControl != null) {
final DBPDataSourceContainer activeDataSource = site.getActiveDataSource();
if (prevConnectionInfo == activeDataSource.getConnectionConfiguration()) {
return;
}
final DBPConnectionConfiguration tmpConnectionInfo = new DBPConnectionConfiguration();
final DataSourceDescriptor tempDataSource = new DataSourceDescriptor(site.getDataSourceRegistry(), activeDataSource.getId(), (DriverDescriptor) activeDataSource.getDriver(), tmpConnectionInfo);
hostPage.saveSettings(tempDataSource);
tmpConnectionInfo.getProperties().putAll(activeDataSource.getConnectionConfiguration().getProperties());
try {
getSite().getRunnableContext().run(true, true, new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("Loading driver properties", 1);
try {
propertySource = propsControl.makeProperties(monitor, site.getDriver(), tmpConnectionInfo);
} finally {
monitor.done();
}
}
});
} catch (InvocationTargetException e) {
setErrorMessage(e.getTargetException().getMessage());
} catch (InterruptedException e) {
// ignore
}
propsControl.loadProperties(propertySource);
prevConnectionInfo = activeDataSource.getConnectionConfiguration();
tempDataSource.dispose();
}
}
use of org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress in project dbeaver by dbeaver.
the class DriverDependenciesTree method resolveLibraries.
public boolean resolveLibraries() {
boolean resolved = false;
try {
runnableContext.run(true, true, new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("Resolve dependencies", 100);
try {
dependencies.resolveDependencies(monitor);
} catch (Exception e) {
throw new InvocationTargetException(e);
} finally {
monitor.done();
}
}
});
resolved = true;
} catch (InterruptedException e) {
// User just canceled download
} catch (InvocationTargetException e) {
DBUserInterface.getInstance().showError("Resolve libraries", "Error resolving driver libraries", e.getTargetException());
}
filesTree.removeAll();
int totalItems = 1;
for (DBPDriverDependencies.DependencyNode node : dependencies.getLibraryMap()) {
DBPDriverLibrary library = node.library;
TreeItem item = new TreeItem(filesTree, SWT.NONE);
item.setData(node);
item.setImage(DBeaverIcons.getImage(library.getIcon()));
item.setText(0, library.getDisplayName());
item.setText(1, CommonUtils.notEmpty(library.getVersion()));
item.setText(2, CommonUtils.notEmpty(library.getDescription()));
if (editable) {
item.setFont(1, boldFont);
}
totalItems++;
if (addDependencies(item, node)) {
item.setExpanded(true);
totalItems += item.getItemCount();
}
}
UIUtils.packColumns(filesTree);
// Check missing files
int missingFiles = 0;
for (DBPDriverDependencies.DependencyNode node : dependencies.getLibraryList()) {
File localFile = node.library.getLocalFile();
if (localFile == null || !localFile.exists()) {
missingFiles++;
}
}
if (missingFiles == 0) {
// UIUtils.showMessageBox(getShell(), "Driver Download", "All driver files are present", SWT.ICON_INFORMATION);
// ((DriverDownloadDialog)getWizard().getContainer()).closeWizard();
}
return resolved;
}
use of org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress in project dbeaver by dbeaver.
the class DriverDependenciesTree method showVersionEditor.
private void showVersionEditor(final TreeItem item) {
disposeOldEditor();
final DBPDriverDependencies.DependencyNode dependencyNode = (DBPDriverDependencies.DependencyNode) item.getData();
if (dependencyNode == null || dependencyNode.library == null || !dependencyNode.library.isDownloadable()) {
return;
}
final List<String> allVersions = new ArrayList<>();
try {
runnableContext.run(true, true, new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
allVersions.addAll(dependencyNode.library.getAvailableVersions(monitor));
} catch (IOException e) {
throw new InvocationTargetException(e);
}
}
});
} catch (InvocationTargetException e) {
DBUserInterface.getInstance().showError("Versions", "Error reading versions", e.getTargetException());
return;
} catch (InterruptedException e) {
return;
}
final String currentVersion = dependencyNode.library.getVersion();
if (currentVersion != null && !allVersions.contains(currentVersion)) {
allVersions.add(currentVersion);
}
final Combo editor = new Combo(filesTree, SWT.DROP_DOWN | SWT.READ_ONLY);
int versionIndex = -1;
for (int i = 0; i < allVersions.size(); i++) {
String version = allVersions.get(i);
editor.add(version);
if (version.equals(currentVersion)) {
versionIndex = i;
}
}
if (versionIndex >= 0) {
editor.select(versionIndex);
}
editor.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String newVersion = editor.getItem(editor.getSelectionIndex());
disposeOldEditor();
setLibraryVersion(dependencyNode.library, newVersion);
}
});
treeEditor.setEditor(editor, item, 1);
editor.setListVisible(true);
}
use of org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress in project dbeaver by dbeaver.
the class ReferenceValueEditor method createEditorSelector.
public boolean createEditorSelector(final Composite parent) {
if (!(valueController instanceof IAttributeController) || valueController.isReadOnly()) {
return false;
}
refConstraint = getEnumerableConstraint();
if (refConstraint == null) {
return false;
}
if (refConstraint instanceof DBSEntityAssociation) {
final DBSEntityAssociation association = (DBSEntityAssociation) refConstraint;
if (association.getReferencedConstraint() != null) {
final DBSEntity refTable = association.getReferencedConstraint().getParentObject();
Composite labelGroup = UIUtils.createPlaceholder(parent, 2);
labelGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
Link dictLabel = UIUtils.createLink(labelGroup, NLS.bind(CoreMessages.dialog_value_view_label_dictionary, refTable.getName()), new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
// Open
final IWorkbenchWindow window = valueController.getValueSite().getWorkbenchWindow();
DBeaverUI.runInUI(window, new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
DBNDatabaseNode tableNode = NavigatorUtils.getNodeByObject(monitor, refTable, true);
if (tableNode != null) {
NavigatorHandlerObjectOpen.openEntityEditor(tableNode, DatabaseDataEditor.class.getName(), window);
}
}
});
}
});
dictLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
Link hintLabel = UIUtils.createLink(labelGroup, "(<a>Define Description</a>)", new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
EditDictionaryPage editDictionaryPage = new EditDictionaryPage("Dictionary structure", refTable);
if (editDictionaryPage.edit(parent.getShell())) {
loaderJob.schedule();
}
}
});
hintLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_END));
}
}
editorSelector = new Table(parent, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
editorSelector.setLinesVisible(true);
editorSelector.setHeaderVisible(true);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 150;
// gd.widthHint = 300;
// gd.grabExcessVerticalSpace = true;
// gd.grabExcessHorizontalSpace = true;
editorSelector.setLayoutData(gd);
UIUtils.createTableColumn(editorSelector, SWT.LEFT, CoreMessages.dialog_value_view_column_value);
UIUtils.createTableColumn(editorSelector, SWT.LEFT, CoreMessages.dialog_value_view_column_description);
UIUtils.packColumns(editorSelector);
editorSelector.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
TableItem[] selection = editorSelector.getSelection();
if (selection != null && selection.length > 0) {
Object value = selection[0].getData();
// editorControl.setText(selection[0].getText());
try {
valueEditor.primeEditorValue(value);
} catch (DBException e1) {
log.error(e1);
}
}
}
});
Control control = valueEditor.getControl();
ModifyListener modifyListener = new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
Object curEditorValue;
try {
curEditorValue = valueEditor.extractEditorValue();
} catch (DBException e1) {
log.error(e1);
return;
}
// Try to select current value in the table
final String curTextValue = valueController.getValueHandler().getValueDisplayString(((IAttributeController) valueController).getBinding(), curEditorValue, DBDDisplayFormat.UI);
boolean valueFound = false;
for (TableItem item : editorSelector.getItems()) {
if (item.getText(0).equals(curTextValue)) {
editorSelector.select(editorSelector.indexOf(item));
editorSelector.showItem(item);
valueFound = true;
break;
}
}
if (!valueFound) {
// Read dictionary
if (loaderJob.getState() == Job.RUNNING) {
// Cancel it and create new one
loaderJob.cancel();
loaderJob = new SelectorLoaderJob();
}
loaderJob.setPattern(curEditorValue);
if (loaderJob.getState() != Job.WAITING) {
loaderJob.schedule(100);
}
}
}
};
if (control instanceof Text) {
((Text) control).addModifyListener(modifyListener);
} else if (control instanceof StyledText) {
((StyledText) control).addModifyListener(modifyListener);
}
loaderJob = new SelectorLoaderJob();
final Object curValue = valueController.getValue();
if (curValue instanceof Number) {
loaderJob.setPattern(curValue);
}
loaderJob.schedule(500);
return true;
}
use of org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress in project dbeaver by serge-rider.
the class CompareObjectsWizard method performFinish.
@Override
public boolean performFinish() {
// Save settings
getSettings().saveTo(new DialogSettingsDelegate(getDialogSettings()));
showError(null);
// Compare
final CompareObjectsExecutor executor = new CompareObjectsExecutor(settings);
try {
UIUtils.run(getContainer(), true, true, new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
CompareReport report = generateReport(monitor, executor);
renderReport(monitor, report);
} catch (DBException e) {
throw new InvocationTargetException(e);
}
}
});
UIUtils.showMessageBox(getShell(), "Objects compare", "Objects compare finished", SWT.ICON_INFORMATION);
} catch (InvocationTargetException e) {
if (executor.getInitializeError() != null) {
showError(executor.getInitializeError().getMessage());
} else {
log.error(e.getTargetException());
showError(e.getTargetException().getMessage());
}
return false;
} catch (InterruptedException e) {
showError("Compare interrupted");
return false;
} finally {
executor.dispose();
}
// Done
return true;
}
Aggregations