Search in sources :

Example 1 with MonthEditingSupport

use of name.abuchen.portfolio.ui.util.viewers.MonthEditingSupport in project portfolio by buchen.

the class ConsumerPriceIndexListView method createTopTable.

@Override
protected void createTopTable(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    TableColumnLayout layout = new TableColumnLayout();
    container.setLayout(layout);
    indices = new TableViewer(container, SWT.FULL_SELECTION);
    ColumnEditingSupport.prepare(indices);
    ShowHideColumnHelper support = new ShowHideColumnHelper(// $NON-NLS-1$
    ConsumerPriceIndexListView.class.getSimpleName() + "@bottom", // $NON-NLS-1$
    getPreferenceStore(), // $NON-NLS-1$
    indices, layout);
    Column column = new Column(Messages.ColumnYear, SWT.None, 80);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return String.valueOf(((ConsumerPriceIndex) element).getYear());
        }
    });
    // $NON-NLS-1$ //$NON-NLS-2$
    ColumnViewerSorter.create(ConsumerPriceIndex.class, "year", "month").attachTo(column, SWT.DOWN);
    // $NON-NLS-1$
    new ValueEditingSupport(ConsumerPriceIndex.class, "year", Values.Year).addListener(this).attachTo(column);
    support.addColumn(column);
    column = new Column(Messages.ColumnMonth, SWT.None, 80);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            int month = ((ConsumerPriceIndex) element).getMonth();
            return Month.of(month).getDisplayName(TextStyle.FULL, Locale.getDefault());
        }
    });
    // $NON-NLS-1$ //$NON-NLS-2$
    ColumnViewerSorter.create(ConsumerPriceIndex.class, "month", "year").attachTo(column);
    // $NON-NLS-1$
    new MonthEditingSupport(ConsumerPriceIndex.class, "month").addListener(this).attachTo(column);
    support.addColumn(column);
    column = new Column(Messages.ColumnIndex, SWT.RIGHT, 80);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            return Values.Index.format(((ConsumerPriceIndex) element).getIndex());
        }
    });
    // $NON-NLS-1$
    ColumnViewerSorter.create(ConsumerPriceIndex.class, "index").attachTo(column);
    // $NON-NLS-1$
    new ValueEditingSupport(ConsumerPriceIndex.class, "index", Values.Index).addListener(this).attachTo(column);
    support.addColumn(column);
    support.createColumns();
    indices.getTable().setHeaderVisible(true);
    indices.getTable().setLinesVisible(true);
    indices.setContentProvider(ArrayContentProvider.getInstance());
    indices.setInput(getClient().getConsumerPriceIndices());
    indices.refresh();
    hookContextMenu(indices.getTable(), new IMenuListener() {

        public void menuAboutToShow(IMenuManager manager) {
            fillContextMenu(manager);
        }
    });
}
Also used : Composite(org.eclipse.swt.widgets.Composite) IMenuListener(org.eclipse.jface.action.IMenuListener) ValueEditingSupport(name.abuchen.portfolio.ui.util.viewers.ValueEditingSupport) MonthEditingSupport(name.abuchen.portfolio.ui.util.viewers.MonthEditingSupport) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) ShowHideColumnHelper(name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper) ConsumerPriceIndex(name.abuchen.portfolio.model.ConsumerPriceIndex) Column(name.abuchen.portfolio.ui.util.viewers.Column) IMenuManager(org.eclipse.jface.action.IMenuManager) TableViewer(org.eclipse.jface.viewers.TableViewer)

Aggregations

ConsumerPriceIndex (name.abuchen.portfolio.model.ConsumerPriceIndex)1 Column (name.abuchen.portfolio.ui.util.viewers.Column)1 MonthEditingSupport (name.abuchen.portfolio.ui.util.viewers.MonthEditingSupport)1 ShowHideColumnHelper (name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper)1 ValueEditingSupport (name.abuchen.portfolio.ui.util.viewers.ValueEditingSupport)1 IMenuListener (org.eclipse.jface.action.IMenuListener)1 IMenuManager (org.eclipse.jface.action.IMenuManager)1 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)1 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 Composite (org.eclipse.swt.widgets.Composite)1