カスタムでGWT 2.1のCellBrowserTreeViewModel
を使用しています。次に、TreeViewModel は を使用しAsyncDataProvider
てデータを動的にフェッチします。これはすべてうまく機能します。ユーザーがノードをクリックすると、AsyncDataProvider が RPC 経由で結果を取得し、CellBrowser が忠実に結果を表示します。
これを理解できないのはばかげていると思いますが、プログラムでCellBrowserにデータをリロード(および表示)するように指示するにはどうすればよいですか? どうにかしてルート ノードの AsyncDataProvider へのハンドルを取得し、その上で updateRowData() と updateRowCount() を呼び出す必要があると推測していますが、ブラウザー (またはそのモデル) にクエリを実行する明確な方法がわかりません。ルート DataProvider 用。
null 引数を探すコードを AsyncDataProvider コンストラクターに追加できると思います。それにより、「ねえ、私はルートです」と認識し、どこかに参照を保存しますが、それはハックのようです。確かにこれを行うより良い方法があります。
ここに非常に多くのコードをダンプして申し訳ありませんが、これをより単純なものに要約し、十分なコンテキストを提供する方法がわかりません。
私の AsyncDataProvider:
private static class CategoryDataProvider extends AsyncDataProvider<Category>
{
private Category selectedCategory;
private CategoryDataProvider(Category selectedCategory)
{
this.selectedCategory = selectedCategory;
}
@Override
protected void onRangeChanged(HasData<Category> display)
{
new AsyncCall<List<Category>>()
{
@Override
protected void callService(AsyncCallback<List<Category>> 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<Category> result)
{
// update the display
updateRowCount(result.size(), true);
updateRowData(0, result);
}
}.go();
}
}
私のモデル:
private static class CategoryTreeModel implements TreeViewModel
{
private SingleSelectionModel<Category> selectionModel;
public CategoryTreeModel(SingleSelectionModel<Category> selectionModel)
{
this.selectionModel = selectionModel;
}
/**
* @return the NodeInfo that provides the children of the specified category
*/
public <T> NodeInfo<?> getNodeInfo(T value)
{
CategoryDataProvider dataProvider = new CategoryDataProvider((Category) value);
// Return a node info that pairs the data with a cell.
return new TreeViewModel.DefaultNodeInfo<Category>(dataProvider, new CategoryCell(), selectionModel, null);
}
/**
* @return true if the specified category represents a leaf node
*/
public boolean isLeaf(Object value)
{
return value != null && ((Category) value).isLeafCategory();
}
}
そして最後に、これが私がそれらをどのように使用しているかです:
CategoryTreeModel model = new CategoryTreeModel(selectionModel);
CellBrowser cellBrowser = new CellBrowser(model, null);