6218c03c0e4cb416eb3a36b7306f0eda2ca13162
[pithos] / web_client / src / gr / grnet / pithos / web / client / CellTreeView.java
1 /*
2  * Copyright 2011 GRNET S.A. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or
5  * without modification, are permitted provided that the following
6  * conditions are met:
7  *
8  *   1. Redistributions of source code must retain the above
9  *      copyright notice, this list of conditions and the following
10  *      disclaimer.
11  *
12  *   2. Redistributions in binary form must reproduce the above
13  *      copyright notice, this list of conditions and the following
14  *      disclaimer in the documentation and/or other materials
15  *      provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  *
30  * The views and conclusions contained in the software and
31  * documentation are those of the authors and should not be
32  * interpreted as representing official policies, either expressed
33  * or implied, of GRNET S.A.
34  */
35 package gr.grnet.pithos.web.client;
36
37 import gr.grnet.pithos.web.client.CellTreeViewModel.ClearSelection;
38 import gr.grnet.pithos.web.client.rest.GetCommand;
39 import gr.grnet.pithos.web.client.rest.RestException;
40 import gr.grnet.pithos.web.client.rest.resource.FolderResource;
41 import gr.grnet.pithos.web.client.rest.resource.MyFolderResource;
42 import gr.grnet.pithos.web.client.rest.resource.OtherUserResource;
43 import gr.grnet.pithos.web.client.rest.resource.OthersFolderResource;
44 import gr.grnet.pithos.web.client.rest.resource.OthersResource;
45 import gr.grnet.pithos.web.client.rest.resource.RestResource;
46 import gr.grnet.pithos.web.client.rest.resource.RestResourceWrapper;
47 import gr.grnet.pithos.web.client.rest.resource.SharedResource;
48 import gr.grnet.pithos.web.client.rest.resource.TrashFolderResource;
49 import gr.grnet.pithos.web.client.rest.resource.TrashResource;
50 import gr.grnet.pithos.web.client.rest.resource.UserResource;
51 import gwtquery.plugins.droppable.client.gwt.DragAndDropCellTree;
52
53 import java.util.Arrays;
54
55 import com.google.gwt.core.client.GWT;
56 import com.google.gwt.resources.client.ClientBundle;
57 import com.google.gwt.resources.client.ImageResource;
58 import com.google.gwt.resources.client.ImageResource.ImageOptions;
59 import com.google.gwt.user.cellview.client.CellTree;
60 import com.google.gwt.user.cellview.client.TreeNode;
61 import com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy.KeyboardSelectionPolicy;
62 import com.google.gwt.user.client.DeferredCommand;
63 import com.google.gwt.user.client.Event;
64 import com.google.gwt.user.client.IncrementalCommand;
65 import com.google.gwt.user.client.ui.Composite;
66 import com.google.gwt.user.client.ui.Tree;
67 import com.google.gwt.view.client.ProvidesKey;
68 import com.google.gwt.view.client.SelectionChangeEvent;
69 import com.google.gwt.view.client.SingleSelectionModel;
70 import com.google.gwt.view.client.TreeViewModel;
71 import com.google.gwt.view.client.SelectionChangeEvent.Handler;
72 import com.google.gwt.view.client.TreeViewModel.NodeInfo;
73
74
75 public class CellTreeView extends Composite{
76         public static final boolean DONE = false;
77         Images images;
78         
79         SingleSelectionModel<RestResource> selectionModel = new SingleSelectionModel<RestResource>(new ProvidesKey<RestResource>() {
80
81                 @Override
82                 public Object getKey(RestResource item) {
83                         return item.getClass().getName()+":"+item.getUri();
84                 }});
85         FolderContextMenu menu;
86         
87         
88         MyFolderResource myFolders=null;
89         TrashResource trash = null;
90         SharedResource myshared = null;
91         OthersResource others = null;
92         
93         CellTreeViewModel model;
94         CellTreeViewUtils utils;
95         
96         public interface Images extends ClientBundle,Tree.Resources, FolderContextMenu.Images {
97
98         @Source("gr/grnet/pithos/resources/folder_home.png")
99         ImageResource home();
100
101         @Source("gr/grnet/pithos/resources/folder_yellow.png")
102         ImageResource folderYellow();
103
104         @Source("gr/grnet/pithos/resources/mimetypes/document.png")
105         ImageResource document();
106
107         @Source("gr/grnet/pithos/resources/internet.png")
108         ImageResource othersShared();
109
110         @Source("gr/grnet/pithos/resources/edit_user.png")
111         ImageResource myShared();
112
113         @Source("gr/grnet/pithos/resources/folder_user.png")
114         ImageResource sharedFolder();
115
116         @Source("gr/grnet/pithos/resources/trashcan_empty.png")
117         ImageResource trash();
118         }
119         DragAndDropCellTree tree;
120         /*public interface BasicResources extends CellTree.BasicResources{
121                 @ImageOptions(flipRtl = true)
122             @Source("cellTreeLoadingBasic.gif")
123             ImageResource cellTreeLoading();
124                 
125                 @Source({"GssCellTreeBasic.css"})
126             CellTree.Style cellTreeStyle();
127         }*/
128         public interface BasicResources extends CellTree.Resources {
129
130             @ImageOptions(flipRtl = true)
131             @Source("cellTreeClosedItem.gif")
132             ImageResource cellTreeClosedItem();
133
134             @ImageOptions(flipRtl = true)
135             @Source("cellTreeLoadingBasic.gif")
136             ImageResource cellTreeLoading();
137
138             @ImageOptions(flipRtl = true)
139             @Source("cellTreeOpenItem.gif")
140             ImageResource cellTreeOpenItem();
141
142             //@Source({CellTree.Style.DEFAULT_CSS,"GssCellTreeBasic.css"})
143             @Source({"GssCellTreeBasic.css"})
144             CellTree.Style cellTreeStyle();
145           }
146         /**
147          * 
148          */
149         public CellTreeView(final Images _images) {
150                 images = _images;
151                 model = new CellTreeViewModel(images,selectionModel);
152             /*
153              * Create the tree using the model. We use <code>null</code> as the default
154              * value of the root node. The default value will be passed to
155              * CustomTreeModel#getNodeInfo();
156              */
157                 CellTree.Resources res = GWT.create(BasicResources.class);
158             tree = new DragAndDropCellTree(model,null, res){
159                 @Override
160                 public void onBrowserEvent(Event event) {
161                         // TODO Auto-generated method stub
162                         super.onBrowserEvent(event);
163                 }
164             };
165             utils=new CellTreeViewUtils(tree);
166             tree.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
167             /*tree.addOpenHandler(new OpenHandler<TreeNode>() {
168                         
169                         @Override
170                         public void onOpen(OpenEvent<TreeNode> event) {
171                                 Window.alert("[NODE OPENED]"+event.getTarget());
172                                 
173                         }
174                 });
175             tree.addOverDroppableHandler(new OverDroppableEventHandler() {
176                         
177                         @Override
178                         public void onOverDroppable(OverDroppableEvent event) {
179                                 GWT.log("OVER:"+event);
180                                 
181                         }
182                 });
183             tree.addAttachHandler(new AttachEvent.Handler() {
184                         
185                         @Override
186                         public void onAttachOrDetach(AttachEvent event) {
187                                 GWT.log("ATTACH:"+event.getSource());
188                                 
189                         }
190                 });*/
191             Handler selectionHandler = new SelectionChangeEvent.Handler() { 
192             @Override 
193             public void onSelectionChange(com.google.gwt.view.client.SelectionChangeEvent event) {
194                 NodeInfo<RestResource> nodeInfo = (NodeInfo<RestResource>) getModel().getNodeInfo(selectionModel.getSelectedObject());
195                 if(nodeInfo==null || nodeInfo.getValueUpdater()==null){
196                         GSS.get().showFileList(getSelection());
197                 }
198                 else
199                         nodeInfo.getValueUpdater().update(selectionModel.getSelectedObject());
200                 GSS.get().setCurrentSelection(selectionModel.getSelectedObject());
201                 
202                 
203             }
204         };
205         selectionModel.addSelectionChangeHandler(selectionHandler);
206             sinkEvents(Event.ONCONTEXTMENU);
207                 sinkEvents(Event.ONMOUSEUP);
208             initWidget(tree);
209             FolderResource loadingResource = new FolderResource("loading");
210             loadingResource.setName("Loading....");
211             loadingResource.setShared(false);
212             RestResourceWrapper loading = new RestResourceWrapper(loadingResource);
213             model.getRootNodes().setList(Arrays.asList((RestResource)loading));
214                 
215             DeferredCommand.addCommand(new IncrementalCommand() {
216
217                         @Override
218                         public boolean execute() {
219                                 return fetchRootFolders();
220                         }
221                 });
222         }
223         
224         public void updateNode(RestResource resource){
225                 NodeInfo<RestResource> nodeInfo = (NodeInfo<RestResource>) getModel().getNodeInfo(resource);
226                 
227                 if(nodeInfo!=null){
228                 if(nodeInfo.getValueUpdater()==null){}
229                 else
230                         nodeInfo.getValueUpdater().update(resource);
231         }
232         }
233         
234         public void updateNodeChildren(final RestResource resource){
235                 
236                 if(resource instanceof RestResourceWrapper){
237                         boolean updated=false;
238                         if(((RestResourceWrapper)resource).getResource().getFolders().size()==0){
239                                 if(((RestResourceWrapper)resource).getResource().getParentURI().equals(getMyFolders().getUri())){
240                                         updateNodeChildren(getMyFolders().getUri());
241                                         return;
242                                 }
243                                 if(model.getMymap().get(((RestResourceWrapper)resource).getResource().getParentURI())!=null){
244                                         model.getMymap().get(((RestResourceWrapper)resource).getResource().getParentURI()).refresh(null);
245                                         updated=true;
246                                 }
247                                 if(model.getOthersmap().get(((RestResourceWrapper)resource).getResource().getParentURI())!=null){
248                                         model.getOthersmap().get(((RestResourceWrapper)resource).getResource().getParentURI()).refresh(null);
249                                         updated=true;
250                                 }
251                                 if(model.getSharedmap().get(((RestResourceWrapper)resource).getResource().getParentURI())!=null){
252                                         model.getSharedmap().get(((RestResourceWrapper)resource).getResource().getParentURI()).refresh(null);
253                                         updated=true;
254                                 }
255                                 if(updated){
256                                         if(utils.doesSharedNodeContainsResourceIn1stLevel(resource.getUri())){
257                                                 updateMySharedNode();
258                                         }
259                                         else if(tree.getRootTreeNode().isChildOpen(2)){
260                                                 utils.refreshNodeContainingResource(tree.getRootTreeNode().setChildOpen(2,true),resource.getUri());
261                                         }
262                                         //return;
263                                 }
264                         }
265                 }
266                 
267                 utils.refreshNodeContainingResource(resource);
268                 if(utils.doesSharedNodeContainsResourceIn1stLevel(resource.getUri())){
269                         updateMySharedNode();
270                 }
271                 else if(tree.getRootTreeNode().isChildOpen(2)){
272                         GWT.log("REFRESH THE OTHER WAY 2:"+resource);
273                         utils.refreshNodeContainingResource(tree.getRootTreeNode().setChildOpen(2,true),resource.getUri());
274                 }
275                 
276         }
277         public void updateNodeChildrenForRemove(final String resource){
278                 GWT.log("********************************");
279                 GWT.log("[UPDATENODECHILDREN]"+resource);
280                 GWT.log("********************************");
281                 boolean updated=false;
282                 TreeNode node=null;
283                 TreeNode sharedNode=null;
284                 if(tree.getRootTreeNode().isChildOpen(0)){
285                         node = utils.getNodeContainingResource2(tree.getRootTreeNode().setChildOpen(0,true), resource);
286                 }
287                         GWT.log("CHECK NODE1:"+node+" "+resource);
288                 
289                         if(tree.getRootTreeNode().isChildOpen(2)){
290                                 GWT.log("CHECK NODE2:"+node);
291                                 if(node==null)
292                                         node = utils.getNodeContainingResource2(tree.getRootTreeNode().setChildOpen(2,true), resource);
293                                 
294                         }
295                 if(node==null)
296                         if(tree.getRootTreeNode().isChildOpen(3)){
297                                 GWT.log("CHECK NODE3:"+node);
298                                 node = utils.getNodeContainingResource2(tree.getRootTreeNode().setChildOpen(3,true), resource);
299                 }
300                 if(node != null && node.getValue() instanceof RestResourceWrapper){
301                         GWT.log("*********************"+((RestResourceWrapper) node.getValue()).getResource().getFolders().size());
302                         RestResourceWrapper wrapper  = (RestResourceWrapper) node.getValue();
303                         if(wrapper.getResource().countNotDeletedSubfolders()==1||wrapper.getResource().countNotDeletedSubfolders()==0){
304                                 updateNodeChildren(((RestResourceWrapper) node.getValue()).getResource().getParentURI());
305                                 if(((RestResourceWrapper) node.getValue()).getResource().getParentURI().equals(myFolders.getUri())){
306                                         if(utils.doesSharedNodeContainsResourceIn1stLevel(resource)||utils.doesSharedNodeContainsResourceIn2ndLevel(resource)){
307                                                 updateMySharedNode();
308                                         }
309                                 }
310                                                         
311                         }
312                         else
313                                 updateNodeChildren(((RestResource) node.getValue()).getUri());
314                         return;
315                 }
316                 updateNodeChildren(resource);
317         }
318         public void updateNodeChildren(final String resource){
319                 
320                         
321                 GWT.log("REFRESH THE OTHER WAY");
322                 utils.refreshNodeContainingResource(resource);
323                 if(utils.doesSharedNodeContainsResourceIn1stLevel(resource)||utils.doesSharedNodeContainsResourceIn2ndLevel(resource)){
324                         GWT.log("REFRESH THE OTHER WAY 1:"+resource);
325                         updateMySharedNode();
326                 }
327                 else if(tree.getRootTreeNode().isChildOpen(2)){
328                         GWT.log("REFRESH THE OTHER WAY 2:"+resource);
329                         utils.refreshNodeContainingResource(tree.getRootTreeNode().setChildOpen(2,true),resource);
330                 }
331         }
332         
333         protected void showPopup(final int x, final int y) {
334                 if (selectionModel.getSelectedObject() == null)
335                         return;
336                 if (menu != null)
337                         menu.hide();
338                 menu = new FolderContextMenu(images);
339                 menu.setPopupPosition(x, y);
340                 menu.show();
341         }
342         private boolean init=false;
343         public boolean fetchRootFolders() {
344                 UserResource userResource = GSS.get().getCurrentUserResource();
345                 if (userResource == null)
346                         return !DONE;
347                 if(!init){
348                         final String path = userResource.getFilesPath();
349                         GetCommand<FolderResource> gf = new GetCommand<FolderResource>(FolderResource.class, path, null) {
350         
351                                 @Override
352                                 public void onComplete() {
353                                         myFolders = new MyFolderResource(getResult());
354                                         //selectionModel.setSelected(myFolders, true);
355                                         //rootNodes.setList(Arrays.asList((RestResource)rootResource));
356                                         //tree.getRootTreeNode().setChildOpen(0, true);
357                                 }
358         
359                                 @Override
360                                 public void onError(Throwable t) {
361                                         GWT.log("Error fetching root folder", t);
362                                         GSS.get().displayError("Unable to fetch root folder");
363                                 }
364         
365                         };
366                         DeferredCommand.addCommand(gf);
367                         DeferredCommand.addCommand(new GetCommand<TrashResource>(TrashResource.class, GSS.get().getCurrentUserResource().getTrashPath(), null) {
368                                 @Override
369                                 public void onComplete() {
370                                         trash = getResult();
371                                 }
372
373                                 @Override
374                                 public void onError(Throwable t) {
375                                         if(t instanceof RestException){
376                                                 int statusCode = ((RestException)t).getHttpStatusCode();
377                                                 // On IE status code 1223 may be returned instead of 204.
378                                                 if(statusCode == 204 || statusCode == 1223){
379                                                         trash = new TrashResource(GSS.get().getCurrentUserResource().getTrashPath());
380                                         }
381                                         else{
382                                                 GWT.log("", t);
383                                                 GSS.get().displayError("Unable to fetch trash folder:"+t.getMessage());
384                                                 trash = new TrashResource(GSS.get().getCurrentUserResource().getTrashPath());
385                                         }
386                                 }
387                         }
388                         });
389                         GetCommand<SharedResource> gs = new GetCommand<SharedResource>(SharedResource.class, userResource.getSharedPath(), null) {
390
391                                 @Override
392                                 public void onComplete() {
393                                         myshared=getResult();
394                                 }
395
396                                 @Override
397                                 public void onError(Throwable t) {
398                                         GWT.log("Error fetching Shared Root folder", t);
399                                         GSS.get().displayError("Unable to fetch Shared Root folder");
400                                 }
401                         };
402                         DeferredCommand.addCommand(gs);
403                         GetCommand<OthersResource> go = new GetCommand<OthersResource>(OthersResource.class,
404                                                 userResource.getOthersPath(), null) {
405
406                                 @Override
407                                 public void onComplete() {
408                                         others = getResult();
409                                 }
410
411                                 @Override
412                                 public void onError(Throwable t) {
413                                         GWT.log("Error fetching Others Root folder", t);
414                                         GSS.get().displayError("Unable to fetch Others Root folder");
415                                 }
416                         };
417                         DeferredCommand.addCommand(go);
418                 }
419                 if(myFolders==null||trash==null||myshared==null||others==null)
420                         return !DONE;
421                 model.getRootNodes().setList(Arrays.asList((RestResource)myFolders,(RestResource)trash,(RestResource)myshared,(RestResource)others));
422                 tree.getRootTreeNode().setChildOpen(0, true);
423                 selectionModel.setSelected(myFolders, true);
424                 return DONE;
425         }
426
427         public Images getImages() {
428                 return images;
429         }
430         
431         
432         public void updateTrashNode(){
433                 DeferredCommand.addCommand(new GetCommand<TrashResource>(TrashResource.class, GSS.get().getCurrentUserResource().getTrashPath(), null) {
434                         @Override
435                         public void onComplete() {
436                                 trash = getResult();
437                                 boolean trashIsOpen = tree.getRootTreeNode().isChildOpen(1);
438                                 model.getRootNodes().getList().set(1, trash);
439                                 model.getRootNodes().refresh();
440                                 tree.getRootTreeNode().setChildOpen(1, true);
441                         }
442
443                         @Override
444                         public void onError(Throwable t) {
445                                 if(t instanceof RestException){
446                                         int statusCode = ((RestException)t).getHttpStatusCode();
447                                         // On IE status code 1223 may be returned instead of 204.
448                                         if(statusCode == 204 || statusCode == 1223){
449                                                 trash = new TrashResource(GSS.get().getCurrentUserResource().getTrashPath());
450                                                 model.getRootNodes().getList().set(1, trash);
451                                                 //model.getRootNodes().refresh();
452                                 }
453                                 else{
454                                         GWT.log("", t);
455                                         GSS.get().displayError("Unable to fetch trash folder:"+t.getMessage());
456                                         trash = new TrashResource(GSS.get().getCurrentUserResource().getTrashPath());
457                                         model.getRootNodes().getList().set(1, trash);
458                                         //model.getRootNodes().refresh();
459                                 }
460                         }
461                 }
462                 });
463         }
464         
465         public void updateRootNode(){
466                 final String path = GSS.get().getCurrentUserResource().getFilesPath();
467                 GetCommand<FolderResource> gf = new GetCommand<FolderResource>(FolderResource.class, path, null) {
468
469                         @Override
470                         public void onComplete() {
471                                 myFolders = new MyFolderResource(getResult());
472                                 model.getRootNodes().getList().set(0, myFolders);
473                                 model.getRootNodes().refresh();
474                                 tree.getRootTreeNode().setChildOpen(0, true);
475                                 
476                         }
477
478                         @Override
479                         public void onError(Throwable t) {
480                                 GWT.log("Error fetching root folder", t);
481                                 GSS.get().displayError("Unable to fetch root folder");
482                         }
483
484                 };
485                 DeferredCommand.addCommand(gf);
486         }
487         
488         public void updateMySharedNode(){
489                 GetCommand<SharedResource> gs = new GetCommand<SharedResource>(SharedResource.class, GSS.get().getCurrentUserResource().getSharedPath(), null) {
490
491                         @Override
492                         public void onComplete() {
493                                 myshared=getResult();
494                                 model.getRootNodes().getList().set(2, myshared);
495                         }
496
497                         @Override
498                         public void onError(Throwable t) {
499                                 GWT.log("Error fetching Shared Root folder", t);
500                                 GSS.get().displayError("Unable to fetch Shared Root folder");
501                         }
502                 };
503                 DeferredCommand.addCommand(gs);
504         }
505         
506         public void updateOtherNode(){
507                 GetCommand<OthersResource> go = new GetCommand<OthersResource>(OthersResource.class,
508                                         GSS.get().getCurrentUserResource().getOthersPath(), null) {
509
510                         @Override
511                         public void onComplete() {
512                                 others = getResult();
513                                 model.getRootNodes().getList().set(3, others);
514                         }
515
516                         @Override
517                         public void onError(Throwable t) {
518                                 GWT.log("Error fetching Others Root folder", t);
519                                 GSS.get().displayError("Unable to fetch Others Root folder");
520                         }
521                 };
522                 DeferredCommand.addCommand(go);
523         }
524         
525         
526         public RestResource getSelection(){
527                 return selectionModel.getSelectedObject();
528         }
529         
530         public void clearSelection(){
531                 if(GSS.get().getCurrentSelection().equals(getSelection()))
532                         GSS.get().setCurrentSelection(null);
533                 selectionModel.setSelected(getSelection(), false);
534         }
535         
536         
537         /**
538          * Retrieve the myFolders.
539          *
540          * @return the myFolders
541          */
542         public MyFolderResource getMyFolders() {
543                 return myFolders;
544         }
545         
546         
547         /**
548          * Retrieve the myshared.
549          *
550          * @return the myshared
551          */
552         public SharedResource getMyshared() {
553                 return myshared;
554         }
555         
556         
557         /**
558          * Retrieve the trash.
559          *
560          * @return the trash
561          */
562         public TrashResource getTrash() {
563                 return trash;
564         }
565         
566         
567         /**
568          * Retrieve the others.
569          *
570          * @return the others
571          */
572         public OthersResource getOthers() {
573                 return others;
574         }
575         
576         
577         /**
578          * Retrieve the model.
579          *
580          * @return the model
581          */
582         public TreeViewModel getModel() {
583                 return model;
584         }
585         
586         
587         
588         /**
589          * Retrieve the utils.
590          *
591          * @return the utils
592          */
593         public CellTreeViewUtils getUtils() {
594                 return utils;
595         }
596         
597         public interface RefreshHandler{
598                 void onRefresh();               
599         }
600         
601         
602         public boolean isTrashOrTrashFolderSelected(){
603                 return (getSelection() instanceof TrashResource) || (getSelection() instanceof TrashFolderResource);
604         }
605         
606         public OtherUserResource getOtherUserResourceOfOtherFolder(OthersFolderResource res){
607                 TreeNode n = utils.getNodeContainingResource(tree.getRootTreeNode().setChildOpen(3, true), res);
608                 
609                 if(n!=null){
610                         if(n.getValue() instanceof OtherUserResource)
611                                 return (OtherUserResource) n.getValue();
612                         TreeNode parent = n.getParent();
613                         
614                         while (parent!=null){
615                                 if(parent.getValue() instanceof OtherUserResource)
616                                         return (OtherUserResource) parent.getValue();
617                                 parent = parent.getParent();
618                         }
619                 }
620                 return null;
621         }
622         
623         public void refreshCurrentNode(boolean clearSelection){
624                 NodeInfo<RestResource> nodeInfo = (NodeInfo<RestResource>) getModel().getNodeInfo(selectionModel.getSelectedObject());
625         if(nodeInfo==null || nodeInfo.getValueUpdater()==null){
626                 GSS.get().showFileList(getSelection(),clearSelection);
627         }
628         else{
629                 if(!clearSelection)
630                         ((ClearSelection)nodeInfo.getValueUpdater()).setClearSelection(clearSelection);
631                 nodeInfo.getValueUpdater().update(selectionModel.getSelectedObject());
632         }
633         }
634         
635 }