Search in sources :

Example 1 with DatabaseObjectsSelectorPanel

use of org.jkiss.dbeaver.ui.navigator.database.DatabaseObjectsSelectorPanel in project dbeaver by serge-rider.

the class NativeToolConfigPanel method createControl.

@Override
public void createControl(Composite parent, TaskConfigurationWizard wizard, Runnable propertyChangeListener) {
    ieWizard = (AbstractNativeToolWizard) wizard;
    {
        Group databasesGroup = UIUtils.createControlGroup(parent, TaskNativeUIMessages.tools_wizard_database_group_title, 1, GridData.FILL_BOTH, 0);
        selectorPanel = new DatabaseObjectsSelectorPanel(databasesGroup, false, this.runnableContext) {

            @Override
            protected boolean isDatabaseFolderVisible(DBNDatabaseFolder folder) {
                return folder.getChildrenClass() == objectClass;
            }

            @Override
            protected boolean isDatabaseObjectVisible(DBSObject obj) {
                return objectClass.isInstance(obj);
            }

            @Override
            protected void onSelectionChange(Object element) {
                selectedObject = element instanceof DBSWrapper && objectClass.isInstance(((DBSWrapper) element).getObject()) ? objectClass.cast(((DBSWrapper) element).getObject()) : null;
                AbstractNativeToolSettings settings = ieWizard.getSettings();
                List<DBSObject> databaseObjects = settings.getDatabaseObjects();
                databaseObjects.clear();
                if (selectedObject != null) {
                    databaseObjects.add(selectedObject);
                }
                if (settings instanceof AbstractImportExportSettings) {
                    ((AbstractImportExportSettings) settings).fillExportObjectsFromInput();
                }
                updateHomeSelector();
                propertyChangeListener.run();
            }

            @Override
            protected boolean isFolderVisible(DBNLocalFolder folder) {
                for (DBNDataSource ds : folder.getNestedDataSources()) {
                    if (isDataSourceVisible(ds)) {
                        return true;
                    }
                }
                return false;
            }

            @Override
            protected boolean isDataSourceVisible(DBNDataSource dataSource) {
                try {
                    return providerClass.isInstance(dataSource.getDataSourceContainer().getDriver().getDataSourceProvider());
                } catch (Exception e) {
                    log.debug(e);
                    return false;
                }
            }
        };
    }
    {
        Composite clientGroup = UIUtils.createControlGroup((Composite) parent, TaskNativeUIMessages.tools_wizard_client_group_title, 1, GridData.FILL_HORIZONTAL, 0);
        homesSelector = new ClientHomesSelector(clientGroup, TaskNativeUIMessages.tools_wizard_client_group_client);
        homesSelector.addSelectionChangedListener(event -> propertyChangeListener.run());
        homesSelector.getPanel().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    }
}
Also used : DBWorkbench(org.jkiss.dbeaver.runtime.DBWorkbench) TaskConfigurationWizard(org.jkiss.dbeaver.tasks.ui.wizard.TaskConfigurationWizard) CommonUtils(org.jkiss.utils.CommonUtils) org.jkiss.dbeaver.model.navigator(org.jkiss.dbeaver.model.navigator) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBTTaskType(org.jkiss.dbeaver.model.task.DBTTaskType) ClientHomesSelector(org.jkiss.dbeaver.ui.dialogs.connection.ClientHomesSelector) DBPDataSourceProvider(org.jkiss.dbeaver.model.DBPDataSourceProvider) DBRRunnableContext(org.jkiss.dbeaver.model.runtime.DBRRunnableContext) DBSWrapper(org.jkiss.dbeaver.model.struct.DBSWrapper) DBTTaskConfigPanel(org.jkiss.dbeaver.tasks.ui.DBTTaskConfigPanel) Group(org.eclipse.swt.widgets.Group) AbstractNativeToolSettings(org.jkiss.dbeaver.tasks.nativetool.AbstractNativeToolSettings) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) InvocationTargetException(java.lang.reflect.InvocationTargetException) AbstractImportExportSettings(org.jkiss.dbeaver.tasks.nativetool.AbstractImportExportSettings) DatabaseObjectsSelectorPanel(org.jkiss.dbeaver.ui.navigator.database.DatabaseObjectsSelectorPanel) List(java.util.List) TaskNativeUIMessages(org.jkiss.dbeaver.tasks.ui.nativetool.internal.TaskNativeUIMessages) Composite(org.eclipse.swt.widgets.Composite) UIUtils(org.jkiss.dbeaver.ui.UIUtils) Log(org.jkiss.dbeaver.Log) GridData(org.eclipse.swt.layout.GridData) Collections(java.util.Collections) Group(org.eclipse.swt.widgets.Group) DBSWrapper(org.jkiss.dbeaver.model.struct.DBSWrapper) Composite(org.eclipse.swt.widgets.Composite) AbstractImportExportSettings(org.jkiss.dbeaver.tasks.nativetool.AbstractImportExportSettings) AbstractNativeToolSettings(org.jkiss.dbeaver.tasks.nativetool.AbstractNativeToolSettings) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) ClientHomesSelector(org.jkiss.dbeaver.ui.dialogs.connection.ClientHomesSelector) GridData(org.eclipse.swt.layout.GridData) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DatabaseObjectsSelectorPanel(org.jkiss.dbeaver.ui.navigator.database.DatabaseObjectsSelectorPanel)

Example 2 with DatabaseObjectsSelectorPanel

use of org.jkiss.dbeaver.ui.navigator.database.DatabaseObjectsSelectorPanel in project dbeaver by serge-rider.

the class SearchDataPage method createControl.

@Override
public void createControl(Composite parent) {
    super.createControl(parent);
    initializeDialogUnits(parent);
    Composite searchGroup = new Composite(parent, SWT.NONE);
    searchGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
    searchGroup.setLayout(new GridLayout(3, false));
    setControl(searchGroup);
    UIUtils.createControlLabel(searchGroup, "String");
    searchText = new Combo(searchGroup, SWT.DROP_DOWN);
    searchText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    if (params.searchString != null) {
        searchText.setText(params.searchString);
    }
    for (String history : searchHistory) {
        searchText.add(history);
    }
    searchText.addModifyListener(e -> {
        params.searchString = searchText.getText();
        updateEnablement();
    });
    Composite optionsGroup = new SashForm(searchGroup, SWT.NONE);
    GridLayout layout = new GridLayout(2, true);
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    optionsGroup.setLayout(layout);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.horizontalSpan = 3;
    optionsGroup.setLayoutData(gd);
    {
        Group databasesGroup = UIUtils.createControlGroup(optionsGroup, "Databases", 1, GridData.FILL_BOTH, 0);
        databasesGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
        selectorPanel = new DatabaseObjectsSelectorPanel(databasesGroup, true, new RunnableContextDelegate(container.getRunnableContext())) {

            @Override
            protected boolean isDatabaseObjectVisible(DBSObject obj) {
                if (obj instanceof DBSDataContainer && obj instanceof DBSEntity) {
                    if ((((DBSDataContainer) obj).getSupportedFeatures() & DBSDataContainer.DATA_SEARCH) == 0) {
                        return false;
                    }
                }
                return super.isDatabaseObjectVisible(obj);
            }

            @Override
            protected void onSelectionChange(Object element) {
                updateEnablement();
            }
        };
    }
    {
        // new Label(searchGroup, SWT.NONE);
        Composite optionsGroup2 = UIUtils.createControlGroup(optionsGroup, "Settings", 2, GridData.FILL_HORIZONTAL, 0);
        optionsGroup2.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_BEGINNING));
        if (params.maxResults <= 0) {
            params.maxResults = 10;
        }
        final Spinner maxResultsSpinner = UIUtils.createLabelSpinner(optionsGroup2, "Sample rows", "Maximum number of rows to search. Don't set to a big number, this might greatly reduce search performance.", params.maxResults, 1, Integer.MAX_VALUE);
        maxResultsSpinner.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
        maxResultsSpinner.addModifyListener(e -> params.maxResults = maxResultsSpinner.getSelection());
        final Button caseCheckbox = UIUtils.createCheckbox(optionsGroup2, UISearchMessages.dialog_search_objects_case_sensitive, "Case sensitive search", params.caseSensitive, 2);
        caseCheckbox.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                params.caseSensitive = caseCheckbox.getSelection();
            }
        });
        final Button fastSearchCheckbox = UIUtils.createCheckbox(optionsGroup2, "Fast search (indexed)", "Search only in indexed columns", params.fastSearch, 2);
        fastSearchCheckbox.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                params.fastSearch = fastSearchCheckbox.getSelection();
            }
        });
        final Button searchNumbersCheckbox = UIUtils.createCheckbox(optionsGroup2, "Search in numbers", "Search in numeric columns (search value must be a number)", params.searchNumbers, 2);
        searchNumbersCheckbox.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                params.searchNumbers = searchNumbersCheckbox.getSelection();
            }
        });
        final Button searchLOBCheckbox = UIUtils.createCheckbox(optionsGroup2, "Search in LOBs", "Search in BLOB/CLOB/binary columns", params.searchLOBs, 2);
        searchLOBCheckbox.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                params.searchLOBs = searchNumbersCheckbox.getSelection();
            }
        });
        final Button searchForeignCheckbox = UIUtils.createCheckbox(optionsGroup2, "Search in foreign objects", "Search in foreign tables or DB links. Searching in such tables may cause performance issues.", params.searchForeignObjects, 2);
        searchForeignCheckbox.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                params.searchForeignObjects = searchForeignCheckbox.getSelection();
            }
        });
    }
    UIUtils.asyncExec(this::restoreCheckedNodes);
    if (!params.selectedNodes.isEmpty()) {
        selectorPanel.setSelection(params.selectedNodes);
    }
    selectorPanel.setEnabled(true);
}
Also used : DBWorkbench(org.jkiss.dbeaver.runtime.DBWorkbench) java.util(java.util) SashForm(org.eclipse.swt.custom.SashForm) DBNNode(org.jkiss.dbeaver.model.navigator.DBNNode) DBPPreferenceStore(org.jkiss.dbeaver.model.preferences.DBPPreferenceStore) UISearchMessages(org.jkiss.dbeaver.ui.search.internal.UISearchMessages) DefaultProgressMonitor(org.jkiss.dbeaver.model.runtime.DefaultProgressMonitor) UIUtils(org.jkiss.dbeaver.ui.UIUtils) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) NavigatorUtils(org.jkiss.dbeaver.ui.navigator.NavigatorUtils) GridData(org.eclipse.swt.layout.GridData) AbstractSearchPage(org.jkiss.dbeaver.ui.search.AbstractSearchPage) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) CommonUtils(org.jkiss.utils.CommonUtils) org.eclipse.swt.widgets(org.eclipse.swt.widgets) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBNDatabaseNode(org.jkiss.dbeaver.model.navigator.DBNDatabaseNode) InvocationTargetException(java.lang.reflect.InvocationTargetException) DatabaseObjectsSelectorPanel(org.jkiss.dbeaver.ui.navigator.database.DatabaseObjectsSelectorPanel) List(java.util.List) RunnableContextDelegate(org.jkiss.dbeaver.runtime.RunnableContextDelegate) DBSDataContainer(org.jkiss.dbeaver.model.struct.DBSDataContainer) DBException(org.jkiss.dbeaver.DBException) SWT(org.eclipse.swt.SWT) ISelection(org.eclipse.jface.viewers.ISelection) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) RunnableContextDelegate(org.jkiss.dbeaver.runtime.RunnableContextDelegate) SashForm(org.eclipse.swt.custom.SashForm) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DatabaseObjectsSelectorPanel(org.jkiss.dbeaver.ui.navigator.database.DatabaseObjectsSelectorPanel) DBSEntity(org.jkiss.dbeaver.model.struct.DBSEntity) DBSDataContainer(org.jkiss.dbeaver.model.struct.DBSDataContainer)

Example 3 with DatabaseObjectsSelectorPanel

use of org.jkiss.dbeaver.ui.navigator.database.DatabaseObjectsSelectorPanel in project dbeaver by dbeaver.

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)

Example 4 with DatabaseObjectsSelectorPanel

use of org.jkiss.dbeaver.ui.navigator.database.DatabaseObjectsSelectorPanel in project dbeaver by dbeaver.

the class NativeToolConfigPanel method createControl.

@Override
public void createControl(Composite parent, TaskConfigurationWizard wizard, Runnable propertyChangeListener) {
    ieWizard = (AbstractNativeToolWizard) wizard;
    {
        Group databasesGroup = UIUtils.createControlGroup(parent, TaskNativeUIMessages.tools_wizard_database_group_title, 1, GridData.FILL_BOTH, 0);
        selectorPanel = new DatabaseObjectsSelectorPanel(databasesGroup, false, this.runnableContext) {

            @Override
            protected boolean isDatabaseFolderVisible(DBNDatabaseFolder folder) {
                return folder.getChildrenClass() == objectClass;
            }

            @Override
            protected boolean isDatabaseObjectVisible(DBSObject obj) {
                return objectClass.isInstance(obj);
            }

            @Override
            protected void onSelectionChange(Object element) {
                selectedObject = element instanceof DBSWrapper && objectClass.isInstance(((DBSWrapper) element).getObject()) ? objectClass.cast(((DBSWrapper) element).getObject()) : null;
                AbstractNativeToolSettings settings = ieWizard.getSettings();
                List<DBSObject> databaseObjects = settings.getDatabaseObjects();
                databaseObjects.clear();
                if (selectedObject != null) {
                    databaseObjects.add(selectedObject);
                }
                if (settings instanceof AbstractImportExportSettings) {
                    ((AbstractImportExportSettings) settings).fillExportObjectsFromInput();
                }
                updateHomeSelector();
                propertyChangeListener.run();
            }

            @Override
            protected boolean isFolderVisible(DBNLocalFolder folder) {
                for (DBNDataSource ds : folder.getNestedDataSources()) {
                    if (isDataSourceVisible(ds)) {
                        return true;
                    }
                }
                return false;
            }

            @Override
            protected boolean isDataSourceVisible(DBNDataSource dataSource) {
                try {
                    return providerClass.isInstance(dataSource.getDataSourceContainer().getDriver().getDataSourceProvider());
                } catch (Exception e) {
                    log.debug(e);
                    return false;
                }
            }
        };
    }
    {
        Composite clientGroup = UIUtils.createControlGroup((Composite) parent, TaskNativeUIMessages.tools_wizard_client_group_title, 1, GridData.FILL_HORIZONTAL, 0);
        homesSelector = new ClientHomesSelector(clientGroup, TaskNativeUIMessages.tools_wizard_client_group_client);
        homesSelector.addSelectionChangedListener(event -> propertyChangeListener.run());
        homesSelector.getPanel().setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    }
}
Also used : DBWorkbench(org.jkiss.dbeaver.runtime.DBWorkbench) TaskConfigurationWizard(org.jkiss.dbeaver.tasks.ui.wizard.TaskConfigurationWizard) CommonUtils(org.jkiss.utils.CommonUtils) org.jkiss.dbeaver.model.navigator(org.jkiss.dbeaver.model.navigator) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DBTTaskType(org.jkiss.dbeaver.model.task.DBTTaskType) ClientHomesSelector(org.jkiss.dbeaver.ui.dialogs.connection.ClientHomesSelector) DBPDataSourceProvider(org.jkiss.dbeaver.model.DBPDataSourceProvider) DBRRunnableContext(org.jkiss.dbeaver.model.runtime.DBRRunnableContext) DBSWrapper(org.jkiss.dbeaver.model.struct.DBSWrapper) DBTTaskConfigPanel(org.jkiss.dbeaver.tasks.ui.DBTTaskConfigPanel) Group(org.eclipse.swt.widgets.Group) AbstractNativeToolSettings(org.jkiss.dbeaver.tasks.nativetool.AbstractNativeToolSettings) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) InvocationTargetException(java.lang.reflect.InvocationTargetException) AbstractImportExportSettings(org.jkiss.dbeaver.tasks.nativetool.AbstractImportExportSettings) DatabaseObjectsSelectorPanel(org.jkiss.dbeaver.ui.navigator.database.DatabaseObjectsSelectorPanel) List(java.util.List) TaskNativeUIMessages(org.jkiss.dbeaver.tasks.ui.nativetool.internal.TaskNativeUIMessages) Composite(org.eclipse.swt.widgets.Composite) UIUtils(org.jkiss.dbeaver.ui.UIUtils) Log(org.jkiss.dbeaver.Log) GridData(org.eclipse.swt.layout.GridData) Collections(java.util.Collections) Group(org.eclipse.swt.widgets.Group) DBSWrapper(org.jkiss.dbeaver.model.struct.DBSWrapper) Composite(org.eclipse.swt.widgets.Composite) AbstractImportExportSettings(org.jkiss.dbeaver.tasks.nativetool.AbstractImportExportSettings) AbstractNativeToolSettings(org.jkiss.dbeaver.tasks.nativetool.AbstractNativeToolSettings) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) ClientHomesSelector(org.jkiss.dbeaver.ui.dialogs.connection.ClientHomesSelector) GridData(org.eclipse.swt.layout.GridData) DBSObject(org.jkiss.dbeaver.model.struct.DBSObject) DatabaseObjectsSelectorPanel(org.jkiss.dbeaver.ui.navigator.database.DatabaseObjectsSelectorPanel)

Example 5 with DatabaseObjectsSelectorPanel

use of org.jkiss.dbeaver.ui.navigator.database.DatabaseObjectsSelectorPanel 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

InvocationTargetException (java.lang.reflect.InvocationTargetException)6 List (java.util.List)6 GridData (org.eclipse.swt.layout.GridData)6 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)6 DBWorkbench (org.jkiss.dbeaver.runtime.DBWorkbench)6 UIUtils (org.jkiss.dbeaver.ui.UIUtils)6 DatabaseObjectsSelectorPanel (org.jkiss.dbeaver.ui.navigator.database.DatabaseObjectsSelectorPanel)6 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)4 SelectionEvent (org.eclipse.swt.events.SelectionEvent)4 Composite (org.eclipse.swt.widgets.Composite)4 Group (org.eclipse.swt.widgets.Group)4 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)4 org.jkiss.dbeaver.model.navigator (org.jkiss.dbeaver.model.navigator)4 DBSEntity (org.jkiss.dbeaver.model.struct.DBSEntity)4 NavigatorUtils (org.jkiss.dbeaver.ui.navigator.NavigatorUtils)4 CommonUtils (org.jkiss.utils.CommonUtils)4 java.util (java.util)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 IDialogConstants (org.eclipse.jface.dialogs.IDialogConstants)2