Note that there are some explanatory texts on larger screens.

plurals
  1. POGWT: How to programmatically reload CellBrowser?
    primarykey
    data
    text
    <p>I'm using GWT 2.1's <a href="http://google-web-toolkit.googlecode.com/svn/javadoc/2.1/index.html?overview-summary.html" rel="noreferrer">CellBrowser</a> with a custom <code>TreeViewModel</code>. The TreeViewModel in turn uses an <code>AsyncDataProvider</code> to fetch data dynamically. This all works beautifully- when the user clicks on a node my AsyncDataProvider fetches the results via RPC, and the CellBrowser dutifully displays them.</p> <p>I feel silly for not being able to figure this out, but how can I programmatically tell the CellBrowser to reload (and display) the data? I'm guessing that I need to somehow get a handle to the AsyncDataProvider for my root node and then call updateRowData() &amp; updateRowCount() on it, but I don't see an obvious way to query the browser (or its model) for the root DataProvider.</p> <p>I guess I could add code to my AsyncDataProvider constructor that looks for a null argument, and by that means recognize "hey, I'm the root" and store a reference somewhere, but that seems hackish. Surely there's a better way to do this.</p> <p>Apologies for dumping so much code here, but I don't know how to boil this down to anything simpler and still provide enough context.</p> <p><strong>My AsyncDataProvider:</strong></p> <pre><code>private static class CategoryDataProvider extends AsyncDataProvider&lt;Category&gt; { private Category selectedCategory; private CategoryDataProvider(Category selectedCategory) { this.selectedCategory = selectedCategory; } @Override protected void onRangeChanged(HasData&lt;Category&gt; display) { new AsyncCall&lt;List&lt;Category&gt;&gt;() { @Override protected void callService(AsyncCallback&lt;List&lt;Category&gt;&gt; cb) { // default to root String categoryId = "-1"; if (selectedCategory != null) { categoryId = selectedCategory.getCategoryId(); } // when a category is clicked, fetch its child categories service.getCategoriesForParent(categoryId, cb); } @Override public void onSuccess(List&lt;Category&gt; result) { // update the display updateRowCount(result.size(), true); updateRowData(0, result); } }.go(); } } </code></pre> <p><strong>My model:</strong></p> <pre><code>private static class CategoryTreeModel implements TreeViewModel { private SingleSelectionModel&lt;Category&gt; selectionModel; public CategoryTreeModel(SingleSelectionModel&lt;Category&gt; selectionModel) { this.selectionModel = selectionModel; } /** * @return the NodeInfo that provides the children of the specified category */ public &lt;T&gt; NodeInfo&lt;?&gt; getNodeInfo(T value) { CategoryDataProvider dataProvider = new CategoryDataProvider((Category) value); // Return a node info that pairs the data with a cell. return new TreeViewModel.DefaultNodeInfo&lt;Category&gt;(dataProvider, new CategoryCell(), selectionModel, null); } /** * @return true if the specified category represents a leaf node */ public boolean isLeaf(Object value) { return value != null &amp;&amp; ((Category) value).isLeafCategory(); } } </code></pre> <p><strong>And finally, here's how I'm using them:</strong></p> <pre><code> CategoryTreeModel model = new CategoryTreeModel(selectionModel); CellBrowser cellBrowser = new CellBrowser(model, null); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload