Search in sources :

Example 1 with SelectDataSourceDialog

use of org.jkiss.dbeaver.ui.dialogs.connection.SelectDataSourceDialog in project dbeaver by dbeaver.

the class OpenHandler method getCurrentConnection.

@Nullable
private static DBPDataSourceContainer getCurrentConnection(ExecutionEvent event) {
    DBPDataSourceContainer dataSourceContainer = getDataSourceContainer(event, false);
    final ProjectRegistry projectRegistry = DBeaverCore.getInstance().getProjectRegistry();
    IProject project = dataSourceContainer != null ? dataSourceContainer.getRegistry().getProject() : projectRegistry.getActiveProject();
    if (dataSourceContainer == null) {
        final DataSourceRegistry dataSourceRegistry = projectRegistry.getDataSourceRegistry(project);
        if (dataSourceRegistry == null) {
            return null;
        }
        if (dataSourceRegistry.getDataSources().size() == 1) {
            dataSourceContainer = dataSourceRegistry.getDataSources().get(0);
        } else if (!dataSourceRegistry.getDataSources().isEmpty()) {
            SelectDataSourceDialog dialog = new SelectDataSourceDialog(HandlerUtil.getActiveShell(event), project, null);
            if (dialog.open() == IDialogConstants.CANCEL_ID) {
                return null;
            }
            dataSourceContainer = dialog.getDataSource();
        }
    }
    return dataSourceContainer;
}
Also used : DataSourceRegistry(org.jkiss.dbeaver.registry.DataSourceRegistry) ProjectRegistry(org.jkiss.dbeaver.registry.ProjectRegistry) SelectDataSourceDialog(org.jkiss.dbeaver.ui.dialogs.connection.SelectDataSourceDialog) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) IProject(org.eclipse.core.resources.IProject) Nullable(org.jkiss.code.Nullable)

Example 2 with SelectDataSourceDialog

use of org.jkiss.dbeaver.ui.dialogs.connection.SelectDataSourceDialog in project dbeaver by dbeaver.

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, scripts.get(0).getProject(), null);
        if (dialog.open() == IDialogConstants.CANCEL_ID) {
            return null;
        }
        DBPDataSourceContainer dataSource = dialog.getDataSource();
        for (IFile script : scripts) {
            EditorUtils.setFileDataSource(script, dataSource, true);
        }
    }
    return null;
}
Also used : DBNResource(org.jkiss.dbeaver.model.navigator.DBNResource) Shell(org.eclipse.swt.widgets.Shell) IFile(org.eclipse.core.resources.IFile) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) ArrayList(java.util.ArrayList) ISelection(org.eclipse.jface.viewers.ISelection) Iterator(java.util.Iterator) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SelectDataSourceDialog(org.jkiss.dbeaver.ui.dialogs.connection.SelectDataSourceDialog) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) IResource(org.eclipse.core.resources.IResource)

Example 3 with SelectDataSourceDialog

use of org.jkiss.dbeaver.ui.dialogs.connection.SelectDataSourceDialog in project dbeaver by dbeaver.

the class DataSourceManagementToolbar method showConnectionSelector.

void showConnectionSelector() {
    SelectDataSourceDialog dialog = new SelectDataSourceDialog(connectionCombo.getShell(), getActiveProject(), connectionCombo.getSelectedItem());
    dialog.setModeless(true);
    if (dialog.open() == IDialogConstants.CANCEL_ID) {
        return;
    }
    DBPDataSourceContainer dataSource = dialog.getDataSource();
    connectionCombo.select(dataSource);
    changeDataSourceSelection(dataSource);
}
Also used : SelectDataSourceDialog(org.jkiss.dbeaver.ui.dialogs.connection.SelectDataSourceDialog)

Aggregations

SelectDataSourceDialog (org.jkiss.dbeaver.ui.dialogs.connection.SelectDataSourceDialog)3 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)2 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1 IResource (org.eclipse.core.resources.IResource)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 Shell (org.eclipse.swt.widgets.Shell)1 Nullable (org.jkiss.code.Nullable)1 DBNNode (org.jkiss.dbeaver.model.navigator.DBNNode)1 DBNResource (org.jkiss.dbeaver.model.navigator.DBNResource)1 DataSourceRegistry (org.jkiss.dbeaver.registry.DataSourceRegistry)1 ProjectRegistry (org.jkiss.dbeaver.registry.ProjectRegistry)1