Search in sources :

Example 1 with NameColumnLabelProvider

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

the class StatementOfAssetsViewer method createColumns.

private // NOSONAR
Control createColumns(// NOSONAR
Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    TableColumnLayout layout = new TableColumnLayout();
    container.setLayout(layout);
    assets = new TableViewer(container, SWT.FULL_SELECTION);
    ColumnViewerToolTipSupport.enableFor(assets, ToolTip.NO_RECREATE);
    ColumnEditingSupport.prepare(assets);
    assets.addSelectionChangedListener(event -> {
        Element element = (Element) ((IStructuredSelection) event.getSelection()).getFirstElement();
        if (element != null && element.isSecurity())
            selectionService.setSelection(new SecuritySelection(client, element.getSecurity()));
    });
    support = new ShowHideColumnHelper(StatementOfAssetsViewer.class.getName(), client, preference, assets, layout);
    // $NON-NLS-1$
    Column column = new Column("0", Messages.ColumnSharesOwned, SWT.RIGHT, 80);
    column.setLabelProvider(new // NOSONAR
    SharesLabelProvider() {

        @Override
        public Long getValue(Object e) {
            Element element = (Element) e;
            return element.isSecurity() ? element.getSecurityPosition().getShares() : null;
        }
    });
    column.setComparator(new ElementComparator(new AttributeComparator(e -> ((Element) e).isSecurity() ? ((Element) e).getSecurityPosition().getShares() : null)));
    support.addColumn(column);
    // $NON-NLS-1$
    column = new NameColumn("1");
    column.setLabelProvider(new // NOSONAR
    NameColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            if (((Element) e).isGroupByTaxonomy())
                return Messages.LabelTotalSum;
            return super.getText(e);
        }

        @Override
        public Font getFont(Object e) {
            return ((Element) e).isGroupByTaxonomy() || ((Element) e).isCategory() ? boldFont : null;
        }

        @Override
        public Image getImage(Object e) {
            if (((Element) e).isCategory())
                return null;
            return super.getImage(e);
        }
    });
    column.setEditingSupport(new // $NON-NLS-1$
    StringEditingSupport(// $NON-NLS-1$
    Named.class, // $NON-NLS-1$
    "name") {

        @Override
        public boolean canEdit(Object element) {
            boolean isCategory = ((Element) element).isCategory();
            boolean isUnassignedCategory = isCategory && Classification.UNASSIGNED_ID.equals(((Element) element).getCategory().getClassification().getId());
            return !isUnassignedCategory ? super.canEdit(element) : false;
        }
    }.setMandatory(true).addListener(new MarkDirtyListener(this.owner)));
    column.getSorter().wrap(ElementComparator::new);
    support.addColumn(column);
    // $NON-NLS-1$
    column = new Column("2", Messages.ColumnTicker, SWT.None, 60);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            Element element = (Element) e;
            return element.isSecurity() ? element.getSecurity().getTickerSymbol() : null;
        }
    });
    column.setComparator(new ElementComparator(new AttributeComparator(e -> ((Element) e).isSecurity() ? ((Element) e).getSecurity().getTickerSymbol() : null)));
    support.addColumn(column);
    // $NON-NLS-1$
    column = new Column("12", Messages.ColumnWKN, SWT.None, 60);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            Element element = (Element) e;
            return element.isSecurity() ? element.getSecurity().getWkn() : null;
        }
    });
    column.setComparator(new ElementComparator(new AttributeComparator(e -> ((Element) e).isSecurity() ? ((Element) e).getSecurity().getWkn() : null)));
    column.setVisible(false);
    support.addColumn(column);
    // $NON-NLS-1$
    column = new IsinColumn("3");
    column.getEditingSupport().addListener(new MarkDirtyListener(this.owner));
    column.getSorter().wrap(ElementComparator::new);
    column.setVisible(false);
    support.addColumn(column);
    // $NON-NLS-1$
    column = new Column("4", Messages.ColumnQuote, SWT.RIGHT, 60);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            Element element = (Element) e;
            if (!element.isSecurity())
                return null;
            Security security = element.getSecurity();
            return Values.Quote.format(security.getCurrencyCode(), element.getSecurityPosition().getPrice().getValue(), client.getBaseCurrency());
        }
    });
    column.setComparator(new ElementComparator(new AttributeComparator(e -> {
        Element element = (Element) e;
        if (!element.isSecurity())
            return null;
        return Money.of(element.getSecurity().getCurrencyCode(), element.getSecurityPosition().getPrice().getValue());
    })));
    support.addColumn(column);
    // $NON-NLS-1$
    column = new Column("qdate", Messages.ColumnDateOfQuote, SWT.LEFT, 80);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            Element element = (Element) e;
            return element.isSecurity() ? Values.Date.format(element.getSecurityPosition().getPrice().getDate()) : null;
        }
    });
    column.setComparator(new ElementComparator(new AttributeComparator(e -> ((Element) e).isSecurity() ? ((Element) e).getSecurityPosition().getPrice().getDate() : null)));
    column.setVisible(false);
    support.addColumn(column);
    // $NON-NLS-1$
    column = new Column("5", Messages.ColumnMarketValue, SWT.RIGHT, 80);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            Element element = (Element) e;
            return Values.Money.format(element.getValuation(), client.getBaseCurrency());
        }

        @Override
        public Font getFont(Object e) {
            return ((Element) e).isGroupByTaxonomy() || ((Element) e).isCategory() ? boldFont : null;
        }
    });
    // $NON-NLS-1$
    column.setSorter(ColumnViewerSorter.create(Element.class, "valuation").wrap(ElementComparator::new));
    support.addColumn(column);
    // $NON-NLS-1$
    column = new Column("6", Messages.ColumnShareInPercent, SWT.RIGHT, 80);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            Element element = (Element) e;
            if (element.isGroupByTaxonomy())
                return Values.Percent.format(1d);
            if (element.isCategory())
                return Values.Percent.format(element.getCategory().getShare());
            else
                return Values.Percent.format(element.getPosition().getShare());
        }

        @Override
        public Font getFont(Object e) {
            return ((Element) e).isGroupByTaxonomy() || ((Element) e).isCategory() ? boldFont : null;
        }
    });
    // $NON-NLS-1$
    column.setSorter(ColumnViewerSorter.create(Element.class, "valuation").wrap(ElementComparator::new));
    support.addColumn(column);
    // $NON-NLS-1$
    column = new Column("7", Messages.ColumnPurchasePrice, SWT.RIGHT, 60);
    column.setDescription(Messages.ColumnPurchasePrice_Description);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            Element element = (Element) e;
            if (element.isSecurity()) {
                Money purchasePrice = element.getSecurityPosition().getFIFOPurchasePrice();
                return Values.Money.formatNonZero(purchasePrice, client.getBaseCurrency());
            }
            return null;
        }
    });
    column.setComparator(new ElementComparator(new AttributeComparator(e -> ((Element) e).isSecurity() ? ((Element) e).getSecurityPosition().getFIFOPurchasePrice() : null)));
    column.setVisible(false);
    support.addColumn(column);
    // $NON-NLS-1$
    column = new Column("ppmvavg", Messages.ColumnPurchasePriceMovingAverage, SWT.RIGHT, 60);
    column.setDescription(Messages.ColumnPurchasePriceMovingAverage_Description);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            Element element = (Element) e;
            if (element.isSecurity()) {
                Money purchasePrice = element.getSecurityPosition().getMovingAveragePurchasePrice();
                return Values.Money.formatNonZero(purchasePrice, client.getBaseCurrency());
            }
            return null;
        }
    });
    column.setComparator(new ElementComparator(new AttributeComparator(e -> ((Element) e).isSecurity() ? ((Element) e).getSecurityPosition().getMovingAveragePurchasePrice() : null)));
    column.setVisible(false);
    support.addColumn(column);
    // $NON-NLS-1$
    column = new Column("8", Messages.ColumnPurchaseValue, SWT.RIGHT, 80);
    column.setDescription(Messages.ColumnPurchaseValue_Description);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            Element element = (Element) e;
            Money purchaseValue = element.getFIFOPurchaseValue();
            return Values.Money.formatNonZero(purchaseValue, client.getBaseCurrency());
        }

        @Override
        public Font getFont(Object e) {
            return ((Element) e).isGroupByTaxonomy() || ((Element) e).isCategory() ? boldFont : null;
        }
    });
    column.setVisible(false);
    column.setSorter(// $NON-NLS-1$
    ColumnViewerSorter.create(Element.class, "FIFOPurchaseValue").wrap(ElementComparator::new));
    support.addColumn(column);
    // $NON-NLS-1$
    column = new Column("pvmvavg", Messages.ColumnPurchaseValueMovingAverage, SWT.RIGHT, 80);
    column.setDescription(Messages.ColumnPurchaseValueMovingAverage_Description);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            Element element = (Element) e;
            Money purchaseValue = element.getMovingAveragePurchaseValue();
            return Values.Money.formatNonZero(purchaseValue, client.getBaseCurrency());
        }

        @Override
        public Font getFont(Object e) {
            return ((Element) e).isGroupByTaxonomy() || ((Element) e).isCategory() ? boldFont : null;
        }
    });
    column.setVisible(false);
    column.setSorter(// $NON-NLS-1$
    ColumnViewerSorter.create(Element.class, "MovingAveragePurchaseValue").wrap(ElementComparator::new));
    support.addColumn(column);
    // $NON-NLS-1$
    column = new Column("9", Messages.ColumnProfitLoss, SWT.RIGHT, 80);
    column.setLabelProvider(new // NOSONAR
    ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            Money profitLoss = ((Element) e).getProfitLoss();
            return Values.Money.formatNonZero(profitLoss, client.getBaseCurrency());
        }

        @Override
        public Color getForeground(Object e) {
            Money profitLoss = ((Element) e).getProfitLoss();
            return Display.getCurrent().getSystemColor(profitLoss.isNegative() ? SWT.COLOR_DARK_RED : SWT.COLOR_DARK_GREEN);
        }

        @Override
        public Image getImage(Object e) {
            Money profitLoss = ((Element) e).getProfitLoss();
            if (profitLoss.isZero())
                return null;
            return profitLoss.isNegative() ? Images.RED_ARROW.image() : Images.GREEN_ARROW.image();
        }

        @Override
        public Font getFont(Object e) {
            return ((Element) e).isGroupByTaxonomy() || ((Element) e).isCategory() ? boldFont : null;
        }
    });
    column.setVisible(false);
    // $NON-NLS-1$
    column.setSorter(ColumnViewerSorter.create(Element.class, "profitLoss").wrap(ElementComparator::new));
    support.addColumn(column);
    column = new NoteColumn();
    column.getEditingSupport().addListener(new MarkDirtyListener(this.owner));
    column.getSorter().wrap(ElementComparator::new);
    support.addColumn(column);
    // create a modifiable copy as all menus share the same list of
    // reporting periods
    List<ReportingPeriod> options = new ArrayList<>(owner.getPart().loadReportingPeriods());
    addPerformanceColumns(options);
    addDividendColumns(options);
    addTaxonomyColumns();
    addAttributeColumns();
    addCurrencyColumns();
    support.createColumns();
    assets.getTable().setHeaderVisible(true);
    assets.getTable().setLinesVisible(true);
    assets.setContentProvider(new StatementOfAssetsContentProvider());
    // 
    assets.addDragSupport(// 
    DND.DROP_MOVE, // 
    new Transfer[] { SecurityTransfer.getTransfer() }, new SecurityDragListener(assets));
    LocalResourceManager resources = new LocalResourceManager(JFaceResources.getResources(), assets.getTable());
    boldFont = resources.createFont(FontDescriptor.createFrom(assets.getTable().getFont()).setStyle(SWT.BOLD));
    return container;
}
Also used : SecuritySelection(name.abuchen.portfolio.ui.selection.SecuritySelection) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) NameColumn(name.abuchen.portfolio.ui.views.columns.NameColumn) NoteColumn(name.abuchen.portfolio.ui.views.columns.NoteColumn) MarkDirtyListener(name.abuchen.portfolio.ui.util.viewers.ColumnEditingSupport.MarkDirtyListener) ArrayList(java.util.ArrayList) Image(org.eclipse.swt.graphics.Image) Security(name.abuchen.portfolio.model.Security) Font(org.eclipse.swt.graphics.Font) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) NameColumnLabelProvider(name.abuchen.portfolio.ui.views.columns.NameColumn.NameColumnLabelProvider) Money(name.abuchen.portfolio.money.Money) ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) SecurityDragListener(name.abuchen.portfolio.ui.dnd.SecurityDragListener) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) ShowHideColumnHelper(name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper) NameColumn(name.abuchen.portfolio.ui.views.columns.NameColumn) TaxonomyColumn(name.abuchen.portfolio.ui.views.columns.TaxonomyColumn) AttributeColumn(name.abuchen.portfolio.ui.views.columns.AttributeColumn) NoteColumn(name.abuchen.portfolio.ui.views.columns.NoteColumn) IsinColumn(name.abuchen.portfolio.ui.views.columns.IsinColumn) Column(name.abuchen.portfolio.ui.util.viewers.Column) Named(name.abuchen.portfolio.model.Named) Composite(org.eclipse.swt.widgets.Composite) Color(org.eclipse.swt.graphics.Color) AttributeComparator(name.abuchen.portfolio.ui.util.AttributeComparator) TableViewer(org.eclipse.jface.viewers.TableViewer) IsinColumn(name.abuchen.portfolio.ui.views.columns.IsinColumn)

Example 2 with NameColumnLabelProvider

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

the class AccountListView method createTopTable.

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

        @Override
        public Color getForeground(Object e) {
            boolean isRetired = ((Account) e).isRetired();
            return isRetired ? Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY) : null;
        }
    });
    column.getEditingSupport().addListener(this);
    accountColumns.addColumn(column);
    column = new Column(Messages.ColumnBalance, SWT.RIGHT, 80);
    column.setDescription(Messages.ColumnBalance_Description);
    column.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object e) {
            return Values.Amount.format(((Account) e).getCurrentAmount(LocalDateTime.now().with(LocalTime.MAX)));
        }
    });
    ColumnViewerSorter.create(o -> ((Account) o).getCurrentAmount(LocalDateTime.now().with(LocalTime.MAX))).attachTo(column);
    accountColumns.addColumn(column);
    column = new CurrencyColumn();
    column.setEditingSupport(new CurrencyEditingSupport() {

        @Override
        public boolean canEdit(Object element) {
            return ((Account) element).getTransactions().isEmpty();
        }
    });
    accountColumns.addColumn(column);
    column = new NoteColumn();
    column.getEditingSupport().addListener(this);
    accountColumns.addColumn(column);
    accountColumns.createColumns();
    accounts.getTable().setHeaderVisible(true);
    accounts.getTable().setLinesVisible(true);
    accounts.setContentProvider(ArrayContentProvider.getInstance());
    resetInput();
    accounts.refresh();
    accounts.addSelectionChangedListener(event -> {
        Account account = (Account) ((IStructuredSelection) event.getSelection()).getFirstElement();
        updateOnAccountSelected(account);
        transactions.setData(Account.class.toString(), account);
        transactions.setInput(account != null ? account.getTransactions() : new ArrayList<AccountTransaction>(0));
        transactions.refresh();
    });
    hookContextMenu(accounts.getTable(), this::fillAccountsContextMenu);
}
Also used : NameColumn(name.abuchen.portfolio.ui.views.columns.NameColumn) Type(name.abuchen.portfolio.model.AccountTransaction.Type) Transaction(name.abuchen.portfolio.model.Transaction) TableViewer(org.eclipse.jface.viewers.TableViewer) CurrencyConverterImpl(name.abuchen.portfolio.money.CurrencyConverterImpl) ActionContributionItem(org.eclipse.jface.action.ActionContributionItem) AccountSnapshot(name.abuchen.portfolio.snapshot.AccountSnapshot) ToolBar(org.eclipse.swt.widgets.ToolBar) CurrencyColumn(name.abuchen.portfolio.ui.views.columns.CurrencyColumn) ModificationListener(name.abuchen.portfolio.ui.util.viewers.ColumnEditingSupport.ModificationListener) SecurityTransactionDialog(name.abuchen.portfolio.ui.dialogs.transactions.SecurityTransactionDialog) Composite(org.eclipse.swt.widgets.Composite) Map(java.util.Map) KeyEvent(org.eclipse.swt.events.KeyEvent) LocalTime(java.time.LocalTime) ColumnViewerToolTipSupport(org.eclipse.jface.viewers.ColumnViewerToolTipSupport) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Separator(org.eclipse.jface.action.Separator) Account(name.abuchen.portfolio.model.Account) CTabFolder(org.eclipse.swt.custom.CTabFolder) ExchangeRateProviderFactory(name.abuchen.portfolio.money.ExchangeRateProviderFactory) MenuManager(org.eclipse.jface.action.MenuManager) CurrencyEditingSupport(name.abuchen.portfolio.ui.views.columns.CurrencyColumn.CurrencyEditingSupport) Display(org.eclipse.swt.widgets.Display) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) PortfolioPart(name.abuchen.portfolio.ui.PortfolioPart) ColumnEditingSupport(name.abuchen.portfolio.ui.util.viewers.ColumnEditingSupport) DateTimeEditingSupport(name.abuchen.portfolio.ui.util.viewers.DateTimeEditingSupport) ShowHideColumnHelper(name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper) List(java.util.List) Colors(name.abuchen.portfolio.ui.util.Colors) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) LocalDate(java.time.LocalDate) SWT(org.eclipse.swt.SWT) AccountTransactionDialog(name.abuchen.portfolio.ui.dialogs.transactions.AccountTransactionDialog) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Money(name.abuchen.portfolio.money.Money) Values(name.abuchen.portfolio.money.Values) Quote(name.abuchen.portfolio.money.Quote) NoteColumn(name.abuchen.portfolio.ui.views.columns.NoteColumn) NameColumnLabelProvider(name.abuchen.portfolio.ui.views.columns.NameColumn.NameColumnLabelProvider) LocalDateTime(java.time.LocalDateTime) Images(name.abuchen.portfolio.ui.Images) Image(org.eclipse.swt.graphics.Image) HashMap(java.util.HashMap) ISeries(org.swtchart.ISeries) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Messages(name.abuchen.portfolio.ui.Messages) AccountTransferDialog(name.abuchen.portfolio.ui.dialogs.transactions.AccountTransferDialog) StringEditingSupport(name.abuchen.portfolio.ui.util.viewers.StringEditingSupport) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) AccountTransferEntry(name.abuchen.portfolio.model.AccountTransferEntry) ValueEditingSupport(name.abuchen.portfolio.ui.util.viewers.ValueEditingSupport) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) SimpleAction(name.abuchen.portfolio.ui.util.SimpleAction) Column(name.abuchen.portfolio.ui.util.viewers.Column) ColumnViewerSorter(name.abuchen.portfolio.ui.util.viewers.ColumnViewerSorter) Action(org.eclipse.jface.action.Action) MutableMoney(name.abuchen.portfolio.money.MutableMoney) TimelineChart(name.abuchen.portfolio.ui.util.chart.TimelineChart) AbstractDropDown(name.abuchen.portfolio.ui.util.AbstractDropDown) CTabItem(org.eclipse.swt.custom.CTabItem) SharesLabelProvider(name.abuchen.portfolio.ui.util.viewers.SharesLabelProvider) ChronoUnit(java.time.temporal.ChronoUnit) OpenDialogAction(name.abuchen.portfolio.ui.dialogs.transactions.OpenDialogAction) Color(org.eclipse.swt.graphics.Color) IMenuManager(org.eclipse.jface.action.IMenuManager) ToolTip(org.eclipse.jface.window.ToolTip) Collections(java.util.Collections) Control(org.eclipse.swt.widgets.Control) Account(name.abuchen.portfolio.model.Account) Composite(org.eclipse.swt.widgets.Composite) NameColumn(name.abuchen.portfolio.ui.views.columns.NameColumn) NoteColumn(name.abuchen.portfolio.ui.views.columns.NoteColumn) Color(org.eclipse.swt.graphics.Color) ArrayList(java.util.ArrayList) CurrencyEditingSupport(name.abuchen.portfolio.ui.views.columns.CurrencyColumn.CurrencyEditingSupport) CurrencyColumn(name.abuchen.portfolio.ui.views.columns.CurrencyColumn) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) NameColumnLabelProvider(name.abuchen.portfolio.ui.views.columns.NameColumn.NameColumnLabelProvider) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) NameColumn(name.abuchen.portfolio.ui.views.columns.NameColumn) CurrencyColumn(name.abuchen.portfolio.ui.views.columns.CurrencyColumn) NoteColumn(name.abuchen.portfolio.ui.views.columns.NoteColumn) Column(name.abuchen.portfolio.ui.util.viewers.Column) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 3 with NameColumnLabelProvider

use of name.abuchen.portfolio.ui.views.columns.NameColumn.NameColumnLabelProvider 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)3 NameColumn (name.abuchen.portfolio.ui.views.columns.NameColumn)3 NameColumnLabelProvider (name.abuchen.portfolio.ui.views.columns.NameColumn.NameColumnLabelProvider)3 NoteColumn (name.abuchen.portfolio.ui.views.columns.NoteColumn)3 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)3 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)3 TableViewer (org.eclipse.jface.viewers.TableViewer)3 Color (org.eclipse.swt.graphics.Color)3 Composite (org.eclipse.swt.widgets.Composite)3 ArrayList (java.util.ArrayList)2 CurrencyConverter (name.abuchen.portfolio.money.CurrencyConverter)2 CurrencyConverterImpl (name.abuchen.portfolio.money.CurrencyConverterImpl)2 Money (name.abuchen.portfolio.money.Money)2 LocalDate (java.time.LocalDate)1 LocalDateTime (java.time.LocalDateTime)1 LocalTime (java.time.LocalTime)1 ChronoUnit (java.time.temporal.ChronoUnit)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1