use of org.jkiss.dbeaver.ui.navigator.dialogs.SelectDataSourceDialog in project dbeaver by serge-rider.
the class NavigatorHandlerAssociateScript method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final Shell activeShell = HandlerUtil.getActiveShell(event);
List<IFile> scripts = new ArrayList<>();
final ISelection selection = HandlerUtil.getCurrentSelection(event);
if (!selection.isEmpty() && selection instanceof IStructuredSelection) {
for (Iterator iter = ((IStructuredSelection) selection).iterator(); iter.hasNext(); ) {
final DBNNode node = RuntimeUtils.getObjectAdapter(iter.next(), DBNNode.class);
if (node instanceof DBNResource) {
IResource resource = ((DBNResource) node).getResource();
if (resource instanceof IFile) {
scripts.add((IFile) resource);
}
}
}
}
if (!scripts.isEmpty()) {
SelectDataSourceDialog dialog = new SelectDataSourceDialog(activeShell, DBWorkbench.getPlatform().getWorkspace().getProject(scripts.get(0).getProject()), null);
if (dialog.open() == IDialogConstants.CANCEL_ID) {
return null;
}
DBPDataSourceContainer dataSource = dialog.getDataSource();
for (IFile script : scripts) {
EditorUtils.setFileDataSource(script, new SimpleDatabaseEditorContext(dataSource));
DBNUtils.refreshNavigatorResource(script, dataSource);
}
}
return null;
}
use of org.jkiss.dbeaver.ui.navigator.dialogs.SelectDataSourceDialog in project dbeaver by serge-rider.
the class SelectDataSourceCombo method showConnectionSelector.
public void showConnectionSelector() {
SelectDataSourceDialog dialog = new SelectDataSourceDialog(getShell(), getActiveProject(), getSelectedItem());
dialog.setModeless(true);
if (dialog.open() == IDialogConstants.CANCEL_ID) {
return;
}
DBPDataSourceContainer dataSource = dialog.getDataSource();
this.select(dataSource);
onDataSourceChange(dataSource);
}
use of org.jkiss.dbeaver.ui.navigator.dialogs.SelectDataSourceDialog in project dbeaver by serge-rider.
the class SelectActiveDataSourceHandler method openDataSourceSelector.
public static void openDataSourceSelector(IWorkbenchWindow workbenchWindow, DBPDataSourceContainer dataSource) {
DBPProject activeProject = dataSource != null ? dataSource.getRegistry().getProject() : DBWorkbench.getPlatform().getWorkspace().getActiveProject();
IEditorPart activeEditor = workbenchWindow.getActivePage().getActiveEditor();
if (!(activeEditor instanceof IDataSourceContainerProviderEx)) {
return;
}
SelectDataSourceDialog dialog = new SelectDataSourceDialog(UIUtils.getActiveWorkbenchShell(), activeProject, dataSource);
dialog.setModeless(true);
if (dialog.open() == IDialogConstants.CANCEL_ID) {
return;
}
DBPDataSourceContainer newDataSource = dialog.getDataSource();
if (newDataSource == dataSource) {
return;
}
((IDataSourceContainerProviderEx) activeEditor).setDataSourceContainer(newDataSource);
}
use of org.jkiss.dbeaver.ui.navigator.dialogs.SelectDataSourceDialog in project dbeaver by serge-rider.
the class PostgreFDWConfigWizardPageInput method createControl.
@Override
public void createControl(Composite parent) {
Composite composite = UIUtils.createComposite(parent, 1);
{
Group databasesGroup = UIUtils.createControlGroup(composite, "Foreign databases", 1, GridData.FILL_BOTH, 0);
selectorPanel = new DatabaseObjectsSelectorPanel(databasesGroup, true, getWizard().getRunnableContext()) {
@Override
protected boolean isDatabaseObjectVisible(DBSObject obj) {
return super.isDatabaseObjectVisible(obj);
}
@Override
protected void onSelectionChange(Object element) {
updateState();
}
@Override
protected boolean isFolderVisible(DBNLocalFolder folder) {
List<DBPDataSourceContainer> dataSources = getWizard().getAvailableDataSources();
for (DBNDataSource ds : folder.getNestedDataSources()) {
if (dataSources.contains(ds.getDataSourceContainer())) {
return true;
}
}
return false;
}
@Override
protected boolean isDataSourceVisible(DBNDataSource dataSource) {
return getWizard().getAvailableDataSources().contains(dataSource.getDataSourceContainer());
}
};
Composite buttonsPanel = UIUtils.createComposite(databasesGroup, 2);
UIUtils.createDialogButton(buttonsPanel, "Add database", new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
SelectDataSourceDialog dialog = new SelectDataSourceDialog(getShell(), selectorPanel.getProject(), null);
if (dialog.open() == IDialogConstants.OK_ID) {
DBPDataSourceContainer dataSource = dialog.getDataSource();
if (dataSource != null) {
getWizard().addAvailableDataSource(dataSource);
refreshDataSources();
}
}
}
});
Button delButton = UIUtils.createDialogButton(buttonsPanel, "Remove database", new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
DBNNode selectedNode = NavigatorUtils.getSelectedNode(selectorPanel.getSelection());
if (selectedNode instanceof DBNDatabaseNode) {
getWizard().removeAvailableDataSource(((DBNDatabaseNode) selectedNode).getDataSourceContainer());
refreshDataSources();
}
}
});
delButton.setEnabled(false);
selectorPanel.addSelectionListener(event -> {
DBNNode selectedNode = NavigatorUtils.getSelectedNode(event.getSelection());
delButton.setEnabled(selectedNode instanceof DBNDatabaseNode);
});
}
setControl(composite);
}
Aggregations