Open StoicBug opened 8 months ago
I have the same issue.
I can see the events firing in the developer console, but none of my handlers is getting called (or at least, the desired action is not performed).
But I'm a bit confused at this point: A CalendarView.addEventHandler takes two arguments, the CalendarEvent and the handler itself. The Calendar.addEventHandler just takes one argument.
But as @dlemmermann stated at #129 , you need to add the event to the calendar, not the view; but at this point I wonder, how do I filter for a specific event, and, what is CalendarView.addEventHandler(CalendarEvent, handler) for then? I tried adding the event handler to the calendar, but it still gets ignored by any events.
urlaub.addEventHandler(evt -> System.out.println(evt));
LoadEvents on the view are working just fine.
Yes, I did manage to solve the problem like you mentioned I need to add the event handler to the calendar not the view:
private void setUpEventListeners() {
EventHandler<CalendarEvent> addHandler = new EventHandler<CalendarEvent>() {
@Override
public void handle(CalendarEvent event) {
if (event.isEntryAdded()) {
Entry<?> newEntry = event.getEntry();
// Convert CalendarFX Entry to your Event model and save to database
Event newEvent = convertToEventModel(newEntry);
System.out.println("New Event: " + newEvent);
// block code for 7 seconds
eventService.addEvent(newEvent);
}
}
};
calendar.addEventHandler(addHandler);
}
But still, I didn't find a solution to filter between the types of events (add, delete, update...), I was trying to build functions my self to detect the type of event but it got too complex.
Yes, I did manage to solve the problem like you mentioned I need to add the event handler to the calendar not the view:
private void setUpEventListeners() { EventHandler<CalendarEvent> addHandler = new EventHandler<CalendarEvent>() { @Override public void handle(CalendarEvent event) { if (event.isEntryAdded()) { Entry<?> newEntry = event.getEntry(); // Convert CalendarFX Entry to your Event model and save to database Event newEvent = convertToEventModel(newEntry); System.out.println("New Event: " + newEvent); // block code for 7 seconds eventService.addEvent(newEvent); } } }; calendar.addEventHandler(addHandler); }
But still, I didn't find a solution to filter between the types of events (add, delete, update...), I was trying to build functions my self to detect the type of event but it got too complex.
Thank you. I changed it to
EventHandler<CalendarEvent> addHandler = new EventHandler<CalendarEvent>() {
@Override
public void handle(CalendarEvent event) {
if(event.getEventType() == CalendarEvent.ENTRY_TITLE_CHANGED)
{
System.out.println("New title: " + event.getEntry().getTitle());
}
}
};
and finally got it working for now.
I'm trying to do CRUD operation with my sql database using CalendarFX, I tried many approaches but still the documentation is not that helpful and I tried a lot, here is my Controller for the CalendarFX:
`java package com.taskhub.taskhub.controllers;
import com.calendarfx.model.*; import com.calendarfx.view.DayView; import com.taskhub.taskhub.dao.EventDao; import com.taskhub.taskhub.dao.EventDaoImpl; import com.taskhub.taskhub.dao.model.Event; import com.taskhub.taskhub.dao.service.IEventsService; import com.taskhub.taskhub.dao.service.IServiceEventsImpl; import javafx.application.Platform; import javafx.event.EventHandler; import javafx.fxml.FXML; import javafx.scene.layout.StackPane; import com.calendarfx.view.CalendarView; import com.calendarfx.model.Entry;
import java.sql.Timestamp; import java.time.LocalDate; import java.time.LocalTime;
public class CalendarController {
}
`