use of org.jkiss.dbeaver.ui.controls.CustomTableEditor in project dbeaver by serge-rider.
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();
}
};
}
use of org.jkiss.dbeaver.ui.controls.CustomTableEditor in project dbeaver by serge-rider.
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;
}
use of org.jkiss.dbeaver.ui.controls.CustomTableEditor 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;
}
use of org.jkiss.dbeaver.ui.controls.CustomTableEditor 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;
}
use of org.jkiss.dbeaver.ui.controls.CustomTableEditor in project dbeaver by dbeaver.
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;
}
Aggregations