Search in sources :

Example 6 with InvestmentVehicle

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;
}
Also used : Line(name.abuchen.portfolio.ui.views.dividends.DividendsViewModel.Line) SecuritySelection(name.abuchen.portfolio.ui.selection.SecuritySelection) Composite(org.eclipse.swt.widgets.Composite) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) InvestmentVehicle(name.abuchen.portfolio.model.InvestmentVehicle) Security(name.abuchen.portfolio.model.Security) TableViewer(org.eclipse.jface.viewers.TableViewer) TableColumn(org.eclipse.swt.widgets.TableColumn)

Example 7 with InvestmentVehicle

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));
}
Also used : Line(name.abuchen.portfolio.ui.views.dividends.DividendsViewModel.Line) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) InvestmentVehicle(name.abuchen.portfolio.model.InvestmentVehicle) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) Font(org.eclipse.swt.graphics.Font)

Example 8 with InvestmentVehicle

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());
        }
    }
}
Also used : HashMap(java.util.HashMap) Taxonomy(name.abuchen.portfolio.model.Taxonomy) Assignment(name.abuchen.portfolio.model.Classification.Assignment) Classification(name.abuchen.portfolio.model.Classification) InvestmentVehicle(name.abuchen.portfolio.model.InvestmentVehicle)

Example 9 with InvestmentVehicle

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);
}
Also used : Classification(name.abuchen.portfolio.model.Classification) InvestmentVehicle(name.abuchen.portfolio.model.InvestmentVehicle)

Example 10 with InvestmentVehicle

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));
}
Also used : ClientSnapshot(name.abuchen.portfolio.snapshot.ClientSnapshot) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) LocalDate(java.time.LocalDate) AssetPosition(name.abuchen.portfolio.snapshot.AssetPosition) LinkedHashMap(java.util.LinkedHashMap) InvestmentVehicle(name.abuchen.portfolio.model.InvestmentVehicle) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

InvestmentVehicle (name.abuchen.portfolio.model.InvestmentVehicle)10 Line (name.abuchen.portfolio.ui.views.dividends.DividendsViewModel.Line)4 LocalDate (java.time.LocalDate)3 HashMap (java.util.HashMap)3 Classification (name.abuchen.portfolio.model.Classification)3 ColumnLabelProvider (org.eclipse.jface.viewers.ColumnLabelProvider)3 ColumnPixelData (org.eclipse.jface.viewers.ColumnPixelData)3 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)3 Font (org.eclipse.swt.graphics.Font)3 Assignment (name.abuchen.portfolio.model.Classification.Assignment)2 Security (name.abuchen.portfolio.model.Security)2 SecuritySelection (name.abuchen.portfolio.ui.selection.SecuritySelection)2 TableColumnLayout (org.eclipse.jface.layout.TableColumnLayout)2 LocalResourceManager (org.eclipse.jface.resource.LocalResourceManager)2 TableViewer (org.eclipse.jface.viewers.TableViewer)2 Composite (org.eclipse.swt.widgets.Composite)2 TableColumn (org.eclipse.swt.widgets.TableColumn)2 MessageFormat (java.text.MessageFormat)1 Month (java.time.Month)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1