Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Custom Event on FX components

903019Jan 17 2013 — edited Jan 21 2013
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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 18 2013
Added on Jan 17 2013
2 comments
786 views