GWT CellList Render Done Handler?

593 Views Asked by At

I use the GWT CellList widget to render Cell elements.

Is there a way to register a render complete or render done event to execute stuff after rendering was done?

2

There are 2 best solutions below

0
apanizo On BEST ANSWER

I had the same question and taking a look into the code I have found a possible solution.

In the HasDataPresenter there are the code which renders the cells into the view (method resolvePendingState(JsArrayInteger modifiedRows):

if (redrawRequired) {
        // Redraw the entire content.
        SafeHtmlBuilder sb = new SafeHtmlBuilder();
        view.replaceAllChildren(newState.rowData, selectionModel, newState.keyboardStealFocus);
        view.resetFocus();
      } else if (range0 != null) {
        // Surgically replace specific rows.

        // Replace range0.
        {
          int absStart = range0.getStart();
          int relStart = absStart - pageStart;
          SafeHtmlBuilder sb = new SafeHtmlBuilder();
          List<T> replaceValues = newState.rowData.subList(relStart, relStart + range0.getLength());
          view.replaceChildren(replaceValues, relStart, selectionModel, newState.keyboardStealFocus);
        }

        // Replace range1 if it exists.
        if (range1 != null) {
          int absStart = range1.getStart();
          int relStart = absStart - pageStart;
          SafeHtmlBuilder sb = new SafeHtmlBuilder();
          List<T> replaceValues = newState.rowData.subList(relStart, relStart + range1.getLength());
          view.replaceChildren(replaceValues, relStart, selectionModel, newState.keyboardStealFocus);
        }

        view.resetFocus();

The method view.replaceAllChildren(....) calls to render cell's render method, and when it has finished a ValueChangeEvent() is fired.

@Override
public void replaceAllChildren(....) {
  SafeHtml html = renderRowValues(...);

  ....

  fireValueChangeEvent();
}

So in your cellList you should do something like:

   cellList.addHandler(new ValueChangeHandler<List<IPost>>() {

        @Override
        public void onValueChange(ValueChangeEvent<List<IPost>> event) {
          //Do something
          //Be careful because this handler could be called from other methods

        }
      }, ValueChangeEvent.getType());
0
dhamibirendra On

Referring GWT CellList Widget Example

You can use your own custom Cell extending AbstractCell (As used ContactCell in the example).

There you will need to override the render method:

@Override public void render(Context context, ContactInfo value, SafeHtmlBuilder sb) {

  (//other codes)
  (// put your logic after render here at the last)
}