use of name.abuchen.portfolio.model.PortfolioTransaction 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.model.PortfolioTransaction in project portfolio by buchen.
the class PortfolioTransactionsViewer method fillTransactionsContextMenu.
private void fillTransactionsContextMenu(IMenuManager manager) {
if (portfolio == null)
return;
IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
PortfolioTransaction firstTransaction = (PortfolioTransaction) selection.getFirstElement();
if (firstTransaction != null && selection.size() == 1) {
Action editAction = createEditAction(firstTransaction);
editAction.setAccelerator(SWT.MOD1 | 'E');
manager.add(editAction);
manager.add(new Separator());
if (fullContextMenu && (firstTransaction.getType() == PortfolioTransaction.Type.BUY || firstTransaction.getType() == PortfolioTransaction.Type.SELL)) {
manager.add(new ConvertBuySellToDeliveryAction(owner.getClient(), new TransactionPair<>(portfolio, firstTransaction)));
manager.add(new Separator());
}
if (fullContextMenu && (firstTransaction.getType() == PortfolioTransaction.Type.DELIVERY_INBOUND || firstTransaction.getType() == PortfolioTransaction.Type.DELIVERY_OUTBOUND)) {
manager.add(new ConvertDeliveryToBuySellAction(owner.getClient(), new TransactionPair<>(portfolio, firstTransaction)));
manager.add(new Separator());
}
if (fullContextMenu)
new SecurityContextMenu(owner).menuAboutToShow(manager, firstTransaction.getSecurity(), portfolio);
else
manager.add(new BookmarkMenu(owner.getPart(), firstTransaction.getSecurity()));
} else if (firstTransaction == null) {
new SecurityContextMenu(owner).menuAboutToShow(manager, null, portfolio);
}
if (firstTransaction != null) {
manager.add(new Separator());
manager.add(new Action(Messages.MenuTransactionDelete) {
@Override
public void run() {
Object[] transactions = selection.toArray();
for (Object transaction : transactions) portfolio.deleteTransaction((PortfolioTransaction) transaction, owner.getClient());
owner.markDirty();
owner.notifyModelUpdated();
}
});
}
}
use of name.abuchen.portfolio.model.PortfolioTransaction in project portfolio by buchen.
the class PortfolioTransactionsViewer method onModified.
@Override
public void onModified(Object element, Object newValue, Object oldValue) {
PortfolioTransaction t = (PortfolioTransaction) element;
if (t.getCrossEntry() != null)
t.getCrossEntry().updateFrom(t);
owner.markDirty();
owner.notifyModelUpdated();
}
use of name.abuchen.portfolio.model.PortfolioTransaction in project portfolio by buchen.
the class PortfolioTransactionsViewer method addColumns.
private void addColumns() {
Column column = new Column(Messages.ColumnDate, SWT.None, 100);
column.setLabelProvider(new TransactionLabelProvider() {
@Override
public String getText(Object element) {
return Values.DateTime.format(((PortfolioTransaction) element).getDateTime());
}
});
// $NON-NLS-1$
ColumnViewerSorter.create(PortfolioTransaction.class, "dateTime").attachTo(column, SWT.DOWN);
// $NON-NLS-1$
new DateTimeEditingSupport(PortfolioTransaction.class, "dateTime").addListener(this).attachTo(column);
support.addColumn(column);
column = new Column(Messages.ColumnTransactionType, SWT.None, 80);
column.setLabelProvider(new TransactionLabelProvider() {
@Override
public String getText(Object element) {
return ((PortfolioTransaction) element).getType().toString();
}
});
// $NON-NLS-1$
ColumnViewerSorter.create(PortfolioTransaction.class, "type").attachTo(column);
support.addColumn(column);
column = new Column(Messages.ColumnSecurity, SWT.None, 250);
column.setLabelProvider(new TransactionLabelProvider() {
@Override
public String getText(Object element) {
PortfolioTransaction t = (PortfolioTransaction) element;
return t.getSecurity() != null ? String.valueOf(t.getSecurity()) : null;
}
});
// $NON-NLS-1$
ColumnViewerSorter.create(PortfolioTransaction.class, "security").attachTo(column);
support.addColumn(column);
column = new Column(Messages.ColumnShares, SWT.RIGHT, 80);
column.setLabelProvider(new SharesLabelProvider() {
private TransactionLabelProvider colors = new TransactionLabelProvider();
@Override
public Long getValue(Object element) {
return ((PortfolioTransaction) element).getShares();
}
@Override
public Color getForeground(Object element) {
return colors.getForeground(element);
}
@Override
public Color getBackground(Object element) {
return colors.getBackground(element);
}
});
// $NON-NLS-1$
ColumnViewerSorter.create(PortfolioTransaction.class, "shares").attachTo(column);
// $NON-NLS-1$
new ValueEditingSupport(PortfolioTransaction.class, "shares", Values.Share).addListener(this).attachTo(column);
support.addColumn(column);
column = new Column(Messages.ColumnQuote, SWT.RIGHT, 80);
column.setLabelProvider(new TransactionLabelProvider() {
@Override
public String getText(Object element) {
PortfolioTransaction t = (PortfolioTransaction) element;
return t.getShares() != 0 ? Values.Quote.format(t.getGrossPricePerShare(), owner.getClient().getBaseCurrency()) : null;
}
});
// $NON-NLS-1$
ColumnViewerSorter.create(PortfolioTransaction.class, "grossPricePerShare").attachTo(column);
support.addColumn(column);
column = new Column(Messages.ColumnAmount, SWT.RIGHT, 80);
column.setLabelProvider(new TransactionLabelProvider() {
@Override
public String getText(Object element) {
return Values.Money.format(((PortfolioTransaction) element).getGrossValue(), owner.getClient().getBaseCurrency());
}
});
// $NON-NLS-1$
ColumnViewerSorter.create(PortfolioTransaction.class, "grossValueAmount").attachTo(column);
support.addColumn(column);
column = new Column(Messages.ColumnFees, SWT.RIGHT, 80);
column.setLabelProvider(new TransactionLabelProvider() {
@Override
public String getText(Object element) {
PortfolioTransaction t = (PortfolioTransaction) element;
return Values.Money.format(t.getUnitSum(Transaction.Unit.Type.FEE), owner.getClient().getBaseCurrency());
}
});
support.addColumn(column);
column = new Column(Messages.ColumnTaxes, SWT.RIGHT, 80);
column.setLabelProvider(new TransactionLabelProvider() {
@Override
public String getText(Object element) {
PortfolioTransaction t = (PortfolioTransaction) element;
return Values.Money.format(t.getUnitSum(Transaction.Unit.Type.TAX), owner.getClient().getBaseCurrency());
}
});
support.addColumn(column);
column = new Column(Messages.ColumnNetValue, SWT.RIGHT, 80);
column.setLabelProvider(new TransactionLabelProvider() {
@Override
public String getText(Object element) {
PortfolioTransaction t = (PortfolioTransaction) element;
return Values.Money.format(t.getMonetaryAmount(), owner.getClient().getBaseCurrency());
}
});
// $NON-NLS-1$
ColumnViewerSorter.create(PortfolioTransaction.class, "amount").attachTo(column);
support.addColumn(column);
column = new Column(Messages.ColumnOffsetAccount, SWT.None, 120);
column.setLabelProvider(new TransactionLabelProvider() {
@Override
public String getText(Object e) {
PortfolioTransaction t = (PortfolioTransaction) e;
return t.getCrossEntry() != null ? t.getCrossEntry().getCrossOwner(t).toString() : null;
}
});
support.addColumn(column);
column = new Column(Messages.ColumnNote, SWT.None, 200);
column.setLabelProvider(new TransactionLabelProvider() {
@Override
public String getText(Object e) {
return ((PortfolioTransaction) e).getNote();
}
@Override
public Image getImage(Object e) {
String note = ((PortfolioTransaction) e).getNote();
return note != null && note.length() > 0 ? Images.NOTE.image() : null;
}
});
// $NON-NLS-1$
ColumnViewerSorter.create(PortfolioTransaction.class, "note").attachTo(column);
// $NON-NLS-1$
new StringEditingSupport(PortfolioTransaction.class, "note").addListener(this).attachTo(column);
support.addColumn(column);
}
use of name.abuchen.portfolio.model.PortfolioTransaction in project portfolio by buchen.
the class ConvertBuySellToDeliveryAction method run.
@Override
public void run() {
// delete existing transaction
PortfolioTransaction buySellTransaction = transaction.getTransaction();
transaction.getOwner().deleteTransaction(buySellTransaction, client);
// create new delivery
PortfolioTransaction delivery = new PortfolioTransaction();
delivery.setType(buySellTransaction.getType() == PortfolioTransaction.Type.BUY ? PortfolioTransaction.Type.DELIVERY_INBOUND : PortfolioTransaction.Type.DELIVERY_OUTBOUND);
delivery.setDateTime(buySellTransaction.getDateTime());
delivery.setMonetaryAmount(buySellTransaction.getMonetaryAmount());
delivery.setSecurity(buySellTransaction.getSecurity());
delivery.setNote(buySellTransaction.getNote());
delivery.setShares(buySellTransaction.getShares());
buySellTransaction.getUnits().forEach(delivery::addUnit);
transaction.getOwner().addTransaction(delivery);
client.markDirty();
}
Aggregations