use of org.jkiss.dbeaver.model.impl.DataSourceContextProvider 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.model.impl.DataSourceContextProvider 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;
}
Aggregations