Hi,
I have presenter which keeps my GUI components intact. I want to pass notifications to all components from a central place.
I created custom event and tried to pass that event on the root node thinking that javafx events goes from top to down thus all components will get that notification but its not working
at all so please help out.
My Custom Event
public class NotificationEvent extends Event {
public static final EventType<NotificationEvent> NOTIFICATION_ARRIVED = new EventType(ANY, "NOTIFICATION_ARRIVED");
private Notification notif;
public NotificationEvent(Notification notif) {
this(NOTIFICATION_ARRIVED);
this.notif = notif;
}
public NotificationEvent(EventType<? extends Event> eventtype) {
super(eventtype);
}
public NotificationEvent(Object obj, EventTarget target, EventType<? extends Event> type) {
super(obj, target, type);
}
public Notification getNotification() {
return notif;
}
}
Place from where I fire custom event to the root node
registerHandler(eventBus.addHandler(UserPermissionsEvent.TYPE, new UserPermissionsEventHandler() {
@Override
public void onUserPermissionEvent(UserPermissionsEvent event) {
NotificationEvent notifEvent = new NotificationEvent(event.getNotification());
getRoot().fireEvent(notifEvent);
}
}));
I put event handler on one of the button to see whether event travels to all components or not but it didn't.
logOutBtn.addEventHandler(NotificationEvent.NOTIFICATION_ARRIVED, new EventHandler<NotificationEvent>() {
@Override
public void handle(NotificationEvent event) {
if (event instanceof NotificationEvent) {
log.debug("----------------------Notification event on logout button -----------" + event.getNotification().getType());
}
}
});
Am I missing something in this. Some input will be really helpful.
Thanks & Reagards,
Ash