Search in sources :

Example 26 with ViewerCell

use of org.eclipse.jface.viewers.ViewerCell 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 27 with ViewerCell

use of org.eclipse.jface.viewers.ViewerCell in project AutoRefactor by JnRouvignac.

the class ChooseRefactoringWizardPage method createRefactoringsTable.

private void createRefactoringsTable(Composite parent) {
    tableViewer = CheckboxTableViewer.newCheckList(parent, SWT.BORDER | SWT.H_SCROLL | SWT.CHECK | SWT.NO_FOCUS | SWT.HIDE_SELECTION);
    createColumns(tableViewer);
    tableViewer.setContentProvider(new ArrayContentProvider());
    final List<RefactoringRule> refactorings = AllCleanUpRules.getAllCleanUpRules();
    tableViewer.setInput(refactorings);
    tableViewer.setCheckStateProvider(new CheckStateProvider(refactorings));
    tableViewer.setComparator(new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object o1, Object o2) {
            return ((RefactoringRule) o1).getName().compareTo(((RefactoringRule) o2).getName());
        }
    });
    tableViewer.addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object refactoring) {
            final String filter = filterText.getText().toLowerCase();
            final RefactoringRule rule = (RefactoringRule) refactoring;
            final String description = rule.getDescription().toLowerCase();
            final String name = rule.getName().toLowerCase();
            return description.contains(filter) || name.contains(filter);
        }
    });
    ColumnViewerToolTipSupport.enableFor(tableViewer, ToolTip.NO_RECREATE);
    tableViewer.setLabelProvider(new StyledCellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            final String filter = filterText.getText().toLowerCase();
            final String name = ((RefactoringRule) cell.getElement()).getName();
            cell.setText(name);
            cell.setStyleRanges(getStyleRanges(name, filter));
        }

        private StyleRange[] getStyleRanges(String text, String filter) {
            final int matchIndex = text.toLowerCase().indexOf(filter);
            final int matchLength = filter.length();
            if (matchIndex != -1 && matchLength != 0) {
                final StyledString styledString = new StyledString(text, defaultStyler);
                styledString.setStyle(matchIndex, matchLength, underlineStyler);
                return styledString.getStyleRanges();
            }
            return null;
        }

        @Override
        public String getToolTipText(Object refactoring) {
            RefactoringRule refactoringRule = (RefactoringRule) refactoring;
            // $NON-NLS-1$
            return refactoringRule.getDescription() + "\n\nWhy to do so:\n" + refactoringRule.getReason();
        }

        @Override
        public Point getToolTipShift(Object object) {
            return new Point(10, 20);
        }
    });
    final Table table = tableViewer.getTable();
    table.setLinesVisible(false);
    table.addListener(SWT.EraseItem, event -> {
        if ((event.detail & SWT.SELECTED) != 0) {
            event.detail &= ~SWT.SELECTED;
        }
    });
    table.addListener(SWT.MouseDown, event -> {
        Point pt = new Point(event.x, event.y);
        TableItem item = table.getItem(pt);
        if (item == null) {
            return;
        }
        int index = table.indexOf(item);
        Object element = tableViewer.getElementAt(index);
        tableViewer.setChecked(element, !tableViewer.getChecked(element));
    });
    table.addListener(SWT.MouseDoubleClick, event -> {
        Point pt = new Point(event.x, event.y);
        TableItem item = table.getItem(pt);
        if (item == null) {
            return;
        }
        int index = table.indexOf(item);
        Object element = tableViewer.getElementAt(index);
        tableViewer.setCheckedElements(new Object[] { element });
        ChooseRefactoringWizardPage.this.getWizard().performFinish();
        ((WizardDialog) ChooseRefactoringWizardPage.this.getWizard().getContainer()).close();
    });
    tableViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true));
    packColumns(table);
    table.setFocus();
}
Also used : StyledCellLabelProvider(org.eclipse.jface.viewers.StyledCellLabelProvider) Table(org.eclipse.swt.widgets.Table) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) TableItem(org.eclipse.swt.widgets.TableItem) TableViewer(org.eclipse.jface.viewers.TableViewer) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) Viewer(org.eclipse.jface.viewers.Viewer) ICheckStateProvider(org.eclipse.jface.viewers.ICheckStateProvider) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) Point(org.eclipse.swt.graphics.Point) ViewerCell(org.eclipse.jface.viewers.ViewerCell) Point(org.eclipse.swt.graphics.Point) RefactoringRule(org.autorefactor.jdt.internal.corext.dom.RefactoringRule) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Example 28 with ViewerCell

use of org.eclipse.jface.viewers.ViewerCell in project translationstudio8 by heartsome.

the class GridTableViewer method editElement.

/**
	 * {@inheritDoc}
	 */
public void editElement(Object element, int column) {
    try {
        getControl().setRedraw(false);
        Widget item = findItem(element);
        if (item != null) {
            ViewerRow row = getViewerRowFromItem(item);
            if (row != null) {
                ViewerCell cell = row.getCell(column);
                if (cell != null) {
                    triggerEditorActivationEvent(new ColumnViewerEditorActivationEvent(cell));
                }
            }
        }
    } finally {
        getControl().setRedraw(true);
    }
// }
}
Also used : Widget(org.eclipse.swt.widgets.Widget) ViewerRow(org.eclipse.jface.viewers.ViewerRow) ColumnViewerEditorActivationEvent(org.eclipse.jface.viewers.ColumnViewerEditorActivationEvent) ViewerCell(org.eclipse.jface.viewers.ViewerCell)

Example 29 with ViewerCell

use of org.eclipse.jface.viewers.ViewerCell in project translationstudio8 by heartsome.

the class GridTableViewer method updateRowHeader.

private void updateRowHeader(Widget widget) {
    if (rowHeaderLabelProvider != null) {
        ViewerCell cell = getViewerRowFromItem(widget).getCell(Integer.MAX_VALUE);
        rowHeaderLabelProvider.update(cell);
    }
}
Also used : ViewerCell(org.eclipse.jface.viewers.ViewerCell)

Example 30 with ViewerCell

use of org.eclipse.jface.viewers.ViewerCell in project translationstudio8 by heartsome.

the class GridTreeViewer method updateRowHeader.

private void updateRowHeader(Widget widget) {
    if (rowHeaderLabelProvider != null) {
        ViewerCell cell = getViewerRowFromItem(widget).getCell(Integer.MAX_VALUE);
        rowHeaderLabelProvider.update(cell);
    }
}
Also used : ViewerCell(org.eclipse.jface.viewers.ViewerCell)

Aggregations

ViewerCell (org.eclipse.jface.viewers.ViewerCell)54 TableViewer (org.eclipse.jface.viewers.TableViewer)21 Composite (org.eclipse.swt.widgets.Composite)21 CellLabelProvider (org.eclipse.jface.viewers.CellLabelProvider)18 GridData (org.eclipse.swt.layout.GridData)18 Table (org.eclipse.swt.widgets.Table)18 GridLayout (org.eclipse.swt.layout.GridLayout)17 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)16 SelectionEvent (org.eclipse.swt.events.SelectionEvent)15 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)12 Button (org.eclipse.swt.widgets.Button)12 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)11 StyledCellLabelProvider (org.eclipse.jface.viewers.StyledCellLabelProvider)11 Label (org.eclipse.swt.widgets.Label)11 StyledString (org.eclipse.jface.viewers.StyledString)10 ColumnWeightData (org.eclipse.jface.viewers.ColumnWeightData)9 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)9 Point (org.eclipse.swt.graphics.Point)9 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)8 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)8