Search code examples
gwtgwtp

Why "mouseover".equals(event.getType()) is not recognized in GWT Header?


I have a table with a nameColumn.

I want that when user mouseOver the title of nameColumn it will trigger a method

I tried:

Header<String> nameColumnHeader = new Header<String>(new ClickableTextCell()) {
        @Override
        public String getValue() {
            return "Name";
        }

        @Override
        public final void onBrowserEvent(Context context, Element elem, NativeEvent event) {
         if ("mouseover".equals(event.getType())) {
           //
           meaningMessagesPopup.show();  
         }
         else if("mouseout".equals(event.getType())){
             meaningMessagesPopup.hide();
         }
        }
    };
table.addColumn(nameColumn, nameColumnHeader);

But seem Gwt did not recognize "mouseover".equals(event.getType())

Do you know how to do the MOUSEOVER event in GWT Header?


Solution

  • i found the answer, that is to create a CustomCell that extends AbstractCell

         private class HeaderCell extends AbstractCell<String> {
    
                private String text;
    
                public HeaderCell(String text) {
                  /*
                   * Let the parent class know that our cell responds to click events and
                   * keydown events.
                   */
                  //super("click", "keydown");
                    super("mouseover"); 
                    this.text=text;
    
                }
    
                @Override
                public void onBrowserEvent(Context context, Element parent, String value,
                    NativeEvent event, ValueUpdater<String> valueUpdater) {
                  // Check that the value is not null.
                  if (value == null) {
                    return;
                  }
    
                  // Call the super handler, which handlers the enter key.
                  super.onBrowserEvent(context, parent, value, event, valueUpdater);
    
    
                  if ("mouseover".equals(event.getType())) {
                      SafeHtmlBuilder sb=new SafeHtmlBuilder();
                        sb.appendHtmlConstant("<b>");
    
    
                        sb.appendHtmlConstant("<font color=\"blue\">");
                        sb.appendEscaped(text);
                        sb.appendHtmlConstant("</font></b>");
    
                        meaningMessagesPopup.setWidget(new HTML(sb.toSafeHtml()));
    
    
                        int left = event.getClientX() -140;
                        int top = event.getClientY() +30;
                        meaningMessagesPopup.setPopupPosition(left, top);
    
                            // Show the popup
                        meaningMessagesPopup.show();
                  }
                  else if ("mouseout".equals(event.getType())) {
                      meaningMessagesPopup.hide();
                  }
                }
    
                @Override
                public void render(Context context, String value, SafeHtmlBuilder sb) {
                  /*
                   * Always do a null check on the value. Cell widgets can pass null to
                   * cells if the underlying data contains a null, or if the data arrives
                   * out of order.
                   */
                  if (value == null) {
                    return;
                  }
    
                  sb.appendEscaped(value);
                }
    
    
            }
    

    Then

      Header<String> nameColumnHeader = new Header<String>(new HeaderCell("my Text...")) {
                        @Override
                        public String getValue() {
                            return "Name";
                        }
      };
      table.addColumn(nameColumn, nameColumnHeader);