GWT Custom header with a TextBox (TextInputCell) in my CellTable -> How to override onBrowserEvent?

970 views Asked by At

I would like to use a custom header with a TextBox (TextInputCell) in my CellTable.

I found this example and tried to adapt it: GWT 2: how can I add Button to the CellTable's header?

public static class BtnHeader extends Header<String>{

public BtnHeader(ButtonCell cell) {
    super(cell);

}
 @Override
   public void onBrowserEvent(Context context, Element elem, NativeEvent nativeEvent)
   {
      int eventType = Event.as(nativeEvent).getTypeInt();
      if (eventType == Event.ONCLICK)
      {
         nativeEvent.preventDefault();
        updateHeader();
      }
   }
@Override
public String getValue() {
    return "Click!";
}
protected void updateHeader() {
    // TODO to redefine in a defiant class

}

}

And in your code:

tnHeader header = new BtnHeader(new ButtonCell()){
            @Override
            protected   void updateHeader(){
                // Actions when clicking button
            }

cTable.addColumn(column, header);

How can I adapt this to my use case ?

I tried the following:

public class TextBoxHeader extends Header<String> {

private String myCaption;

public TextBoxHeader(TextInputCell cell, String caption) {
    super(cell);
    myCaption = caption;
}   

@Override
public String getValue() {
    // TODO Auto-generated method stub
    return myCaption;
}   

protected void updateHeader() {
    // TODO to redefine in a defiant class
} 

}

The whole part with the onBrowserEvent is missing. How to implement it ? The documentation (http://www.gwtproject.org/javadoc/latest/com/google/gwt/cell/client/TextInputCell.html) shows that onBrowserEvent is not protected. What to do now ?

Cheers, Tim

1

There are 1 answers

0
Tim On

Ok I found the solution. Instead of extending Header, I used a TextInputCell and put it in the Header. I then added a ValueUpdater to the header and I could react to the changes in the input field.

        TextInputCell cell = new TextInputCell("Program");
    com.google.gwt.user.cellview.client.Header<String> header = new com.google.gwt.user.cellview.client.Header<String>(cell) {

        @Override
        public String getValue() {
            // TODO Auto-generated method stub
            return "";
        }
    };  

    header.setUpdater(new ValueUpdater<String>() {

        @Override
        public void update(String value) {

        }
    });

Cheers, Tim