Search in sources :

Example 16 with ViewerComparator

use of org.eclipse.jface.viewers.ViewerComparator in project tdq-studio-se by Talend.

the class AbstractMatchAnalysisTableViewer method initTable.

/**
 * DOC zshen Comment method "initTable".
 *
 * @param headers the name of column
 * @param columnMap all of columns which can be used by current Table
 * @param pixelDataOfHeaders the width of the column
 */
public void initTable(List<String> headers, List<MetadataColumn> columnMap, boolean withSorter) {
    TableLayout tLayout = new TableLayout();
    innerTable.setLayout(tLayout);
    innerTable.setHeaderVisible(true);
    innerTable.setLinesVisible(true);
    GridData gd = new GridData(GridData.FILL_BOTH);
    innerTable.setLayoutData(gd);
    for (int index = 0; index < headers.size(); index++) {
        final int sortIndex = index;
        String columnTechnologyLabel = headers.get(index);
        String columnLabel = getInternationalizedLabel(columnTechnologyLabel);
        if (columnLabel != null) {
            if (columnLabel.length() == 1) {
                columnLabel = columnLabel + PluginConstant.SPACE_STRING + PluginConstant.SPACE_STRING;
            }
            tLayout.addColumnData(new ColumnPixelData(columnLabel.length() * getHeaderDisplayWeight(index)));
            final TableViewerColumn tableColumn = new TableViewerColumn(this, SWT.LEFT);
            tableColumn.getColumn().setText(columnLabel);
            addEditingSupportForColumn(tableColumn, columnTechnologyLabel);
            if (withSorter) {
                final ViewerComparator comparator = getComparator();
                tableColumn.getColumn().addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        ((GroupStatisticsRowCompartor) comparator).setColumn(sortIndex);
                        int dir = getTable().getSortDirection();
                        if (getTable().getSortColumn() == tableColumn.getColumn()) {
                            dir = dir == SWT.UP ? SWT.DOWN : SWT.UP;
                        } else {
                            dir = SWT.DOWN;
                        }
                        getTable().setSortDirection(dir);
                        getTable().setSortColumn(tableColumn.getColumn());
                        refresh();
                    }
                });
            }
        }
    }
    CellEditor[] editors = getCellEditor(headers, columnMap);
    // add menu
    addContextMenu();
    AbstractMatchCellModifier<T> cellModifier = getTableCellModifier();
    if (cellModifier != null) {
        cellModifier.setColumnMap(columnMap);
        this.setCellModifier(cellModifier);
    }
    this.setCellEditors(editors);
    this.setColumnProperties(headers.toArray(new String[headers.size()]));
    this.setContentProvider(getTableContentProvider());
    this.setLabelProvider(getTableLabelProvider());
    GridData tableGD = new GridData(GridData.FILL_BOTH);
    tableGD.heightHint = getTableHeightHint();
    innerTable.setLayoutData(tableGD);
}
Also used : ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) CellEditor(org.eclipse.jface.viewers.CellEditor) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) SWT(org.eclipse.swt.SWT) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableLayout(org.eclipse.jface.viewers.TableLayout) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 17 with ViewerComparator

use of org.eclipse.jface.viewers.ViewerComparator in project whole by wholeplatform.

the class EditorPreferencePage method createContents.

protected Control createContents(Composite parent) {
    Label label;
    GridData gd;
    Composite topComposite = new Composite(parent, SWT.NONE);
    topComposite.setLayout(new GridLayout(1, false));
    topComposite.setFont(parent.getFont());
    gd = new GridData(GridData.FILL_BOTH);
    gd.horizontalSpan = 1;
    topComposite.setLayoutData(gd);
    Label fontsLabel = new Label(topComposite, SWT.LEFT);
    fontsLabel.setText("Font category:");
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 2;
    fontsLabel.setLayoutData(gd);
    Composite fontComposite = new Composite(topComposite, SWT.BORDER);
    GridLayout fontLayout = new GridLayout(3, false);
    fontComposite.setLayout(fontLayout);
    fontComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    monospaceFont = new FontFieldEditor(PreferenceConstants.MONOSPACE_FONT, "Monospace", fontComposite);
    sanserifFont = new FontFieldEditor(PreferenceConstants.SANSERIF_FONT, "Sans Serif", fontComposite);
    serifFont = new FontFieldEditor(PreferenceConstants.SERIF_FONT, "Serif", fontComposite);
    GridLayout bgLayout = new GridLayout(2, false);
    bgLayout.marginHeight = 5;
    bgLayout.marginWidth = 10;
    topComposite.setLayout(bgLayout);
    Label bgLabel = new Label(topComposite, SWT.LEFT);
    bgLabel.setText("Hilight category:");
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 2;
    bgLabel.setLayoutData(gd);
    bgCategoryTable = new TableViewer(topComposite, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER);
    bgCategoryTable.setContentProvider(new ArrayContentProvider());
    bgCategoryTable.setLabelProvider(new PresentationLabelProvider(bgCategoryTable));
    bgCategoryTable.setComparator(new ViewerComparator());
    gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.FILL_BOTH);
    gd.widthHint = convertWidthInCharsToPixels(25);
    // convertHeightInCharsToPixels(5);
    gd.heightHint = 90;
    bgCategoryTable.getControl().setLayoutData(gd);
    bgColumn = new TableColumn(bgCategoryTable.getTable(), SWT.LEFT);
    Composite bgStylesComposite = new Composite(topComposite, SWT.NONE);
    GridLayout bgStylesLayout = new GridLayout(2, false);
    bgStylesLayout.marginHeight = 0;
    bgStylesLayout.marginWidth = 0;
    bgStylesComposite.setLayout(bgStylesLayout);
    bgStylesComposite.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
    label = new Label(bgStylesComposite, SWT.LEFT);
    label.setText("Color:");
    label.setLayoutData(new GridData());
    bgColorSelector = new ColorSelector(bgStylesComposite);
    Label fgLabel = new Label(topComposite, SWT.NONE);
    fgLabel.setText("Syntax category:");
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = 2;
    fgLabel.setLayoutData(gd);
    fgCategoryTable = new TableViewer(topComposite, SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER);
    fgCategoryTable.setContentProvider(new ArrayContentProvider());
    fgCategoryTable.setLabelProvider(new PresentationLabelProvider(fgCategoryTable));
    fgCategoryTable.setComparator(new ViewerComparator());
    gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.FILL_BOTH);
    gd.widthHint = convertWidthInCharsToPixels(25);
    // convertHeightInCharsToPixels(4);
    gd.heightHint = 52;
    fgCategoryTable.getControl().setLayoutData(gd);
    fgColumn = new TableColumn(fgCategoryTable.getTable(), SWT.LEFT);
    Composite fgStylesComposite = new Composite(topComposite, SWT.NONE);
    GridLayout fgStylesLayout = new GridLayout(2, false);
    fgStylesLayout.marginHeight = 0;
    fgStylesLayout.marginWidth = 0;
    fgStylesComposite.setLayout(fgStylesLayout);
    fgStylesComposite.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
    label = new Label(fgStylesComposite, SWT.LEFT);
    label.setText("Color:");
    label.setLayoutData(new GridData());
    fgColorSelector = new ColorSelector(fgStylesComposite);
    label = new Label(fgStylesComposite, SWT.LEFT);
    label.setText("Font:");
    label.setLayoutData(new GridData());
    classCombo = new Combo(fgStylesComposite, SWT.DROP_DOWN | SWT.READ_ONLY);
    classCombo.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
    label = new Label(fgStylesComposite, SWT.LEFT);
    label.setText("Style:");
    label.setLayoutData(new GridData());
    styleCombo = new Combo(fgStylesComposite, SWT.DROP_DOWN | SWT.READ_ONLY);
    styleCombo.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
    label = new Label(fgStylesComposite, SWT.LEFT);
    label.setText("Size:");
    label.setLayoutData(new GridData());
    sizeCombo = new Combo(fgStylesComposite, SWT.DROP_DOWN | SWT.READ_ONLY);
    sizeCombo.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
    bgCategoryTable.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            if (!event.getSelection().isEmpty()) {
                handleBgCategoryListSelection();
            }
        }
    });
    bgCategoryTable.getControl().addControlListener(new ControlAdapter() {

        public void controlResized(ControlEvent e) {
            bgColumn.setWidth(bgCategoryTable.getControl().getSize().x - 4);
        }
    });
    bgColorSelector.addListener(new IPropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent event) {
            RGB newRGB = (RGB) event.getNewValue();
            String key = getSelectedKey(bgCategoryTable);
            if (key != null && newRGB != null && !newRGB.equals(event.getOldValue())) {
                store.putValue(key, StringConverter.asString(newRGB));
            }
        }
    });
    fgCategoryTable.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            if (!event.getSelection().isEmpty()) {
                handleFgCategoryListSelection();
            }
        }
    });
    fgCategoryTable.getControl().addControlListener(new ControlAdapter() {

        public void controlResized(ControlEvent e) {
            fgColumn.setWidth(fgCategoryTable.getControl().getSize().x - 24);
        }
    });
    fgColorSelector.addListener(new IPropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent event) {
            RGB newRGB = (RGB) event.getNewValue();
            String key = getSelectedKey(fgCategoryTable);
            if (key != null && newRGB != null && !newRGB.equals(event.getOldValue())) {
                store.putValue(key, StringConverter.asString(newRGB));
            }
        }
    });
    classCombo.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent e) {
        }

        public void widgetSelected(SelectionEvent e) {
            String key = getSelectedKey(fgCategoryTable);
            store.putValue(key + PreferenceConstants.CLASS, FontClass.nameOf(classCombo.getSelectionIndex()));
        }
    });
    styleCombo.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent e) {
        }

        public void widgetSelected(SelectionEvent e) {
            String key = getSelectedKey(fgCategoryTable);
            store.putValue(key + PreferenceConstants.STYLE, FontStyle.nameOf(styleCombo.getSelectionIndex()));
        }
    });
    sizeCombo.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent e) {
        }

        public void widgetSelected(SelectionEvent e) {
            String key = getSelectedKey(fgCategoryTable);
            store.putValue(key + PreferenceConstants.SIZE, FontSize.nameOf(sizeCombo.getSelectionIndex()));
        }
    });
    initialize();
    return topComposite;
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) Composite(org.eclipse.swt.widgets.Composite) FontFieldEditor(org.eclipse.jface.preference.FontFieldEditor) ControlAdapter(org.eclipse.swt.events.ControlAdapter) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) RGB(org.eclipse.swt.graphics.RGB) TableColumn(org.eclipse.swt.widgets.TableColumn) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ColorSelector(org.eclipse.jface.preference.ColorSelector) ControlEvent(org.eclipse.swt.events.ControlEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 18 with ViewerComparator

use of org.eclipse.jface.viewers.ViewerComparator in project portfolio by buchen.

the class ListSelectionDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite composite = (Composite) super.createDialogArea(parent);
    Composite container = new Composite(composite, SWT.None);
    GridDataFactory.fillDefaults().grab(true, true).hint(400, 300).applyTo(container);
    GridLayoutFactory.fillDefaults().numColumns(1).applyTo(container);
    Label label = new Label(container, SWT.None);
    label.setText(this.message);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(label);
    searchText = new Text(container, SWT.BORDER);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(searchText);
    searchText.setFocus();
    Composite tableArea = new Composite(container, SWT.NONE);
    GridDataFactory.fillDefaults().grab(false, true).applyTo(tableArea);
    tableArea.setLayout(new FillLayout());
    TableColumnLayout layout = new TableColumnLayout();
    tableArea.setLayout(layout);
    elementFilter = new ElementFilter();
    int style = SWT.BORDER | SWT.FULL_SELECTION;
    if (isMultiSelection)
        style |= SWT.MULTI;
    tableViewer = new TableViewer(tableArea, style);
    final Table table = tableViewer.getTable();
    table.setHeaderVisible(false);
    table.setLinesVisible(false);
    TableViewerColumn column = new TableViewerColumn(tableViewer, SWT.None);
    layout.setColumnData(column.getColumn(), new ColumnWeightData(100));
    tableViewer.setLabelProvider(labelProvider);
    tableViewer.setContentProvider(ArrayContentProvider.getInstance());
    tableViewer.addFilter(elementFilter);
    tableViewer.setInput(elements);
    tableViewer.setComparator(new ViewerComparator());
    hookListener();
    return composite;
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) FillLayout(org.eclipse.swt.layout.FillLayout) TableViewer(org.eclipse.jface.viewers.TableViewer) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn)

Example 19 with ViewerComparator

use of org.eclipse.jface.viewers.ViewerComparator in project portfolio by buchen.

the class OpenPreferenceDialogHandler method execute.

@Execute
public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell) {
    PreferenceManager pm = new PreferenceManager();
    // $NON-NLS-1$
    pm.addToRoot(new PreferenceNode(PortfolioPlugin.PLUGIN_ID + ".updates", new UpdatePreferencePage()));
    // $NON-NLS-1$
    pm.addToRoot(new PreferenceNode(PortfolioPlugin.PLUGIN_ID + ".language", new LanguagePreferencePage()));
    // $NON-NLS-1$
    pm.addToRoot(new PreferenceNode(PortfolioPlugin.PLUGIN_ID + ".proxy", new ProxyPreferencePage()));
    // $NON-NLS-1$
    pm.addToRoot(new PreferenceNode(PortfolioPlugin.PLUGIN_ID + ".presentation", new PresentationPreferencePage()));
    // $NON-NLS-1$
    pm.addToRoot(new PreferenceNode(PortfolioPlugin.PLUGIN_ID + ".general", new GeneralPreferencePage()));
    // $NON-NLS-1$
    pm.addToRoot(new PreferenceNode(PortfolioPlugin.PLUGIN_ID + ".apikeys", new APIKeysPreferencePage()));
    PreferenceDialog dialog = new PreferenceDialog(shell, pm);
    dialog.setPreferenceStore(PortfolioPlugin.getDefault().getPreferenceStore());
    dialog.create();
    dialog.getTreeViewer().setComparator(new ViewerComparator());
    dialog.getTreeViewer().expandAll();
    dialog.open();
}
Also used : UpdatePreferencePage(name.abuchen.portfolio.ui.preferences.UpdatePreferencePage) LanguagePreferencePage(name.abuchen.portfolio.ui.preferences.LanguagePreferencePage) ProxyPreferencePage(name.abuchen.portfolio.ui.preferences.ProxyPreferencePage) PreferenceDialog(org.eclipse.jface.preference.PreferenceDialog) PreferenceNode(org.eclipse.jface.preference.PreferenceNode) APIKeysPreferencePage(name.abuchen.portfolio.ui.preferences.APIKeysPreferencePage) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) PresentationPreferencePage(name.abuchen.portfolio.ui.preferences.PresentationPreferencePage) GeneralPreferencePage(name.abuchen.portfolio.ui.preferences.GeneralPreferencePage) PreferenceManager(org.eclipse.jface.preference.PreferenceManager) Execute(org.eclipse.e4.core.di.annotations.Execute)

Example 20 with ViewerComparator

use of org.eclipse.jface.viewers.ViewerComparator in project titan.EclipsePlug-ins by eclipse.

the class OutlinePage method createControl.

@Override
public void createControl(final Composite parent) {
    super.createControl(parent);
    final IPreferenceStore store = Activator.getDefault().getPreferenceStore();
    viewer = getTreeViewer();
    viewer.setContentProvider(new OutlineContentProvider());
    viewer.setLabelProvider(new OutlineLabelProvider());
    OutlineViewSorter comperator = new OutlineViewSorter();
    comperator.setSortByName(store.getBoolean(PreferenceConstants.OUTLINE_SORTED));
    viewer.setComparator(comperator);
    viewer.setAutoExpandLevel(2);
    viewer.setInput(getModule());
    viewer.addSelectionChangedListener(this);
    IActionBars bars = getSite().getActionBars();
    Action sortToggler = new Action("Sort") {

        @Override
        public void run() {
            ViewerComparator comperator = viewer.getComparator();
            if (comperator == null) {
                comperator = new OutlineViewSorter();
                viewer.setComparator(comperator);
            }
            if (comperator instanceof OutlineViewSorter) {
                store.setValue(PreferenceConstants.OUTLINE_SORTED, isChecked());
                ((OutlineViewSorter) comperator).setSortByName(isChecked());
            }
            viewer.refresh();
        }
    };
    sortToggler.setImageDescriptor(ImageCache.getImageDescriptor("sort_alphabetically.gif"));
    sortToggler.setChecked(store.getBoolean(PreferenceConstants.OUTLINE_SORTED));
    bars.getToolBarManager().add(sortToggler);
}
Also used : Action(org.eclipse.jface.action.Action) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) OutlineViewSorter(org.eclipse.titan.designer.editors.OutlineViewSorter) IActionBars(org.eclipse.ui.IActionBars)

Aggregations

ViewerComparator (org.eclipse.jface.viewers.ViewerComparator)110 Viewer (org.eclipse.jface.viewers.Viewer)64 Composite (org.eclipse.swt.widgets.Composite)59 TableViewer (org.eclipse.jface.viewers.TableViewer)50 GridData (org.eclipse.swt.layout.GridData)50 GridLayout (org.eclipse.swt.layout.GridLayout)34 Label (org.eclipse.swt.widgets.Label)29 LabelProvider (org.eclipse.jface.viewers.LabelProvider)23 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)22 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)22 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)22 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)22 SelectionEvent (org.eclipse.swt.events.SelectionEvent)21 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)19 ColumnWeightData (org.eclipse.jface.viewers.ColumnWeightData)18 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)17 Button (org.eclipse.swt.widgets.Button)17 TreeViewer (org.eclipse.jface.viewers.TreeViewer)16 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)15 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)15