use of org.jkiss.dbeaver.model.connection.DBPConnectionEventType in project dbeaver by serge-rider.
the class EditShellCommandsDialogPage method updateEvent.
private void updateEvent(boolean commandChange) {
DBPConnectionEventType eventType = getSelectedEventType();
if (eventType != null) {
DBRShellCommand command = eventsCache.get(eventType);
if (command == null) {
//$NON-NLS-1$
command = new DBRShellCommand("");
eventsCache.put(eventType, command);
}
boolean prevEnabled = command.isEnabled();
if (commandChange) {
command.setCommand(commandText.getText());
} else {
TableItem item = getEventItem(eventType);
if (item != null) {
command.setEnabled(item.getChecked());
}
command.setShowProcessPanel(showProcessCheck.getSelection());
command.setWaitProcessFinish(waitFinishCheck.getSelection());
command.setTerminateAtDisconnect(terminateCheck.getSelection());
if (prevEnabled != command.isEnabled()) {
selectEventType(eventType);
}
}
} else if (!commandChange) {
selectEventType(null);
}
}
use of org.jkiss.dbeaver.model.connection.DBPConnectionEventType in project dbeaver by serge-rider.
the class EditShellCommandsDialogPage method createControl.
@Override
public void createControl(Composite parent) {
Composite group = UIUtils.createPlaceholder(parent, 2);
group.setLayoutData(new GridData(GridData.FILL_BOTH));
{
Composite eventGroup = new Composite(group, SWT.NONE);
eventGroup.setLayout(new GridLayout(1, false));
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, new Listener() {
public void handleEvent(Event 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 = new Composite(group, SWT.NONE);
detailsGroup.setLayout(new GridLayout(1, false));
detailsGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
//UIUtils.createControlGroup(group, "Event", 1, GridData.FILL_BOTH | GridData.HORIZONTAL_ALIGN_BEGINNING, 0);
UIUtils.createControlLabel(detailsGroup, CoreMessages.dialog_connection_events_label_command);
commandText = new Text(detailsGroup, SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
commandText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent 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);
terminateCheck = UIUtils.createCheckbox(detailsGroup, CoreMessages.dialog_connection_events_checkbox_terminate_at_disconnect, false);
terminateCheck.addSelectionListener(eventEditAdapter);
Group helpGroup = new Group(detailsGroup, SWT.NONE);
helpGroup.setText("Command parameters");
helpGroup.setLayout(new GridLayout(2, false));
helpGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
Label infoLabel = new Label(helpGroup, SWT.NONE);
infoLabel.setText("You may use following variables:");
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 2;
infoLabel.setLayoutData(gd);
addVariableLegend(helpGroup, RegistryConstants.VARIABLE_HOST, "target host");
addVariableLegend(helpGroup, RegistryConstants.VARIABLE_PORT, "target port");
addVariableLegend(helpGroup, RegistryConstants.VARIABLE_SERVER, "target server name");
addVariableLegend(helpGroup, RegistryConstants.VARIABLE_DATABASE, "target database");
addVariableLegend(helpGroup, RegistryConstants.VARIABLE_USER, "user name");
addVariableLegend(helpGroup, RegistryConstants.VARIABLE_PASSWORD, "password (plain)");
addVariableLegend(helpGroup, RegistryConstants.VARIABLE_URL, "JDBC URL");
}
selectEventType(null);
setControl(group);
}
use of org.jkiss.dbeaver.model.connection.DBPConnectionEventType in project dbeaver by serge-rider.
the class DataSourceRegistry method saveDataSource.
private void saveDataSource(XMLBuilder xml, DataSourceDescriptor dataSource) throws IOException {
clearSecuredPasswords(dataSource);
xml.startElement(RegistryConstants.TAG_DATA_SOURCE);
xml.addAttribute(RegistryConstants.ATTR_ID, dataSource.getId());
xml.addAttribute(RegistryConstants.ATTR_PROVIDER, dataSource.getDriver().getProviderDescriptor().getId());
xml.addAttribute(RegistryConstants.ATTR_DRIVER, dataSource.getDriver().getId());
xml.addAttribute(RegistryConstants.ATTR_NAME, dataSource.getName());
xml.addAttribute(RegistryConstants.ATTR_SAVE_PASSWORD, dataSource.isSavePassword());
if (dataSource.isShowSystemObjects()) {
xml.addAttribute(RegistryConstants.ATTR_SHOW_SYSTEM_OBJECTS, dataSource.isShowSystemObjects());
}
if (dataSource.isShowUtilityObjects()) {
xml.addAttribute(RegistryConstants.ATTR_SHOW_UTIL_OBJECTS, dataSource.isShowUtilityObjects());
}
xml.addAttribute(RegistryConstants.ATTR_READ_ONLY, dataSource.isConnectionReadOnly());
if (dataSource.getFolder() != null) {
xml.addAttribute(RegistryConstants.ATTR_FOLDER, dataSource.getFolder().getFolderPath());
}
final String lockPasswordHash = dataSource.getLockPasswordHash();
if (!CommonUtils.isEmpty(lockPasswordHash)) {
xml.addAttribute(RegistryConstants.ATTR_LOCK_PASSWORD, lockPasswordHash);
}
{
// Connection info
DBPConnectionConfiguration connectionInfo = dataSource.getConnectionConfiguration();
xml.startElement(RegistryConstants.TAG_CONNECTION);
if (!CommonUtils.isEmpty(connectionInfo.getHostName())) {
xml.addAttribute(RegistryConstants.ATTR_HOST, connectionInfo.getHostName());
}
if (!CommonUtils.isEmpty(connectionInfo.getHostPort())) {
xml.addAttribute(RegistryConstants.ATTR_PORT, connectionInfo.getHostPort());
}
xml.addAttribute(RegistryConstants.ATTR_SERVER, CommonUtils.notEmpty(connectionInfo.getServerName()));
xml.addAttribute(RegistryConstants.ATTR_DATABASE, CommonUtils.notEmpty(connectionInfo.getDatabaseName()));
xml.addAttribute(RegistryConstants.ATTR_URL, CommonUtils.notEmpty(connectionInfo.getUrl()));
saveSecuredCredentials(xml, dataSource, null, connectionInfo.getUserName(), dataSource.isSavePassword() ? connectionInfo.getUserPassword() : null);
if (!CommonUtils.isEmpty(connectionInfo.getClientHomeId())) {
xml.addAttribute(RegistryConstants.ATTR_HOME, connectionInfo.getClientHomeId());
}
if (connectionInfo.getConnectionType() != null) {
xml.addAttribute(RegistryConstants.ATTR_TYPE, connectionInfo.getConnectionType().getId());
}
if (connectionInfo.getConnectionColor() != null) {
xml.addAttribute(RegistryConstants.ATTR_COLOR, connectionInfo.getConnectionColor());
}
// Save other
if (connectionInfo.getKeepAliveInterval() > 0) {
xml.addAttribute(RegistryConstants.ATTR_KEEP_ALIVE, connectionInfo.getKeepAliveInterval());
}
for (Map.Entry<String, String> entry : connectionInfo.getProperties().entrySet()) {
xml.startElement(RegistryConstants.TAG_PROPERTY);
xml.addAttribute(RegistryConstants.ATTR_NAME, CommonUtils.toString(entry.getKey()));
xml.addAttribute(RegistryConstants.ATTR_VALUE, CommonUtils.toString(entry.getValue()));
xml.endElement();
}
for (Map.Entry<String, String> entry : connectionInfo.getProviderProperties().entrySet()) {
xml.startElement(RegistryConstants.TAG_PROVIDER_PROPERTY);
xml.addAttribute(RegistryConstants.ATTR_NAME, CommonUtils.toString(entry.getKey()));
xml.addAttribute(RegistryConstants.ATTR_VALUE, CommonUtils.toString(entry.getValue()));
xml.endElement();
}
// Save events
for (DBPConnectionEventType eventType : connectionInfo.getDeclaredEvents()) {
DBRShellCommand command = connectionInfo.getEvent(eventType);
xml.startElement(RegistryConstants.TAG_EVENT);
xml.addAttribute(RegistryConstants.ATTR_TYPE, eventType.name());
xml.addAttribute(RegistryConstants.ATTR_ENABLED, command.isEnabled());
xml.addAttribute(RegistryConstants.ATTR_SHOW_PANEL, command.isShowProcessPanel());
xml.addAttribute(RegistryConstants.ATTR_WAIT_PROCESS, command.isWaitProcessFinish());
xml.addAttribute(RegistryConstants.ATTR_TERMINATE_AT_DISCONNECT, command.isTerminateAtDisconnect());
xml.addText(command.getCommand());
xml.endElement();
}
// Save network handlers' configurations
for (DBWHandlerConfiguration configuration : connectionInfo.getDeclaredHandlers()) {
xml.startElement(RegistryConstants.TAG_NETWORK_HANDLER);
xml.addAttribute(RegistryConstants.ATTR_TYPE, configuration.getType().name());
xml.addAttribute(RegistryConstants.ATTR_ID, CommonUtils.notEmpty(configuration.getId()));
xml.addAttribute(RegistryConstants.ATTR_ENABLED, configuration.isEnabled());
xml.addAttribute(RegistryConstants.ATTR_SAVE_PASSWORD, configuration.isSavePassword());
if (!CommonUtils.isEmpty(configuration.getUserName())) {
saveSecuredCredentials(xml, dataSource, "network/" + configuration.getId(), configuration.getUserName(), configuration.isSavePassword() ? configuration.getPassword() : null);
}
for (Map.Entry<String, String> entry : configuration.getProperties().entrySet()) {
if (CommonUtils.isEmpty(entry.getValue())) {
continue;
}
xml.startElement(RegistryConstants.TAG_PROPERTY);
xml.addAttribute(RegistryConstants.ATTR_NAME, entry.getKey());
xml.addAttribute(RegistryConstants.ATTR_VALUE, CommonUtils.notEmpty(entry.getValue()));
xml.endElement();
}
xml.endElement();
}
// Save bootstrap info
{
DBPConnectionBootstrap bootstrap = connectionInfo.getBootstrap();
if (bootstrap.hasData()) {
xml.startElement(RegistryConstants.TAG_BOOTSTRAP);
if (bootstrap.getDefaultAutoCommit() != null) {
xml.addAttribute(RegistryConstants.ATTR_AUTOCOMMIT, bootstrap.getDefaultAutoCommit());
}
if (bootstrap.getDefaultTransactionIsolation() != null) {
xml.addAttribute(RegistryConstants.ATTR_TXN_ISOLATION, bootstrap.getDefaultTransactionIsolation());
}
if (!CommonUtils.isEmpty(bootstrap.getDefaultObjectName())) {
xml.addAttribute(RegistryConstants.ATTR_DEFAULT_OBJECT, bootstrap.getDefaultObjectName());
}
if (bootstrap.isIgnoreErrors()) {
xml.addAttribute(RegistryConstants.ATTR_IGNORE_ERRORS, true);
}
for (String query : bootstrap.getInitQueries()) {
xml.startElement(RegistryConstants.TAG_QUERY);
xml.addText(query);
xml.endElement();
}
xml.endElement();
}
}
xml.endElement();
}
{
// Filters
Collection<DataSourceDescriptor.FilterMapping> filterMappings = dataSource.getObjectFilters();
if (!CommonUtils.isEmpty(filterMappings)) {
xml.startElement(RegistryConstants.TAG_FILTERS);
for (DataSourceDescriptor.FilterMapping filter : filterMappings) {
if (filter.defaultFilter != null && !filter.defaultFilter.isEmpty()) {
saveObjectFiler(xml, filter.typeName, null, filter.defaultFilter);
}
for (Map.Entry<String, DBSObjectFilter> cf : filter.customFilters.entrySet()) {
if (!cf.getValue().isEmpty()) {
saveObjectFiler(xml, filter.typeName, cf.getKey(), cf.getValue());
}
}
}
xml.endElement();
}
}
// Virtual model
if (dataSource.getVirtualModel().hasValuableData()) {
xml.startElement(RegistryConstants.TAG_VIRTUAL_META_DATA);
dataSource.getVirtualModel().serialize(xml);
xml.endElement();
}
// Preferences
{
// Save only properties who are differs from default values
SimplePreferenceStore prefStore = dataSource.getPreferenceStore();
for (String propName : prefStore.preferenceNames()) {
String propValue = prefStore.getString(propName);
String defValue = prefStore.getDefaultString(propName);
if (propValue == null || CommonUtils.equalObjects(propValue, defValue)) {
continue;
}
xml.startElement(RegistryConstants.TAG_CUSTOM_PROPERTY);
xml.addAttribute(RegistryConstants.ATTR_NAME, propName);
xml.addAttribute(RegistryConstants.ATTR_VALUE, propValue);
xml.endElement();
}
}
if (!CommonUtils.isEmpty(dataSource.getDescription())) {
xml.startElement(RegistryConstants.TAG_DESCRIPTION);
xml.addText(dataSource.getDescription());
xml.endElement();
}
xml.endElement();
}
use of org.jkiss.dbeaver.model.connection.DBPConnectionEventType in project dbeaver by dbeaver.
the class ConnectionPageGeneral method configureEvents.
private void configureEvents() {
DataSourceDescriptor dataSource = getActiveDataSource();
EditShellCommandsDialog dialog = new EditShellCommandsDialog(getShell(), dataSource);
if (dialog.open() == IDialogConstants.OK_ID) {
eventsButton.setFont(getFont());
for (DBPConnectionEventType eventType : dataSource.getConnectionConfiguration().getDeclaredEvents()) {
if (dataSource.getConnectionConfiguration().getEvent(eventType).isEnabled()) {
eventsButton.setFont(boldFont);
break;
}
}
}
}
use of org.jkiss.dbeaver.model.connection.DBPConnectionEventType in project dbeaver by dbeaver.
the class EditShellCommandsDialogPage method createControl.
@Override
public void createControl(Composite parent) {
Composite group = UIUtils.createPlaceholder(parent, 2);
group.setLayoutData(new GridData(GridData.FILL_BOTH));
{
Composite eventGroup = new Composite(group, SWT.NONE);
eventGroup.setLayout(new GridLayout(1, false));
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, new Listener() {
public void handleEvent(Event 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 = new Composite(group, SWT.NONE);
detailsGroup.setLayout(new GridLayout(1, false));
detailsGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
// UIUtils.createControlGroup(group, "Event", 1, GridData.FILL_BOTH | GridData.HORIZONTAL_ALIGN_BEGINNING, 0);
UIUtils.createControlLabel(detailsGroup, CoreMessages.dialog_connection_events_label_command);
commandText = new Text(detailsGroup, SWT.BORDER | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
commandText.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent 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(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
DBRShellCommand command = getActiveCommand();
if (command != null) {
command.setWorkingDirectory(workingDirectory.getText());
}
}
});
}
new VariablesHintLabel(detailsGroup, DataSourceDescriptor.CONNECT_VARIABLES);
}
selectEventType(null);
setControl(group);
}
Aggregations