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("Bind 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 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()) {
DBeaverUI.asyncExec(new Runnable() {
@Override
public void run() {
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;
}
use of org.jkiss.dbeaver.ui.controls.CustomTableEditor 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;
}
use of org.jkiss.dbeaver.ui.controls.CustomTableEditor in project dbeaver by serge-rider.
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);
}
}
}
}
});
}
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(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 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;
}
Aggregations