How do I tell a GWT cell widget data has changed via the Event Bus? -



How do I tell a GWT cell widget data has changed via the Event Bus? -

i have gwt cell tree utilize display file construction cms. using asyncdataprovider loads info custom rpc class created. have web socket scheme broadcast events (file create, renamed, moved, deleted etc) other clients working in system.

what trying wrap head around when recieve 1 of these events, how correctly update cell tree?

i suppose problem analogus having 2 instances of cell tree on page, presenting same server-side info , wanting ensure when user updated one, other updated well, via using eventbus.

i sense should pretty simple have spent 6 hours on no headway. code included below:

note: not using requestfactory though may custom rpc framework. also, fileentity simple representation of file has name accessible getname().

class="lang-java prettyprint-override">private void drawtree() { // fileservice injected before on , own custom rpc service treeviewmodel model = new customtreemodel(new filedataprovider(fileservice)); celltree tree = new celltree(model, "root"); tree.setanimationenabled(true); getview().getworkspace().add(tree); } private static class customtreemodel implements treeviewmodel { // trying utilize single asyncdataprovider have single point of loading info can manipulate (not sure if right way go) public customtreemodel(filedataprovider dataprovider) { this.provider = provider; } public <t> nodeinfo<?> getnodeinfo(final t value) { if (!(value instanceof fileentity)) { // have root file loaded in presenter, if @ root of tree, add together via list here listdataprovider<fileentity> dataprovider = new listdataprovider<fileentity>(); dataprovider.getlist().add(treeworkspacepresenter.rootfolder); homecoming new defaultnodeinfo<fileentity>(dataprovider, new filecell()); } else { // otherwise know loading tree kid data, , invoke asyncprovider load server provider.setfocusfile(value); homecoming new defaultnodeinfo<fileentity>(provider, new filecell()); } } public boolean isleaf(object value) { if(value == null || value instanceof folder) homecoming false; homecoming true; } } public class filedataprovider extends asyncdataprovider<fileentity> { private fileentity focusfile; private fileservice service; @inject public filedataprovider(fileservice service){ this.service = service; } public void setfocusfile(fileentity focusfile){ this.focusfile = focusfile; } @override protected void onrangechanged(hasdata<fileentity> display) { service.getchildren(((folder) focusfile), new reciever<list<fileentity>>() { @override public void onsuccess(list<fileentity> files) { updaterowdata(0, files); } @override public void onfailure(throwable error) { window.alert(error.tostring()); } }); } } /** * cell used render files. */ public static class filecell extends abstractcell<fileentity> { private fileentity file; public fileentity getfile() { homecoming file; } @override public void render(context context, fileentity file, safehtmlbuilder sb) { if (file != null) { this.file = file; sb.appendescaped(file.getname()); } } }

currently there no direct back upwards individual tree item refresh in latest gwt version.

but there workaround this. each tree item associated value. using value can corresponding tree item.

in case, assume, know item update/refresh ie know file entity has changed. utilize file entity search corresponding tree item. 1 time tree item need expand , collapse or collapse , expand parent item. makes parent item re-render children. changed file entity 1 among children. refreshed.

public void refreshfileentity(fileentity fileentity) { treenode fileentitynode = getfileentitynode(fileentity, celltree.getroottreenode() // expnad , collapse run loop ( int = 0; < fileentitynode.getparent().getchildcount(); i++ ) { if ( !fileentitynode.getparent().ischildleaf( ) ) { fileentitynode.getparent().setchildopen( i, true ); } } } public treenode getfileentitynode(fileentity fileentity, treenode treenode) { if(treenode.getchildren == null) { homecoming null; } for(treenode node : treenode.getchildren()) { if(fileentity.getid().equals( node.getvalue.getid() )) { homecoming node; } getentitynode(fileentity, node); } }

gwt event-bus

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -