use of name.abuchen.portfolio.ui.dialogs.EditReportingPeriodsDialog in project portfolio by buchen.
the class ReportingPeriodDropDown method menuAboutToShow.
@Override
public void menuAboutToShow(IMenuManager manager) {
boolean isFirst = true;
for (final ReportingPeriod period : periods) {
Action action = new Action(period.toString()) {
@Override
public void run() {
periods.remove(period);
periods.addFirst(period);
setLabel(period.toString());
if (listener != null)
listener.reportingPeriodUpdated();
}
};
if (isFirst)
action.setChecked(true);
isFirst = false;
manager.add(action);
}
manager.add(new Separator());
manager.add(new Action(Messages.LabelReportingAddPeriod) {
@Override
public void run() {
ReportingPeriodDialog dialog = new ReportingPeriodDialog(getToolBar().getShell(), periods.getFirst());
if (dialog.open() == Dialog.OK) {
ReportingPeriod period = dialog.getReportingPeriod();
periods.addFirst(period);
setLabel(period.toString());
if (listener != null)
listener.reportingPeriodUpdated();
if (periods.size() > 20)
periods.removeLast();
}
}
});
manager.add(new Action(Messages.MenuReportingPeriodManage) {
@Override
public void run() {
EditReportingPeriodsDialog dialog = new EditReportingPeriodsDialog(getToolBar().getShell());
dialog.setReportingPeriods(periods);
if (dialog.open() == Dialog.OK) {
ReportingPeriod currentSelection = periods.getFirst();
periods.clear();
periods.addAll(dialog.getReportingPeriods());
// make sure at least one entry exists
if (periods.isEmpty())
periods.add(currentSelection);
if (listener != null && !currentSelection.equals(periods.getFirst())) {
setLabel(periods.getFirst().toString());
listener.reportingPeriodUpdated();
}
}
}
});
}
Aggregations