Question

does anyone know how to trigger the "Show More" functionality of a GWT CellTree programmatically, without having to click on the Show More button?

My aim is to implement a kind of pager that increments the number of elements displayed when the user scrolls down a ScollPanel, so it would be something like:

//inside pager class

onScroll(ScrollEvent)
{

    //here I would call CellTree's show more

}

I've been looking the CellTree and CellTreeNodeView classes code but I couldn't find a clear way to do it.

I know the class CellTreeNodeView has a showMore function which is the one who performs this action, but I don't know how to get it called from another class. I'd need a CellTreeNodeView object, and dont' know how to get it.

Thanks!

Was it helpful?

Solution

It is a package protected method in a package protected class CellTreeNodeView i.e only code in com.google.gwt.user.cellview.client can invoke it.

  void showMore() 

Extremely hacky solution

1) The only way around it is . Copy CellTreeNodeView and CellTree into your code base (maintain the package )

2) Change the accessors to public to allow you to invoke showMore as per your requirement.

3) Ensure you test for all possible flows.

4) Ensure the copied classes in your code base appear in a higher classpath hieararchy to GWT Compiler than gwt-user jar thus ensuring your modified classes get picked up rather than original ones.

OTHER TIPS

Finally I got it working exactly as I wanted, and without having to copy the code from the protected original GWT.

The point was firing the same event as the "Show more" button, so I created a fake onMouseDown event, and triggered it with the show more button as the target:

final ScrollPanel sp = new ScrollPanel();

sp.addScrollHandler(new ScrollHandler() {

  @Override
  public void onScroll(ScrollEvent event)
  {
    int maxScrollBottom = sp.getWidget().getOffsetHeight()
        - sp.getOffsetHeight();

    if (sp.getVerticalScrollPosition() >= maxScrollBottom) {
      NativeEvent clickEvent = Document.get().createMouseDownEvent(0,0,0,0,0,false,false,false,false,0);
      Element target = (Element) cellTree.getCellTree().getElement().getLastChild().getFirstChild().getLastChild();
      target.dispatchEvent(clickEvent);
    }
  }
});

Thank you a lot, anyway! :D

My workaround is this one:

public static void makeShowMoreVisible(Element element, boolean isVisible) {
    ArrayList<Element> result = new ArrayList<Element>();
    findShowMore(result, element);  

    for (Element elt : result) {
        if (isVisible) {
            element.getStyle().clearDisplay();
        } else {  
            element.getStyle().setDisplay(Display.NONE); 
        }
    }
}

private static void findShowMore(ArrayList res, Element element) {
    String c;

    if (element == null) {
        return;
    }

    if (element.getInnerText().equals("Show more")) {
        res.add(element);
    }

    for (int i = 0; i < DOM.getChildCount(element); i++) {
        Element child = DOM.getChild(element, i);
        findShowMore(res, child);   
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top