Search in sources :

Example 11 with SelectionAdapter

use of org.eclipse.swt.events.SelectionAdapter in project dbeaver by serge-rider.

the class TextViewDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite dialogGroup = (Composite) super.createDialogArea(parent);
    ReferenceValueEditor referenceValueEditor = new ReferenceValueEditor(getValueController(), this);
    boolean isForeignKey = referenceValueEditor.isReferenceValue();
    Label label = new Label(dialogGroup, SWT.NONE);
    label.setText(CoreMessages.dialog_data_label_value);
    boolean readOnly = getValueController().isReadOnly();
    boolean useHex = !isForeignKey;
    final DBSTypedObject valueType = getValueController().getValueType();
    long maxSize = valueType.getMaxLength();
    if (useHex) {
        editorContainer = new CTabFolder(dialogGroup, SWT.FLAT | SWT.TOP);
        editorContainer.setLayoutData(new GridData(GridData.FILL_BOTH));
        lengthLabel = new Label(editorContainer, SWT.RIGHT);
        lengthLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        editorContainer.setTopRight(lengthLabel, SWT.FILL);
    }
    int selectedType = 0;
    if (getDialogSettings().get(VALUE_TYPE_SELECTOR) != null) {
        selectedType = getDialogSettings().getInt(VALUE_TYPE_SELECTOR);
    }
    {
        int style = SWT.NONE;
        if (readOnly) {
            style |= SWT.READ_ONLY;
        }
        if (useHex) {
            style |= SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.WRAP;
        } else {
            // Use border only for plain text editor, otherwise tab folder's border will be used
            style |= SWT.BORDER;
        }
        textEdit = new StyledText(useHex ? editorContainer : dialogGroup, style);
        textEdit.setMargins(3, 3, 3, 3);
        if (maxSize > 0 && valueType.getDataKind() == DBPDataKind.STRING) {
            textEdit.setTextLimit((int) maxSize);
        }
        if (readOnly) {
        //textEdit.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
        }
        GridData gd = new GridData(isForeignKey ? GridData.FILL_HORIZONTAL : GridData.FILL_BOTH);
        gd.widthHint = 300;
        if (!isForeignKey) {
            gd.heightHint = 200;
            gd.grabExcessVerticalSpace = true;
        }
        textEdit.setLayoutData(gd);
        textEdit.setFocus();
        textEdit.setEditable(!readOnly);
        textEdit.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(ModifyEvent e) {
                dirty = true;
                updateValueLength();
            }
        });
        UIUtils.fillDefaultStyledTextContextMenu(textEdit);
        if (useHex) {
            CTabItem item = new CTabItem(editorContainer, SWT.NO_FOCUS);
            item.setText("Text");
            item.setImage(DBeaverIcons.getImage(DBIcon.TYPE_TEXT));
            item.setControl(textEdit);
        }
    }
    Point minSize = null;
    if (useHex) {
        hexEditControl = new HexEditControl(editorContainer, readOnly ? SWT.READ_ONLY : SWT.NONE, 6, 8);
        GridData gd = new GridData(GridData.FILL_BOTH);
        gd.heightHint = 200;
        gd.minimumWidth = hexEditControl.computeSize(SWT.DEFAULT, SWT.DEFAULT).x;
        hexEditControl.setLayoutData(gd);
        minSize = hexEditControl.computeSize(SWT.DEFAULT, SWT.DEFAULT);
        minSize.x += 50;
        minSize.y += 50;
        CTabItem item = new CTabItem(editorContainer, SWT.NO_FOCUS);
        item.setText("Hex");
        item.setImage(DBeaverIcons.getImage(DBIcon.TYPE_BINARY));
        item.setControl(hexEditControl);
        if (selectedType >= editorContainer.getItemCount()) {
            selectedType = 0;
        }
        editorContainer.setSelection(selectedType);
        editorContainer.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent event) {
                getDialogSettings().put(VALUE_TYPE_SELECTOR, editorContainer.getSelectionIndex());
            }
        });
        hexEditControl.addListener(SWT.Modify, new Listener() {

            @Override
            public void handleEvent(Event event) {
                dirty = true;
            }
        });
        updateValueLength();
    }
    primeEditorValue(getValueController().getValue());
    if (isForeignKey) {
        referenceValueEditor.createEditorSelector(dialogGroup);
    }
    if (minSize != null) {
        // Set default size as minimum
        getShell().setMinimumSize(minSize);
    }
    return dialogGroup;
}
Also used : CTabFolder(org.eclipse.swt.custom.CTabFolder) StyledText(org.eclipse.swt.custom.StyledText) ModifyListener(org.eclipse.swt.events.ModifyListener) ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Point(org.eclipse.swt.graphics.Point) ReferenceValueEditor(org.jkiss.dbeaver.ui.data.editors.ReferenceValueEditor) CTabItem(org.eclipse.swt.custom.CTabItem) Point(org.eclipse.swt.graphics.Point) HexEditControl(org.jkiss.dbeaver.ui.editors.binary.HexEditControl) DBSTypedObject(org.jkiss.dbeaver.model.struct.DBSTypedObject) ModifyEvent(org.eclipse.swt.events.ModifyEvent) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 12 with SelectionAdapter

use of org.eclipse.swt.events.SelectionAdapter in project dbeaver by serge-rider.

the class EditBootstrapQueriesDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    getShell().setText("Bootstrap SQL queries");
    Composite composite = (Composite) super.createDialogArea(parent);
    Group group = UIUtils.createControlGroup(composite, "SQL Queries", 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(CoreMessages.dialog_filter_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(), "Enter SQL", "");
            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(CoreMessages.dialog_filter_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);
        }
    });
    ignoreErrorButton = UIUtils.createCheckbox(composite, "Ignore SQL errors", ignoreErrors);
    UIUtils.packColumns(queriesTable, true);
    return composite;
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) CustomTableEditor(org.jkiss.dbeaver.ui.controls.CustomTableEditor) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 13 with SelectionAdapter

use of org.eclipse.swt.events.SelectionAdapter in project dbeaver by serge-rider.

the class EditObjectFilterDialog method createEditableList.

private Table createEditableList(String name, List<String> values) {
    Group group = UIUtils.createControlGroup(blockControl, name, 2, GridData.FILL_BOTH, 0);
    final Table valueTable = 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;
    valueTable.setLayoutData(gd);
    // valueTable.setHeaderVisible(true);
    valueTable.setLinesVisible(true);
    final TableColumn valueColumn = UIUtils.createTableColumn(valueTable, SWT.LEFT, CoreMessages.dialog_filter_table_column_value);
    valueColumn.setWidth(300);
    if (!CommonUtils.isEmpty(values)) {
        for (String value : values) {
            new TableItem(valueTable, SWT.LEFT).setText(value);
        }
    }
    final CustomTableEditor tableEditor = new CustomTableEditor(valueTable) {

        @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(CoreMessages.dialog_filter_button_add);
    addButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    addButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            TableItem newItem = new TableItem(valueTable, SWT.LEFT);
            valueTable.setSelection(newItem);
            tableEditor.closeEditor();
            tableEditor.showEditor(newItem);
        }
    });
    final Button removeButton = new Button(buttonsGroup, SWT.PUSH);
    removeButton.setText(CoreMessages.dialog_filter_button_remove);
    removeButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    removeButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            int selectionIndex = valueTable.getSelectionIndex();
            if (selectionIndex >= 0) {
                tableEditor.closeEditor();
                valueTable.remove(selectionIndex);
                removeButton.setEnabled(valueTable.getSelectionIndex() >= 0);
            }
        }
    });
    removeButton.setEnabled(false);
    final Button clearButton = new Button(buttonsGroup, SWT.PUSH);
    clearButton.setText(CoreMessages.dialog_filter_button_clear);
    clearButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    clearButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            tableEditor.closeEditor();
            valueTable.removeAll();
            removeButton.setEnabled(false);
        }
    });
    valueTable.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            int selectionIndex = valueTable.getSelectionIndex();
            removeButton.setEnabled(selectionIndex >= 0);
        }
    });
    return valueTable;
}
Also used : SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) CustomTableEditor(org.jkiss.dbeaver.ui.controls.CustomTableEditor) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 14 with SelectionAdapter

use of org.eclipse.swt.events.SelectionAdapter 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);
}
Also used : DBPConnectionEventType(org.jkiss.dbeaver.model.connection.DBPConnectionEventType) ModifyListener(org.eclipse.swt.events.ModifyListener) ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DBRShellCommand(org.jkiss.dbeaver.model.runtime.DBRShellCommand) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 15 with SelectionAdapter

use of org.eclipse.swt.events.SelectionAdapter in project dbeaver by serge-rider.

the class ConnectionPageAbstract method createDriverPanel.

protected void createDriverPanel(Composite parent) {
    int numColumns = ((GridLayout) parent.getLayout()).numColumns;
    Composite panel = UIUtils.createPlaceholder(parent, 4, 5);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.horizontalSpan = numColumns;
    panel.setLayoutData(gd);
    Composite placeholder = UIUtils.createPlaceholder(panel, 1);
    gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_END);
    gd.horizontalSpan = 4;
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    placeholder.setLayoutData(gd);
    if (!site.isNew() && !site.getDriver().isEmbedded()) {
        Link netConfigLink = new Link(panel, SWT.NONE);
        netConfigLink.setText("<a>Network settings (SSH, SSL, Proxy, ...)</a>");
        netConfigLink.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                site.openSettingsPage(ConnectionPageNetwork.PAGE_NAME);
            }
        });
        gd = new GridData(GridData.HORIZONTAL_ALIGN_END);
        gd.horizontalSpan = 4;
        netConfigLink.setLayoutData(gd);
    }
    Label divLabel = new Label(panel, SWT.SEPARATOR | SWT.HORIZONTAL);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 4;
    divLabel.setLayoutData(gd);
    Label driverLabel = new Label(panel, SWT.NONE);
    driverLabel.setText(CoreMessages.dialog_connection_driver);
    gd = new GridData(GridData.HORIZONTAL_ALIGN_END);
    driverLabel.setLayoutData(gd);
    driverText = new Text(panel, SWT.READ_ONLY);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalSpan = 2;
    //gd.widthHint = 200;
    driverText.setLayoutData(gd);
    Button driverButton = new Button(panel, SWT.PUSH);
    driverButton.setText(CoreMessages.dialog_connection_edit_driver_button);
    gd = new GridData(GridData.HORIZONTAL_ALIGN_END);
    driverButton.setLayoutData(gd);
    driverButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (site.openDriverEditor()) {
                updateDriverInfo(site.getDriver());
            }
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        }
    });
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)833 SelectionEvent (org.eclipse.swt.events.SelectionEvent)832 GridData (org.eclipse.swt.layout.GridData)511 GridLayout (org.eclipse.swt.layout.GridLayout)429 Composite (org.eclipse.swt.widgets.Composite)421 Button (org.eclipse.swt.widgets.Button)405 Label (org.eclipse.swt.widgets.Label)266 Text (org.eclipse.swt.widgets.Text)196 Group (org.eclipse.swt.widgets.Group)138 ModifyEvent (org.eclipse.swt.events.ModifyEvent)123 ModifyListener (org.eclipse.swt.events.ModifyListener)123 Combo (org.eclipse.swt.widgets.Combo)98 ToolItem (org.eclipse.swt.widgets.ToolItem)79 TableViewer (org.eclipse.jface.viewers.TableViewer)78 MenuItem (org.eclipse.swt.widgets.MenuItem)77 Menu (org.eclipse.swt.widgets.Menu)76 ToolBar (org.eclipse.swt.widgets.ToolBar)68 Table (org.eclipse.swt.widgets.Table)67 ArrayList (java.util.ArrayList)63 Point (org.eclipse.swt.graphics.Point)63