Skip to content

Commit

Permalink
Dividend view remembers state whether to use gross value for dividends
Browse files Browse the repository at this point in the history
Issue: #607
  • Loading branch information
buchen committed Sep 4, 2016
1 parent 4eb567d commit f70f508
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
Expand Up @@ -22,11 +22,13 @@
import name.abuchen.portfolio.ui.Images;
import name.abuchen.portfolio.ui.Messages;
import name.abuchen.portfolio.ui.util.AbstractDropDown;
import name.abuchen.portfolio.ui.util.SimpleAction;

public class DividendsView extends AbstractFinanceView
{
private static final String KEY_TAB = DividendsView.class.getSimpleName() + "-tab"; //$NON-NLS-1$
private static final String KEY_YEAR = DividendsView.class.getSimpleName() + "-year"; //$NON-NLS-1$
private static final String KEY_USE_GROSS_VALUE = DividendsView.class.getSimpleName() + "-use-gross-value"; //$NON-NLS-1$

@Inject
private Client client;
Expand All @@ -50,9 +52,15 @@ public void setupModel()
LocalDate now = LocalDate.now();
if (year <= now.getYear() - 10 || year > now.getYear())
year = now.getYear() - 2;

model.updateWith(year);
model.addUpdateListener(() -> preferences.setValue(KEY_YEAR, model.getStartYear()));

boolean useGrossValue = preferences.getBoolean(KEY_USE_GROSS_VALUE);
model.setUseGrossValue(useGrossValue);

model.addUpdateListener(() -> {
preferences.setValue(KEY_YEAR, model.getStartYear());
preferences.setValue(KEY_USE_GROSS_VALUE, model.usesGrossValue());
});
}

@Override
Expand Down Expand Up @@ -92,15 +100,8 @@ public void menuAboutToShow(IMenuManager manager)
@Override
public void menuAboutToShow(IMenuManager manager)
{
Action action = new Action(Messages.LabelUseGrossDividends)
{
@Override
public void run()
{
model.setUseGrossValue(!model.usesGrossValue());
model.recalculate();
}
};
Action action = new SimpleAction(Messages.LabelUseGrossDividends,
a -> model.setUseGrossValue(!model.usesGrossValue()));
action.setChecked(model.usesGrossValue());
manager.add(action);
}
Expand Down
Expand Up @@ -101,6 +101,8 @@ public boolean usesGrossValue()
public void setUseGrossValue(boolean useGrossValue)
{
this.useGrossValue = useGrossValue;
calculate();
fireUpdateChange();
}

/**
Expand Down

0 comments on commit f70f508

Please sign in to comment.