Search in sources :

Example 1 with NamedObjectPatternFilter

use of org.jkiss.dbeaver.ui.controls.NamedObjectPatternFilter in project dbeaver by serge-rider.

the class FilterSettingsDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    getShell().setText(ResultSetMessages.controls_resultset_filter_title);
    getShell().setImage(DBeaverIcons.getImage(UIIcon.FILTER));
    Composite composite = (Composite) super.createDialogArea(parent);
    TabFolder tabFolder = new TabFolder(composite, SWT.NONE);
    tabFolder.setLayoutData(new GridData(GridData.FILL_BOTH));
    TreeColumn criteriaColumn;
    {
        Composite columnsGroup = UIUtils.createPlaceholder(tabFolder, 1);
        FilteredTree filteredTree = new FilteredTree(columnsGroup, SWT.SINGLE | SWT.FULL_SELECTION | SWT.CHECK, new NamedObjectPatternFilter(), true) {

            @Override
            protected TreeViewer doCreateTreeViewer(Composite parent, int style) {
                columnsViewer = new CheckboxTreeViewer(parent, style);
                return columnsViewer;
            }
        };
        columnsViewer.setContentProvider(new TreeContentProvider() {

            @Override
            public Object[] getChildren(Object parentElement) {
                final java.util.List<DBDAttributeBinding> nestedBindings = ((DBDAttributeBinding) parentElement).getNestedBindings();
                if (nestedBindings == null || nestedBindings.isEmpty()) {
                    return null;
                }
                final DBDAttributeBinding[] res = nestedBindings.toArray(new DBDAttributeBinding[0]);
                Arrays.sort(res, activeSorter);
                return res;
            }

            @Override
            public boolean hasChildren(Object element) {
                final java.util.List<DBDAttributeBinding> nestedBindings = ((DBDAttributeBinding) element).getNestedBindings();
                return nestedBindings != null && !nestedBindings.isEmpty();
            }
        });
        columnsViewer.setLabelProvider(new ColumnLabelProvider());
        columnsViewer.setCheckStateProvider(new CheckStateProvider());
        final Tree columnsTree = columnsViewer.getTree();
        GridData gd = new GridData(GridData.FILL_BOTH);
        gd.heightHint = 300;
        columnsTree.setLayoutData(gd);
        columnsTree.setHeaderVisible(true);
        columnsTree.setLinesVisible(true);
        UIUtils.createTreeColumn(columnsTree, SWT.LEFT, ResultSetMessages.controls_resultset_filter_column_name);
        UIUtils.createTreeColumn(columnsTree, SWT.LEFT, "#");
        UIUtils.createTreeColumn(columnsTree, SWT.LEFT, ResultSetMessages.controls_resultset_filter_column_order);
        criteriaColumn = UIUtils.createTreeColumn(columnsTree, SWT.LEFT, ResultSetMessages.controls_resultset_filter_column_criteria);
        treeEditor = new FilterSettingsTreeEditor(columnsTree);
        columnsViewer.addCheckStateListener(event -> {
            DBDAttributeConstraint constraint = getBindingConstraint((DBDAttributeBinding) event.getElement());
            constraint.setVisible(event.getChecked());
        });
        {
            ToolBar toolbar = new ToolBar(columnsGroup, SWT.HORIZONTAL | SWT.RIGHT);
            gd = new GridData(GridData.FILL_HORIZONTAL);
            gd.verticalIndent = 3;
            toolbar.setLayoutData(gd);
            toolbar.setLayout(new FillLayout());
            moveTopButton = createToolItem(toolbar, ResultSetMessages.dialog_toolbar_move_to_top, UIIcon.ARROW_TOP, () -> {
                int selectionIndex = getSelectionIndex(columnsViewer.getTree());
                moveColumns(selectionIndex, 0);
            });
            moveTopButton.setEnabled(false);
            moveUpButton = createToolItem(toolbar, ResultSetMessages.dialog_toolbar_move_up, UIIcon.ARROW_UP, () -> {
                int selectionIndex = getSelectionIndex(columnsViewer.getTree());
                swapColumns(selectionIndex, selectionIndex - 1);
            });
            moveUpButton.setEnabled(false);
            moveDownButton = createToolItem(toolbar, ResultSetMessages.dialog_toolbar_move_down, UIIcon.ARROW_DOWN, () -> {
                int selectionIndex = getSelectionIndex(columnsViewer.getTree());
                swapColumns(selectionIndex, selectionIndex + 1);
            });
            moveDownButton.setEnabled(false);
            moveBottomButton = createToolItem(toolbar, ResultSetMessages.dialog_toolbar_move_to_bottom, UIIcon.ARROW_BOTTOM, () -> {
                int selectionIndex = getSelectionIndex(columnsViewer.getTree());
                moveColumns(selectionIndex, getItemsCount() - 1);
            });
            moveBottomButton.setEnabled(false);
            UIUtils.createToolBarSeparator(toolbar, SWT.VERTICAL);
            createToolItem(toolbar, ResultSetMessages.dialog_toolbar_sort, UIIcon.SORT, () -> {
                attributes.sort(ALPHA_SORTER);
                for (int i = 0; i < attributes.size(); i++) {
                    final DBDAttributeConstraint constraint = getBindingConstraint(attributes.get(i));
                    constraint.setVisualPosition(i);
                }
                columnsViewer.refresh();
            });
            UIUtils.createToolBarSeparator(toolbar, SWT.VERTICAL);
            ToolItem showAllButton = createToolItem(toolbar, ResultSetMessages.dialog_toolbar_show_all, null, () -> {
                for (DBDAttributeConstraint constraint : constraints) {
                    constraint.setVisible(true);
                }
                columnsViewer.refresh();
            });
            showAllButton.setImage(UIUtils.getShardImage(ISharedImages.IMG_ETOOL_DEF_PERSPECTIVE));
            ToolItem showNoneButton = createToolItem(toolbar, ResultSetMessages.dialog_toolbar_show_none, null, () -> {
                for (DBDAttributeConstraint constraint : constraints) {
                    constraint.setVisible(false);
                }
                columnsViewer.refresh();
            });
            showNoneButton.setImage(UIUtils.getShardImage(ISharedImages.IMG_ELCL_REMOVEALL));
            createToolItem(toolbar, ResultSetMessages.dialog_toolbar_reset, UIIcon.REFRESH, () -> {
                dataFilter.reset();
                constraints = new ArrayList<>(dataFilter.getConstraints());
                refreshData();
                // columnsViewer.refresh();
                // $NON-NLS-1$
                orderText.setText("");
                // $NON-NLS-1$
                whereText.setText("");
            });
            columnsViewer.addSelectionChangedListener(event -> {
                int selectionIndex = getSelectionIndex(columnsViewer.getTree());
                moveTopButton.setEnabled(selectionIndex > 0);
                moveUpButton.setEnabled(selectionIndex > 0);
                moveDownButton.setEnabled(selectionIndex >= 0 && selectionIndex < getItemsCount() - 1);
                moveBottomButton.setEnabled(selectionIndex >= 0 && selectionIndex < getItemsCount() - 1);
            });
        }
        TabItem libsTab = new TabItem(tabFolder, SWT.NONE);
        libsTab.setText(ResultSetMessages.controls_resultset_filter_group_columns);
        libsTab.setToolTipText("Set criteria and order for individual column(s)");
        libsTab.setControl(columnsGroup);
    }
    createCustomFilters(tabFolder);
    // Fill columns
    columnsViewer.setInput(attributes);
    refreshData();
    // Pack UI
    UIUtils.asyncExec(() -> UIUtils.packColumns(columnsViewer.getTree(), true, new float[] { .45f, .05f, .05f, .45f }));
    if (criteriaColumn.getWidth() < 200) {
        criteriaColumn.setWidth(200);
    }
    if (!resultSetViewer.supportsDataFilter()) {
        Label warnLabel = new Label(composite, SWT.NONE);
        warnLabel.setText(ResultSetMessages.controls_resultset_filter_warning_custom_order_disabled);
        warnLabel.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_RED));
    }
    return parent;
}
Also used : java.util(java.util) Image(org.eclipse.swt.graphics.Image) CustomTreeEditor(org.jkiss.dbeaver.ui.controls.CustomTreeEditor) ControlEnableState(org.eclipse.jface.dialogs.ControlEnableState) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) Nullable(org.jkiss.code.Nullable) DBDDataFilter(org.jkiss.dbeaver.model.data.DBDDataFilter) DBCExecutionContext(org.jkiss.dbeaver.model.exec.DBCExecutionContext) NotNull(org.jkiss.code.NotNull) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) DBeaverIcons(org.jkiss.dbeaver.ui.DBeaverIcons) UIUtils(org.jkiss.dbeaver.ui.UIUtils) UIIcon(org.jkiss.dbeaver.ui.UIIcon) ResultSetMessages(org.jkiss.dbeaver.ui.controls.resultset.internal.ResultSetMessages) GridData(org.eclipse.swt.layout.GridData) FillLayout(org.eclipse.swt.layout.FillLayout) HelpEnabledDialog(org.jkiss.dbeaver.ui.dialogs.HelpEnabledDialog) TreeContentProvider(org.jkiss.dbeaver.ui.controls.TreeContentProvider) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GeneralUtils(org.jkiss.dbeaver.utils.GeneralUtils) CommonUtils(org.jkiss.utils.CommonUtils) DBValueFormatting(org.jkiss.dbeaver.model.DBValueFormatting) DBDAttributeConstraint(org.jkiss.dbeaver.model.data.DBDAttributeConstraint) org.eclipse.swt.widgets(org.eclipse.swt.widgets) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) org.eclipse.jface.viewers(org.eclipse.jface.viewers) ISharedImages(org.eclipse.ui.ISharedImages) List(java.util.List) DBIcon(org.jkiss.dbeaver.model.DBIcon) SWT(org.eclipse.swt.SWT) IHelpContextIds(org.jkiss.dbeaver.ui.IHelpContextIds) SQLUtils(org.jkiss.dbeaver.model.sql.SQLUtils) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridLayout(org.eclipse.swt.layout.GridLayout) NamedObjectPatternFilter(org.jkiss.dbeaver.ui.controls.NamedObjectPatternFilter) DBDAttributeConstraint(org.jkiss.dbeaver.model.data.DBDAttributeConstraint) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) DBDAttributeBinding(org.jkiss.dbeaver.model.data.DBDAttributeBinding) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) NamedObjectPatternFilter(org.jkiss.dbeaver.ui.controls.NamedObjectPatternFilter) FillLayout(org.eclipse.swt.layout.FillLayout) DBDAttributeConstraint(org.jkiss.dbeaver.model.data.DBDAttributeConstraint) TreeContentProvider(org.jkiss.dbeaver.ui.controls.TreeContentProvider) java.util(java.util) GridData(org.eclipse.swt.layout.GridData)

Example 2 with NamedObjectPatternFilter

use of org.jkiss.dbeaver.ui.controls.NamedObjectPatternFilter in project dbeaver by serge-rider.

the class DashboardDatabaseSelectDialog method createDialogArea.

@Override
protected Composite createDialogArea(Composite parent) {
    Composite dialogArea = super.createDialogArea(parent);
    {
        treeViewer = DialogUtils.createFilteredTree(dialogArea, SWT.BORDER, new NamedObjectPatternFilter(), null);
        GridData gd = new GridData(GridData.FILL_BOTH);
        gd.heightHint = 300;
        gd.widthHint = 300;
        treeViewer.getControl().setLayoutData(gd);
        treeViewer.getTree().setHeaderVisible(true);
        UIUtils.createTreeColumn(treeViewer.getTree(), SWT.LEFT, UIDashboardMessages.dialog_dashboard_database_select_column_name);
        UIUtils.createTreeColumn(treeViewer.getTree(), SWT.LEFT, UIDashboardMessages.dialog_dashboard_database_select_column_description);
        treeViewer.setContentProvider(new TreeContentProvider() {

            @Override
            public Object[] getChildren(Object parentElement) {
                List<? extends DBPNamedObject> result = null;
                if (parentElement instanceof List) {
                    result = (List) parentElement;
                } else if (parentElement instanceof DBPDataSourceProviderDescriptor) {
                    result = ((DBPDataSourceProviderDescriptor) parentElement).getEnabledDrivers();
                    if (result.size() <= 1) {
                        result = null;
                    }
                }
                if (result == null) {
                    return new Object[0];
                }
                result.sort(DBUtils.nameComparator());
                return result.toArray();
            }

            @Override
            public boolean hasChildren(Object element) {
                if (element instanceof DBPDriver) {
                    return false;
                }
                return ((DBPDataSourceProviderDescriptor) element).getEnabledDrivers().size() > 1;
            }
        });
        treeViewer.setLabelProvider(new CellLabelProvider() {

            @Override
            public void update(ViewerCell cell) {
                DBPNamedObject element = (DBPNamedObject) cell.getElement();
                if (cell.getColumnIndex() == 0) {
                    cell.setText(element.getName());
                    DBPImage icon = null;
                    if (element instanceof DBPDriver) {
                        icon = ((DBPDriver) element).getIcon();
                    } else if (element instanceof DBPDataSourceProviderDescriptor) {
                        icon = ((DBPDataSourceProviderDescriptor) element).getIcon();
                    }
                    if (icon != null) {
                        cell.setImage(DBeaverIcons.getImage(icon));
                    }
                } else {
                    if (element instanceof DBPDriver) {
                        cell.setText(CommonUtils.notEmpty(((DBPDriver) element).getDescription()));
                    } else if (element instanceof DBPDataSourceProviderDescriptor) {
                        cell.setText(((DBPDataSourceProviderDescriptor) element).getDescription());
                    }
                }
            }
        });
        treeViewer.setInput(DBWorkbench.getPlatform().getDataSourceProviderRegistry().getDataSourceProviders());
        treeViewer.addDoubleClickListener(event -> {
            if (target != null) {
                okPressed();
            }
        });
        treeViewer.addSelectionChangedListener(event -> {
            this.target = null;
            ISelection selection = event.getSelection();
            if (selection instanceof IStructuredSelection) {
                Object selectedObject = ((IStructuredSelection) selection).getFirstElement();
                if (selectedObject instanceof DBPNamedObject) {
                    this.target = (DBPNamedObject) selectedObject;
                }
            }
            this.updateButtons();
        });
        UIUtils.asyncExec(() -> {
            treeViewer.expandAll();
            UIUtils.packColumns(treeViewer.getTree(), true, null);
        });
    }
    return dialogArea;
}
Also used : DBWorkbench(org.jkiss.dbeaver.runtime.DBWorkbench) TreeContentProvider(org.jkiss.dbeaver.ui.controls.TreeContentProvider) CommonUtils(org.jkiss.utils.CommonUtils) Shell(org.eclipse.swt.widgets.Shell) UIDashboardMessages(org.jkiss.dbeaver.ui.dashboard.internal.UIDashboardMessages) DBUtils(org.jkiss.dbeaver.model.DBUtils) UIDashboardActivator(org.jkiss.dbeaver.ui.dashboard.internal.UIDashboardActivator) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) DBPImage(org.jkiss.dbeaver.model.DBPImage) org.eclipse.jface.viewers(org.eclipse.jface.viewers) BaseDialog(org.jkiss.dbeaver.ui.dialogs.BaseDialog) List(java.util.List) DBeaverIcons(org.jkiss.dbeaver.ui.DBeaverIcons) DBPDriver(org.jkiss.dbeaver.model.connection.DBPDriver) DBPDataSourceProviderDescriptor(org.jkiss.dbeaver.model.connection.DBPDataSourceProviderDescriptor) Composite(org.eclipse.swt.widgets.Composite) UIUtils(org.jkiss.dbeaver.ui.UIUtils) SWT(org.eclipse.swt.SWT) DialogUtils(org.jkiss.dbeaver.ui.dialogs.DialogUtils) GridData(org.eclipse.swt.layout.GridData) Control(org.eclipse.swt.widgets.Control) DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject) NamedObjectPatternFilter(org.jkiss.dbeaver.ui.controls.NamedObjectPatternFilter) DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject) Composite(org.eclipse.swt.widgets.Composite) NamedObjectPatternFilter(org.jkiss.dbeaver.ui.controls.NamedObjectPatternFilter) DBPImage(org.jkiss.dbeaver.model.DBPImage) TreeContentProvider(org.jkiss.dbeaver.ui.controls.TreeContentProvider) DBPDriver(org.jkiss.dbeaver.model.connection.DBPDriver) GridData(org.eclipse.swt.layout.GridData) DBPNamedObject(org.jkiss.dbeaver.model.DBPNamedObject) List(java.util.List) DBPDataSourceProviderDescriptor(org.jkiss.dbeaver.model.connection.DBPDataSourceProviderDescriptor)

Aggregations

List (java.util.List)2 IDialogConstants (org.eclipse.jface.dialogs.IDialogConstants)2 IDialogSettings (org.eclipse.jface.dialogs.IDialogSettings)2 org.eclipse.jface.viewers (org.eclipse.jface.viewers)2 SWT (org.eclipse.swt.SWT)2 GridData (org.eclipse.swt.layout.GridData)2 DBeaverIcons (org.jkiss.dbeaver.ui.DBeaverIcons)2 UIUtils (org.jkiss.dbeaver.ui.UIUtils)2 NamedObjectPatternFilter (org.jkiss.dbeaver.ui.controls.NamedObjectPatternFilter)2 TreeContentProvider (org.jkiss.dbeaver.ui.controls.TreeContentProvider)2 CommonUtils (org.jkiss.utils.CommonUtils)2 java.util (java.util)1 ControlEnableState (org.eclipse.jface.dialogs.ControlEnableState)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Image (org.eclipse.swt.graphics.Image)1 FillLayout (org.eclipse.swt.layout.FillLayout)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 org.eclipse.swt.widgets (org.eclipse.swt.widgets)1 Composite (org.eclipse.swt.widgets.Composite)1