use of org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress in project dbeaver by dbeaver.
the class GenericConnectionPage method createEmbeddedDatabase.
private void createEmbeddedDatabase() {
String paramCreate = CommonUtils.toString(site.getDriver().getDriverParameter(GenericConstants.PARAM_CREATE_URL_PARAM));
DataSourceDescriptor dataSource = (DataSourceDescriptor) site.getActiveDataSource();
final DataSourceDescriptor testDataSource = new DataSourceDescriptor(site.getDataSourceRegistry(), dataSource.getId(), dataSource.getDriver(), new DBPConnectionConfiguration(dataSource.getConnectionConfiguration()));
saveSettings(testDataSource);
DBPConnectionConfiguration cfg = testDataSource.getConnectionConfiguration();
cfg.setUrl(cfg.getUrl() + paramCreate);
String databaseName = cfg.getDatabaseName();
testDataSource.setName(databaseName);
if (!UIUtils.confirmAction(getShell(), "Create Database", "Are you sure you want to create database '" + databaseName + "'?")) {
testDataSource.dispose();
return;
}
try {
site.getRunnableContext().run(true, true, new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
createEmbeddedDatabase(monitor, testDataSource);
} catch (DBException e1) {
throw new InvocationTargetException(e1);
}
}
});
MessageDialog.openInformation(getShell(), "Database Create", "Database '" + databaseName + "' created!");
} catch (InvocationTargetException e1) {
DBUserInterface.getInstance().showError("Create database", "Error creating database", e1.getTargetException());
} catch (InterruptedException e1) {
// Just ignore
}
}
use of org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress in project dbeaver by dbeaver.
the class ExasolCreateForeignKeyDialog method handleRefTableSelect.
private void handleRefTableSelect(ISelection selection) {
DBNDatabaseNode refTableNode = null;
if (!selection.isEmpty() && selection instanceof IStructuredSelection && ((IStructuredSelection) selection).size() == 1) {
final Object element = ((IStructuredSelection) selection).getFirstElement();
if (element instanceof DBNDatabaseNode && ((DBNDatabaseNode) element).getObject() instanceof DBSTable && ((DBNDatabaseNode) element).getObject().isPersisted()) {
refTableNode = (DBNDatabaseNode) element;
}
}
if (refTableNode != null) {
if (refTableNode.getObject() == curRefTable) {
// The same selection
return;
} else {
curRefTable = (ExasolTable) refTableNode.getObject();
}
}
uniqueKeyCombo.removeAll();
try {
curConstraints = new ArrayList<>();
curConstraint = null;
if (refTableNode != null) {
final ExasolTable refTable = (ExasolTable) refTableNode.getObject();
DBeaverUI.runInProgressService(new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
// Cache own table columns
ownTable.getAttributes(monitor);
// Cache ref table columns
refTable.getAttributes(monitor);
// Get constraints
final Collection<? extends ExasolTableUniqueKey> constraints = refTable.getConstraints(monitor);
if (!CommonUtils.isEmpty(constraints)) {
for (ExasolTableUniqueKey constraint : constraints) {
if (constraint.getConstraintType().isUnique()) {
curConstraints.add(constraint);
}
}
}
} catch (DBException e) {
throw new InvocationTargetException(e);
}
}
});
}
for (DBSTableConstraint constraint : curConstraints) {
uniqueKeyCombo.add(constraint.getName());
}
uniqueKeyCombo.select(0);
uniqueKeyCombo.setEnabled(curConstraints.size() > 1);
if (curConstraints.size() == 1) {
curConstraint = curConstraints.get(0);
}
} catch (InvocationTargetException e) {
DBUserInterface.getInstance().showError(CoreMessages.dialog_struct_edit_fk_error_load_constraints_title, CoreMessages.dialog_struct_edit_fk_error_load_constraints_message, e.getTargetException());
} catch (InterruptedException e) {
// do nothing
}
handleUniqueKeySelect();
updatePageState();
}
use of org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress in project dbeaver by dbeaver.
the class SQLAttributeResolver method resolveAll.
@Override
protected String[] resolveAll(final TemplateContext context) {
final DBCExecutionContext executionContext = ((DBPContextProvider) context).getExecutionContext();
if (executionContext == null) {
return super.resolveAll(context);
}
TemplateVariable tableVariable = ((SQLContext) context).getTemplateVariable("table");
final String tableName = tableVariable == null ? null : tableVariable.getDefaultValue();
if (!CommonUtils.isEmpty(tableName)) {
final List<DBSEntityAttribute> attributes = new ArrayList<>();
DBRRunnableWithProgress runnable = new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
List<DBSEntity> entities = new ArrayList<>();
SQLEntityResolver.resolveTables(monitor, executionContext, context, entities);
if (!CommonUtils.isEmpty(entities)) {
DBSEntity table = DBUtils.findObject(entities, tableName);
if (table != null) {
attributes.addAll(CommonUtils.safeCollection(table.getAttributes(monitor)));
}
}
} catch (DBException e) {
throw new InvocationTargetException(e);
}
}
};
RuntimeUtils.runTask(runnable, "Resolve attributes", 1000);
if (!CommonUtils.isEmpty(attributes)) {
String[] result = new String[attributes.size()];
for (int i = 0; i < attributes.size(); i++) {
DBSEntityAttribute entity = attributes.get(i);
result[i] = entity.getName();
}
return result;
}
}
return super.resolveAll(context);
}
use of org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress in project dbeaver by dbeaver.
the class BaseTextEditor method saveToExternalFile.
public void saveToExternalFile() {
IEditorInput editorInput = getEditorInput();
IFile curFile = EditorUtils.getFileFromInput(editorInput);
String fileName = curFile == null ? null : curFile.getName();
final Document document = getDocument();
final File saveFile = DialogUtils.selectFileForSave(getSite().getShell(), "Save SQL script", new String[] { "*.sql", "*.txt", "*", "*.*" }, fileName);
if (document == null || saveFile == null) {
return;
}
try {
DBeaverUI.runInProgressService(new DBRRunnableWithProgress() {
@Override
public void run(final DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
StringReader cr = new StringReader(document.get());
ContentUtils.saveContentToFile(cr, saveFile, GeneralUtils.UTF8_ENCODING, monitor);
} catch (Exception e) {
throw new InvocationTargetException(e);
}
}
});
} catch (InterruptedException e) {
// do nothing
} catch (InvocationTargetException e) {
DBUserInterface.getInstance().showError("Save failed", null, e.getTargetException());
}
afterSaveToFile(saveFile);
}
use of org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress in project dbeaver by dbeaver.
the class NavigatorHandlerLinkEditor method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final IWorkbenchPage activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
final IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
if (activeEditor == null) {
return null;
}
NavigatorViewBase navigatorView = NavigatorUtils.getActiveNavigatorView(event);
if (navigatorView == null) {
return null;
}
if (navigatorView instanceof ProjectExplorerView) {
if (activeEditor instanceof SQLEditor) {
IFile file = EditorUtils.getFileFromInput(activeEditor.getEditorInput());
if (file != null) {
showResourceInNavigator(navigatorView, file);
}
} else if (activeEditor.getEditorInput() instanceof ProjectFileEditorInput) {
IFile editorFile = ((ProjectFileEditorInput) activeEditor.getEditorInput()).getFile();
showResourceInNavigator(navigatorView, editorFile);
}
} else if (activeEditor.getEditorInput() instanceof IDatabaseEditorInput) {
IDatabaseEditorInput editorInput = (IDatabaseEditorInput) activeEditor.getEditorInput();
DBNNode dbnNode = editorInput.getNavigatorNode();
if (dbnNode != null) {
navigatorView.showNode(dbnNode);
}
} else if (activeEditor instanceof IDataSourceContainerProvider) {
DBPDataSourceContainer dsContainer = ((IDataSourceContainerProvider) activeEditor).getDataSourceContainer();
@NotNull final DBSObject activeObject;
if (dsContainer != null) {
DBPDataSource dataSource = dsContainer.getDataSource();
if (dataSource != null) {
activeObject = DBUtils.getDefaultOrActiveObject(dataSource);
} else {
activeObject = dsContainer;
}
final NavigatorViewBase view = navigatorView;
DBeaverUI.runInUI(activePage.getWorkbenchWindow(), new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
DBSObject showObject = activeObject;
if (showObject instanceof DBPDataSource) {
showObject = ((DBPDataSource) showObject).getContainer();
}
DBNDatabaseNode objectNode = view.getModel().getNodeByObject(monitor, showObject, true);
if (objectNode != null) {
view.showNode(objectNode);
}
}
});
}
}
activePage.activate(navigatorView);
return null;
}
Aggregations