Search in sources :

Example 1 with CustomTableEditor

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

the class EditObjectFilterDialog method createEditableList.

private Table createEditableList(String name, List<String> values) {
    Group group = UIUtils.createControlGroup(blockControl, name, 2, GridData.FILL_BOTH, 0);
    final Table valueTable = new Table(group, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    final GridData gd = new GridData(GridData.FILL_BOTH);
    gd.widthHint = 300;
    gd.heightHint = 100;
    valueTable.setLayoutData(gd);
    // valueTable.setHeaderVisible(true);
    valueTable.setLinesVisible(true);
    final TableColumn valueColumn = UIUtils.createTableColumn(valueTable, SWT.LEFT, CoreMessages.dialog_filter_table_column_value);
    valueColumn.setWidth(300);
    if (!CommonUtils.isEmpty(values)) {
        for (String value : values) {
            new TableItem(valueTable, SWT.LEFT).setText(value);
        }
    }
    final CustomTableEditor tableEditor = new CustomTableEditor(valueTable) {

        @Override
        protected Control createEditor(Table table, int index, TableItem item) {
            Text editor = new Text(table, SWT.BORDER);
            editor.setText(item.getText());
            return editor;
        }

        @Override
        protected void saveEditorValue(Control control, int index, TableItem item) {
            item.setText(((Text) control).getText());
        }
    };
    Composite buttonsGroup = UIUtils.createPlaceholder(group, 1, 5);
    buttonsGroup.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
    final Button addButton = new Button(buttonsGroup, SWT.PUSH);
    addButton.setText(CoreMessages.dialog_filter_button_add);
    addButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    addButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            TableItem newItem = new TableItem(valueTable, SWT.LEFT);
            valueTable.setSelection(newItem);
            tableEditor.closeEditor();
            tableEditor.showEditor(newItem);
        }
    });
    final Button removeButton = new Button(buttonsGroup, SWT.PUSH);
    removeButton.setText(CoreMessages.dialog_filter_button_remove);
    removeButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    removeButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            int selectionIndex = valueTable.getSelectionIndex();
            if (selectionIndex >= 0) {
                tableEditor.closeEditor();
                valueTable.remove(selectionIndex);
                removeButton.setEnabled(valueTable.getSelectionIndex() >= 0);
            }
        }
    });
    removeButton.setEnabled(false);
    final Button clearButton = new Button(buttonsGroup, SWT.PUSH);
    clearButton.setText(CoreMessages.dialog_filter_button_clear);
    clearButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    clearButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            tableEditor.closeEditor();
            valueTable.removeAll();
            removeButton.setEnabled(false);
        }
    });
    valueTable.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            int selectionIndex = valueTable.getSelectionIndex();
            removeButton.setEnabled(selectionIndex >= 0);
        }
    });
    return valueTable;
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) CustomTableEditor(org.jkiss.dbeaver.ui.controls.CustomTableEditor) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 2 with CustomTableEditor

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

the class SQLQueryParameterBindDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    getShell().setText("Bind parameter(s)");
    final Composite composite = (Composite) super.createDialogArea(parent);
    Table paramTable = new Table(composite, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    final GridData gd = new GridData(GridData.FILL_BOTH);
    gd.widthHint = 400;
    gd.heightHint = 200;
    paramTable.setLayoutData(gd);
    paramTable.setHeaderVisible(true);
    paramTable.setLinesVisible(true);
    final TableColumn indexColumn = UIUtils.createTableColumn(paramTable, SWT.LEFT, "#");
    indexColumn.setWidth(40);
    final TableColumn nameColumn = UIUtils.createTableColumn(paramTable, SWT.LEFT, "Name");
    nameColumn.setWidth(100);
    final TableColumn valueColumn = UIUtils.createTableColumn(paramTable, SWT.LEFT, "Value");
    valueColumn.setWidth(200);
    for (SQLQueryParameter param : parameters) {
        if (param.getPrevious() != null) {
            // Skip duplicates
            List<SQLQueryParameter> dups = dupParameters.get(param.getName());
            if (dups == null) {
                dups = new ArrayList<>();
                dupParameters.put(param.getName(), dups);
            }
            dups.add(param);
            continue;
        }
        TableItem item = new TableItem(paramTable, SWT.NONE);
        item.setData(param);
        item.setImage(DBeaverIcons.getImage(DBIcon.TREE_ATTRIBUTE));
        item.setText(0, String.valueOf(param.getOrdinalPosition() + 1));
        item.setText(1, param.getTitle());
        item.setText(2, CommonUtils.notEmpty(param.getValue()));
    }
    final CustomTableEditor tableEditor = new CustomTableEditor(paramTable) {

        {
            firstTraverseIndex = 2;
            lastTraverseIndex = 2;
            editOnEnter = false;
        }

        @Override
        protected Control createEditor(Table table, int index, TableItem item) {
            if (index != 2) {
                return null;
            }
            SQLQueryParameter param = (SQLQueryParameter) item.getData();
            Text editor = new Text(table, SWT.BORDER);
            editor.setText(CommonUtils.notEmpty(param.getValue()));
            editor.selectAll();
            return editor;
        }

        @Override
        protected void saveEditorValue(Control control, int index, TableItem item) {
            SQLQueryParameter param = (SQLQueryParameter) item.getData();
            String newValue = ((Text) control).getText();
            item.setText(2, newValue);
            param.setValue(newValue);
            if (param.isNamed()) {
                final List<SQLQueryParameter> dups = dupParameters.get(param.getName());
                if (dups != null) {
                    for (SQLQueryParameter dup : dups) {
                        dup.setValue(newValue);
                    }
                }
            }
            savedParamValues.put(param.getName().toUpperCase(Locale.ENGLISH), new SQLQueryParameterRegistry.ParameterInfo(param.getName(), newValue));
        }
    };
    if (!parameters.isEmpty()) {
        paramTable.select(0);
        tableEditor.showEditor(paramTable.getItem(0), 2);
    }
    updateStatus(GeneralUtils.makeInfoStatus("Use Tab to switch. String values must be quoted. You can use expressions in values"));
    return composite;
}
Also used : SQLQueryParameter(org.jkiss.dbeaver.model.sql.SQLQueryParameter) CustomTableEditor(org.jkiss.dbeaver.ui.controls.CustomTableEditor) GridData(org.eclipse.swt.layout.GridData)

Example 3 with CustomTableEditor

use of org.jkiss.dbeaver.ui.controls.CustomTableEditor in project dbeaver by dbeaver.

the class EditObjectFilterDialog method createEditableList.

private Table createEditableList(String name, List<String> values) {
    Group group = UIUtils.createControlGroup(blockControl, name, 2, GridData.FILL_BOTH, 0);
    final Table valueTable = new Table(group, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    final GridData gd = new GridData(GridData.FILL_BOTH);
    gd.widthHint = 300;
    gd.heightHint = 100;
    valueTable.setLayoutData(gd);
    // valueTable.setHeaderVisible(true);
    valueTable.setLinesVisible(true);
    final TableColumn valueColumn = UIUtils.createTableColumn(valueTable, SWT.LEFT, CoreMessages.dialog_filter_table_column_value);
    valueColumn.setWidth(300);
    fillFilterValues(valueTable, values);
    final CustomTableEditor tableEditor = new CustomTableEditor(valueTable) {

        @Override
        protected Control createEditor(Table table, int index, TableItem item) {
            Text editor = new Text(table, SWT.BORDER);
            editor.setText(item.getText());
            return editor;
        }

        @Override
        protected void saveEditorValue(Control control, int index, TableItem item) {
            item.setText(((Text) control).getText());
        }
    };
    Composite buttonsGroup = UIUtils.createPlaceholder(group, 1, 5);
    buttonsGroup.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
    final Button addButton = new Button(buttonsGroup, SWT.PUSH);
    addButton.setText(CoreMessages.dialog_filter_button_add);
    addButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    addButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            TableItem newItem = new TableItem(valueTable, SWT.LEFT);
            valueTable.setSelection(newItem);
            tableEditor.closeEditor();
            tableEditor.showEditor(newItem);
        }
    });
    final Button removeButton = new Button(buttonsGroup, SWT.PUSH);
    removeButton.setText(CoreMessages.dialog_filter_button_remove);
    removeButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    removeButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            int selectionIndex = valueTable.getSelectionIndex();
            if (selectionIndex >= 0) {
                tableEditor.closeEditor();
                valueTable.remove(selectionIndex);
                removeButton.setEnabled(valueTable.getSelectionIndex() >= 0);
            }
        }
    });
    removeButton.setEnabled(false);
    final Button clearButton = new Button(buttonsGroup, SWT.PUSH);
    clearButton.setText(CoreMessages.dialog_filter_button_clear);
    clearButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    clearButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            tableEditor.closeEditor();
            valueTable.removeAll();
            removeButton.setEnabled(false);
        }
    });
    valueTable.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            int selectionIndex = valueTable.getSelectionIndex();
            removeButton.setEnabled(selectionIndex >= 0);
        }
    });
    return valueTable;
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) CustomTableEditor(org.jkiss.dbeaver.ui.controls.CustomTableEditor) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 4 with CustomTableEditor

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

the class EditBootstrapQueriesDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    getShell().setText(CoreMessages.dialog_connection_edit_wizard_general_bootstrap_query_title);
    Composite composite = (Composite) super.createDialogArea(parent);
    Group group = UIUtils.createControlGroup(composite, CoreMessages.dialog_connection_edit_wizard_general_bootstrap_query_sql_label, 2, GridData.FILL_BOTH, 0);
    queriesTable = new Table(group, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    final GridData gd = new GridData(GridData.FILL_BOTH);
    gd.widthHint = 300;
    gd.heightHint = 100;
    queriesTable.setLayoutData(gd);
    queriesTable.setLinesVisible(true);
    final TableColumn valueColumn = UIUtils.createTableColumn(queriesTable, SWT.LEFT, "SQL");
    valueColumn.setWidth(300);
    for (String value : queries) {
        new TableItem(queriesTable, SWT.LEFT).setText(value);
    }
    final CustomTableEditor tableEditor = new CustomTableEditor(queriesTable) {

        @Override
        protected Control createEditor(Table table, int index, TableItem item) {
            Text editor = new Text(table, SWT.BORDER);
            editor.setText(item.getText());
            return editor;
        }

        @Override
        protected void saveEditorValue(Control control, int index, TableItem item) {
            item.setText(((Text) control).getText());
        }
    };
    Composite buttonsGroup = UIUtils.createPlaceholder(group, 1, 5);
    buttonsGroup.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
    final Button addButton = new Button(buttonsGroup, SWT.PUSH);
    addButton.setText(UIMessages.button_add);
    addButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    addButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            tableEditor.closeEditor();
            String sql = EditTextDialog.editText(getShell(), CoreMessages.dialog_connection_edit_wizard_general_bootstrap_query_sql_title, "");
            if (sql != null) {
                TableItem newItem = new TableItem(queriesTable, SWT.LEFT);
                newItem.setText(sql);
                queriesTable.setSelection(newItem);
                UIUtils.packColumns(queriesTable, true);
            }
        }
    });
    final Button removeButton = new Button(buttonsGroup, SWT.PUSH);
    removeButton.setText(UIMessages.button_remove);
    removeButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    removeButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            int selectionIndex = queriesTable.getSelectionIndex();
            if (selectionIndex >= 0) {
                tableEditor.closeEditor();
                queriesTable.remove(selectionIndex);
                removeButton.setEnabled(queriesTable.getSelectionIndex() >= 0);
            }
        }
    });
    removeButton.setEnabled(false);
    queriesTable.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            int selectionIndex = queriesTable.getSelectionIndex();
            removeButton.setEnabled(selectionIndex >= 0);
        }
    });
    queriesTable.addControlListener(new ControlAdapter() {

        @Override
        public void controlResized(ControlEvent e) {
            int sbWidth = 0;
            if (queriesTable.getVerticalBar() != null) {
                sbWidth = queriesTable.getVerticalBar().getSize().x;
            }
            queriesTable.getColumn(0).setWidth(queriesTable.getSize().x - queriesTable.getBorderWidth() * 2 - sbWidth);
        }
    });
    ignoreErrorButton = UIUtils.createCheckbox(composite, CoreMessages.dialog_connection_edit_wizard_general_bootstrap_query_ignore_error_lable, ignoreErrors);
    VariablesHintLabel variablesHintLabel = new VariablesHintLabel(composite, CoreMessages.dialog_connection_edit_wizard_shell_cmd_variables_hint_label, CoreMessages.dialog_connection_edit_wizard_shell_cmd_variables_hint_title, DataSourceDescriptor.CONNECT_VARIABLES);
    if (dataSourceDescriptor != null) {
        variablesHintLabel.setResolver(new DataSourceVariableResolver(dataSourceDescriptor, dataSourceDescriptor.getConnectionConfiguration()));
    }
    UIUtils.asyncExec(() -> UIUtils.packColumns(queriesTable, true));
    return composite;
}
Also used : ControlAdapter(org.eclipse.swt.events.ControlAdapter) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) CustomTableEditor(org.jkiss.dbeaver.ui.controls.CustomTableEditor) VariablesHintLabel(org.jkiss.dbeaver.ui.controls.VariablesHintLabel) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ControlEvent(org.eclipse.swt.events.ControlEvent) DataSourceVariableResolver(org.jkiss.dbeaver.model.connection.DataSourceVariableResolver)

Example 5 with CustomTableEditor

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

the class PrefPageConfirmations method createContents.

@Override
protected Control createContents(Composite parent) {
    ResourceBundle coreBundle = DBeaverActivator.getCoreResourceBundle();
    ResourceBundle rsvBundle = ResourceBundle.getBundle(ResultSetMessages.BUNDLE_NAME);
    ResourceBundle navigatorBundle = ResourceBundle.getBundle(UINavigatorMessages.BUNDLE_NAME);
    ResourceBundle sqlBundle = ResourceBundle.getBundle(SQLEditorMessages.BUNDLE_NAME);
    Composite composite = UIUtils.createPlaceholder(parent, 1);
    confirmTable = new Table(composite, SWT.BORDER | SWT.FULL_SELECTION);
    confirmTable.setLayoutData(new GridData(GridData.FILL_BOTH));
    confirmTable.setHeaderVisible(true);
    confirmTable.setLinesVisible(true);
    UIUtils.createTableColumn(confirmTable, SWT.LEFT, CoreMessages.pref_page_confirmations_table_column_confirmation);
    UIUtils.createTableColumn(confirmTable, SWT.LEFT, CoreMessages.pref_page_confirmations_table_column_group);
    UIUtils.createTableColumn(confirmTable, SWT.RIGHT, CoreMessages.pref_page_confirmations_table_column_value);
    final CustomTableEditor tableEditor = new CustomTableEditor(confirmTable) {

        {
            firstTraverseIndex = 2;
            lastTraverseIndex = 2;
            editOnEnter = false;
        }

        @Override
        protected Control createEditor(Table table, int index, TableItem item) {
            if (index != 2) {
                return null;
            }
            CCombo editor = new CCombo(table, SWT.DROP_DOWN | SWT.READ_ONLY);
            editor.setItems(new String[] { CoreMessages.pref_page_confirmations_combo_always, CoreMessages.pref_page_confirmations_combo_never, CoreMessages.pref_page_confirmations_combo_prompt });
            editor.setText(item.getText(2));
            return editor;
        }

        @Override
        protected void saveEditorValue(Control control, int index, TableItem item) {
            item.setText(2, ((CCombo) control).getText());
        }
    };
    createConfirmItem(CoreMessages.pref_page_confirmations_group_general_actions, coreBundle, DBeaverPreferences.CONFIRM_EXIT);
    createConfirmItem(CoreMessages.pref_page_confirmations_group_general_actions, rsvBundle, ResultSetPreferences.CONFIRM_ORDER_RESULTSET);
    // createConfirmItem(CoreMessages.pref_page_confirmations_group_general_actions, rsvBundle, ResultSetPreferences.CONFIRM_RS_EDIT_CLOSE);
    createConfirmItem(CoreMessages.pref_page_confirmations_group_general_actions, rsvBundle, ResultSetPreferences.CONFIRM_RS_FETCH_ALL);
    createConfirmItem(CoreMessages.pref_page_confirmations_group_general_actions, coreBundle, DBeaverPreferences.CONFIRM_TXN_DISCONNECT);
    createConfirmItem(CoreMessages.pref_page_confirmations_group_general_actions, coreBundle, DBeaverPreferences.CONFIRM_DRIVER_DOWNLOAD);
    createConfirmItem(CoreMessages.pref_page_confirmations_group_general_actions, coreBundle, DBeaverPreferences.CONFIRM_VERSION_CHECK);
    // createConfirmItem(CoreMessages.pref_page_confirmations_group_object_editor, navigatorBundle, NavigatorPreferences.CONFIRM_ENTITY_EDIT_CLOSE);
    createConfirmItem(CoreMessages.pref_page_confirmations_group_object_editor, navigatorBundle, NavigatorPreferences.CONFIRM_ENTITY_DELETE);
    createConfirmItem(CoreMessages.pref_page_confirmations_group_object_editor, navigatorBundle, NavigatorPreferences.CONFIRM_ENTITY_REJECT);
    createConfirmItem(CoreMessages.pref_page_confirmations_group_object_editor, navigatorBundle, NavigatorPreferences.CONFIRM_ENTITY_REVERT);
    createConfirmItem(CoreMessages.pref_page_confirmations_group_object_editor, rsvBundle, ResultSetPreferences.CONFIRM_KEEP_STATEMENT_OPEN);
    createConfirmItem(CoreMessages.pref_page_confirmations_group_object_editor, sqlBundle, SQLPreferenceConstants.CONFIRM_DANGER_SQL);
    createConfirmItem(CoreMessages.pref_page_confirmations_group_object_editor, sqlBundle, SQLPreferenceConstants.CONFIRM_MASS_PARALLEL_SQL);
    createConfirmItem(CoreMessages.pref_page_confirmations_group_object_editor, sqlBundle, SQLPreferenceConstants.CONFIRM_RUNNING_QUERY_CLOSE);
    createConfirmItem(CoreMessages.pref_page_confirmations_group_object_editor, sqlBundle, SQLPreferenceConstants.CONFIRM_RESULT_TABS_CLOSE);
    // createConfirmItem(CoreMessages.pref_page_confirmations_group_object_editor, navigatorBundle, NavigatorPreferences.CONFIRM_EDITOR_CLOSE);
    UIUtils.asyncExec(() -> UIUtils.packColumns(confirmTable, true));
    return composite;
}
Also used : Control(org.eclipse.swt.widgets.Control) Table(org.eclipse.swt.widgets.Table) CustomTableEditor(org.jkiss.dbeaver.ui.controls.CustomTableEditor) CCombo(org.eclipse.swt.custom.CCombo) Composite(org.eclipse.swt.widgets.Composite) TableItem(org.eclipse.swt.widgets.TableItem) GridData(org.eclipse.swt.layout.GridData) ResourceBundle(java.util.ResourceBundle)

Aggregations

GridData (org.eclipse.swt.layout.GridData)18 CustomTableEditor (org.jkiss.dbeaver.ui.controls.CustomTableEditor)18 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)10 SelectionEvent (org.eclipse.swt.events.SelectionEvent)10 IDialogSettings (org.eclipse.jface.dialogs.IDialogSettings)4 StatusDialog (org.eclipse.jface.dialogs.StatusDialog)4 SWT (org.eclipse.swt.SWT)4 GridLayout (org.eclipse.swt.layout.GridLayout)4 org.eclipse.swt.widgets (org.eclipse.swt.widgets)4 Log (org.jkiss.dbeaver.Log)4 SQLQueryParameter (org.jkiss.dbeaver.model.sql.SQLQueryParameter)4 DBSProcedureParameter (org.jkiss.dbeaver.model.struct.rdb.DBSProcedureParameter)4 DBeaverIcons (org.jkiss.dbeaver.ui.DBeaverIcons)4 UIUtils (org.jkiss.dbeaver.ui.UIUtils)4 TableColumnSortListener (org.jkiss.dbeaver.ui.controls.TableColumnSortListener)4 CommonUtils (org.jkiss.utils.CommonUtils)4 StringWriter (java.io.StringWriter)2 java.util (java.util)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2