Search in sources :

Example 16 with CustomTableEditor

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

the class ProcedureParameterBindDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    getShell().setText(procedure.getProcedureType().name() + " " + procedure.getName() + " parameter(s)");
    final Composite composite = (Composite) super.createDialogArea(parent);
    final 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 nameColumn = UIUtils.createTableColumn(paramTable, SWT.LEFT, "Name");
    nameColumn.setWidth(100);
    final TableColumn valueColumn = UIUtils.createTableColumn(paramTable, SWT.LEFT, "Value");
    valueColumn.setWidth(200);
    final TableColumn typeColumn = UIUtils.createTableColumn(paramTable, SWT.LEFT, "Type");
    typeColumn.setWidth(60);
    final TableColumn kindColumn = UIUtils.createTableColumn(paramTable, SWT.LEFT, "Kind");
    kindColumn.setWidth(40);
    for (DBSProcedureParameter param : parameters) {
        TableItem item = new TableItem(paramTable, SWT.NONE);
        item.setData(param);
        item.setImage(DBeaverIcons.getImage(DBIcon.TREE_ATTRIBUTE));
        item.setText(0, param.getName());
        Object value = values.get(param);
        item.setText(1, CommonUtils.toString(value, ""));
        item.setText(2, param.getParameterType().getFullTypeName());
        item.setText(3, param.getParameterKind().getTitle());
    }
    final CustomTableEditor tableEditor = new CustomTableEditor(paramTable) {

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

        @Override
        protected Control createEditor(Table table, int index, TableItem item) {
            if (index != 1) {
                return null;
            }
            DBSProcedureParameter param = (DBSProcedureParameter) item.getData();
            Text editor = new Text(table, SWT.BORDER);
            editor.setText(CommonUtils.toString(values.get(param), ""));
            editor.selectAll();
            return editor;
        }

        @Override
        protected void saveEditorValue(Control control, int index, TableItem item) {
            DBSProcedureParameter param = (DBSProcedureParameter) item.getData();
            String newValue = ((Text) control).getText();
            item.setText(1, newValue);
            values.put(param, newValue);
        }
    };
    if (!parameters.isEmpty()) {
        UIUtils.asyncExec(() -> {
            paramTable.select(0);
            tableEditor.showEditor(paramTable.getItem(0), 1);
        });
    }
    updateStatus(GeneralUtils.makeInfoStatus("Use Tab to switch."));
    return composite;
}
Also used : CustomTableEditor(org.jkiss.dbeaver.ui.controls.CustomTableEditor) DBSProcedureParameter(org.jkiss.dbeaver.model.struct.rdb.DBSProcedureParameter) GridData(org.eclipse.swt.layout.GridData)

Example 17 with CustomTableEditor

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

the class PostgreDebugPanelFunction method createParametersGroup.

private void createParametersGroup(Composite parent) {
    Group composite = UIUtils.createControlGroup(parent, "Function parameters", 2, GridData.FILL_BOTH, SWT.DEFAULT);
    parametersTable = new Table(composite, SWT.SINGLE | SWT.FULL_SELECTION | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
    final GridData gd = new GridData(GridData.FILL_BOTH);
    parametersTable.setLayoutData(gd);
    parametersTable.setHeaderVisible(true);
    parametersTable.setLinesVisible(true);
    final TableColumn nameColumn = UIUtils.createTableColumn(parametersTable, SWT.LEFT, "Name");
    nameColumn.setWidth(100);
    final TableColumn valueColumn = UIUtils.createTableColumn(parametersTable, SWT.LEFT, "Value");
    valueColumn.setWidth(200);
    final TableColumn typeColumn = UIUtils.createTableColumn(parametersTable, SWT.LEFT, "Type");
    typeColumn.setWidth(60);
    final TableColumn kindColumn = UIUtils.createTableColumn(parametersTable, SWT.LEFT, "Kind");
    kindColumn.setWidth(40);
    new CustomTableEditor(parametersTable) {

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

        @Override
        protected Control createEditor(Table table, int index, TableItem item) {
            if (index != 1) {
                return null;
            }
            DBSProcedureParameter param = (DBSProcedureParameter) item.getData();
            Text editor = new Text(table, SWT.BORDER);
            editor.setText(CommonUtils.toString(parameterValues.get(param), ""));
            editor.selectAll();
            return editor;
        }

        @Override
        protected void saveEditorValue(Control control, int index, TableItem item) {
            DBSProcedureParameter param = (DBSProcedureParameter) item.getData();
            String newValue = ((Text) control).getText();
            item.setText(1, newValue);
            parameterValues.put(param, newValue);
            container.updateDialogState();
        }
    };
}
Also used : CustomTableEditor(org.jkiss.dbeaver.ui.controls.CustomTableEditor) DBSProcedureParameter(org.jkiss.dbeaver.model.struct.rdb.DBSProcedureParameter) GridData(org.eclipse.swt.layout.GridData)

Example 18 with CustomTableEditor

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

the class AttributesSelectorPage method createColumnsGroup.

protected void createColumnsGroup(Composite panel) {
    columnsGroup = new Composite(panel, SWT.NONE);
    columnsGroup.setLayout(new GridLayout(1, false));
    columnsGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
    UIUtils.createControlLabel(columnsGroup, EditorsMessages.dialog_struct_columns_select_group_columns);
    // columnsViewer = new TableViewer(columnsGroup, SWT.BORDER | SWT.SINGLE | SWT.CHECK);
    columnsTable = new Table(columnsGroup, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION | SWT.CHECK);
    columnsTable.setHeaderVisible(true);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.minimumWidth = 300;
    gd.minimumHeight = 150;
    columnsTable.setLayoutData(gd);
    columnsTable.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            handleItemSelect((TableItem) e.item, true);
        }
    });
    createAttributeColumns(columnsTable);
    final CustomTableEditor tableEditor = new CustomTableEditor(columnsTable) {

        @Override
        protected Control createEditor(Table table, final int index, final TableItem item) {
            return createCellEditor(table, index, item, (AttributeInfo) item.getData());
        }

        @Override
        protected void saveEditorValue(Control control, int index, TableItem item) {
            saveCellValue(control, index, item, (AttributeInfo) item.getData());
        }
    };
    toggleButton = new Button(columnsGroup, SWT.PUSH);
    toggleButton.setText("Select All");
    gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    gd.widthHint = 120;
    toggleButton.setLayoutData(gd);
    toggleButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            TableItem[] items = columnsTable.getItems();
            if (hasCheckedColumns()) {
                // Clear all checked
                for (TableItem item : items) {
                    if (item.getChecked()) {
                        item.setChecked(false);
                        handleItemSelect(item, true);
                    }
                }
            } else {
                // Check all
                for (TableItem item : items) {
                    if (!item.getChecked()) {
                        item.setChecked(true);
                        handleItemSelect(item, true);
                    }
                }
            }
        }
    });
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) CustomTableEditor(org.jkiss.dbeaver.ui.controls.CustomTableEditor) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

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