Search in sources :

Example 1 with DataSourceVariableResolver

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;
}
Also used : ControlAdapter(org.eclipse.swt.events.ControlAdapter) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) CustomTableEditor(org.jkiss.dbeaver.ui.controls.CustomTableEditor) VariablesHintLabel(org.jkiss.dbeaver.ui.controls.VariablesHintLabel) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ControlEvent(org.eclipse.swt.events.ControlEvent) DataSourceVariableResolver(org.jkiss.dbeaver.model.connection.DataSourceVariableResolver)

Example 2 with DataSourceVariableResolver

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()));
    }
}
Also used : DBPConnectionConfiguration(org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration) SSHTunnelImpl(org.jkiss.dbeaver.model.net.ssh.SSHTunnelImpl) DBWHandlerConfiguration(org.jkiss.dbeaver.model.net.DBWHandlerConfiguration) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) DataSourceVariableResolver(org.jkiss.dbeaver.model.connection.DataSourceVariableResolver) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with DataSourceVariableResolver

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);
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) CommonUtils(org.jkiss.utils.CommonUtils) DataSourceVariableResolver(org.jkiss.dbeaver.model.connection.DataSourceVariableResolver) org.eclipse.swt.widgets(org.eclipse.swt.widgets) HashMap(java.util.HashMap) ArrayUtils(org.jkiss.utils.ArrayUtils) CoreMessages(org.jkiss.dbeaver.core.CoreMessages) DBPConnectionEventType(org.jkiss.dbeaver.model.connection.DBPConnectionEventType) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) DBeaverIcons(org.jkiss.dbeaver.ui.DBeaverIcons) UIUtils(org.jkiss.dbeaver.ui.UIUtils) SWT(org.eclipse.swt.SWT) Map(java.util.Map) VariablesHintLabel(org.jkiss.dbeaver.ui.controls.VariablesHintLabel) UIIcon(org.jkiss.dbeaver.ui.UIIcon) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridData(org.eclipse.swt.layout.GridData) DataSourceDescriptor(org.jkiss.dbeaver.registry.DataSourceDescriptor) TextWithOpenFolder(org.jkiss.dbeaver.ui.controls.TextWithOpenFolder) GridLayout(org.eclipse.swt.layout.GridLayout) DBRShellCommand(org.jkiss.dbeaver.model.runtime.DBRShellCommand) DBPConnectionEventType(org.jkiss.dbeaver.model.connection.DBPConnectionEventType) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DBRShellCommand(org.jkiss.dbeaver.model.runtime.DBRShellCommand) VariablesHintLabel(org.jkiss.dbeaver.ui.controls.VariablesHintLabel) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DataSourceVariableResolver(org.jkiss.dbeaver.model.connection.DataSourceVariableResolver) TextWithOpenFolder(org.jkiss.dbeaver.ui.controls.TextWithOpenFolder)

Example 4 with DataSourceVariableResolver

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);
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) CommonUtils(org.jkiss.utils.CommonUtils) DataSourceVariableResolver(org.jkiss.dbeaver.model.connection.DataSourceVariableResolver) org.eclipse.swt.widgets(org.eclipse.swt.widgets) HashMap(java.util.HashMap) ArrayUtils(org.jkiss.utils.ArrayUtils) CoreMessages(org.jkiss.dbeaver.core.CoreMessages) DBPConnectionEventType(org.jkiss.dbeaver.model.connection.DBPConnectionEventType) DBPDataSourceContainer(org.jkiss.dbeaver.model.DBPDataSourceContainer) DBeaverIcons(org.jkiss.dbeaver.ui.DBeaverIcons) UIUtils(org.jkiss.dbeaver.ui.UIUtils) SWT(org.eclipse.swt.SWT) Map(java.util.Map) VariablesHintLabel(org.jkiss.dbeaver.ui.controls.VariablesHintLabel) UIIcon(org.jkiss.dbeaver.ui.UIIcon) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridData(org.eclipse.swt.layout.GridData) DataSourceDescriptor(org.jkiss.dbeaver.registry.DataSourceDescriptor) TextWithOpenFolder(org.jkiss.dbeaver.ui.controls.TextWithOpenFolder) GridLayout(org.eclipse.swt.layout.GridLayout) DBRShellCommand(org.jkiss.dbeaver.model.runtime.DBRShellCommand) DBPConnectionEventType(org.jkiss.dbeaver.model.connection.DBPConnectionEventType) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DBRShellCommand(org.jkiss.dbeaver.model.runtime.DBRShellCommand) VariablesHintLabel(org.jkiss.dbeaver.ui.controls.VariablesHintLabel) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DataSourceVariableResolver(org.jkiss.dbeaver.model.connection.DataSourceVariableResolver) TextWithOpenFolder(org.jkiss.dbeaver.ui.controls.TextWithOpenFolder)

Example 5 with DataSourceVariableResolver

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;
}
Also used : ControlAdapter(org.eclipse.swt.events.ControlAdapter) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) CustomTableEditor(org.jkiss.dbeaver.ui.controls.CustomTableEditor) VariablesHintLabel(org.jkiss.dbeaver.ui.controls.VariablesHintLabel) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ControlEvent(org.eclipse.swt.events.ControlEvent) DataSourceVariableResolver(org.jkiss.dbeaver.model.connection.DataSourceVariableResolver)

Aggregations

DataSourceVariableResolver (org.jkiss.dbeaver.model.connection.DataSourceVariableResolver)10 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)6 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)4 SelectionEvent (org.eclipse.swt.events.SelectionEvent)4 GridData (org.eclipse.swt.layout.GridData)4 DBWHandlerConfiguration (org.jkiss.dbeaver.model.net.DBWHandlerConfiguration)4 DataSourceDescriptor (org.jkiss.dbeaver.registry.DataSourceDescriptor)4 VariablesHintLabel (org.jkiss.dbeaver.ui.controls.VariablesHintLabel)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 SWT (org.eclipse.swt.SWT)2 ControlAdapter (org.eclipse.swt.events.ControlAdapter)2 ControlEvent (org.eclipse.swt.events.ControlEvent)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 org.eclipse.swt.widgets (org.eclipse.swt.widgets)2 CoreMessages (org.jkiss.dbeaver.core.CoreMessages)2 DBPConnectionConfiguration (org.jkiss.dbeaver.model.connection.DBPConnectionConfiguration)2 DBPConnectionEventType (org.jkiss.dbeaver.model.connection.DBPConnectionEventType)2 DBPDriver (org.jkiss.dbeaver.model.connection.DBPDriver)2