use of org.jkiss.dbeaver.model.connection.DataSourceVariableResolver in project dbeaver by serge-rider.
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;
}
use of org.jkiss.dbeaver.model.connection.DataSourceVariableResolver in project dbeaver by serge-rider.
the class SSHTunnelConfiguratorUI method testTunnelConnection.
private void testTunnelConnection() {
DBWHandlerConfiguration configuration = new DBWHandlerConfiguration(savedConfiguration);
configuration.setProperties(Collections.emptyMap());
saveSettings(configuration);
DBPDataSourceContainer dataSource = configuration.getDataSource();
if (dataSource != null) {
configuration.resolveDynamicVariables(new DataSourceVariableResolver(dataSource, dataSource.getConnectionConfiguration()));
} else {
configuration.resolveDynamicVariables(SystemVariablesResolver.INSTANCE);
}
try {
final String[] tunnelVersions = new String[2];
UIUtils.runInProgressDialog(monitor -> {
monitor.beginTask("Instantiate SSH tunnel", 2);
SSHTunnelImpl tunnel = new SSHTunnelImpl();
DBPConnectionConfiguration connectionConfig = new DBPConnectionConfiguration();
connectionConfig.setHostName("localhost");
connectionConfig.setHostPort(configuration.getStringProperty(DBWHandlerConfiguration.PROP_PORT));
try {
monitor.subTask("Initialize tunnel");
tunnel.initializeHandler(monitor, DBWorkbench.getPlatform(), configuration, connectionConfig);
monitor.worked(1);
// Get info
tunnelVersions[0] = tunnel.getImplementation().getClientVersion();
tunnelVersions[1] = tunnel.getImplementation().getServerVersion();
// Close it
monitor.subTask("Close tunnel");
tunnel.closeTunnel(monitor);
monitor.worked(1);
} catch (Exception e) {
throw new InvocationTargetException(e);
}
monitor.done();
});
MessageDialog.openInformation(hostText.getShell(), ModelMessages.dialog_connection_wizard_start_connection_monitor_success, "Connected!\n\nClient version: " + tunnelVersions[0] + "\nServer version: " + tunnelVersions[1]);
} catch (InvocationTargetException ex) {
DBWorkbench.getPlatformUI().showError(CoreMessages.dialog_connection_wizard_start_dialog_error_title, null, GeneralUtils.makeExceptionStatus(ex.getTargetException()));
}
}
use of org.jkiss.dbeaver.model.connection.DataSourceVariableResolver in project dbeaver by serge-rider.
the class ConnectionPageShellCommands method createControl.
@Override
public void createControl(Composite parent) {
Composite group = UIUtils.createPlaceholder(parent, 2, 5);
group.setLayoutData(new GridData(GridData.FILL_BOTH));
{
Composite eventGroup = UIUtils.createPlaceholder(group, 1);
eventGroup.setLayoutData(new GridData(GridData.FILL_VERTICAL));
UIUtils.createControlLabel(eventGroup, CoreMessages.dialog_connection_events_label_event);
eventTypeTable = new Table(eventGroup, SWT.BORDER | SWT.CHECK | SWT.SINGLE | SWT.FULL_SELECTION);
eventTypeTable.setLayoutData(new GridData(GridData.FILL_VERTICAL));
eventTypeTable.addListener(SWT.Selection, event -> {
if (event.detail == SWT.CHECK) {
eventTypeTable.select(eventTypeTable.indexOf((TableItem) event.item));
}
});
for (DBPConnectionEventType eventType : DBPConnectionEventType.values()) {
DBRShellCommand command = eventsCache.get(eventType);
TableItem item = new TableItem(eventTypeTable, SWT.NONE);
item.setData(eventType);
item.setText(eventType.getTitle());
item.setImage(DBeaverIcons.getImage(UIIcon.EVENT));
item.setChecked(command != null && command.isEnabled());
}
eventTypeTable.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
DBPConnectionEventType eventType = getSelectedEventType();
selectEventType(eventType);
DBRShellCommand command = eventType == null ? null : eventsCache.get(eventType);
boolean enabled = ((TableItem) e.item).getChecked();
if (enabled || (command != null && enabled != command.isEnabled())) {
updateEvent(false);
}
}
});
}
{
Composite detailsGroup = UIUtils.createPlaceholder(group, 1, 5);
detailsGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
UIUtils.createControlLabel(detailsGroup, CoreMessages.dialog_connection_events_label_command);
commandText = new Text(detailsGroup, SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
commandText.addModifyListener(e -> updateEvent(true));
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.heightHint = 60;
gd.widthHint = 300;
commandText.setLayoutData(gd);
SelectionAdapter eventEditAdapter = new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
updateEvent(false);
}
};
showProcessCheck = UIUtils.createCheckbox(detailsGroup, CoreMessages.dialog_connection_events_checkbox_show_process, false);
showProcessCheck.addSelectionListener(eventEditAdapter);
waitFinishCheck = UIUtils.createCheckbox(detailsGroup, CoreMessages.dialog_connection_events_checkbox_wait_finish, false);
waitFinishCheck.addSelectionListener(eventEditAdapter);
waitFinishTimeoutMs = createWaitFinishTimeout(detailsGroup);
waitFinishTimeoutMs.addSelectionListener(eventEditAdapter);
terminateCheck = UIUtils.createCheckbox(detailsGroup, CoreMessages.dialog_connection_events_checkbox_terminate_at_disconnect, false);
terminateCheck.addSelectionListener(eventEditAdapter);
{
Composite pauseComposite = UIUtils.createPlaceholder(detailsGroup, 2, 5);
pauseComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
pauseAfterExecute = UIUtils.createLabelSpinner(pauseComposite, CoreMessages.dialog_connection_edit_wizard_shell_cmd_pause_label, CoreMessages.dialog_connection_edit_wizard_shell_cmd_pause_tooltip, 0, 0, Integer.MAX_VALUE);
pauseAfterExecute.addSelectionListener(eventEditAdapter);
UIUtils.createControlLabel(pauseComposite, CoreMessages.dialog_connection_edit_wizard_shell_cmd_directory_label);
workingDirectory = new TextWithOpenFolder(pauseComposite, CoreMessagesdialog_connection_edit_wizard_shell_cmd_directory_title);
workingDirectory.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
workingDirectory.getTextControl().addModifyListener(e -> {
DBRShellCommand command = getActiveCommand();
if (command != null) {
command.setWorkingDirectory(workingDirectory.getText());
}
});
}
VariablesHintLabel variablesHintLabel = new VariablesHintLabel(detailsGroup, CoreMessages.dialog_connection_edit_wizard_shell_cmd_variables_hint_label, CoreMessages.dialog_connection_edit_wizard_shell_cmd_variables_hint_title, DataSourceDescriptor.CONNECT_VARIABLES);
variablesHintLabel.setResolver(new DataSourceVariableResolver(dataSource, dataSource.getConnectionConfiguration()));
}
selectEventType(null);
setControl(group);
}
use of org.jkiss.dbeaver.model.connection.DataSourceVariableResolver in project dbeaver by dbeaver.
the class ConnectionPageShellCommands method createControl.
@Override
public void createControl(Composite parent) {
Composite group = UIUtils.createPlaceholder(parent, 2, 5);
group.setLayoutData(new GridData(GridData.FILL_BOTH));
{
Composite eventGroup = UIUtils.createPlaceholder(group, 1);
eventGroup.setLayoutData(new GridData(GridData.FILL_VERTICAL));
UIUtils.createControlLabel(eventGroup, CoreMessages.dialog_connection_events_label_event);
eventTypeTable = new Table(eventGroup, SWT.BORDER | SWT.CHECK | SWT.SINGLE | SWT.FULL_SELECTION);
eventTypeTable.setLayoutData(new GridData(GridData.FILL_VERTICAL));
eventTypeTable.addListener(SWT.Selection, event -> {
if (event.detail == SWT.CHECK) {
eventTypeTable.select(eventTypeTable.indexOf((TableItem) event.item));
}
});
for (DBPConnectionEventType eventType : DBPConnectionEventType.values()) {
DBRShellCommand command = eventsCache.get(eventType);
TableItem item = new TableItem(eventTypeTable, SWT.NONE);
item.setData(eventType);
item.setText(eventType.getTitle());
item.setImage(DBeaverIcons.getImage(UIIcon.EVENT));
item.setChecked(command != null && command.isEnabled());
}
eventTypeTable.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
DBPConnectionEventType eventType = getSelectedEventType();
selectEventType(eventType);
DBRShellCommand command = eventType == null ? null : eventsCache.get(eventType);
boolean enabled = ((TableItem) e.item).getChecked();
if (enabled || (command != null && enabled != command.isEnabled())) {
updateEvent(false);
}
}
});
}
{
Composite detailsGroup = UIUtils.createPlaceholder(group, 1, 5);
detailsGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
UIUtils.createControlLabel(detailsGroup, CoreMessages.dialog_connection_events_label_command);
commandText = new Text(detailsGroup, SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
commandText.addModifyListener(e -> updateEvent(true));
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.heightHint = 60;
gd.widthHint = 300;
commandText.setLayoutData(gd);
SelectionAdapter eventEditAdapter = new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
updateEvent(false);
}
};
showProcessCheck = UIUtils.createCheckbox(detailsGroup, CoreMessages.dialog_connection_events_checkbox_show_process, false);
showProcessCheck.addSelectionListener(eventEditAdapter);
waitFinishCheck = UIUtils.createCheckbox(detailsGroup, CoreMessages.dialog_connection_events_checkbox_wait_finish, false);
waitFinishCheck.addSelectionListener(eventEditAdapter);
waitFinishTimeoutMs = createWaitFinishTimeout(detailsGroup);
waitFinishTimeoutMs.addSelectionListener(eventEditAdapter);
terminateCheck = UIUtils.createCheckbox(detailsGroup, CoreMessages.dialog_connection_events_checkbox_terminate_at_disconnect, false);
terminateCheck.addSelectionListener(eventEditAdapter);
{
Composite pauseComposite = UIUtils.createPlaceholder(detailsGroup, 2, 5);
pauseComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
pauseAfterExecute = UIUtils.createLabelSpinner(pauseComposite, CoreMessages.dialog_connection_edit_wizard_shell_cmd_pause_label, CoreMessages.dialog_connection_edit_wizard_shell_cmd_pause_tooltip, 0, 0, Integer.MAX_VALUE);
pauseAfterExecute.addSelectionListener(eventEditAdapter);
UIUtils.createControlLabel(pauseComposite, CoreMessages.dialog_connection_edit_wizard_shell_cmd_directory_label);
workingDirectory = new TextWithOpenFolder(pauseComposite, CoreMessagesdialog_connection_edit_wizard_shell_cmd_directory_title);
workingDirectory.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
workingDirectory.getTextControl().addModifyListener(e -> {
DBRShellCommand command = getActiveCommand();
if (command != null) {
command.setWorkingDirectory(workingDirectory.getText());
}
});
}
VariablesHintLabel variablesHintLabel = new VariablesHintLabel(detailsGroup, CoreMessages.dialog_connection_edit_wizard_shell_cmd_variables_hint_label, CoreMessages.dialog_connection_edit_wizard_shell_cmd_variables_hint_title, DataSourceDescriptor.CONNECT_VARIABLES);
variablesHintLabel.setResolver(new DataSourceVariableResolver(dataSource, dataSource.getConnectionConfiguration()));
}
selectEventType(null);
setControl(group);
}
use of org.jkiss.dbeaver.model.connection.DataSourceVariableResolver 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