Search in sources :

Example 76 with ControlEvent

use of org.eclipse.swt.events.ControlEvent 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 77 with ControlEvent

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

the class StringEditorTable method createEditableList.

public static Table createEditableList(@NotNull Composite parent, @NotNull String name, @Nullable List<String> values, @Nullable DBPImage icon, @Nullable IContentProposalProvider proposalProvider) {
    Group group = UIUtils.createControlGroup(parent, 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, UIMessages.properties_value);
    valueTable.addControlListener(new ControlAdapter() {

        @Override
        public void controlResized(ControlEvent e) {
            valueColumn.setWidth(valueTable.getClientArea().width);
        }
    });
    fillFilterValues(valueTable, values, icon);
    final CustomTableEditor tableEditor = new CustomTableEditor(valueTable) {

        {
            firstTraverseIndex = 0;
            lastTraverseIndex = 0;
        // editOnEnter = false;
        }

        @Override
        protected Control createEditor(Table table, int index, TableItem item) {
            Text editor = new Text(table, SWT.BORDER);
            editor.setText(item.getText());
            editor.addModifyListener(e -> {
                // Save value immediately. This solves MacOS problems with focus events.
                saveEditorValue(editor, index, item);
            });
            if (proposalProvider != null) {
                setProposalAdapter(ContentAssistUtils.installContentProposal(editor, new SmartTextContentAdapter(), proposalProvider));
            }
            return editor;
        }

        @Override
        protected void saveEditorValue(Control control, int index, TableItem item) {
            item.setText(((Text) control).getText().trim());
        }
    };
    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));
    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 = 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(UIMessages.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);
        }
    });
    addButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            TableItem newItem = new TableItem(valueTable, SWT.LEFT);
            if (icon != null) {
                newItem.setImage(DBeaverIcons.getImage(icon));
            }
            valueTable.setSelection(newItem);
            tableEditor.closeEditor();
            tableEditor.showEditor(newItem);
            removeButton.setEnabled(true);
        }
    });
    valueTable.addSelectionListener(new SelectionAdapter() {

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

Example 78 with ControlEvent

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

the class SpreadsheetPresentation method createPresentation.

@Override
public void createPresentation(@NotNull IResultSetController controller, @NotNull Composite parent) {
    super.createPresentation(controller, parent);
    this.italicFont = UIUtils.modifyFont(parent.getFont(), SWT.ITALIC);
    this.spreadsheet = new Spreadsheet(parent, SWT.MULTI | SWT.VIRTUAL | SWT.H_SCROLL | SWT.V_SCROLL, controller.getSite(), this, new ContentProvider(), new GridLabelProvider(), this);
    this.spreadsheet.setLayoutData(new GridData(GridData.FILL_BOTH));
    this.spreadsheet.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (e.detail != SWT.DRAG && e.detail != SWT.DROP_DOWN) {
                updateGridCursor((GridCell) e.data);
            }
            fireSelectionChanged(new SpreadsheetSelectionImpl());
        }
    });
    this.spreadsheet.addMouseWheelListener(e -> {
    });
    spreadsheet.addControlListener(new ControlAdapter() {

        @Override
        public void controlResized(ControlEvent e) {
            spreadsheet.cancelInlineEditor();
        }
    });
    activateTextKeyBindings(controller, spreadsheet);
    applyCurrentThemeSettings();
    trackPresentationControl();
    TextEditorUtils.enableHostEditorKeyBindingsSupport(controller.getSite(), spreadsheet);
}
Also used : ControlAdapter(org.eclipse.swt.events.ControlAdapter) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ControlEvent(org.eclipse.swt.events.ControlEvent)

Example 79 with ControlEvent

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

the class PostgreCreateExtensionDialog method createDialogArea.

@Override
protected Composite createDialogArea(Composite parent) {
    final Composite composite = super.createDialogArea(parent);
    final Composite group = new Composite(composite, SWT.NONE);
    group.setLayout(new GridLayout(2, false));
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.widthHint = 600;
    gd.heightHint = 200;
    gd.verticalIndent = 0;
    gd.horizontalIndent = 0;
    group.setLayoutData(gd);
    // $NON-NLS-2$
    final Text databaseText = UIUtils.createLabelText(group, PostgreMessages.dialog_create_extension_database, newextension.getDatabase().getName(), SWT.BORDER | SWT.READ_ONLY);
    final Combo schemaCombo = UIUtils.createLabelCombo(group, PostgreMessages.dialog_create_extension_schema, SWT.BORDER | SWT.DROP_DOWN | SWT.READ_ONLY);
    final Label lblExtension = UIUtils.createLabel(group, PostgreMessages.dialog_create_extension_name);
    extTable = new TableViewer(group, SWT.BORDER | SWT.UNDERLINE_SINGLE | SWT.V_SCROLL | SWT.H_SCROLL | SWT.FULL_SELECTION);
    {
        final Table table = extTable.getTable();
        table.setLayoutData(new GridData(GridData.FILL_BOTH));
        table.setLinesVisible(true);
        table.setHeaderVisible(true);
        table.addControlListener(new ControlAdapter() {

            @Override
            public void controlResized(ControlEvent e) {
                UIUtils.packColumns(table);
                UIUtils.maxTableColumnsWidth(table);
                table.removeControlListener(this);
            }
        });
    }
    ViewerColumnController columnController = new ViewerColumnController("AvailabelExtensionDialog", extTable);
    columnController.addColumn(PostgreMessages.dialog_create_extension_column_name, null, SWT.NONE, true, true, new CellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            cell.setText(((PostgreAvailableExtension) cell.getElement()).getName());
        }
    });
    columnController.addColumn(PostgreMessages.dialog_create_extension_column_version, null, SWT.NONE, true, true, new CellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            cell.setText(((PostgreAvailableExtension) cell.getElement()).getVersion());
        }
    });
    columnController.addColumn(PostgreMessages.dialog_create_extension_column_description, null, SWT.NONE, true, true, new CellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            cell.setText(((PostgreAvailableExtension) cell.getElement()).getDescription());
        }
    });
    columnController.createColumns();
    extTable.addSelectionChangedListener(event -> {
        IStructuredSelection selection = (IStructuredSelection) event.getSelection();
        if (!selection.isEmpty()) {
            // installed.get(extensionCombo.getSelectionIndex());
            extension = (PostgreAvailableExtension) selection.getFirstElement();
            checkEnabled();
        }
    });
    extTable.setContentProvider(new ListContentProvider());
    schemaCombo.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            schema = allSchemas.get(schemaCombo.getSelectionIndex());
            checkEnabled();
        }
    });
    new AbstractJob("Load schemas") {

        @Override
        protected IStatus run(DBRProgressMonitor monitor) {
            try {
                allSchemas = new ArrayList<>(newextension.getDatabase().getSchemas(monitor));
                UIUtils.syncExec(() -> {
                    for (PostgreSchema schema : allSchemas) {
                        schemaCombo.add(schema.getName());
                    }
                    schema = DBUtils.findObject(allSchemas, PostgreConstants.PUBLIC_SCHEMA_NAME);
                    if (schema != null) {
                        schemaCombo.setText(schema.getName());
                    }
                });
            } catch (DBException e) {
                return GeneralUtils.makeExceptionStatus(e);
            }
            return Status.OK_STATUS;
        }
    }.schedule();
    new AbstractJob("Load available extensions") {

        @Override
        protected IStatus run(DBRProgressMonitor monitor) {
            try {
                final List<PostgreAvailableExtension> installed = new ArrayList<>(newextension.getDatabase().getAvailableExtensions(monitor));
                UIUtils.syncExec(() -> {
                    extTable.setInput(installed);
                });
            } catch (DBException e) {
                return GeneralUtils.makeExceptionStatus(e);
            }
            return Status.OK_STATUS;
        }
    }.schedule();
    return composite;
}
Also used : PostgreAvailableExtension(org.jkiss.dbeaver.ext.postgresql.model.PostgreAvailableExtension) ViewerColumnController(org.jkiss.dbeaver.ui.controls.ViewerColumnController) DBException(org.jkiss.dbeaver.DBException) IStatus(org.eclipse.core.runtime.IStatus) ControlAdapter(org.eclipse.swt.events.ControlAdapter) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) ListContentProvider(org.jkiss.dbeaver.ui.controls.ListContentProvider) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ArrayList(java.util.ArrayList) List(java.util.List) CellLabelProvider(org.eclipse.jface.viewers.CellLabelProvider) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ViewerCell(org.eclipse.jface.viewers.ViewerCell) AbstractJob(org.jkiss.dbeaver.model.runtime.AbstractJob) GridData(org.eclipse.swt.layout.GridData) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor) ControlEvent(org.eclipse.swt.events.ControlEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) PostgreSchema(org.jkiss.dbeaver.ext.postgresql.model.PostgreSchema)

Example 80 with ControlEvent

use of org.eclipse.swt.events.ControlEvent in project dbeaver by dbeaver.

the class SpreadsheetPresentation method createPresentation.

@Override
public void createPresentation(@NotNull IResultSetController controller, @NotNull Composite parent) {
    super.createPresentation(controller, parent);
    this.italicFont = UIUtils.modifyFont(parent.getFont(), SWT.ITALIC);
    this.spreadsheet = new Spreadsheet(parent, SWT.MULTI | SWT.VIRTUAL | SWT.H_SCROLL | SWT.V_SCROLL, controller.getSite(), this, new ContentProvider(), new GridLabelProvider(), this);
    this.spreadsheet.setLayoutData(new GridData(GridData.FILL_BOTH));
    this.spreadsheet.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (e.detail != SWT.DRAG && e.detail != SWT.DROP_DOWN) {
                updateGridCursor((GridCell) e.data);
            }
            fireSelectionChanged(new SpreadsheetSelectionImpl());
        }
    });
    this.spreadsheet.addMouseWheelListener(e -> {
    });
    spreadsheet.addControlListener(new ControlAdapter() {

        @Override
        public void controlResized(ControlEvent e) {
            spreadsheet.cancelInlineEditor();
        }
    });
    activateTextKeyBindings(controller, spreadsheet);
    applyCurrentThemeSettings();
    trackPresentationControl();
    TextEditorUtils.enableHostEditorKeyBindingsSupport(controller.getSite(), spreadsheet);
}
Also used : ControlAdapter(org.eclipse.swt.events.ControlAdapter) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ControlEvent(org.eclipse.swt.events.ControlEvent)

Aggregations

ControlEvent (org.eclipse.swt.events.ControlEvent)187 ControlAdapter (org.eclipse.swt.events.ControlAdapter)135 Composite (org.eclipse.swt.widgets.Composite)76 GridData (org.eclipse.swt.layout.GridData)67 ControlListener (org.eclipse.swt.events.ControlListener)54 GridLayout (org.eclipse.swt.layout.GridLayout)50 SelectionEvent (org.eclipse.swt.events.SelectionEvent)49 TableColumn (org.eclipse.swt.widgets.TableColumn)42 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)41 Point (org.eclipse.swt.graphics.Point)38 Table (org.eclipse.swt.widgets.Table)37 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)36 FillLayout (org.eclipse.swt.layout.FillLayout)35 Tree (org.eclipse.swt.widgets.Tree)35 TreeViewer (org.eclipse.jface.viewers.TreeViewer)33 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)32 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)31 AdapterFactoryTreeEditor (org.eclipse.emf.edit.ui.celleditor.AdapterFactoryTreeEditor)30 AdapterFactoryContentProvider (org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider)30 AdapterFactoryLabelProvider (org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider)30