use of name.abuchen.portfolio.model.InvestmentPlan in project portfolio by buchen.
the class InvestmentPlanListView method onModified.
@Override
public void onModified(Object element, Object newValue, Object oldValue) {
InvestmentPlan plan = (InvestmentPlan) element;
if (plan.getAccount() != null && plan.getAccount().equals(InvestmentPlanModel.DELIVERY))
plan.setAccount(null);
markDirty();
}
use of name.abuchen.portfolio.model.InvestmentPlan in project portfolio by buchen.
the class InvestmentPlanListView method createTopTable.
@Override
protected void createTopTable(Composite parent) {
Composite container = new Composite(parent, SWT.NONE);
TableColumnLayout layout = new TableColumnLayout();
container.setLayout(layout);
plans = new TableViewer(container, SWT.FULL_SELECTION);
ColumnEditingSupport.prepare(plans);
planColumns = new // $NON-NLS-1$
ShowHideColumnHelper(// $NON-NLS-1$
InvestmentPlanListView.class.getSimpleName() + "@top", getPreferenceStore(), plans, layout);
addColumns(planColumns);
planColumns.createColumns();
plans.getTable().setHeaderVisible(true);
plans.getTable().setLinesVisible(true);
plans.setContentProvider(ArrayContentProvider.getInstance());
plans.setInput(getClient().getPlans());
plans.addSelectionChangedListener(event -> {
InvestmentPlan plan = (InvestmentPlan) ((IStructuredSelection) event.getSelection()).getFirstElement();
if (plan != null)
transactions.setInput(plan.getPortfolio(), plan.getTransactions());
else
transactions.setInput(null, null);
transactions.refresh();
});
hookContextMenu(plans.getTable(), this::fillPlansContextMenu);
}
use of name.abuchen.portfolio.model.InvestmentPlan in project portfolio by buchen.
the class InvestmentPlanListView method fillPlansContextMenu.
private void fillPlansContextMenu(IMenuManager manager) {
final InvestmentPlan plan = (InvestmentPlan) ((IStructuredSelection) plans.getSelection()).getFirstElement();
if (plan == null)
return;
manager.add(new Action(Messages.InvestmentPlanMenuGenerateTransactions) {
@Override
public void run() {
CurrencyConverterImpl converter = new CurrencyConverterImpl(factory, getClient().getBaseCurrency());
List<PortfolioTransaction> latest = plan.generateTransactions(converter);
if (latest.isEmpty()) {
MessageDialog.openInformation(getActiveShell(), Messages.LabelInfo, MessageFormat.format(Messages.InvestmentPlanInfoNoTransactionsGenerated, Values.Date.format(plan.getDateOfNextTransactionToBeGenerated())));
} else {
markDirty();
plans.refresh();
transactions.markTransactions(latest);
transactions.setInput(plan.getPortfolio(), plan.getTransactions());
}
}
});
manager.add(new Separator());
//
new OpenDialogAction(this, Messages.MenuEditInvestmentPlan).type(InvestmentPlanDialog.class, //
d -> d.setPlan(plan)).onSuccess(d -> {
markDirty();
plans.setInput(getClient().getPlans());
}).addTo(manager);
manager.add(new Action(Messages.InvestmentPlanMenuDelete) {
@Override
public void run() {
getClient().removePlan(plan);
markDirty();
plans.setInput(getClient().getPlans());
transactions.setInput(null, null);
}
});
}
use of name.abuchen.portfolio.model.InvestmentPlan 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.InvestmentPlan in project portfolio by buchen.
the class CreateInvestmentPlanTxJob method run.
@Override
protected IStatus run(IProgressMonitor monitor) {
try {
if (startAfterOtherJob != null)
startAfterOtherJob.join();
Map<InvestmentPlan, List<PortfolioTransaction>> tx = new HashMap<>();
CurrencyConverterImpl converter = new CurrencyConverterImpl(factory, getClient().getBaseCurrency());
getClient().getPlans().stream().filter(InvestmentPlan::isAutoGenerate).forEach(plan -> {
List<PortfolioTransaction> transactions = plan.generateTransactions(converter);
if (!transactions.isEmpty())
tx.put(plan, transactions);
});
if (!tx.isEmpty()) {
Display.getDefault().asyncExec(() -> {
String message;
if (tx.size() == 1) {
Entry<InvestmentPlan, List<PortfolioTransaction>> entry = tx.entrySet().iterator().next();
message = MessageFormat.format(Messages.InvestmentPlanTxCreated, entry.getKey().getName(), entry.getValue().size());
} else {
int count = tx.values().stream().mapToInt(List::size).sum();
StringBuilder builder = new StringBuilder();
builder.append(MessageFormat.format(Messages.InvestmentPlanTxForMultiplePlansCreated, count));
for (Entry<InvestmentPlan, List<PortfolioTransaction>> entry : tx.entrySet()) builder.append(// $NON-NLS-1$
MessageFormat.format(// $NON-NLS-1$
"\n{0}: {1}", // $NON-NLS-1$
entry.getKey().getName(), entry.getValue().size()));
message = builder.toString();
}
// FIXME Oxygen supports custom button labels
MessageDialog.openInformation(Display.getCurrent().getActiveShell(), Messages.LabelInfo, message);
});
}
} catch (// NOSONAR
InterruptedException ignore) {
// ignore
}
return Status.OK_STATUS;
}
Aggregations