use of name.abuchen.portfolio.model.InvestmentVehicle in project portfolio by buchen.
the class DividendsViewModel method calculate.
private void calculate() {
// determine the number of full months within period
LocalDate now = LocalDate.now();
if (startYear > now.getYear())
throw new IllegalArgumentException();
this.noOfmonths = (now.getYear() - startYear) * 12 + now.getMonthValue();
Predicate<Transaction> predicate = new ReportingPeriod.FromXtoY(LocalDate.of(startYear - 1, Month.DECEMBER, 31), now).containsTransaction();
Map<InvestmentVehicle, Line> vehicle2line = new HashMap<>();
this.sum = new Line(null, this.noOfmonths);
this.transactions = new ArrayList<>();
Client filteredClient = clientFilter.getSelectedFilter().filter(client);
for (Account account : filteredClient.getAccounts()) {
for (AccountTransaction t : account.getTransactions()) {
if (t.getType() != AccountTransaction.Type.DIVIDENDS)
continue;
if (!predicate.test(t))
continue;
transactions.add(new TransactionPair<>(account, t));
Money dividendValue = useGrossValue ? t.getGrossValue() : t.getMonetaryAmount();
long value = dividendValue.with(converter.at(t.getDateTime())).getAmount();
int index = (t.getDateTime().getYear() - startYear) * 12 + t.getDateTime().getMonthValue() - 1;
Line line = vehicle2line.computeIfAbsent(t.getSecurity(), s -> new Line(s, noOfmonths));
line.values[index] += value;
line.sum += value;
sum.values[index] += value;
sum.sum += value;
}
}
this.lines = new ArrayList<>(vehicle2line.values());
}
use of name.abuchen.portfolio.model.InvestmentVehicle in project portfolio by buchen.
the class AbstractNodeTreeViewer method doChangeAssignmentWeight.
private void doChangeAssignmentWeight(TaxonomyNode node, int oldWeight) {
int change = oldWeight - node.getWeight();
if (// was 'fixed' after editing, e.g. was >= 100%
change == 0)
return;
if (node.getWeight() == 0)
node.getParent().removeChild(node);
// change total weight as recorded in the model
InvestmentVehicle investmentVehicle = node.getAssignment().getInvestmentVehicle();
final int totalWeight = getModel().getWeightByInvestmentVehicle(investmentVehicle) - change;
getModel().setWeightByInvestmentVehicle(investmentVehicle, totalWeight);
// check if change is fixing weight errors -> no new unassigned vehicles
change = Math.min(change, Classification.ONE_HUNDRED_PERCENT - totalWeight);
if (change == 0)
return;
// change existing unassigned node *or* create new unassigned node
TaxonomyNode unassigned = getModel().getUnassignedNode().getChildByInvestmentVehicle(investmentVehicle);
if (unassigned != null) {
// change existing node in unassigned category
int newWeight = unassigned.getWeight() + change;
if (newWeight <= 0) {
getModel().getUnassignedNode().removeChild(unassigned);
getModel().setWeightByInvestmentVehicle(investmentVehicle, totalWeight - unassigned.getWeight());
} else {
unassigned.setWeight(newWeight);
getModel().setWeightByInvestmentVehicle(investmentVehicle, totalWeight + change);
}
} else if (change > 0) {
// create a new node, but only if change is positive
Assignment assignment = new Assignment(investmentVehicle);
assignment.setWeight(change);
getModel().getUnassignedNode().addChild(assignment);
getModel().setWeightByInvestmentVehicle(investmentVehicle, totalWeight + change);
}
// do not fire model change -> called within modification listener
}
use of name.abuchen.portfolio.model.InvestmentVehicle in project portfolio by buchen.
the class TaxonomyNode method moveTo.
private void moveTo(int index, TaxonomyNode target) {
Classification classification = target.getClassification();
if (classification == null)
throw new UnsupportedOperationException();
if (isAssignment()) {
InvestmentVehicle investmentVehicle = getAssignment().getInvestmentVehicle();
TaxonomyNode sibling = target.getChildByInvestmentVehicle(investmentVehicle);
if (sibling != null) {
sibling.absorb(this);
return;
}
}
// change parent, update children collections and rank
this.getParent().removeChild(this);
this.parent = target;
if (isClassification()) {
getClassification().setParent(classification);
classification.getChildren().add(getClassification());
} else {
classification.getAssignments().add(getAssignment());
}
List<TaxonomyNode> siblings = target.getChildren();
if (index == -1)
index = siblings.size();
int insertAt = target.isRoot() ? Math.min(index, siblings.size() - 1) : index;
siblings.add(insertAt, this);
for (int ii = 0; ii < siblings.size(); ii++) siblings.get(ii).setRank(ii);
}
use of name.abuchen.portfolio.model.InvestmentVehicle in project portfolio by buchen.
the class DividendsMatrixTab method createMonthColumn.
private void createMonthColumn(TableViewer records, TableColumnLayout layout, LocalDate start, int index) {
TableViewerColumn column = new TableViewerColumn(records, SWT.RIGHT);
column.getColumn().setText(formatter.format(start));
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
Line line = (DividendsViewModel.Line) element;
return line.getVehicle() != null ? Values.Amount.formatNonZero(line.getValue(index)) : Values.Amount.format(line.getValue(index));
}
@Override
public String getToolTipText(Object element) {
InvestmentVehicle vehicle = ((DividendsViewModel.Line) element).getVehicle();
return TextUtil.tooltip(vehicle != null ? vehicle.getName() : null);
}
@Override
public Font getFont(Object element) {
InvestmentVehicle vehicle = ((DividendsViewModel.Line) element).getVehicle();
return vehicle != null ? null : boldFont;
}
});
layout.setColumnData(column.getColumn(), new ColumnPixelData(50));
}
use of name.abuchen.portfolio.model.InvestmentVehicle in project portfolio by buchen.
the class DividendsMatrixTab method createSecurityColumn.
protected void createSecurityColumn(TableViewer records, TableColumnLayout layout, boolean isSorted) {
TableViewerColumn column = new TableViewerColumn(records, SWT.NONE);
column.getColumn().setText(Messages.ColumnSecurity);
column.setLabelProvider(new ColumnLabelProvider() {
@Override
public Image getImage(Object element) {
InvestmentVehicle vehicle = ((DividendsViewModel.Line) element).getVehicle();
return vehicle != null ? Images.SECURITY.image() : null;
}
@Override
public String getText(Object element) {
InvestmentVehicle vehicle = ((DividendsViewModel.Line) element).getVehicle();
return vehicle != null ? vehicle.getName() : Messages.ColumnSum;
}
@Override
public Font getFont(Object element) {
InvestmentVehicle vehicle = ((DividendsViewModel.Line) element).getVehicle();
return vehicle != null ? null : boldFont;
}
});
ColumnViewerSorter.create((o1, o2) -> {
int direction = ColumnViewerSorter.SortingContext.getSortDirection();
DividendsViewModel.Line line1 = (DividendsViewModel.Line) o1;
DividendsViewModel.Line line2 = (DividendsViewModel.Line) o2;
if (line1.getVehicle() == null)
return direction == SWT.DOWN ? 1 : -1;
if (line2.getVehicle() == null)
return direction == SWT.DOWN ? -1 : 1;
String n1 = line1.getVehicle().getName();
String n2 = line2.getVehicle().getName();
return n1.compareToIgnoreCase(n2);
}).attachTo(records, column, isSorted);
layout.setColumnData(column.getColumn(), new ColumnPixelData(200));
}
Aggregations