/*
             * Weekdays MO, TU, .... SU
             */
private void updateRule() {
        Recur.Builder<LocalDate> rBuilder = new Recur.Builder<>();
        switch (frequencyBox.getValue()) {
            case DAILY:
                rBuilder.frequency(net.fortuna.ical4j.model.Recur.Frequency.DAILY);
                break;
            case MONTHLY:
                rBuilder.frequency(net.fortuna.ical4j.model.Recur.Frequency.MONTHLY);
                break;
            case WEEKLY:
                rBuilder.frequency(net.fortuna.ical4j.model.Recur.Frequency.WEEKLY);
                break;
            case YEARLY:
                rBuilder.frequency(net.fortuna.ical4j.model.Recur.Frequency.YEARLY);
                break;
            default:
                break;
        }
        int interval = repeatCountSpinner.getValue();
        if (interval > 1) {
            rBuilder.interval(interval);
        } else {
            rBuilder.interval(0);
        }
        if (endsOnButton.isSelected()) {
            LocalDate date = endsOnDatePicker.getValue();
            rBuilder.until(date);
        }
        if (endsAfterButton.isSelected()) {
            rBuilder.count(endsAfterCounterSpinner.getValue());
        }
        if (frequencyBox.getValue() == Frequency.MONTHLY) {
            if (repeatByDayOfTheMonth.isSelected()) {
                int value = getSkinnable().getStartDate().getDayOfMonth();
                rBuilder.monthList(new NumberList(value, value, false));
            } else {
                LocalDate localDate = getSkinnable().getStartDate();
                // TODO: use zone id of context (entry, calendar)
                ZonedDateTime zonedDateTime = ZonedDateTime.of(localDate,
                        LocalTime.now(), ZoneId.systemDefault());
                int hits = 1;
                ZonedDateTime current = zonedDateTime.withDayOfMonth(1);
                do {
                    if (current.getDayOfWeek()
                            .equals(zonedDateTime.getDayOfWeek())) {
                        hits++;
                    }
                    current = current.plusDays(1);
                } while (current.toLocalDate().isBefore(localDate));
                WeekDayList weekdays = new WeekDayList();
                switch (zonedDateTime.getDayOfWeek()) {
                    case FRIDAY:
                        weekdays.add(new WeekDay(WeekDay.FR, hits));
                        break;
                    case MONDAY:
                        weekdays.add(new WeekDay(WeekDay.MO, hits));
                        break;
                    case SATURDAY:
                        weekdays.add(new WeekDay(WeekDay.SA, hits));
                        break;
                    case SUNDAY:
                        weekdays.add(new WeekDay(WeekDay.SU, hits));
                        break;
                    case THURSDAY:
                        weekdays.add(new WeekDay(WeekDay.TH, hits));
                        break;
                    case TUESDAY:
                        weekdays.add(new WeekDay(WeekDay.TU, hits));
                        break;
                    case WEDNESDAY:
                        weekdays.add(new WeekDay(WeekDay.WE, hits));
                        break;
                    default:
                        break;
                }
                rBuilder.dayList(weekdays);
            }
        }
        if (frequencyBox.getValue() == Frequency.WEEKLY) {
            /*
             * Weekdays MO, TU, .... SU
             */
            WeekDayList weekdays = new WeekDayList();
            maybeAddWeekday(weekdays, WeekDay.MO,
                    weekDayMondayButton);
            maybeAddWeekday(weekdays, WeekDay.TU,
                    weekDayTuesdayButton);
            maybeAddWeekday(weekdays, WeekDay.WE,
                    weekDayWednesdayButton);
            maybeAddWeekday(weekdays, WeekDay.TH,
                    weekDayThursdayButton);
            maybeAddWeekday(weekdays, WeekDay.FR,
                    weekDayFridayButton);
            maybeAddWeekday(weekdays, WeekDay.SA,
                    weekDaySaturdayButton);
            maybeAddWeekday(weekdays, WeekDay.SU,
                    weekDaySundayButton);
            rBuilder.dayList(weekdays);
        }
        Recur<LocalDate> rule = rBuilder.build();
        getSkinnable().setRecurrenceRule(rule.toString());
        if (LoggingDomain.RECURRENCE.isLoggable(Level.FINE)) {
            LoggingDomain.RECURRENCE.fine(
                    "test dumping 10 recurrences starting with today's date");
            LocalDate today = LocalDate.of(2015, 8, 18);
            List<LocalDate> dates = rule.getDates(today, today, LocalDate.MAX, 10);
            for (LocalDate repeatingDate : dates) {
                LoggingDomain.RECURRENCE.fine(repeatingDate.toString());
            }
        }
    }
}
if (frequencyBox.getValue() == Frequency.WEEKLY) {
/*
* Weekdays MO, TU, .... SU
*/
WeekDayList weekdays = new WeekDayList();
maybeAddWeekday(weekdays, WeekDay.MO,
case WEDNESDAY:
weekdays.add(new WeekDay(WeekDay.WE, hits));
break;
default:
break;
}
rBuilder.dayList(weekdays);
}
}
if (frequencyBox.getValue() == Frequency.WEEKLY) {
/*
* Weekdays MO, TU, .... SU
*/
WeekDayList weekdays = new WeekDayList();
maybeAddWeekday(weekdays, WeekDay.MO,
weekDayMondayButton);
maybeAddWeekday(weekdays, WeekDay.TU,
weekDayTuesdayButton);
maybeAddWeekday(weekdays, WeekDay.WE,
weekDayWednesdayButton);
maybeAddWeekday(weekdays, WeekDay.TH,
weekDayThursdayButton);
maybeAddWeekday(weekdays, WeekDay.FR,
break;
case SUNDAY:
weekdays.add(new WeekDay(WeekDay.SU, hits));
break;
case THURSDAY:
weekdays.add(new WeekDay(WeekDay.TH, hits));
break;
case TUESDAY:
weekdays.add(new WeekDay(WeekDay.TU, hits));
break;
case WEDNESDAY:
weekdays.add(new WeekDay(WeekDay.WE, hits));
break;
default:
break;
}
rBuilder.dayList(weekdays);
}
}
if (frequencyBox.getValue() == Frequency.WEEKLY) {
/*
* Weekdays MO, TU, .... SU
*/
WeekDayList weekdays = new WeekDayList();
maybeAddWeekday(weekdays, WeekDay.MO,
weekDayMondayButton);
maybeAddWeekday(weekdays, WeekDay.TU,
weekDayTuesdayButton);
maybeAddWeekday(weekdays, WeekDay.WE,
weekDayWednesdayButton);
maybeAddWeekday(weekdays, WeekDay.TH,
weekDayThursdayButton);
maybeAddWeekday(weekdays, WeekDay.FR,
weekDayFridayButton);
maybeAddWeekday(weekdays, WeekDay.SA,
weekDaySaturdayButton);
maybeAddWeekday(weekdays, WeekDay.SU,
weekDaySundayButton);
rBuilder.dayList(weekdays);
}
Recur<LocalDate> rule = rBuilder.build();
getSkinnable().setRecurrenceRule(rule.toString());
if (LoggingDomain.RECURRENCE.isLoggable(Level.FINE)) {