Search in sources :

Example 6 with NameColumn

use of name.abuchen.portfolio.ui.views.columns.NameColumn in project portfolio by buchen.

the class PortfolioListView method createTopTable.

// //////////////////////////////////////////////////////////////
// top table: accounts
// //////////////////////////////////////////////////////////////
protected void createTopTable(Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    TableColumnLayout layout = new TableColumnLayout();
    container.setLayout(layout);
    portfolios = new TableViewer(container, SWT.FULL_SELECTION);
    ColumnEditingSupport.prepare(portfolios);
    portfolioColumns = new // $NON-NLS-1$
    ShowHideColumnHelper(// $NON-NLS-1$
    PortfolioListView.class.getSimpleName() + "@top2", getPreferenceStore(), portfolios, layout);
    // $NON-NLS-1$
    Column column = new NameColumn("0", Messages.ColumnPortfolio, SWT.None, 100);
    column.setLabelProvider(new NameColumnLabelProvider() {

        @Override
        public Color getForeground(Object e) {
            boolean isRetired = ((Portfolio) e).isRetired();
            return isRetired ? Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY) : null;
        }
    });
    column.getEditingSupport().addListener(this);
    portfolioColumns.addColumn(column);
    column = new Column(Messages.ColumnReferenceAccount, SWT.None, 160);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            Portfolio p = (Portfolio) e;
            return p.getReferenceAccount() != null ? p.getReferenceAccount().getName() : null;
        }
    });
    // $NON-NLS-1$
    ColumnViewerSorter.create(Portfolio.class, "referenceAccount").attachTo(column);
    // $NON-NLS-1$
    new ListEditingSupport(Portfolio.class, "referenceAccount", getClient().getAccounts()).addListener(this).attachTo(column);
    portfolioColumns.addColumn(column);
    column = new NoteColumn();
    column.getEditingSupport().addListener(this);
    portfolioColumns.addColumn(column);
    portfolioColumns.createColumns();
    portfolios.getTable().setHeaderVisible(true);
    portfolios.getTable().setLinesVisible(true);
    portfolios.setContentProvider(ArrayContentProvider.getInstance());
    setInput();
    portfolios.addSelectionChangedListener(event -> {
        Portfolio portfolio = (Portfolio) ((IStructuredSelection) event.getSelection()).getFirstElement();
        if (portfolio != null) {
            transactions.setInput(portfolio, portfolio.getTransactions());
            transactions.refresh();
            CurrencyConverter converter = new CurrencyConverterImpl(factory, portfolio.getReferenceAccount().getCurrencyCode());
            statementOfAssets.setInput(PortfolioSnapshot.create(portfolio, converter, LocalDate.now()));
        } else {
            transactions.setInput(null, null);
            transactions.refresh();
            statementOfAssets.setInput((PortfolioSnapshot) null);
        }
    });
    hookContextMenu(portfolios.getTable(), this::fillPortfolioContextMenu);
}
Also used : Composite(org.eclipse.swt.widgets.Composite) NameColumnLabelProvider(name.abuchen.portfolio.ui.views.columns.NameColumn.NameColumnLabelProvider) NameColumn(name.abuchen.portfolio.ui.views.columns.NameColumn) NoteColumn(name.abuchen.portfolio.ui.views.columns.NoteColumn) Color(org.eclipse.swt.graphics.Color) Portfolio(name.abuchen.portfolio.model.Portfolio) CurrencyConverterImpl(name.abuchen.portfolio.money.CurrencyConverterImpl) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) NameColumnLabelProvider(name.abuchen.portfolio.ui.views.columns.NameColumn.NameColumnLabelProvider) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) NameColumn(name.abuchen.portfolio.ui.views.columns.NameColumn) NoteColumn(name.abuchen.portfolio.ui.views.columns.NoteColumn) Column(name.abuchen.portfolio.ui.util.viewers.Column) ListEditingSupport(name.abuchen.portfolio.ui.util.viewers.ListEditingSupport) TableViewer(org.eclipse.jface.viewers.TableViewer)

Aggregations

Column (name.abuchen.portfolio.ui.util.viewers.Column)6 NameColumn (name.abuchen.portfolio.ui.views.columns.NameColumn)6 NoteColumn (name.abuchen.portfolio.ui.views.columns.NoteColumn)6 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)5 ArrayList (java.util.ArrayList)3 AttributeColumn (name.abuchen.portfolio.ui.views.columns.AttributeColumn)3 IsinColumn (name.abuchen.portfolio.ui.views.columns.IsinColumn)3 NameColumnLabelProvider (name.abuchen.portfolio.ui.views.columns.NameColumn.NameColumnLabelProvider)3 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)3 TableViewer (org.eclipse.jface.viewers.TableViewer)3 Color (org.eclipse.swt.graphics.Color)3 Image (org.eclipse.swt.graphics.Image)3 Composite (org.eclipse.swt.widgets.Composite)3 Account (name.abuchen.portfolio.model.Account)2 Named (name.abuchen.portfolio.model.Named)2 Security (name.abuchen.portfolio.model.Security)2 CurrencyConverter (name.abuchen.portfolio.money.CurrencyConverter)2 CurrencyConverterImpl (name.abuchen.portfolio.money.CurrencyConverterImpl)2 Money (name.abuchen.portfolio.money.Money)2 MarkDirtyListener (name.abuchen.portfolio.ui.util.viewers.ColumnEditingSupport.MarkDirtyListener)2