use of name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper in project portfolio by buchen.
the class SecuritiesPerformanceView method createBottomTable.
@Override
protected // NOSONAR
void createBottomTable(// NOSONAR
Composite parent) {
Composite sash = new Composite(parent, SWT.NONE);
sash.setLayout(new SashLayout(sash, SWT.HORIZONTAL | SWT.END));
// folder
CTabFolder folder = new CTabFolder(sash, SWT.BORDER);
CTabItem item = new CTabItem(folder, SWT.NONE);
item.setText(Messages.SecurityTabChart);
Composite chartComposite = new Composite(folder, SWT.NONE);
GridLayoutFactory.fillDefaults().numColumns(2).spacing(0, 0).applyTo(chartComposite);
item.setControl(chartComposite);
chart = new SecuritiesChart(chartComposite, getClient(), new CurrencyConverterImpl(factory, getClient().getBaseCurrency()));
latest = new SecurityDetailsViewer(sash, SWT.BORDER, getClient());
latest.getControl().setLayoutData(new SashLayoutData(SWTHelper.getPackedWidth(latest.getControl())));
item = new CTabItem(folder, SWT.NONE);
item.setText(Messages.SecurityTabTransactions);
Composite container = new Composite(folder, SWT.NONE);
item.setControl(container);
TableColumnLayout layout = new TableColumnLayout();
container.setLayout(layout);
folder.setSelection(0);
transactions = new TableViewer(container, SWT.FULL_SELECTION);
ShowHideColumnHelper support = new ShowHideColumnHelper(// $NON-NLS-1$
SecuritiesPerformanceView.class.getSimpleName() + "@bottom4", // $NON-NLS-1$
getPreferenceStore(), transactions, layout);
// date
Column column = new Column(Messages.ColumnDate, SWT.None, 80);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object e) {
Transaction t = (Transaction) e;
return Values.DateTime.format(t.getDateTime());
}
});
// $NON-NLS-1$
column.setSorter(ColumnViewerSorter.create(Transaction.class, "dateTime"), SWT.DOWN);
support.addColumn(column);
// transaction type
column = new Column(Messages.ColumnTransactionType, SWT.None, 80);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object t) {
if (t instanceof PortfolioTransaction)
return ((PortfolioTransaction) t).getType().toString();
else if (t instanceof AccountTransaction)
return ((AccountTransaction) t).getType().toString();
else if (t instanceof DividendTransaction)
return AccountTransaction.Type.DIVIDENDS.toString();
else
return Messages.LabelQuote;
}
});
support.addColumn(column);
// shares
column = new Column(Messages.ColumnShares, SWT.None, 80);
column.setLabelProvider(new // NOSONAR
SharesLabelProvider() {
@Override
public // NOSONAR
Long getValue(// NOSONAR
Object t) {
if (t instanceof PortfolioTransaction)
return ((PortfolioTransaction) t).getShares();
else if (t instanceof DividendInitialTransaction)
return ((DividendInitialTransaction) t).getPosition().getShares();
else if (t instanceof DividendFinalTransaction)
return ((DividendFinalTransaction) t).getPosition().getShares();
else if (t instanceof DividendTransaction)
return ((DividendTransaction) t).getShares() != 0L ? ((DividendTransaction) t).getShares() : null;
else
return null;
}
});
support.addColumn(column);
// dividend amount
column = new Column(Messages.ColumnDividendPayment, SWT.RIGHT, 80);
column.setDescription(Messages.ColumnGrossDividend);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object t) {
if (t instanceof DividendTransaction)
return Values.Money.format(((DividendTransaction) t).getGrossValue(), getClient().getBaseCurrency());
else
return null;
}
});
support.addColumn(column);
// dividend per share
column = new Column(Messages.ColumnDividendPerShare, SWT.RIGHT, 80);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object t) {
if (t instanceof DividendTransaction)
return Values.AmountFraction.formatNonZero(((DividendTransaction) t).getDividendPerShare());
else
return null;
}
});
support.addColumn(column);
// dividend per share
column = new Column(Messages.ColumnPersonalDividendYield, SWT.RIGHT, 80);
column.setDescription(Messages.ColumnPersonalDividendYield_Description);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object t) {
if (t instanceof DividendTransaction)
return Values.Percent2.formatNonZero(((DividendTransaction) t).getPersonalDividendYield());
else
return null;
}
});
support.addColumn(column);
// dividend per share (moving average)
column = new Column(Messages.ColumnPersonalDividendYieldMovingAverage, SWT.RIGHT, 80);
column.setDescription(Messages.ColumnPersonalDividendYieldMovingAverage_Description);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object t) {
if (t instanceof DividendTransaction)
return Values.Percent2.formatNonZero(((DividendTransaction) t).getPersonalDividendYieldMovingAverage());
else
return null;
}
});
support.addColumn(column);
// einstandskurs / bewertung
column = new Column(Messages.ColumnAmount, SWT.RIGHT, 80);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object t) {
if (t instanceof DividendTransaction)
return null;
else
return Values.Money.format(((Transaction) t).getMonetaryAmount(), getClient().getBaseCurrency());
}
});
support.addColumn(column);
// purchase quote
column = new Column(Messages.ColumnQuote, SWT.RIGHT, 80);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object t) {
if (t instanceof PortfolioTransaction) {
PortfolioTransaction p = (PortfolioTransaction) t;
return Values.Quote.format(p.getGrossPricePerShare(), getClient().getBaseCurrency());
} else
return null;
}
});
support.addColumn(column);
// gegenkonto
column = new Column(Messages.ColumnAccount, SWT.None, 120);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object t) {
if (t instanceof PortfolioTransaction) {
PortfolioTransaction p = (PortfolioTransaction) t;
return p.getCrossEntry() != null ? p.getCrossEntry().getCrossOwner(p).toString() : null;
} else if (t instanceof DividendTransaction) {
return ((DividendTransaction) t).getAccount().getName();
} else {
return null;
}
}
});
support.addColumn(column);
// note
// $NON-NLS-1$
column = new Column("note", Messages.ColumnNote, SWT.LEFT, 22);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object r) {
return ((Transaction) r).getNote();
}
@Override
public Image getImage(Object r) {
String note = ((Transaction) r).getNote();
return note != null && note.length() > 0 ? Images.NOTE.image() : null;
}
});
// $NON-NLS-1$
column.setSorter(ColumnViewerSorter.create(Transaction.class, "note"));
support.addColumn(column);
support.createColumns();
transactions.getTable().setHeaderVisible(true);
transactions.getTable().setLinesVisible(true);
transactions.setContentProvider(ArrayContentProvider.getInstance());
}
use of name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper in project portfolio by buchen.
the class SecuritiesPerformanceView method createTopTable.
@Override
protected void createTopTable(Composite parent) {
Composite container = new Composite(parent, SWT.NONE);
TableColumnLayout layout = new TableColumnLayout();
container.setLayout(layout);
records = new TableViewer(container, SWT.FULL_SELECTION);
recordColumns = new ShowHideColumnHelper(SecuritiesPerformanceView.class.getName(), getClient(), getPreferenceStore(), records, layout);
updateTitle(getDefaultTitle());
recordColumns.addListener(() -> updateTitle(getDefaultTitle()));
ColumnViewerToolTipSupport.enableFor(records, ToolTip.NO_RECREATE);
ColumnEditingSupport.prepare(records);
createCommonColumns();
createDividendColumns();
addPerformanceColumns();
createRiskColumns();
createAdditionalColumns();
recordColumns.createColumns();
records.getTable().setHeaderVisible(true);
records.getTable().setLinesVisible(true);
records.setContentProvider(ArrayContentProvider.getInstance());
//
records.addDragSupport(//
DND.DROP_MOVE, //
new Transfer[] { SecurityTransfer.getTransfer() }, new SecurityDragListener(records));
hookContextMenu(records.getTable(), this::fillContextMenu);
records.addSelectionChangedListener(new // NOSONAR
ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
SecurityPerformanceRecord record = (SecurityPerformanceRecord) ((IStructuredSelection) event.getSelection()).getFirstElement();
Security security = null;
List<Transaction> transactionList = null;
if (record != null) {
transactionList = record.getTransactions();
security = record.getSecurity();
}
transactions.setInput(transactionList);
transactions.refresh();
chart.updateChart(security);
latest.setInput(security);
}
});
records.addSelectionChangedListener(event -> {
SecurityPerformanceRecord record = (SecurityPerformanceRecord) ((IStructuredSelection) event.getSelection()).getFirstElement();
if (record != null)
selectionService.setSelection(new SecuritySelection(getClient(), record.getSecurity()));
});
records.addFilter(new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (recordFilter.isEmpty())
return true;
for (Predicate<SecurityPerformanceRecord> predicate : recordFilter) {
if (!predicate.test((SecurityPerformanceRecord) element))
return false;
}
return true;
}
});
reportingPeriodUpdated();
}
use of name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper in project portfolio by buchen.
the class SecurityListView method createPricesTable.
// //////////////////////////////////////////////////////////////
// tab item: prices
// //////////////////////////////////////////////////////////////
protected Composite createPricesTable(Composite parent) {
Composite container = new Composite(parent, SWT.NONE);
TableColumnLayout layout = new TableColumnLayout();
container.setLayout(layout);
prices = new TableViewer(container, SWT.FULL_SELECTION | SWT.MULTI);
ColumnEditingSupport.prepare(prices);
ShowHideColumnHelper support = new // $NON-NLS-1$
ShowHideColumnHelper(// $NON-NLS-1$
SecurityListView.class.getSimpleName() + "@prices", getPreferenceStore(), prices, layout);
Column column = new Column(Messages.ColumnDate, SWT.None, 80);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return Values.Date.format(((SecurityPrice) element).getDate());
}
@Override
public Color getBackground(Object element) {
SecurityPrice current = (SecurityPrice) element;
List<?> all = (List<?>) prices.getInput();
int index = all.indexOf(current);
if (index == 0)
return null;
SecurityPrice previous = (SecurityPrice) all.get(index - 1);
int days = Dates.daysBetween(previous.getDate(), current.getDate());
return days > 3 ? Colors.WARNING : null;
}
});
// $NON-NLS-1$
ColumnViewerSorter.create(SecurityPrice.class, "date").attachTo(column, SWT.UP);
// $NON-NLS-1$
new DateEditingSupport(SecurityPrice.class, "date").addListener(this).attachTo(column);
support.addColumn(column);
column = new Column(Messages.ColumnQuote, SWT.RIGHT, 80);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
Security security = (Security) prices.getData(Security.class.toString());
SecurityPrice price = (SecurityPrice) element;
return Values.Quote.format(security.getCurrencyCode(), price.getValue(), getClient().getBaseCurrency());
}
});
// $NON-NLS-1$
ColumnViewerSorter.create(SecurityPrice.class, "value").attachTo(column);
// $NON-NLS-1$
new ValueEditingSupport(SecurityPrice.class, "value", Values.Quote).addListener(this).attachTo(column);
support.addColumn(column);
support.createColumns();
prices.getTable().setHeaderVisible(true);
prices.getTable().setLinesVisible(true);
prices.setContentProvider(ArrayContentProvider.getInstance());
hookContextMenu(prices.getTable(), this::fillPricesContextMenu);
return container;
}
use of name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper in project portfolio by buchen.
the class PerformanceView method createTransactionViewer.
private TableViewer createTransactionViewer(CTabFolder folder, String title) {
Composite container = new Composite(folder, SWT.NONE);
TableColumnLayout layout = new TableColumnLayout();
container.setLayout(layout);
TableViewer transactionViewer = new TableViewer(container, SWT.FULL_SELECTION);
transactionViewer.addSelectionChangedListener(event -> {
TransactionPair<?> tx = ((TransactionPair<?>) ((IStructuredSelection) event.getSelection()).getFirstElement());
if (tx != null && tx.getTransaction().getSecurity() != null)
selectionService.setSelection(new SecuritySelection(getClient(), tx.getTransaction().getSecurity()));
});
ShowHideColumnHelper support = new // $NON-NLS-1$
ShowHideColumnHelper(// $NON-NLS-1$
PerformanceView.class.getSimpleName() + "@2" + title, getPreferenceStore(), transactionViewer, layout);
Column column = new Column(Messages.ColumnDate, SWT.None, 100);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return Values.DateTime.format(((TransactionPair<?>) element).getTransaction().getDateTime());
}
});
column.setSorter(ColumnViewerSorter.create(e -> ((TransactionPair<?>) e).getTransaction().getDateTime()), SWT.UP);
support.addColumn(column);
column = new Column(Messages.ColumnTransactionType, SWT.LEFT, 100);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
Transaction t = ((TransactionPair<?>) element).getTransaction();
return t instanceof AccountTransaction ? ((AccountTransaction) t).getType().toString() : ((PortfolioTransaction) t).getType().toString();
}
});
column.setSorter(ColumnViewerSorter.create(e -> {
Transaction t = ((TransactionPair<?>) e).getTransaction();
return t instanceof AccountTransaction ? ((AccountTransaction) t).getType().toString() : ((PortfolioTransaction) t).getType().toString();
}));
support.addColumn(column);
column = new Column(Messages.ColumnAmount, SWT.RIGHT, 80);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
return Values.Money.format(((TransactionPair<?>) element).getTransaction().getMonetaryAmount(), getClient().getBaseCurrency());
}
});
column.setSorter(ColumnViewerSorter.create(e -> ((TransactionPair<?>) e).getTransaction().getMonetaryAmount()));
support.addColumn(column);
addTaxesColumn(support);
addFeesColumn(support);
addSecurityColumn(support);
addPortfolioColumn(support);
addAccountColumn(support);
column = new NoteColumn();
column.setEditingSupport(null);
support.addColumn(column);
support.createColumns();
transactionViewer.getTable().setHeaderVisible(true);
transactionViewer.getTable().setLinesVisible(true);
transactionViewer.setContentProvider(ArrayContentProvider.getInstance());
CTabItem item = new CTabItem(folder, SWT.NONE);
item.setText(title);
item.setControl(container);
return transactionViewer;
}
use of name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper in project portfolio by buchen.
the class PerformanceView method addAccountColumn.
private void addAccountColumn(ShowHideColumnHelper support) {
Column column = new Column(Messages.ColumnAccount, SWT.LEFT, 100);
Function<Object, Account> getAccount = element -> {
TransactionPair<?> pair = (TransactionPair<?>) element;
if (pair.getOwner() instanceof Account)
return (Account) pair.getOwner();
CrossEntry crossEntry = pair.getTransaction().getCrossEntry();
if (crossEntry == null)
return null;
TransactionOwner<?> other = crossEntry.getCrossOwner(pair.getTransaction());
return other instanceof Account ? ((Account) other) : null;
};
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
Account account = getAccount.apply(element);
return account != null ? account.getName() : null;
}
@Override
public Image getImage(Object element) {
Account account = getAccount.apply(element);
return account != null ? Images.ACCOUNT.image() : null;
}
});
column.setSorter(ColumnViewerSorter.create(e -> {
Account account = getAccount.apply(e);
return account != null ? account.getName() : null;
}));
support.addColumn(column);
}
Aggregations