Search in sources :

Example 1 with SelectDataSourceDialog

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;
}
Also used : IFile(org.eclipse.core.resources.IFile) SimpleDatabaseEditorContext(org.jkiss.dbeaver.ui.editors.SimpleDatabaseEditorContext) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DBNResource(org.jkiss.dbeaver.model.navigator.DBNResource) Shell(org.eclipse.swt.widgets.Shell) ISelection(org.eclipse.jface.viewers.ISelection) Iterator(java.util.Iterator) SelectDataSourceDialog(org.jkiss.dbeaver.ui.navigator.dialogs.SelectDataSourceDialog) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) IResource(org.eclipse.core.resources.IResource)

Example 2 with SelectDataSourceDialog

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);
}
Also used : SelectDataSourceDialog(org.jkiss.dbeaver.ui.navigator.dialogs.SelectDataSourceDialog) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Example 3 with SelectDataSourceDialog

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);
}
Also used : DBPProject(org.jkiss.dbeaver.model.app.DBPProject) IEditorPart(org.eclipse.ui.IEditorPart) SelectDataSourceDialog(org.jkiss.dbeaver.ui.navigator.dialogs.SelectDataSourceDialog)

Example 4 with SelectDataSourceDialog

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);
}
Also used : DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity) DBWorkbench(org.jkiss.dbeaver.runtime.DBWorkbench) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ActiveWizardPage(org.jkiss.dbeaver.ui.dialogs.ActiveWizardPage) Button(org.eclipse.swt.widgets.Button) SelectDataSourceDialog(org.jkiss.dbeaver.ui.navigator.dialogs.SelectDataSourceDialog) org.jkiss.dbeaver.model.navigator(org.jkiss.dbeaver.model.navigator) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) Group(org.eclipse.swt.widgets.Group) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) InvocationTargetException(java.lang.reflect.InvocationTargetException) ArrayList(java.util.ArrayList) DatabaseObjectsSelectorPanel(org.jkiss.dbeaver.ui.navigator.database.DatabaseObjectsSelectorPanel) List(java.util.List) Composite(org.eclipse.swt.widgets.Composite) UIUtils(org.jkiss.dbeaver.ui.UIUtils) NavigatorUtils(org.jkiss.dbeaver.ui.navigator.NavigatorUtils) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridData(org.eclipse.swt.layout.GridData) Group(org.eclipse.swt.widgets.Group) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DatabaseObjectsSelectorPanel(org.jkiss.dbeaver.ui.navigator.database.DatabaseObjectsSelectorPanel) SelectDataSourceDialog(org.jkiss.dbeaver.ui.navigator.dialogs.SelectDataSourceDialog) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer)

Aggregations

SelectDataSourceDialog (org.jkiss.dbeaver.ui.navigator.dialogs.SelectDataSourceDialog)4 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)3 ArrayList (java.util.ArrayList)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Iterator (java.util.Iterator)1 List (java.util.List)1 IFile (org.eclipse.core.resources.IFile)1 IResource (org.eclipse.core.resources.IResource)1 IDialogConstants (org.eclipse.jface.dialogs.IDialogConstants)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GridData (org.eclipse.swt.layout.GridData)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1 Group (org.eclipse.swt.widgets.Group)1 Shell (org.eclipse.swt.widgets.Shell)1 IEditorPart (org.eclipse.ui.IEditorPart)1 DBPProject (org.jkiss.dbeaver.model.app.DBPProject)1