java - How to select one of GWT CellTree nodes after first data fetch? -
i'm trying select first root node of celltree after asynchronous data fetching server. here code:
public class mytreemodel implements treeviewmodel{ private myserviceasync myservice = gwt.create(myservice.class); public <t> nodeinfo<?> getnodeinfo(t value) { cell<myto> cell = new abstractcell<myto>() { @override public void render(context context, myto value, safehtmlbuilder sb) { //rendering node... } }; return new defaultnodeinfo<myto>(value instanceof myto ? createbranchdataprovider((myto)value) : //fetching child nodes ceraterootdataprovider(), cell); //fetching root nodes } @override public boolean isleaf(object value) { if (value instanceof myto) { myto = (myto)value; return to.isleafnode(); } return false; } private abstractdataprovider<myto> ceraterootdataprovider() { asyncdataprovider<myto> dataprovider = new asyncdataprovider<myto>() { @override protected void onrangechanged(hasdata<myto> display) { asynccallback<list<myto>> callback = new asynccallback<list<myto>>() { @override public void onsuccess(list<myto> result) { updaterowcount(result.size(), true); updaterowdata(0, result); } @override public void onfailure(throwable caught) { window.alert(caught.tostring()); } }; myservice.getrootnodes(callback); } }; return dataprovider; } private abstractdataprovider<myto> createbranchdataprovider(final myto value) { asyncdataprovider<myto> dataprovider = new asyncdataprovider<myto>() { @override protected void onrangechanged(hasdata<myto> display) { asynccallback<list<myto>> callback = new asynccallback<list<myto>>() { @override public void onsuccess(list<myto> result) { updaterowcount(result.size(), true); updaterowdata(0, result); } @override public void onfailure(throwable caught) { window.alert(caught.tostring()); } }; myservice.getchildnodes(value.getid(), callback); } }; return dataprovider; }
for data stored on client side solution looks pretty simple: call
tree.getroottreenode().setchildopen(0, true, true);
but if want fetch data asynchronously catch indexoutofboundsexception in case try same after creation tree, because data not obtained yet. how can know when onsuccess() event fired in ceraterootdataprovider()? or use solution? please suggest something.
i see 2 options calling
tree.getroottreenode().setchildopen(0, true, true);
in right moment:
direct dependency on presenter: add constructor
mytreemodel
object. send corresponding presenter parameter. add , callpresenter.ondataloadingcomplete()
@ end ofonsuccess
method.custom event: create custom event. fire @ end of
onsuccess
method. subscribe in place can call access `tree``object. call necessary code.
Comments
Post a Comment