use of org.jkiss.dbeaver.ui.navigator.dialogs.SelectDatabaseDialog in project dbeaver by serge-rider.
the class SelectActiveSchemaHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
if (SelectActiveDataSourceHandler.getDataSourceContainerProvider(HandlerUtil.getActiveEditor(event)) == null) {
return null;
}
DBPDataSourceContainer dataSourceContainer = DataSourceToolbarUtils.getCurrentDataSource(HandlerUtil.getActiveWorkbenchWindow(event));
if (dataSourceContainer == null) {
log.debug("No active connection. Action is in disabled state.");
return null;
}
DBCExecutionContext executionContext = getExecutionContextFromPart(HandlerUtil.getActiveEditor(event));
ContextDefaultObjectsReader contextDefaultObjectsReader = new ContextDefaultObjectsReader(dataSourceContainer.getDataSource(), executionContext);
try {
UIUtils.runInProgressService(contextDefaultObjectsReader);
} catch (InvocationTargetException e) {
DBWorkbench.getPlatformUI().showError("Schema list", "Error reading schema list", e.getTargetException());
return null;
} catch (InterruptedException e) {
return null;
}
DBSObject selectedDB = null;
DBSObject defaultObject = contextDefaultObjectsReader.getDefaultObject();
if (defaultObject != null) {
for (DBSObject object : contextDefaultObjectsReader.getObjectList()) {
if (object == defaultObject || object == defaultObject.getParentObject()) {
selectedDB = object;
}
}
}
DBNDatabaseNode selectedNode = selectedDB == null ? null : DBWorkbench.getPlatform().getNavigatorModel().getNodeByObject(selectedDB);
SelectDatabaseDialog dialog = new SelectDatabaseDialog(HandlerUtil.getActiveShell(event), dataSourceContainer, contextDefaultObjectsReader.getDefaultCatalogName(), contextDefaultObjectsReader.getNodeList(), selectedNode == null ? null : Collections.singletonList(selectedNode));
dialog.setModeless(true);
if (dialog.open() == IDialogConstants.CANCEL_ID) {
return null;
}
DBNDatabaseNode node = dialog.getSelectedObject();
if (node != null && node.getObject() != defaultObject) {
// Change current schema
changeDataBaseSelection(dataSourceContainer, executionContext, contextDefaultObjectsReader.getDefaultCatalogName(), dialog.getCurrentInstanceName(), node.getNodeName());
}
return null;
}
use of org.jkiss.dbeaver.ui.navigator.dialogs.SelectDatabaseDialog in project dbeaver by dbeaver.
the class SelectActiveSchemaHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
if (SelectActiveDataSourceHandler.getDataSourceContainerProvider(HandlerUtil.getActiveEditor(event)) == null) {
return null;
}
DBPDataSourceContainer dataSourceContainer = DataSourceToolbarUtils.getCurrentDataSource(HandlerUtil.getActiveWorkbenchWindow(event));
if (dataSourceContainer == null) {
log.debug("No active connection. Action is in disabled state.");
return null;
}
DBCExecutionContext executionContext = getExecutionContextFromPart(HandlerUtil.getActiveEditor(event));
ContextDefaultObjectsReader contextDefaultObjectsReader = new ContextDefaultObjectsReader(dataSourceContainer.getDataSource(), executionContext);
try {
UIUtils.runInProgressService(contextDefaultObjectsReader);
} catch (InvocationTargetException e) {
DBWorkbench.getPlatformUI().showError("Schema list", "Error reading schema list", e.getTargetException());
return null;
} catch (InterruptedException e) {
return null;
}
DBSObject selectedDB = null;
DBSObject defaultObject = contextDefaultObjectsReader.getDefaultObject();
if (defaultObject != null) {
for (DBSObject object : contextDefaultObjectsReader.getObjectList()) {
if (object == defaultObject || object == defaultObject.getParentObject()) {
selectedDB = object;
}
}
}
DBNDatabaseNode selectedNode = selectedDB == null ? null : DBWorkbench.getPlatform().getNavigatorModel().getNodeByObject(selectedDB);
SelectDatabaseDialog dialog = new SelectDatabaseDialog(HandlerUtil.getActiveShell(event), dataSourceContainer, contextDefaultObjectsReader.getDefaultCatalogName(), contextDefaultObjectsReader.getNodeList(), selectedNode == null ? null : Collections.singletonList(selectedNode));
dialog.setModeless(true);
if (dialog.open() == IDialogConstants.CANCEL_ID) {
return null;
}
DBNDatabaseNode node = dialog.getSelectedObject();
if (node != null && node.getObject() != defaultObject) {
// Change current schema
changeDataBaseSelection(dataSourceContainer, executionContext, contextDefaultObjectsReader.getDefaultCatalogName(), dialog.getCurrentInstanceName(), node.getNodeName());
}
return null;
}
Aggregations