Michael
Michael

Reputation: 33307

GWT CellList Render Done Handler?

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?

Upvotes: 0

Views: 551

Answers (2)

apanizo
apanizo

Reputation: 628

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());

Upvotes: 1

dhamibirendra
dhamibirendra

Reputation: 3046

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)
}

Upvotes: 0

Related Questions