Search in sources :

Example 1 with EditReportingPeriodsDialog

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();
                }
            }
        }
    });
}
Also used : ReportingPeriod(name.abuchen.portfolio.snapshot.ReportingPeriod) Action(org.eclipse.jface.action.Action) EditReportingPeriodsDialog(name.abuchen.portfolio.ui.dialogs.EditReportingPeriodsDialog) Separator(org.eclipse.jface.action.Separator) ReportingPeriodDialog(name.abuchen.portfolio.ui.dialogs.ReportingPeriodDialog)

Aggregations

ReportingPeriod (name.abuchen.portfolio.snapshot.ReportingPeriod)1 EditReportingPeriodsDialog (name.abuchen.portfolio.ui.dialogs.EditReportingPeriodsDialog)1 ReportingPeriodDialog (name.abuchen.portfolio.ui.dialogs.ReportingPeriodDialog)1 Action (org.eclipse.jface.action.Action)1 Separator (org.eclipse.jface.action.Separator)1