Skip to content

Commit

Permalink
securities table now also uses the new setting for "quote stale after…
Browse files Browse the repository at this point in the history
… days"
  • Loading branch information
ma4nn committed Oct 12, 2022
1 parent ad73b3b commit 3f5fec6
Showing 1 changed file with 28 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import name.abuchen.portfolio.snapshot.ReportingPeriod;
import name.abuchen.portfolio.ui.Images;
import name.abuchen.portfolio.ui.Messages;
import name.abuchen.portfolio.ui.UIConstants;
import name.abuchen.portfolio.ui.dialogs.transactions.AccountTransactionDialog;
import name.abuchen.portfolio.ui.dialogs.transactions.InvestmentPlanDialog;
import name.abuchen.portfolio.ui.dialogs.transactions.OpenDialogAction;
Expand Down Expand Up @@ -163,6 +164,8 @@ public void run()

private TableViewer securities;

private int numberOfTradeDaysAfterQuoteIsStale;

private Map<Security, QuoteQualityMetrics> metricsCache = new HashMap<Security, QuoteQualityMetrics>()
{
private static final long serialVersionUID = 1L;
Expand All @@ -180,6 +183,9 @@ public SecuritiesTable(Composite parent, AbstractFinanceView view)
{
this.view = view;

this.numberOfTradeDaysAfterQuoteIsStale = view.getPart().getClientInput().getEclipsePreferences()
.getInt(UIConstants.Preferences.QUOTES_STALE_AFTER_DAYS_PATH, 7);

Composite container = new Composite(parent, SWT.NONE);
TableColumnLayout layout = new TableColumnLayout();
container.setLayout(layout);
Expand Down Expand Up @@ -491,6 +497,14 @@ private void addColumnDateOfLatestPrice() // NOSONAR

column.setLabelProvider(new DateLabelProvider(dataProvider)
{
private int numberOfDaysWithWarning;

public DateLabelProvider setNumberOfDaysWithWarning(int numberOfDays)
{
this.numberOfDaysWithWarning = numberOfDays;
return this;
}

@Override
public Color getBackground(Object element)
{
Expand All @@ -503,10 +517,10 @@ public Color getBackground(Object element)
if (QuoteFeed.MANUAL.equals(feed))
return null;

LocalDate sevenDaysAgo = LocalDate.now().minusDays(7);
return latest.getDate().isBefore(sevenDaysAgo) ? Colors.theme().warningBackground() : null;
LocalDate daysAgo = LocalDate.now().minusDays(this.numberOfDaysWithWarning);
return latest.getDate().isBefore(daysAgo) ? Colors.theme().warningBackground() : null;
}
});
}.setNumberOfDaysWithWarning(this.numberOfTradeDaysAfterQuoteIsStale));
column.setSorter(ColumnViewerSorter.create(dataProvider::apply));
support.addColumn(column);
}
Expand All @@ -528,6 +542,14 @@ private void addColumnDateOfLatestHistoricalPrice() // NOSONAR

column.setLabelProvider(new DateLabelProvider(dataProvider)
{
private int numberOfDaysWithWarning;

public DateLabelProvider setNumberOfDaysWithWarning(int numberOfDays)
{
this.numberOfDaysWithWarning = numberOfDays;
return this;
}

@Override
public Color getBackground(Object element)
{
Expand All @@ -540,12 +562,13 @@ public Color getBackground(Object element)
return null;

SecurityPrice latest = prices.get(prices.size() - 1);
if (!((Security) element).isRetired() && latest.getDate().isBefore(LocalDate.now().minusDays(7)))
if (!((Security) element).isRetired() && latest.getDate()
.isBefore(LocalDate.now().minusDays(numberOfDaysWithWarning)))
return Colors.theme().warningBackground();
else
return null;
}
});
}.setNumberOfDaysWithWarning(this.numberOfTradeDaysAfterQuoteIsStale));
column.setSorter(ColumnViewerSorter.create(dataProvider::apply));
support.addColumn(column);
}
Expand Down

0 comments on commit 3f5fec6

Please sign in to comment.