API REVIEW request for RT-19709: API to enable accelerators lazily.

Paru Somashekar parvathi.somashekar at oracle.com
Tue May 1 12:02:56 PDT 2012


JIRA : http://javafx-jira.kenai.com/browse/RT-19709
API to enable accelerators lazily.

Currently accelerators are not invoked when menu items are disabled and 
are invoked only
when the menu items are enabled. Applications need a handler / callback, 
when a accelerator
is invoked, so it can enable or disable the menu item and then the 
accelerator is fired there after
(if the menuitem was enabled.)

----------------------------------------------

Adding a onMenuValidation API that would be called automatically at the 
same time that onShowing handler
is called and when an accelerator is triggered.
/**
  * <p>Called when a accelerator for the Menuitem is invoked</p>
  */
     public static final EventType<Event> MENUVALIDATION_EVENT = new 
EventType<Event>();
private ObjectProperty<EventHandler<Event>> onMenuValidation;

/**
  * The event handler that is associated with invocation of an 
accelerator for a MenuItem. This
  * can happen when a key sequence for an accelerator is pressed. The 
event handler is also
  * invoked when onShowing event handler is called.
*/
public final void setOnMenuValidation(EventHandler<Event> value) {
     onMenuValidationProperty().set( value);
}

public final EventHandler<Event> getOnMenuValidation() {
     return onMenuValidation == null ? null : onMenuValidation.get();
}

public final ObjectProperty<EventHandler<Event>> 
onMenuValidationProperty() {
     if (onMenuValidation == null) {
         onMenuValidation = new ObjectPropertyBase<EventHandler<Event>>() {
             @Override protected void invalidated() {
                 
eventHandlerManager.setEventHandler(MENUVALIDATION_EVENT, get());
              }
              @Override public Object getBean() {
                  return MenuItem.this;
              }
              @Override public String getName() {
                  return "onMenuValidation";
              }
          };
     }
     return onMenuValidation;
}


More information about the openjfx-dev mailing list