use of name.abuchen.portfolio.model.Account in project portfolio by buchen.
the class InvestmentPlanListView method addColumns.
private void addColumns(ShowHideColumnHelper support) {
// $NON-NLS-1$
Column column = new NameColumn("0", Messages.ColumnName, SWT.None, 100);
column.getEditingSupport().addListener(this);
support.addColumn(column);
column = new Column(Messages.ColumnSecurity, SWT.NONE, 250);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object e) {
return ((InvestmentPlan) e).getSecurity().getName();
}
@Override
public Image getImage(Object element) {
return Images.SECURITY.image();
}
});
// $NON-NLS-1$
ColumnViewerSorter.create(Security.class, "name").attachTo(column);
List<Security> securities = new ArrayList<>(getClient().getSecurities());
Collections.sort(securities, new Security.ByName());
// $NON-NLS-1$
new ListEditingSupport(InvestmentPlan.class, "security", securities).addListener(this).attachTo(column);
support.addColumn(column);
column = new Column(Messages.ColumnPortfolio, SWT.None, 120);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object e) {
return ((InvestmentPlan) e).getPortfolio().getName();
}
@Override
public Image getImage(Object element) {
return Images.PORTFOLIO.image();
}
});
// $NON-NLS-1$
ColumnViewerSorter.create(InvestmentPlan.class, "portfolio").attachTo(column);
// $NON-NLS-1$
new ListEditingSupport(InvestmentPlan.class, "portfolio", getClient().getActivePortfolios()).addListener(this).attachTo(column);
support.addColumn(column);
column = new Column(Messages.ColumnAccount, SWT.None, 120);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object e) {
InvestmentPlan plan = (InvestmentPlan) e;
return plan.getAccount() != null ? plan.getAccount().getName() : Messages.InvestmentPlanOptionDelivery;
}
@Override
public Image getImage(Object e) {
InvestmentPlan plan = (InvestmentPlan) e;
return plan.getAccount() != null ? Images.ACCOUNT.image() : null;
}
});
// $NON-NLS-1$
ColumnViewerSorter.create(Account.class, "name").attachTo(column);
List<Account> accounts = new ArrayList<>();
accounts.add(InvestmentPlanModel.DELIVERY);
accounts.addAll(getClient().getAccounts());
// $NON-NLS-1$
new ListEditingSupport(InvestmentPlan.class, "account", accounts).addListener(this).attachTo(column);
support.addColumn(column);
column = new Column(Messages.ColumnStartDate, SWT.None, 80);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object e) {
return Values.Date.format(((InvestmentPlan) e).getStart());
}
});
// $NON-NLS-1$
ColumnViewerSorter.create(InvestmentPlan.class, "start").attachTo(column);
// $NON-NLS-1$
new DateEditingSupport(InvestmentPlan.class, "start").addListener(this).attachTo(column);
support.addColumn(column);
column = new Column(Messages.ColumnInterval, SWT.None, 80);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object e) {
return MessageFormat.format(Messages.InvestmentPlanIntervalLabel, ((InvestmentPlan) e).getInterval());
}
});
// $NON-NLS-1$
ColumnViewerSorter.create(InvestmentPlan.class, "interval").attachTo(column);
List<Integer> available = new ArrayList<>();
for (int ii = 1; ii <= 12; ii++) available.add(ii);
// $NON-NLS-1$
new ListEditingSupport(InvestmentPlan.class, "interval", available).addListener(this).attachTo(column);
support.addColumn(column);
column = new Column(Messages.ColumnAmount, SWT.RIGHT, 80);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object e) {
InvestmentPlan plan = (InvestmentPlan) e;
return Values.Money.format(Money.of(plan.getCurrencyCode(), plan.getAmount()));
}
});
// $NON-NLS-1$
ColumnViewerSorter.create(InvestmentPlan.class, "amount").attachTo(column);
// $NON-NLS-1$
new ValueEditingSupport(InvestmentPlan.class, "amount", Values.Amount).addListener(this).attachTo(column);
support.addColumn(column);
column = new Column(Messages.ColumnFees, SWT.RIGHT, 80);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object e) {
InvestmentPlan plan = (InvestmentPlan) e;
return Values.Money.format(Money.of(plan.getCurrencyCode(), plan.getFees()));
}
});
// $NON-NLS-1$
ColumnViewerSorter.create(InvestmentPlan.class, "fees").attachTo(column);
// $NON-NLS-1$
new ValueEditingSupport(InvestmentPlan.class, "fees", Values.Amount).addListener(this).attachTo(column);
support.addColumn(column);
column = new Column(Messages.ColumnAutoGenerate, SWT.LEFT, 80);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object e) {
// $NON-NLS-1$
return "";
}
@Override
public Image getImage(Object e) {
return ((InvestmentPlan) e).isAutoGenerate() ? Images.CHECK.image() : null;
}
});
// $NON-NLS-1$
ColumnViewerSorter.create(InvestmentPlan.class, "autoGenerate").attachTo(column);
// $NON-NLS-1$
new BooleanEditingSupport(InvestmentPlan.class, "autoGenerate").addListener(this).attachTo(column);
support.addColumn(column);
column = new NoteColumn();
column.getEditingSupport().addListener(this);
column.setVisible(false);
support.addColumn(column);
}
use of name.abuchen.portfolio.model.Account 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);
}
use of name.abuchen.portfolio.model.Account in project portfolio by buchen.
the class AccountListView method addNewButton.
private void addNewButton(ToolBar toolBar) {
SimpleAction.Runnable newAccountAction = a -> {
Account account = new Account();
account.setName(Messages.LabelNoName);
account.setCurrencyCode(getClient().getBaseCurrency());
getClient().addAccount(account);
markDirty();
resetInput();
accounts.editElement(account, 0);
};
AbstractDropDown.create(toolBar, Messages.MenuCreateAccountOrTransaction, Images.PLUS.image(), SWT.NONE, (dd, manager) -> {
manager.add(new SimpleAction(Messages.AccountMenuAdd, newAccountAction));
manager.add(new Separator());
Account account = (Account) accounts.getStructuredSelection().getFirstElement();
new AccountContextMenu(AccountListView.this).menuAboutToShow(manager, account, null);
});
}
use of name.abuchen.portfolio.model.Account in project portfolio by buchen.
the class AccountListView method fillTransactionsContextMenu.
private // NOSONAR
void fillTransactionsContextMenu(// NOSONAR
IMenuManager manager) {
Account account = (Account) transactions.getData(Account.class.toString());
if (account == null)
return;
AccountTransaction transaction = (AccountTransaction) ((IStructuredSelection) transactions.getSelection()).getFirstElement();
if (transaction != null) {
Action action = createEditAction(account, transaction);
action.setAccelerator(SWT.MOD1 | 'E');
manager.add(action);
manager.add(new Separator());
}
accountMenu.menuAboutToShow(manager, account, transaction != null ? transaction.getSecurity() : null);
if (transaction != null) {
manager.add(new Separator());
manager.add(new Action(Messages.AccountMenuDeleteTransaction) {
@Override
public void run() {
Object[] selection = ((IStructuredSelection) transactions.getSelection()).toArray();
Account account = (Account) transactions.getData(Account.class.toString());
if (selection == null || selection.length == 0 || account == null)
return;
for (Object transaction : selection) account.deleteTransaction((AccountTransaction) transaction, getClient());
markDirty();
transaction2balance.clear();
updateBalance(account);
accounts.refresh();
transactions.setInput(account.getTransactions());
}
});
}
}
use of name.abuchen.portfolio.model.Account in project portfolio by buchen.
the class AccountListView method notifyModelUpdated.
@Override
public void notifyModelUpdated() {
resetInput();
Account account = (Account) ((IStructuredSelection) accounts.getSelection()).getFirstElement();
if (getClient().getAccounts().contains(account))
accounts.setSelection(new StructuredSelection(account));
else
accounts.setSelection(StructuredSelection.EMPTY);
}
Aggregations