Search in sources :

Example 1 with TableColumnSortListener

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

the class AttributesSelectorPage method createAttributeColumns.

protected void createAttributeColumns(Table columnsTable) {
    TableColumn colName = UIUtils.createTableColumn(columnsTable, SWT.NONE, EditorsMessages.dialog_struct_columns_select_column);
    colName.addListener(SWT.Selection, new TableColumnSortListener(columnsTable, 0));
    // $NON-NLS-1$
    TableColumn colPosition = UIUtils.createTableColumn(columnsTable, SWT.CENTER, "#");
    colPosition.addListener(SWT.Selection, new TableColumnSortListener(columnsTable, 1));
    // $NON-NLS-1$
    TableColumn colType = UIUtils.createTableColumn(columnsTable, SWT.RIGHT, EditorsMessages.dialog_struct_columns_type);
    colType.addListener(SWT.Selection, new TableColumnSortListener(columnsTable, 2));
}
Also used : TableColumnSortListener(org.jkiss.dbeaver.ui.controls.TableColumnSortListener)

Example 2 with TableColumnSortListener

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

the class QueryLogViewer method createColumns.

private void createColumns(boolean showConnection) {
    for (TableColumn tableColumn : logTable.getColumns()) {
        tableColumn.dispose();
    }
    columns.clear();
    final IDialogSettings dialogSettings = UIUtils.getDialogSettings(VIEWER_ID);
    int colIndex = 0;
    for (final LogColumn logColumn : ALL_COLUMNS) {
        if (!showConnection && (logColumn == COLUMN_DATA_SOURCE || logColumn == COLUMN_CONTEXT)) {
            continue;
        }
        final TableColumn tableColumn = UIUtils.createTableColumn(logTable, SWT.NONE, logColumn.title);
        tableColumn.setData(logColumn);
        // $NON-NLS-1$
        final String colWidth = dialogSettings.get("column-" + logColumn.id);
        if (colWidth != null) {
            tableColumn.setWidth(Integer.parseInt(colWidth));
        } else {
            tableColumn.setWidth(logColumn.widthHint);
        }
        tableColumn.setToolTipText(logColumn.toolTip);
        final ColumnDescriptor cd = new ColumnDescriptor(logColumn, tableColumn);
        columns.add(cd);
        tableColumn.addListener(SWT.Selection, new TableColumnSortListener(logTable, colIndex));
        tableColumn.addListener(SWT.Resize, event -> {
            final int width = tableColumn.getWidth();
            // $NON-NLS-1$
            dialogSettings.put("column-" + logColumn.id, String.valueOf(width));
        });
        colIndex++;
    }
}
Also used : IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) TableColumnSortListener(org.jkiss.dbeaver.ui.controls.TableColumnSortListener)

Example 3 with TableColumnSortListener

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

the class SQLQueryParameterBindDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    getShell().setText(SQLEditorMessages.dialog_sql_param_title);
    final Composite composite = (Composite) super.createDialogArea(parent);
    SashForm sash = new SashForm(composite, SWT.VERTICAL);
    sash.setLayoutData(new GridData(GridData.FILL_BOTH));
    {
        final Composite paramsComposite = UIUtils.createComposite(sash, 1);
        paramTable = new Table(paramsComposite, 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.addListener(SWT.Selection, new TableColumnSortListener(paramTable, 0));
        indexColumn.setWidth(40);
        final TableColumn nameColumn = UIUtils.createTableColumn(paramTable, SWT.LEFT, SQLEditorMessages.dialog_sql_param_column_name);
        nameColumn.addListener(SWT.Selection, new TableColumnSortListener(paramTable, 1));
        nameColumn.setWidth(100);
        final TableColumn valueColumn = UIUtils.createTableColumn(paramTable, SWT.LEFT, SQLEditorMessages.dialog_sql_param_column_value);
        valueColumn.setWidth(200);
        fillParameterList(isHideIfSet());
        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.NONE);
                editor.setText(CommonUtils.notEmpty(param.getValue()));
                editor.selectAll();
                editor.addTraverseListener(e -> {
                    if (e.detail == SWT.TRAVERSE_RETURN && (e.stateMask & SWT.CTRL) == SWT.CTRL) {
                        UIUtils.asyncExec(SQLQueryParameterBindDialog.this::okPressed);
                    }
                });
                editor.addModifyListener(e -> saveEditorValue(editor, index, item));
                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);
                param.setVariableSet(!CommonUtils.isEmpty(newValue));
                if (param.isNamed()) {
                    final List<SQLQueryParameter> dups = dupParameters.get(param.getName());
                    if (dups != null) {
                        for (SQLQueryParameter dup : dups) {
                            dup.setValue(newValue);
                            dup.setVariableSet(!CommonUtils.isEmpty(newValue));
                        }
                    }
                    queryContext.setVariable(param.getVarName(), param.getValue());
                }
                savedParamValues.put(param.getName().toUpperCase(Locale.ENGLISH), new SQLQueryParameterRegistry.ParameterInfo(param.getName(), newValue));
                updateQueryPreview();
            }
        };
        if (!parameters.isEmpty()) {
            UIUtils.asyncExec(() -> {
                if (paramTable.getItemCount() > 0) {
                    paramTable.select(0);
                    tableEditor.showEditor(paramTable.getItem(0), 2);
                }
            });
        }
    }
    {
        final Composite queryComposite = new Composite(sash, SWT.BORDER);
        queryComposite.setLayout(new FillLayout());
        try {
            queryPreviewPanel = DBWorkbench.getService(UIServiceSQL.class).createSQLPanel(site, queryComposite, new DataSourceContextProvider(query.getDataSource()), "Query preview", false, query.getText());
        } catch (Exception e) {
            log.error(e);
        }
    }
    sash.setWeights(new int[] { 600, 400 });
    hideIfSetCheck = UIUtils.createCheckbox(composite, SQLEditorMessages.dialog_sql_param_hide_checkbox, SQLEditorMessages.dialog_sql_param_hide_checkbox_tip, isHideIfSet(), 1);
    hideIfSetCheck.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            fillParameterList(hideIfSetCheck.getSelection());
        }
    });
    updateStatus(GeneralUtils.makeInfoStatus(SQLEditorMessages.dialog_sql_param_hint));
    updateQueryPreview();
    return composite;
}
Also used : DBWorkbench(org.jkiss.dbeaver.runtime.DBWorkbench) java.util(java.util) SashForm(org.eclipse.swt.custom.SashForm) SQLScriptContext(org.jkiss.dbeaver.model.sql.SQLScriptContext) IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) TableColumnSortListener(org.jkiss.dbeaver.ui.controls.TableColumnSortListener) UIServiceSQL(org.jkiss.dbeaver.runtime.ui.UIServiceSQL) CustomTableEditor(org.jkiss.dbeaver.ui.controls.CustomTableEditor) DBeaverIcons(org.jkiss.dbeaver.ui.DBeaverIcons) UIUtils(org.jkiss.dbeaver.ui.UIUtils) Log(org.jkiss.dbeaver.Log) GridData(org.eclipse.swt.layout.GridData) SQLQuery(org.jkiss.dbeaver.model.sql.SQLQuery) FillLayout(org.eclipse.swt.layout.FillLayout) StatusDialog(org.eclipse.jface.dialogs.StatusDialog) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GeneralUtils(org.jkiss.dbeaver.utils.GeneralUtils) CommonUtils(org.jkiss.utils.CommonUtils) DataSourceContextProvider(org.jkiss.dbeaver.model.impl.DataSourceContextProvider) StringWriter(java.io.StringWriter) org.eclipse.swt.widgets(org.eclipse.swt.widgets) SQLEditorMessages(org.jkiss.dbeaver.ui.editors.sql.internal.SQLEditorMessages) List(java.util.List) DBIcon(org.jkiss.dbeaver.model.DBIcon) SWT(org.eclipse.swt.SWT) SQLQueryParameter(org.jkiss.dbeaver.model.sql.SQLQueryParameter) SQLUtils(org.jkiss.dbeaver.model.sql.SQLUtils) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SQLQueryParameterRegistry(org.jkiss.dbeaver.model.sql.registry.SQLQueryParameterRegistry) GridLayout(org.eclipse.swt.layout.GridLayout) TableColumnSortListener(org.jkiss.dbeaver.ui.controls.TableColumnSortListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DataSourceContextProvider(org.jkiss.dbeaver.model.impl.DataSourceContextProvider) FillLayout(org.eclipse.swt.layout.FillLayout) SQLQueryParameter(org.jkiss.dbeaver.model.sql.SQLQueryParameter) SashForm(org.eclipse.swt.custom.SashForm) CustomTableEditor(org.jkiss.dbeaver.ui.controls.CustomTableEditor) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(java.util.List) UIServiceSQL(org.jkiss.dbeaver.runtime.ui.UIServiceSQL)

Example 4 with TableColumnSortListener

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

the class EditTaskVariablesDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    final Composite composite = (Composite) super.createDialogArea(parent);
    {
        final Composite paramsComposite = UIUtils.createComposite(composite, 1);
        paramsComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
        variablesTable = new Table(paramsComposite, 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;
        variablesTable.setLayoutData(gd);
        variablesTable.setHeaderVisible(true);
        variablesTable.setLinesVisible(!UIStyles.isDarkTheme());
        final TableColumn nameColumn = UIUtils.createTableColumn(variablesTable, SWT.LEFT, TaskUIMessages.edit_task_variabl_dialog_column_variable);
        nameColumn.addListener(SWT.Selection, new TableColumnSortListener(variablesTable, 1));
        nameColumn.setWidth(100);
        final TableColumn valueColumn = UIUtils.createTableColumn(variablesTable, SWT.LEFT, TaskUIMessages.edit_task_variabl_dialog_column_value);
        valueColumn.setWidth(300);
        final CustomTableEditor tableEditor = new CustomTableEditor(variablesTable) {

            {
                firstTraverseIndex = 0;
                lastTraverseIndex = 1;
                editOnEnter = false;
            }

            @Override
            protected Control createEditor(Table table, int index, TableItem item) {
                Text editor = new Text(table, SWT.NONE);
                editor.setText(item.getText(index));
                editor.selectAll();
                editor.addTraverseListener(e -> {
                    if (e.detail == SWT.TRAVERSE_RETURN && (e.stateMask & SWT.CTRL) == SWT.CTRL) {
                        UIUtils.asyncExec(EditTaskVariablesDialog.this::okPressed);
                    }
                });
                editor.addModifyListener(e -> saveEditorValue(editor, index, item));
                return editor;
            }

            @Override
            protected void saveEditorValue(Control control, int index, TableItem item) {
                String newValue = ((Text) control).getText();
                item.setText(index, newValue);
            }
        };
        ToolBar toolbar = new ToolBar(composite, SWT.FLAT | SWT.HORIZONTAL);
        final ToolItem newButton = new ToolItem(toolbar, SWT.NONE);
        newButton.setImage(DBeaverIcons.getImage(UIIcon.ROW_ADD));
        ToolItem deleteButton = new ToolItem(toolbar, SWT.NONE);
        deleteButton.setImage(DBeaverIcons.getImage(UIIcon.ROW_DELETE));
        deleteButton.setEnabled(false);
        newButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                TableItem newItem = new TableItem(variablesTable, SWT.NONE);
                variablesTable.setSelection(newItem);
                tableEditor.showEditor(newItem);
                deleteButton.setEnabled(true);
            }
        });
        deleteButton.addSelectionListener(new SelectionAdapter() {

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

            @Override
            public void widgetSelected(SelectionEvent e) {
                deleteButton.setEnabled(variablesTable.getSelectionIndex() >= 0);
            }
        });
        for (Map.Entry<String, Object> param : variables.entrySet()) {
            TableItem item = new TableItem(variablesTable, SWT.NONE);
            item.setText(0, param.getKey());
            item.setText(1, CommonUtils.toString(param.getValue()));
        }
        if (variablesTable.getItemCount() == 0) {
            new TableItem(variablesTable, SWT.NONE);
        }
        tableEditor.showEditor(variablesTable.getItem(0));
    }
    return composite;
}
Also used : StatusDialog(org.eclipse.jface.dialogs.StatusDialog) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) CommonUtils(org.jkiss.utils.CommonUtils) TaskUIMessages(org.jkiss.dbeaver.tasks.ui.internal.TaskUIMessages) org.eclipse.swt.widgets(org.eclipse.swt.widgets) UIStyles(org.jkiss.dbeaver.ui.UIStyles) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) TableColumnSortListener(org.jkiss.dbeaver.ui.controls.TableColumnSortListener) CustomTableEditor(org.jkiss.dbeaver.ui.controls.CustomTableEditor) LinkedHashMap(java.util.LinkedHashMap) DBeaverIcons(org.jkiss.dbeaver.ui.DBeaverIcons) UIUtils(org.jkiss.dbeaver.ui.UIUtils) SWT(org.eclipse.swt.SWT) Map(java.util.Map) Log(org.jkiss.dbeaver.Log) UIIcon(org.jkiss.dbeaver.ui.UIIcon) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridData(org.eclipse.swt.layout.GridData) TableColumnSortListener(org.jkiss.dbeaver.ui.controls.TableColumnSortListener) 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 5 with TableColumnSortListener

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

the class EditTaskVariablesDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    final Composite composite = (Composite) super.createDialogArea(parent);
    {
        final Composite paramsComposite = UIUtils.createComposite(composite, 1);
        paramsComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
        variablesTable = new Table(paramsComposite, 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;
        variablesTable.setLayoutData(gd);
        variablesTable.setHeaderVisible(true);
        variablesTable.setLinesVisible(!UIStyles.isDarkTheme());
        final TableColumn nameColumn = UIUtils.createTableColumn(variablesTable, SWT.LEFT, TaskUIMessages.edit_task_variabl_dialog_column_variable);
        nameColumn.addListener(SWT.Selection, new TableColumnSortListener(variablesTable, 1));
        nameColumn.setWidth(100);
        final TableColumn valueColumn = UIUtils.createTableColumn(variablesTable, SWT.LEFT, TaskUIMessages.edit_task_variabl_dialog_column_value);
        valueColumn.setWidth(300);
        final CustomTableEditor tableEditor = new CustomTableEditor(variablesTable) {

            {
                firstTraverseIndex = 0;
                lastTraverseIndex = 1;
                editOnEnter = false;
            }

            @Override
            protected Control createEditor(Table table, int index, TableItem item) {
                Text editor = new Text(table, SWT.NONE);
                editor.setText(item.getText(index));
                editor.selectAll();
                editor.addTraverseListener(e -> {
                    if (e.detail == SWT.TRAVERSE_RETURN && (e.stateMask & SWT.CTRL) == SWT.CTRL) {
                        UIUtils.asyncExec(EditTaskVariablesDialog.this::okPressed);
                    }
                });
                editor.addModifyListener(e -> saveEditorValue(editor, index, item));
                return editor;
            }

            @Override
            protected void saveEditorValue(Control control, int index, TableItem item) {
                String newValue = ((Text) control).getText();
                item.setText(index, newValue);
            }
        };
        ToolBar toolbar = new ToolBar(composite, SWT.FLAT | SWT.HORIZONTAL);
        final ToolItem newButton = new ToolItem(toolbar, SWT.NONE);
        newButton.setImage(DBeaverIcons.getImage(UIIcon.ROW_ADD));
        ToolItem deleteButton = new ToolItem(toolbar, SWT.NONE);
        deleteButton.setImage(DBeaverIcons.getImage(UIIcon.ROW_DELETE));
        deleteButton.setEnabled(false);
        newButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                TableItem newItem = new TableItem(variablesTable, SWT.NONE);
                variablesTable.setSelection(newItem);
                tableEditor.showEditor(newItem);
                deleteButton.setEnabled(true);
            }
        });
        deleteButton.addSelectionListener(new SelectionAdapter() {

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

            @Override
            public void widgetSelected(SelectionEvent e) {
                deleteButton.setEnabled(variablesTable.getSelectionIndex() >= 0);
            }
        });
        for (Map.Entry<String, Object> param : variables.entrySet()) {
            TableItem item = new TableItem(variablesTable, SWT.NONE);
            item.setText(0, param.getKey());
            item.setText(1, CommonUtils.toString(param.getValue()));
        }
        if (variablesTable.getItemCount() == 0) {
            new TableItem(variablesTable, SWT.NONE);
        }
        tableEditor.showEditor(variablesTable.getItem(0));
    }
    return composite;
}
Also used : StatusDialog(org.eclipse.jface.dialogs.StatusDialog) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) CommonUtils(org.jkiss.utils.CommonUtils) TaskUIMessages(org.jkiss.dbeaver.tasks.ui.internal.TaskUIMessages) org.eclipse.swt.widgets(org.eclipse.swt.widgets) UIStyles(org.jkiss.dbeaver.ui.UIStyles) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) TableColumnSortListener(org.jkiss.dbeaver.ui.controls.TableColumnSortListener) CustomTableEditor(org.jkiss.dbeaver.ui.controls.CustomTableEditor) LinkedHashMap(java.util.LinkedHashMap) DBeaverIcons(org.jkiss.dbeaver.ui.DBeaverIcons) UIUtils(org.jkiss.dbeaver.ui.UIUtils) SWT(org.eclipse.swt.SWT) Map(java.util.Map) Log(org.jkiss.dbeaver.Log) UIIcon(org.jkiss.dbeaver.ui.UIIcon) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridData(org.eclipse.swt.layout.GridData) TableColumnSortListener(org.jkiss.dbeaver.ui.controls.TableColumnSortListener) 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)

Aggregations

TableColumnSortListener (org.jkiss.dbeaver.ui.controls.TableColumnSortListener)8 IDialogSettings (org.eclipse.jface.dialogs.IDialogSettings)6 StatusDialog (org.eclipse.jface.dialogs.StatusDialog)4 SWT (org.eclipse.swt.SWT)4 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)4 SelectionEvent (org.eclipse.swt.events.SelectionEvent)4 GridData (org.eclipse.swt.layout.GridData)4 org.eclipse.swt.widgets (org.eclipse.swt.widgets)4 Log (org.jkiss.dbeaver.Log)4 DBeaverIcons (org.jkiss.dbeaver.ui.DBeaverIcons)4 UIUtils (org.jkiss.dbeaver.ui.UIUtils)4 CustomTableEditor (org.jkiss.dbeaver.ui.controls.CustomTableEditor)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 Map (java.util.Map)2 IDialogConstants (org.eclipse.jface.dialogs.IDialogConstants)2 SashForm (org.eclipse.swt.custom.SashForm)2