2 * Copyright 2011 GRNET S.A. All rights reserved.
4 * Redistribution and use in source and binary forms, with or
5 * without modification, are permitted provided that the following
8 * 1. Redistributions of source code must retain the above
9 * copyright notice, this list of conditions and the following
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.
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.
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.
35 package gr.grnet.pithos.web.client;
37 import static com.google.gwt.query.client.GQuery.$;
38 import gr.grnet.pithos.web.client.CellTreeView.Images;
39 import gr.grnet.pithos.web.client.CellTreeView.RefreshHandler;
40 import gr.grnet.pithos.web.client.rest.GetCommand;
41 import gr.grnet.pithos.web.client.rest.MultipleGetCommand;
42 import gr.grnet.pithos.web.client.rest.RestException;
43 import gr.grnet.pithos.web.client.rest.resource.FileResource;
44 import gr.grnet.pithos.web.client.rest.resource.FolderResource;
45 import gr.grnet.pithos.web.client.rest.resource.MyFolderResource;
46 import gr.grnet.pithos.web.client.rest.resource.OtherUserResource;
47 import gr.grnet.pithos.web.client.rest.resource.OthersFolderResource;
48 import gr.grnet.pithos.web.client.rest.resource.OthersResource;
49 import gr.grnet.pithos.web.client.rest.resource.RestResource;
50 import gr.grnet.pithos.web.client.rest.resource.RestResourceWrapper;
51 import gr.grnet.pithos.web.client.rest.resource.SharedFolderResource;
52 import gr.grnet.pithos.web.client.rest.resource.SharedResource;
53 import gr.grnet.pithos.web.client.rest.resource.TrashFolderResource;
54 import gr.grnet.pithos.web.client.rest.resource.TrashResource;
55 import gwtquery.plugins.draggable.client.DragAndDropManager;
56 import gwtquery.plugins.draggable.client.DraggableOptions;
57 import gwtquery.plugins.draggable.client.StopDragException;
58 import gwtquery.plugins.draggable.client.DraggableOptions.CursorAt;
59 import gwtquery.plugins.draggable.client.DraggableOptions.DragFunction;
60 import gwtquery.plugins.draggable.client.DraggableOptions.RevertOption;
61 import gwtquery.plugins.draggable.client.events.DragContext;
62 import gwtquery.plugins.droppable.client.DroppableOptions;
63 import gwtquery.plugins.droppable.client.DroppableOptions.DroppableFunction;
64 import gwtquery.plugins.droppable.client.events.DragAndDropContext;
65 import gwtquery.plugins.droppable.client.gwt.DragAndDropNodeInfo;
67 import java.util.ArrayList;
68 import java.util.HashMap;
69 import java.util.List;
72 import com.google.gwt.cell.client.AbstractCell;
73 import com.google.gwt.cell.client.Cell;
74 import com.google.gwt.cell.client.ValueUpdater;
75 import com.google.gwt.core.client.GWT;
76 import com.google.gwt.dom.client.Style.Cursor;
77 import com.google.gwt.safehtml.client.SafeHtmlTemplates;
78 import com.google.gwt.safehtml.shared.SafeHtml;
79 import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
80 import com.google.gwt.user.client.DeferredCommand;
81 import com.google.gwt.user.client.ui.AbstractImagePrototype;
82 import com.google.gwt.view.client.AsyncDataProvider;
83 import com.google.gwt.view.client.HasData;
84 import com.google.gwt.view.client.ListDataProvider;
85 import com.google.gwt.view.client.ProvidesKey;
86 import com.google.gwt.view.client.SingleSelectionModel;
87 import com.google.gwt.view.client.TreeViewModel;
91 public class CellTreeViewModel implements TreeViewModel{
93 private final ListDataProvider<RestResource> rootNodes = new ListDataProvider<RestResource>();
94 private Map<String,FolderResource> folderCache=new HashMap<String, FolderResource>();
96 SingleSelectionModel<RestResource> selectionModel;
97 Map<String, MyFolderDataProvider> mymap = new HashMap<String, MyFolderDataProvider>();
98 Map<String, MyFolderDataProvider> sharedmap = new HashMap<String, MyFolderDataProvider>();
99 Map<String, MyFolderDataProvider> othersmap = new HashMap<String, MyFolderDataProvider>();
100 static interface Templates extends SafeHtmlTemplates {
101 Templates INSTANCE = GWT.create(Templates.class);
103 @Template(" <div id='dragHelper' class='{0}'></div>")
104 SafeHtml outerHelper(String cssClassName);
107 void configureDragOperation(final DraggableOptions options) {
109 // set a custom element as drag helper. The content of the helper will be
110 // set when the drag will start
111 options.setHelper($(Templates.INSTANCE.outerHelper(
112 "drag").asString()));
113 // opacity of the drag helper
114 options.setOpacity((float) 0.9);
115 // cursor during the drag operation
116 options.setCursor(Cursor.MOVE);
117 // the cell being greater than the helper, force the position of the
118 // helper on the mouse cursor.
119 options.setCursorAt(new CursorAt(10, 10, null, null));
120 // append the helper to the body element
121 options.setAppendTo("body");
122 options.setCancel("select");
123 // set the revert option
124 options.setRevert(RevertOption.ON_INVALID_DROP);
126 options.setOnBeforeDragStart(new DragFunction() {
129 public void f(DragContext context) {
130 RestResource value = context.getDraggableData();
131 if(!CellTreeViewModel.this.selectionModel.isSelected(value)){
132 throw new StopDragException();
134 if(value instanceof TrashResource || value instanceof SharedResource || value instanceof OthersResource || value instanceof OtherUserResource){
135 throw new StopDragException();
140 // use a Function to fill the content of the helper
141 // we could also add a DragStartEventHandler on the DragAndDropTreeCell and
142 // DragAndDropCellList.
144 options.setOnDragStart(new DragFunction() {
145 public void f(DragContext context) {
146 RestResourceWrapper memberInfo = context.getDraggableData();
147 context.getHelper().setInnerHTML(memberInfo.getName());
156 public CellTreeViewModel(final Images _images,SingleSelectionModel<RestResource> selectionModel ) {
159 this.selectionModel=selectionModel;
162 private final Cell<RestResource> departmentCell = new AbstractCell<RestResource>("contextmenu"){
165 public void render(com.google.gwt.cell.client.Cell.Context arg0, RestResource arg1, SafeHtmlBuilder arg2) {
169 if(arg1 instanceof TrashFolderResource){
170 html = AbstractImagePrototype.create(images.folderYellow()).getHTML();
171 FolderResource res = ((RestResourceWrapper)arg1).getResource();
172 name = res.getName();
173 id = res.getParentName() +"."+name;
175 else if(arg1 instanceof RestResourceWrapper){
176 FolderResource res = ((RestResourceWrapper)arg1).getResource();
178 html = AbstractImagePrototype.create(images.sharedFolder()).getHTML();
179 else if(res.getParentName()==null){
180 html = AbstractImagePrototype.create(images.home()).getHTML();
183 html = AbstractImagePrototype.create(images.folderYellow()).getHTML();
184 name = res.getName();
185 if(res.getParentName() != null){
186 id = res.getParentName()+"."+name;
192 else if(arg1 instanceof TrashResource){
193 html = AbstractImagePrototype.create(images.trash()).getHTML();
198 else if(arg1 instanceof SharedResource){
199 html = AbstractImagePrototype.create(images.myShared()).getHTML();
203 else if(arg1 instanceof OthersResource){
204 html = AbstractImagePrototype.create(images.othersShared()).getHTML();
205 name = "Other's Shared";
208 else if(arg1 instanceof OtherUserResource){
209 html = AbstractImagePrototype.create(images.permUser()).getHTML();
210 name = ((OtherUserResource)arg1).getName();
213 arg2.appendHtmlConstant(html);
214 arg2.append(FileList.Templates.INSTANCE.spanWithIdAndClass(id, "papala", name));
217 public void onBrowserEvent(Cell.Context context, com.google.gwt.dom.client.Element parent, RestResource value, com.google.gwt.dom.client.NativeEvent event, com.google.gwt.cell.client.ValueUpdater<RestResource> valueUpdater) {
218 if(event.getType().equals("contextmenu")){
219 selectionModel.setSelected(value, true);
220 Pithos.get().setCurrentSelection(value);
221 Pithos.get().getTreeView().showPopup(event.getClientX(), event.getClientY());
229 public <T> NodeInfo<?> getNodeInfo(final T value) {
232 DragAndDropNodeInfo n = new DragAndDropNodeInfo<RestResource>(getRootNodes(), departmentCell,
233 selectionModel, null);
234 configureFolderDrop(n);
235 configureDragOperation(n.getDraggableOptions());
238 else if (value instanceof MyFolderResource) {
240 MyFolderDataProvider dataProvider = new MyFolderDataProvider(
241 ((MyFolderResource) value),MyFolderResource.class);
242 DragAndDropNodeInfo<RestResource> n = new DragAndDropNodeInfo<RestResource>(dataProvider, departmentCell,
243 selectionModel, new ResourceValueUpdater());
244 mymap.put(((MyFolderResource) value).getUri(), dataProvider);
246 // permission cell are not draggable
247 //n.setCellDroppableOnly();
248 configureFolderDrop(n);
249 configureDragOperation(n.getDraggableOptions());
253 else if (value instanceof SharedResource) {
255 MyFolderDataProvider dataProvider = new MyFolderDataProvider(
256 ((SharedResource) value), SharedFolderResource.class);
257 sharedmap.put(((SharedResource) value).getUri(), dataProvider);
258 DragAndDropNodeInfo<RestResource> n = new DragAndDropNodeInfo<RestResource>(dataProvider, departmentCell,
259 selectionModel, new ResourceValueUpdater());
260 configureFolderDrop(n);
261 configureDragOperation(n.getDraggableOptions());
264 else if (value instanceof TrashResource) {
266 ListDataProvider<RestResource> trashProvider = new ListDataProvider<RestResource>();
267 List<RestResource> r = new ArrayList<RestResource>();
268 for(FolderResource f : Pithos.get().getTreeView().getTrash().getFolders()){
269 r.add(new TrashFolderResource(f));
271 trashProvider.setList(r);
272 DragAndDropNodeInfo<RestResource> n = new DragAndDropNodeInfo<RestResource>(trashProvider, departmentCell,
273 selectionModel, new ResourceValueUpdater());
274 configureFolderDrop(n);
275 configureDragOperation(n.getDraggableOptions());
278 else if (value instanceof OthersResource) {
280 OthersDataProvider dataProvider = new OthersDataProvider(
281 ((OthersResource) value), SharedFolderResource.class);
282 DragAndDropNodeInfo<RestResource> n = new DragAndDropNodeInfo<RestResource>(dataProvider, departmentCell,
283 selectionModel, null);
284 configureFolderDrop(n);
285 configureDragOperation(n.getDraggableOptions());
288 else if (value instanceof SharedFolderResource) {
290 MyFolderDataProvider dataProvider = new MyFolderDataProvider(
291 ((SharedFolderResource) value),SharedFolderResource.class);
292 DragAndDropNodeInfo<RestResource> n = new DragAndDropNodeInfo<RestResource>(dataProvider, departmentCell,
293 selectionModel, new ResourceValueUpdater());
294 sharedmap.put(((SharedFolderResource) value).getUri(), dataProvider);
295 configureFolderDrop(n);
296 configureDragOperation(n.getDraggableOptions());
299 else if (value instanceof OthersFolderResource) {
301 MyFolderDataProvider dataProvider = new MyFolderDataProvider(
302 ((OthersFolderResource) value),OthersFolderResource.class);
303 DragAndDropNodeInfo<RestResource> n = new DragAndDropNodeInfo<RestResource>(dataProvider, departmentCell,
304 selectionModel, new ResourceValueUpdater());
305 //nodeInfos.put(((OthersFolderResource) value).getUri(), n);
306 othersmap.put(((OthersFolderResource) value).getUri(), dataProvider);
307 configureFolderDrop(n);
308 configureDragOperation(n.getDraggableOptions());
311 else if (value instanceof OtherUserResource) {
313 MyFolderDataProvider dataProvider = new MyFolderDataProvider(
314 ((OtherUserResource) value),OthersFolderResource.class);
315 DragAndDropNodeInfo<RestResource> n = new DragAndDropNodeInfo<RestResource>(dataProvider, departmentCell,
316 selectionModel, new ResourceValueUpdater());
317 configureFolderDrop(n);
318 configureDragOperation(n.getDraggableOptions());
321 // TODO Auto-generated method stub
325 private void configureFolderDrop(DragAndDropNodeInfo<RestResource> n){
326 DroppableOptions options = n.getDroppableOptions();
327 options.setDroppableHoverClass("droppableHover");
328 // use a DroppableFunction here. We can also add a DropHandler in the tree
330 options.setOnOver(new DroppableFunction() {
333 public void f(final DragAndDropContext context) {
334 if(context.getDroppableData()!=null && context.getDroppableData() instanceof RestResource){
336 Pithos.get().getTreeView().getUtils().openNodeContainingResource((RestResource) context.getDroppableData(), new RefreshHandler() {
339 public void onRefresh() {
341 DragAndDropManager.getInstance().update(context);//initialize(context, GQueryUi.Event.create(com.google.gwt.user.client.Event.getCurrentEvent()));
349 options.setOnDrop(new DroppableFunction() {
351 public void f(DragAndDropContext context) {
353 DnDFolderPopupMenu popup ;
354 if(context.getDraggableData() instanceof FileResource){
355 // if(context.getDroppableData() instanceof RestResourceWrapper)
356 // popup = new DnDFolderPopupMenu(images, ((RestResourceWrapper) context.getDroppableData()).getResource(), Arrays.asList(context.getDraggableData()));
358 // popup = new DnDFolderPopupMenu(images, null, Arrays.asList(context.getDraggableData()));
362 // if(context.getDroppableData() instanceof RestResourceWrapper)
363 // popup = new DnDFolderPopupMenu(images, ((RestResourceWrapper) context.getDroppableData()).getResource(), context.getDraggableData());
365 // popup = new DnDFolderPopupMenu(images, null, context.getDraggableData());
368 int left = context.getDroppable().getAbsoluteLeft() + 40;
369 int top = context.getDroppable().getAbsoluteTop() + 20;
370 // popup.setPopupPosition(left, top);
378 public boolean isLeaf(Object value) {
379 if(value instanceof RestResourceWrapper)
380 return ((RestResourceWrapper)value).getResource().getFolders().size()==0;
381 else if(value instanceof TrashResource)
382 return ((TrashResource)value).getFolders().size()==0;
383 else if(value instanceof SharedResource)
384 return ((SharedResource)value).getFolders().size()==0;
385 else if(value instanceof OthersResource)
386 return ((OthersResource)value).getOtherUsers().size()==0;
387 else if(value instanceof OtherUserResource)
388 return ((OtherUserResource)value).getFolders().size()==0;
393 * Retrieve the selectionModel.
395 * @return the selectionModel
397 public SingleSelectionModel<RestResource> getSelectionModel() {
398 return selectionModel;
400 static interface ClearSelection{
401 public void setClearSelection(boolean clearSelection);
403 class ResourceValueUpdater implements ValueUpdater<RestResource>,ClearSelection{
404 boolean clearSelection=true;
408 * Modify the clearSelection.
410 * @param clearSelection the clearSelection to set
412 public void setClearSelection(boolean clearSelection) {
413 this.clearSelection = clearSelection;
416 public void update(final RestResource value) {
417 if(value instanceof MyFolderResource){
418 GetCommand<FolderResource> gf = new GetCommand<FolderResource>(FolderResource.class, value.getUri(), null) {
421 public void onComplete() {
422 FolderResource rootResource = getResult();
423 //((MyFolderResource)value).getResource().setFiles(rootResource.getFiles());
424 ((MyFolderResource)value).setResource(rootResource);
425 if(Pithos.get().getTreeView().getSelection().getUri().equals(value.getUri()))
426 selectionModel.setSelected(value, true);
427 Pithos.get().onResourceUpdate(value,clearSelection);
432 public void onError(Throwable t) {
433 GWT.log("Error fetching root folder", t);
434 Pithos.get().displayError("Unable to fetch root folder");
438 DeferredCommand.addCommand(gf);
440 else if(value instanceof TrashResource){
441 DeferredCommand.addCommand(new GetCommand<TrashResource>(TrashResource.class, Pithos.get().getCurrentUserResource().getTrashPath(), null) {
443 public void onComplete() {
444 //trash = getResult();
445 ((TrashResource)value).setFolders(getResult().getFolders());
446 ((TrashResource)value).setFiles(getResult().getFiles());
447 for(RestResource r : getRootNodes().getList()){
448 if(r instanceof TrashResource)
449 getRootNodes().getList().set(getRootNodes().getList().indexOf(r), Pithos.get().getTreeView().getTrash());
451 Pithos.get().getTreeView().updateNodeChildren(Pithos.get().getTreeView().getTrash());
452 //Pithos.get().showFileList(true);
453 Pithos.get().onResourceUpdate(value,clearSelection);
457 public void onError(Throwable t) {
458 if(t instanceof RestException){
459 int statusCode = ((RestException)t).getHttpStatusCode();
460 // On IE status code 1223 may be returned instead of 204.
461 if(statusCode == 204 || statusCode == 1223){
462 ((TrashResource)value).setFolders(new ArrayList<FolderResource>());
463 ((TrashResource)value).setFiles(new ArrayList<FileResource>());
467 Pithos.get().displayError("Unable to fetch trash folder:"+t.getMessage());
468 //Pithos.get().getTreeView().getTrash() = new TrashResource(Pithos.get().getCurrentUserResource().getTrashPath());
474 else if(value instanceof OthersFolderResource){
475 GetCommand<FolderResource> gf = new GetCommand<FolderResource>(FolderResource.class, value.getUri(), null) {
478 public void onComplete() {
479 FolderResource rootResource = getResult();
480 //((MyFolderResource)value).getResource().setFiles(rootResource.getFiles());
481 ((OthersFolderResource)value).setResource(rootResource);
482 if(Pithos.get().getTreeView().getSelection().getUri().equals(value.getUri()))
483 selectionModel.setSelected(value, true);
484 Pithos.get().onResourceUpdate(value,clearSelection);
489 public void onError(Throwable t) {
490 GWT.log("Error fetching root folder", t);
491 Pithos.get().displayError("Unable to fetch root folder");
495 DeferredCommand.addCommand(gf);
497 else if(value instanceof SharedFolderResource){
498 GetCommand<FolderResource> gf = new GetCommand<FolderResource>(FolderResource.class, value.getUri(), null) {
501 public void onComplete() {
502 FolderResource rootResource = getResult();
503 //((MyFolderResource)value).getResource().setFiles(rootResource.getFiles());
504 ((SharedFolderResource)value).setResource(rootResource);
505 if(Pithos.get().getTreeView().getSelection().getUri().equals(value.getUri()))
506 selectionModel.setSelected(value, true);
507 Pithos.get().onResourceUpdate(value,clearSelection);
512 public void onError(Throwable t) {
513 GWT.log("Error fetching root folder", t);
514 Pithos.get().displayError("Unable to fetch root folder");
518 DeferredCommand.addCommand(gf);
520 else if(value instanceof SharedResource){
521 GetCommand<SharedResource> gf = new GetCommand<SharedResource>(SharedResource.class, value.getUri(), null) {
524 public void onComplete() {
525 SharedResource rootResource = getResult();
526 ((SharedResource)value).setFolders(getResult().getFolders());
527 ((SharedResource)value).setFiles(getResult().getFiles());
529 if(Pithos.get().getTreeView().getSelection().getUri().equals(value.getUri()))
530 selectionModel.setSelected(value, true);
531 Pithos.get().onResourceUpdate(value,clearSelection);
536 public void onError(Throwable t) {
537 GWT.log("Error fetching root folder", t);
538 Pithos.get().displayError("Unable to fetch root folder");
542 DeferredCommand.addCommand(gf);
544 else if(value instanceof OtherUserResource){
545 GetCommand<OtherUserResource> gf = new GetCommand<OtherUserResource>(OtherUserResource.class, value.getUri(), null) {
548 public void onComplete() {
549 OtherUserResource rootResource = getResult();
550 ((OtherUserResource)value).setFolders(getResult().getFolders());
551 ((OtherUserResource)value).setFiles(getResult().getFiles());
553 if(Pithos.get().getTreeView().getSelection().getUri().equals(value.getUri()))
554 selectionModel.setSelected(value, true);
555 Pithos.get().onResourceUpdate(value,clearSelection);
560 public void onError(Throwable t) {
561 GWT.log("Error fetching root folder", t);
562 Pithos.get().displayError("Unable to fetch root folder");
566 DeferredCommand.addCommand(gf);
572 class MyFolderDataProvider extends AsyncDataProvider<RestResource>{
573 private RestResource restResource;
574 private Class resourceClass;
575 public MyFolderDataProvider(RestResource department, Class resourceClass) {
576 super(new ProvidesKey<RestResource>() {
579 public Object getKey(RestResource item) {
580 return item.getUri();
582 this.restResource = department;
583 this.resourceClass=resourceClass;
587 protected void onRangeChanged(final HasData<RestResource> view) {
592 * Retrieve the restResource.
594 * @return the restResource
596 public RestResource getRestResource() {
602 * Modify the restResource.
604 * @param restResource the restResource to set
606 public void setRestResource(RestResource restResource) {
607 this.restResource = restResource;
609 List<RestResource> res =null;
610 public void refresh(final RefreshHandler refresh){
611 FolderResource cache = null;
612 if(restResource instanceof RestResourceWrapper && !((RestResourceWrapper)restResource).getResource().isNeedsExpanding())
613 cache = ((RestResourceWrapper)restResource).getResource();
614 GetCommand<FolderResource> gf = new GetCommand<FolderResource>(FolderResource.class, restResource.getUri(),cache ) {
617 public void onComplete() {
618 if(restResource instanceof RestResourceWrapper){
619 ((RestResourceWrapper)restResource).setResource(getResult());//restResource = getResult();
620 ((RestResourceWrapper)restResource).getResource().setNeedsExpanding(false);
622 if(usedCachedVersion()&&res!=null){
624 updateRowCount(res.size(), true);
625 updateRowData(0,res);
628 String[] folderPaths = null;
629 if(resourceClass.equals(MyFolderResource.class))
630 folderPaths=((MyFolderResource) restResource).getResource().getSubfolderPaths().toArray(new String[] {});
631 else if(resourceClass.equals(SharedFolderResource.class) && restResource instanceof SharedResource)
632 folderPaths=((SharedResource) restResource).getSubfolderPaths().toArray(new String[] {});
633 else if(resourceClass.equals(SharedFolderResource.class)){
634 folderPaths=((SharedFolderResource) restResource).getResource().getSubfolderPaths().toArray(new String[] {});
635 GWT.log("------------>"+folderPaths);
637 else if(resourceClass.equals(TrashFolderResource.class))
638 folderPaths=((TrashFolderResource) restResource).getResource().getSubfolderPaths().toArray(new String[] {});
639 else if(resourceClass.equals(OthersFolderResource.class) && restResource instanceof OtherUserResource)
640 folderPaths=((OtherUserResource) restResource).getSubfolderPaths().toArray(new String[] {});
641 else if(resourceClass.equals(OthersFolderResource.class))
642 folderPaths=((OthersFolderResource) restResource).getResource().getSubfolderPaths().toArray(new String[] {});
643 MultipleGetCommand.Cached[] cached = null;
644 if(restResource instanceof RestResourceWrapper)
645 cached=((RestResourceWrapper)restResource).getResource().getCache();
646 MultipleGetCommand<FolderResource> gf2 = new MultipleGetCommand<FolderResource>(FolderResource.class,
647 folderPaths, cached) {
650 public void onComplete() {
651 res = new ArrayList<RestResource>();
652 for(FolderResource r : getResult()){
656 else if(resourceClass.equals(MyFolderResource.class))
657 res.add(new MyFolderResource(r));
658 else if(resourceClass.equals(SharedFolderResource.class)){
659 res.add(new SharedFolderResource(r));
661 else if(resourceClass.equals(TrashFolderResource.class))
662 res.add(new TrashFolderResource(r));
663 else if(resourceClass.equals(OthersFolderResource.class))
664 res.add(new OthersFolderResource(r));
666 if(restResource instanceof RestResourceWrapper)
667 ((RestResourceWrapper)restResource).getResource().setFolders(getResult());
668 updateRowCount(res.size(), true);
669 updateRowData(0,res);
675 public void onError(Throwable t) {
676 Pithos.get().displayError("Unable to fetch subfolders");
677 GWT.log("Unable to fetch subfolders", t);
681 public void onError(String p, Throwable throwable) {
682 GWT.log("Path:"+p, throwable);
686 DeferredCommand.addCommand(gf2);
691 public void onError(Throwable t) {
693 GWT.log("Error fetching root folder", t);
694 Pithos.get().displayError("Unable to fetch root folder");
698 DeferredCommand.addCommand(gf);
703 class OthersDataProvider extends AsyncDataProvider<RestResource>{
704 private RestResource restResource;
705 private Class resourceClass;
706 public OthersDataProvider(RestResource department, Class resourceClass) {
707 super(new ProvidesKey<RestResource>() {
710 public Object getKey(RestResource item) {
711 return item.getUri();
713 this.restResource = department;
714 this.resourceClass=resourceClass;
718 protected void onRangeChanged(final HasData<RestResource> view) {
723 * Retrieve the restResource.
725 * @return the restResource
727 public RestResource getRestResource() {
733 * Modify the restResource.
735 * @param restResource the restResource to set
737 public void setRestResource(RestResource restResource) {
738 this.restResource = restResource;
741 public void refresh(final RefreshHandler refresh){
742 GetCommand<OthersResource> go = new GetCommand<OthersResource>(OthersResource.class,
743 restResource.getUri(), null) {
746 public void onComplete() {
747 final OthersResource others = getResult();
748 MultipleGetCommand<OtherUserResource> gogo = new MultipleGetCommand<OtherUserResource>(OtherUserResource.class,
749 others.getOthers().toArray(new String[] {}), null) {
752 public void onComplete() {
753 List<OtherUserResource> res = getResult();
754 updateRowCount(res.size(), true);
755 List<RestResource> r = new ArrayList<RestResource>();
761 public void onError(Throwable t) {
762 GWT.log("Error fetching Others Root folder", t);
763 Pithos.get().displayError("Unable to fetch Others Root folder");
767 public void onError(String p, Throwable throwable) {
768 GWT.log("Path:"+p, throwable);
771 DeferredCommand.addCommand(gogo);
775 public void onError(Throwable t) {
776 GWT.log("Error fetching Others Root folder", t);
777 Pithos.get().displayError("Unable to fetch Others Root folder");
780 DeferredCommand.addCommand(go);
787 * Retrieve the rootNodes.
789 * @return the rootNodes
791 public ListDataProvider<RestResource> getRootNodes() {
797 * Retrieve the mymap.
801 public Map<String, MyFolderDataProvider> getMymap() {
807 * Retrieve the sharedmap.
809 * @return the sharedmap
811 public Map<String, MyFolderDataProvider> getSharedmap() {
817 * Retrieve the othersmap.
819 * @return the othersmap
821 public Map<String, MyFolderDataProvider> getOthersmap() {