我不确定如何将条目正确添加到日历中。我想根据数据库的输入来填充。我已经尝试了以下方法,但是不确定如何设置日期和条目。我正在获取数据并将其放入ObserverableList。在我的情况下,数据库表是CalendarData
public class CalendarController<CalendarEvent> extends Application {
private RosterService rosterService = new RosterServiceImpl();
private ObservableList<CalendarData> calendarList = FXCollections.observableArrayList();
public ObservableList<CalendarData> getCalendarDataList() {
if (!calendarList.isEmpty())
calendarList.clear();
calendarList = FXCollections.observableList((List<CalendarData>) rosterService.listCalendarData());
return calendarList;
}
@Override
public void start(Stage primaryStage) throws Exception {
CalendarView calendarView = new CalendarView();
Calendar shifts = new Calendar("ShiftRoster");
shifts.setStyle(Style.STYLE1);
CalendarSource myCalendarSource = new CalendarSource("My Calendars");
// myCalendarSource.getCalendars().addAll(shifts, holidays);
calendarView.getCalendarSources().addAll(myCalendarSource);
calendarView.setRequestedTime(LocalTime.now());
getCalendarDataList();
for(CalendarData task : calendarList){
Entry<String> entry = new Entry<String>(task.getShiftType());
LocalDate date = task.getShiftDate();
shifts.addEntries(dates);
}
CalendarSource calendarSourceTasks = new CalendarSource("Shifts");
calendarSourceTasks.getCalendars().addAll(shifts);
calendarView.getCalendarSources().setAll(calendarSourceTasks);
通过执行以下代码已解决:
CalendarView calendarView = new CalendarView();
Calendar shifts = new Calendar("ShiftRoster");
shifts.setStyle(Style.STYLE1);
ZoneId id = ZoneId.of("Australia/Brisbane");
getCalendarDataList();
for (CalendarData task : calendarList) {
Entry<String> dentistAppointment = new Entry<>(task.getEmployeename());
String startTime = task.getStartTIme();
String endTime = task.getEndTime();
LocalDate date = task.getShiftDate();
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("H:mm:ss");
LocalTime start = LocalTime.parse(startTime, dtf);
LocalTime end = LocalTime.parse(endTime, dtf);
if (!start.isAfter(end)) {
dentistAppointment.setInterval(date);
dentistAppointment.setInterval(start, end);
shifts.addEntry(dentistAppointment);
}
if (!end.isAfter(start)) {
dentistAppointment.setInterval(date);
dentistAppointment.setInterval(date,start, date.plusDays(1),end);
shifts.addEntry(dentistAppointment);
}
}
CalendarSource calendarSourceTasks = new CalendarSource("Shifts");
calendarSourceTasks.getCalendars().addAll(shifts);
calendarView.getCalendarSources().setAll(calendarSourceTasks);