use of name.abuchen.portfolio.model.InvestmentVehicle in project portfolio by buchen.
the class DividendsMatrixTab method createControl.
@Override
public Control createControl(Composite parent) {
LocalResourceManager resources = new LocalResourceManager(JFaceResources.getResources(), parent);
boldFont = resources.createFont(FontDescriptor.createFrom(parent.getFont()).setStyle(SWT.BOLD));
Composite container = new Composite(parent, SWT.NONE);
tableLayout = new TableColumnLayout();
container.setLayout(tableLayout);
tableViewer = new TableViewer(container, SWT.FULL_SELECTION);
ColumnViewerToolTipSupport.enableFor(tableViewer, ToolTip.NO_RECREATE);
createColumns(tableViewer, tableLayout);
tableViewer.getTable().setHeaderVisible(true);
tableViewer.getTable().setLinesVisible(true);
tableViewer.setContentProvider(ArrayContentProvider.getInstance());
tableViewer.addSelectionChangedListener(event -> {
InvestmentVehicle vehicle = ((DividendsViewModel.Line) ((IStructuredSelection) event.getSelection()).getFirstElement()).getVehicle();
if (vehicle != null && vehicle instanceof Security)
selectionService.setSelection(new SecuritySelection(model.getClient(), (Security) vehicle));
});
tableViewer.setInput(model.getAllLines());
for (TableColumn c : tableViewer.getTable().getColumns()) c.pack();
model.addUpdateListener(() -> updateColumns(tableViewer, tableLayout));
return container;
}
use of name.abuchen.portfolio.model.InvestmentVehicle in project portfolio by buchen.
the class DividendsYearMatrixTab method createYearColumn.
private void createYearColumn(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;
long value = 0;
for (int ii = index; ii < index + 12 && ii < line.getNoOfMonths(); ii++) value += line.getValue(ii);
return line.getVehicle() != null ? Values.Amount.formatNonZero(value) : Values.Amount.format(value);
}
@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 GroupByTaxonomy method createCategoriesAndAllocate.
private void createCategoriesAndAllocate(final Map<InvestmentVehicle, Item> vehicle2position) {
for (Classification classification : taxonomy.getRoot().getChildren()) {
final Map<InvestmentVehicle, Item> vehicle2item = new HashMap<>();
// first: assign items to categories
// item.weight records both the weight
// (a) already assigned to any category
// (b) assigned to this category
classification.accept(new Taxonomy.Visitor() {
@Override
public void visit(Classification classification, Assignment assignment) {
Item item = vehicle2position.get(assignment.getInvestmentVehicle());
if (item != null) {
// record (a)
item.weight += assignment.getWeight();
SecurityPosition position = item.position;
if (assignment.getWeight() == Classification.ONE_HUNDRED_PERCENT) {
vehicle2item.put(assignment.getInvestmentVehicle(), item);
} else {
Item other = vehicle2item.get(assignment.getInvestmentVehicle());
if (other == null) {
other = new Item(position);
vehicle2item.put(assignment.getInvestmentVehicle(), other);
}
// record (b) into the copy
other.weight += assignment.getWeight();
}
}
}
});
if (!vehicle2item.isEmpty()) {
AssetCategory category = new AssetCategory(classification, converter, date, valuation);
categories.add(category);
for (Entry<InvestmentVehicle, Item> entry : vehicle2item.entrySet()) {
Item item = entry.getValue();
SecurityPosition position = item.position;
if (item.weight != Classification.ONE_HUNDRED_PERCENT)
position = SecurityPosition.split(position, item.weight);
category.addPosition(new AssetPosition(position, converter, date, getValuation()));
}
// sort positions by name
Collections.sort(category.getPositions(), new AssetPosition.ByDescription());
}
}
}
use of name.abuchen.portfolio.model.InvestmentVehicle in project portfolio by buchen.
the class GroupByTaxonomy method allocateLeftOvers.
private void allocateLeftOvers(final Map<InvestmentVehicle, Item> vehicle2position) {
Classification classification = new Classification(null, Classification.UNASSIGNED_ID, Messages.LabelWithoutClassification);
AssetCategory unassigned = new AssetCategory(classification, converter, date, getValuation());
for (Entry<InvestmentVehicle, Item> entry : vehicle2position.entrySet()) {
Item item = entry.getValue();
if (item.weight < Classification.ONE_HUNDRED_PERCENT) {
SecurityPosition position = item.position;
if (item.weight != 0)
position = SecurityPosition.split(position, Classification.ONE_HUNDRED_PERCENT - item.weight);
unassigned.addPosition(new AssetPosition(position, converter, date, getValuation()));
}
}
if (!unassigned.getPositions().isEmpty())
categories.add(unassigned);
}
use of name.abuchen.portfolio.model.InvestmentVehicle in project portfolio by buchen.
the class StackedChartViewer method updateChart.
private void updateChart() {
final Map<InvestmentVehicle, VehicleBuilder> vehicle2builder = new HashMap<>();
final Map<TaxonomyNode, SeriesBuilder> node2series = new LinkedHashMap<>();
getModel().visitAll(node -> {
if (node.isClassification()) {
node2series.put(node, new SeriesBuilder(node, dates.size()));
} else {
InvestmentVehicle vehicle = node.getAssignment().getInvestmentVehicle();
VehicleBuilder builder = vehicle2builder.get(vehicle);
if (builder == null) {
builder = new VehicleBuilder();
vehicle2builder.put(vehicle, builder);
}
builder.add(node.getWeight(), node2series.get(node.getParent()));
}
});
final long[] totals = new long[dates.size()];
int index = 0;
for (LocalDate current : dates) {
ClientSnapshot snapshot = ClientSnapshot.create(getModel().getFilteredClient(), getModel().getCurrencyConverter(), current);
totals[index] = snapshot.getMonetaryAssets().getAmount();
Map<InvestmentVehicle, AssetPosition> p = snapshot.getPositionsByVehicle();
for (Map.Entry<InvestmentVehicle, VehicleBuilder> entry : vehicle2builder.entrySet()) {
AssetPosition pos = p.get(entry.getKey());
if (pos != null)
entry.getValue().book(index, pos);
}
index++;
}
// if the unassigned category is excluded, reduce the total values
if (getModel().isUnassignedCategoryInChartsExcluded()) {
SeriesBuilder unassigned = node2series.get(getModel().getUnassignedNode());
for (int ii = 0; ii < totals.length; ii++) totals[ii] -= unassigned.values[ii];
}
Stream<SeriesBuilder> seriesStream = node2series.values().stream().filter(SeriesBuilder::hasValues);
if (getModel().isUnassignedCategoryInChartsExcluded())
seriesStream = seriesStream.filter(s -> !s.node.isUnassignedCategory());
List<SeriesBuilder> series = seriesStream.collect(Collectors.toList());
if (getModel().isOrderByTaxonomyInStackChart()) {
// reverse because chart is stacked bottom-up
Collections.reverse(series);
} else {
Collections.sort(series);
}
Display.getDefault().asyncExec(() -> rebuildChartSeries(totals, series));
}
Aggregations