Wednesday, November 24, 2010

Re: CellList -- is prefilled sizing possible?

I have made a rough implementation of an InfinitePagerPanel. It
involves a small cheat, but here is the code (hopefully google groups
doesn't butcher the formatting):

public class InfinitePagerPanel extends AbstractPager {

private DockLayoutPanel pagerPanel;
private PagerScrollbar scrollbar;

public InfinitePagerPanel() {
pagerPanel = new DockLayoutPanel(Unit.PX);
scrollbar = new PagerScrollbar();
pagerPanel.addEast(scrollbar, 16);
initWidget(pagerPanel);
}

@Override
public void setDisplay(HasRows display) {
assert display instanceof Widget : "display must be of type Widget";
pagerPanel.add((Widget) display);
super.setDisplay(display);
}

public void setStartRow(int start) {
scrollbar.setScrollPosition(start * PagerScrollbar.INFLATION_SIZE);
}

@Override
protected void onRangeOrRowCountChanged() {
scrollbar.updateRowCount(getDisplay().getRowCount());
}

private class PagerScrollbar extends ScrollPanel implements
ScrollHandler {

protected static final int INFLATION_SIZE = 25;

private HTML content;

public PagerScrollbar() {
super();
content = new HTML("<div></div>");
super.setWidget(content);
super.addScrollHandler(this);
}

public void updateRowCount(int rowCount) {
content.setHTML("<div style=\"height:" + (rowCount *
INFLATION_SIZE) + "px; width:1px;\"></div>");
}

@Override
public void onScroll(ScrollEvent event) {
int start = (super.getScrollPosition() / INFLATION_SIZE);
int length = getDisplay().getVisibleRange().getLength();
getDisplay().setVisibleRange(start, length);
}

}

}

The cheat is that I have put a ScrollPanel with empty contents beside
the CellList and then whenever the scrollbar has a scroll change, the
CellList updates. For the most part it works. The only problem I have
is that when I try using the "up" arrow on the scrollbar, the content
doesn't scroll upwards (it has a very strange effect). I'll see about
producing a simple example to reproduce the problem.

INFLATION_SIZE is my way of making the scrollbar in the scroll panel
reflect the actual number of elements in the list (I figured 25px per
row will give a fairly accurate display even if the rows are a bit
bigger or smaller than 25 px).

The setStartRow(int start) function is there so that I can jump the
list to a specific row (this is a feature my particular implementation
requires).

Any suggestions/comments would be greatly appreciated.

Thanks,

Andrew Arnott

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment