Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    How to show tooltips for disabled MenuItems

    I got tooltips working on menu items exploiting ListGrid.setHoverCustomizer() (since Menu extends ListGrid, menu items can be actually considered as grid records).
    Now the problem is that listgrids don't show hover text for disabled rows, hence I loose tooltips on disabled menu items.
    So I could add a mousemove handler to the menu, but - in order to show a proper tooltip for the hovering item - I should somewhat detect which listgrid record corresponds to the mouse position: is it possible?
    An alternative would be using a custom style to render menu items as disabled without actually disabling them, but I don't know how to prevent user clicks on them.

    I'm using SmartGWT 4.0.

    #2
    getEventRow()

    Comment


      #3
      Solved

      Ok, I replaced the menu hover based on ListGrid's HoverCustomizer with a MouseMoveHandler that delays hovering for both active and inactive menu items.
      For other folks with the same need I leave here a snippet with the complete solution I ended with:

      Code:
          private int currentEventRow = -1;
          private Timer timer;
      
          void assembleUI () {
              ...
              menu.addMouseMoveHandler(new MouseMoveHandler() {
                  @Override
                  public void onMouseMove(final MouseMoveEvent event) {
                      final int eventRow = menu.getEventRow();
                      if (currentEventRow != eventRow) {
                          /*
                           * mouse moved to a different menu item
                           */
                          currentEventRow = eventRow;
                          timer = new Timer() {
                              @Override
                              public void run() {
                                  final String hoverHTML = getHoverHTML(eventRow);
                                  if (hoverHTML != null) {
                                      showHover(hoverHTML, menu.getHoverStyle(), menu.getHoverWidth());
                                  }
                                  timer = null;
                              }
                          };
                          timer.schedule(menu.getHoverDelay());
                      }
                  }
              });
      
              menu.addMouseOutHandler(new MouseOutHandler() {
                  @Override
                  public void onMouseOut(MouseOutEvent event) {
                      cancelPreviousHover();
                  }
              });
          }
      
          /**
           * Cancel previous hover schedule.
           */
          protected void cancelPreviousHover() {
              if (timer != null) {
                  timer.cancel();
              }
              currentEventRow = -1;
              Hover.hide();
          }
      
      
          private static native void showHover(final String contents, final String hoverStyle, final int hoverWidth)
          /*-{
              $wnd.isc.Hover.show(contents, { baseStyle: hoverStyle, width: hoverWidth, moveWithMouse: false });
          }-*/;
      Last edited by d.cavestro; 8 Aug 2013, 06:54.

      Comment

      Working...
      X