transactionsColumns = new ShowHideColumnHelper(AccountListView.class.getSimpleName() + "@bottom5", //$NON-NLS-1$
getPreferenceStore(), transactions, layout);
Column column = new Column(Messages.ColumnDate, SWT.None, 80);
column.setLabelProvider(new ColumnLabelProvider()
{
@Override
public String getText(Object e)
{
AccountTransaction t = (AccountTransaction) e;
return Values.Date.format(t.getDate());
}
@Override
public Color getForeground(Object element)
{
return colorFor((AccountTransaction) element);
}
});
ColumnViewerSorter.create(AccountTransaction.class, "date").attachTo(column, SWT.DOWN); //$NON-NLS-1$
new DateEditingSupport(AccountTransaction.class, "date").addListener(this).attachTo(column); //$NON-NLS-1$
transactionsColumns.addColumn(column);
column = new Column(Messages.ColumnTransactionType, SWT.None, 100);
column.setLabelProvider(new ColumnLabelProvider()
{
@Override
public String getText(Object e)
{
AccountTransaction t = (AccountTransaction) e;
return t.getType().toString();
}
@Override
public Color getForeground(Object element)
{
return colorFor((AccountTransaction) element);
}
});
column.setSorter(ColumnViewerSorter.create(AccountTransaction.class, "type")); //$NON-NLS-1$
transactionsColumns.addColumn(column);
column = new Column(Messages.ColumnAmount, SWT.RIGHT, 80);
column.setLabelProvider(new ColumnLabelProvider()
{
@Override
public String getText(Object e)
{
AccountTransaction t = (AccountTransaction) e;
long v = t.getAmount();
if (EnumSet.of(Type.REMOVAL, Type.FEES, Type.TAXES, Type.BUY, Type.TRANSFER_OUT).contains(t.getType()))
v = -v;
return Values.Amount.format(v);
}
@Override
public Color getForeground(Object element)
{
return colorFor((AccountTransaction) element);
}
});
column.setSorter(ColumnViewerSorter.create(AccountTransaction.class, "amount")); //$NON-NLS-1$
new ValueEditingSupport(AccountTransaction.class, "amount", Values.Amount).addListener(this).attachTo(column); //$NON-NLS-1$
transactionsColumns.addColumn(column);
column = new Column(Messages.ColumnSecurity, SWT.None, 250);
column.setLabelProvider(new ColumnLabelProvider()
{
@Override
public String getText(Object e)
{
AccountTransaction t = (AccountTransaction) e;
return t.getSecurity() != null ? String.valueOf(t.getSecurity()) : null;
}
@Override
public Color getForeground(Object element)
{
return colorFor((AccountTransaction) element);
}
});
column.setSorter(ColumnViewerSorter.create(AccountTransaction.class, "security")); //$NON-NLS-1$
List<Security> securities = new ArrayList<Security>(getClient().getSecurities());
Collections.sort(securities, new Security.ByName());
new ListEditingSupport(AccountTransaction.class, "security", securities) //$NON-NLS-1$
{
@Override
public boolean canEdit(Object element)
{
AccountTransaction t = (AccountTransaction) element;
return t.getType() == AccountTransaction.Type.BUY //
|| t.getType() == AccountTransaction.Type.SELL //
|| t.getType() == AccountTransaction.Type.DIVIDENDS;
}
}.addListener(this).attachTo(column);
transactionsColumns.addColumn(column);
column = new Column(Messages.ColumnShares, SWT.RIGHT, 80);
column.setLabelProvider(new SharesLabelProvider()
{
@Override
public Long getValue(Object e)
{
AccountTransaction t = (AccountTransaction) e;
if (t.getCrossEntry() instanceof BuySellEntry)
{
return ((BuySellEntry) t.getCrossEntry()).getPortfolioTransaction().getShares();
}
else if (t.getType() == Type.DIVIDENDS && t.getShares() != 0)
{
return t.getShares();
}
else
{
return null;
}
}
@Override
public Color getForeground(Object element)
{
return colorFor((AccountTransaction) element);
}
});
new ValueEditingSupport(AccountTransaction.class, "shares", Values.Share) //$NON-NLS-1$
{
@Override
public boolean canEdit(Object element)
{
AccountTransaction t = (AccountTransaction) element;
return t.getType() == AccountTransaction.Type.DIVIDENDS;
}
}.addListener(this).attachTo(column);
transactionsColumns.addColumn(column);
column = new Column(Messages.ColumnPurchasePrice, SWT.RIGHT, 80);
column.setLabelProvider(new ColumnLabelProvider()
{
@Override
public String getText(Object e)
{
AccountTransaction t = (AccountTransaction) e;
if (t.getCrossEntry() instanceof BuySellEntry)
{
PortfolioTransaction portfolioTransaction = ((BuySellEntry) t.getCrossEntry())
.getPortfolioTransaction();
return Values.Amount.format(portfolioTransaction.getActualPurchasePrice());
}
else if (t.getType() == Type.DIVIDENDS && t.getShares() != 0)
{
return Values.Amount.format(Math.round(t.getAmount() * Values.Share.divider() / t.getShares()));
}
else
{
return null;
}
}
@Override
public Color getForeground(Object element)
{
return colorFor((AccountTransaction) element);
}
});
transactionsColumns.addColumn(column);
column = new Column(Messages.ColumnOffsetAccount, SWT.None, 120);
column.setLabelProvider(new ColumnLabelProvider()
{
@Override
public String getText(Object e)
{
AccountTransaction t = (AccountTransaction) e;
return t.getCrossEntry() != null ? t.getCrossEntry().getCrossEntity(t).toString() : null;
}
@Override
public Color getForeground(Object element)
{
return colorFor((AccountTransaction) element);
}
});
transactionsColumns.addColumn(column);
column = new Column(Messages.ColumnNote, SWT.None, 200);
column.setLabelProvider(new ColumnLabelProvider()
{
@Override
public String getText(Object e)
{
return ((AccountTransaction) e).getNote();