Merge branch 'master' into packaging
[pithos-web-client] / src / gr / grnet / pithos / web / client / FileList.java
1 /*
2  * Copyright 2011-2012 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
36 package gr.grnet.pithos.web.client;
37
38 import gr.grnet.pithos.web.client.foldertree.File;
39 import gr.grnet.pithos.web.client.foldertree.Folder;
40 import gr.grnet.pithos.web.client.foldertree.FolderTreeView;
41
42 import java.util.ArrayList;
43 import java.util.Collections;
44 import java.util.Comparator;
45 import java.util.Iterator;
46 import java.util.List;
47 import java.util.Set;
48
49 import com.google.gwt.cell.client.Cell.Context;
50 import com.google.gwt.cell.client.ImageResourceCell;
51 import com.google.gwt.cell.client.SafeHtmlCell;
52 import com.google.gwt.cell.client.TextCell;
53 import com.google.gwt.cell.client.ValueUpdater;
54 import com.google.gwt.core.client.GWT;
55 import com.google.gwt.event.dom.client.ContextMenuEvent;
56 import com.google.gwt.event.dom.client.ContextMenuHandler;
57 import com.google.gwt.http.client.URL;
58 import com.google.gwt.i18n.client.DateTimeFormat;
59 import com.google.gwt.resources.client.ImageResource;
60 import com.google.gwt.resources.client.ClientBundle.Source;
61 import com.google.gwt.resources.client.ImageResource.ImageOptions;
62 import com.google.gwt.resources.client.ImageResource.RepeatStyle;
63 import com.google.gwt.safehtml.client.SafeHtmlTemplates;
64 import com.google.gwt.safehtml.shared.SafeHtml;
65 import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
66 import com.google.gwt.user.cellview.client.CellTable;
67 import com.google.gwt.user.cellview.client.Column;
68 import com.google.gwt.user.client.Command;
69 import com.google.gwt.user.client.DOM;
70 import com.google.gwt.user.client.Event;
71 import com.google.gwt.user.client.Window;
72 import com.google.gwt.user.client.ui.Composite;
73 import com.google.gwt.user.client.ui.VerticalPanel;
74 import com.google.gwt.view.client.ListDataProvider;
75 import com.google.gwt.view.client.MultiSelectionModel;
76 import com.google.gwt.view.client.ProvidesKey;
77 import com.google.gwt.view.client.SelectionChangeEvent;
78
79 /**
80  * A composite that displays the list of files in a particular folder.
81  */
82 public class FileList extends Composite {
83
84         ListDataProvider<File> provider = new ListDataProvider<File>();
85
86     /**
87        * The styles applied to the table.
88        */
89     interface TableStyle extends CellTable.Style {
90         String cellTableFirstColumnShared();
91     }
92
93         interface TableResources extends CellTable.Resources {
94             @Override
95                 @Source({CellTable.Style.DEFAULT_CSS, "PithosCellTable.css"})
96             TableStyle cellTableStyle();
97             
98             @Source("share.png")
99             @ImageOptions(repeatStyle = RepeatStyle.None)
100             ImageResource cellTableSharedIcon();
101         }
102         
103         static interface Templates extends SafeHtmlTemplates {
104             Templates INSTANCE = GWT.create(Templates.class);
105
106             @Template("<div id='dragHelper' style='border:1px solid black; background-color:#ffffff; color:black; width:150px;z-index:100'></div>")
107             SafeHtml outerHelper();
108
109         @Template("<span id='{0}'>{0}</span>")
110         public SafeHtml filenameSpan(String filename);
111
112         @Template("<a href='{0}' title='{1}' rel='lytebox[mnf]' onclick='myLytebox.start(this, false, false); return false;'>(view)</a>")
113         public SafeHtml viewLink(String link, String title);
114
115         @Template("<table><tr><td rowspan='3'>{0}</td><td style='font-size:95%;' id='{1}'>{1}</td></tr><tr><td>{2}</td></tr></table>")
116         public SafeHtml rendelContactCell(String imageHtml, String name, String fileSize);
117
118         @Template("<span id='{0}' class='{1}'>{2}</span>")
119         public SafeHtml spanWithIdAndClass(String id, String cssClass, String content);
120         }
121
122         protected final DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a");
123
124         /**
125          * Specifies that the images available for this composite will be the ones
126          * available in FileContextMenu.
127          */
128         public interface Images extends FolderTreeView.Images {
129
130                 @Source("gr/grnet/pithos/resources/blank.gif")
131                 ImageResource blank();
132
133                 @Source("gr/grnet/pithos/resources/asc.png")
134                 ImageResource asc();
135
136                 @Source("gr/grnet/pithos/resources/desc.png")
137                 ImageResource desc();
138
139                 @Source("gr/grnet/pithos/resources/mimetypes/document_shared.png")
140                 ImageResource documentShared();
141
142                 @Source("gr/grnet/pithos/resources/mimetypes/kcmfontinst.png")
143                 ImageResource wordprocessor();
144
145                 @Source("gr/grnet/pithos/resources/mimetypes/log.png")
146                 ImageResource spreadsheet();
147
148                 @Source("gr/grnet/pithos/resources/mimetypes/kpresenter_kpr.png")
149                 ImageResource presentation();
150
151                 @Source("gr/grnet/pithos/resources/mimetypes/acroread.png")
152                 ImageResource pdf();
153
154                 @Source("gr/grnet/pithos/resources/mimetypes/image.png")
155                 ImageResource image();
156
157                 @Source("gr/grnet/pithos/resources/mimetypes/video2.png")
158                 ImageResource video();
159
160                 @Source("gr/grnet/pithos/resources/mimetypes/knotify.png")
161                 ImageResource audio();
162
163                 @Source("gr/grnet/pithos/resources/mimetypes/html.png")
164                 ImageResource html();
165
166                 @Source("gr/grnet/pithos/resources/mimetypes/txt.png")
167                 ImageResource txt();
168
169                 @Source("gr/grnet/pithos/resources/mimetypes/ark2.png")
170                 ImageResource zip();
171
172                 @Source("gr/grnet/pithos/resources/mimetypes/kcmfontinst_shared.png")
173                 ImageResource wordprocessorShared();
174
175                 @Source("gr/grnet/pithos/resources/mimetypes/log_shared.png")
176                 ImageResource spreadsheetShared();
177
178                 @Source("gr/grnet/pithos/resources/mimetypes/kpresenter_kpr_shared.png")
179                 ImageResource presentationShared();
180
181                 @Source("gr/grnet/pithos/resources/mimetypes/acroread_shared.png")
182                 ImageResource pdfShared();
183
184                 @Source("gr/grnet/pithos/resources/mimetypes/image_shared.png")
185                 ImageResource imageShared();
186
187                 @Source("gr/grnet/pithos/resources/mimetypes/video2_shared.png")
188                 ImageResource videoShared();
189
190                 @Source("gr/grnet/pithos/resources/mimetypes/knotify_shared.png")
191                 ImageResource audioShared();
192
193                 @Source("gr/grnet/pithos/resources/mimetypes/html_shared.png")
194                 ImageResource htmlShared();
195
196                 @Source("gr/grnet/pithos/resources/mimetypes/txt_shared.png")
197                 ImageResource txtShared();
198
199                 @Source("gr/grnet/pithos/resources/mimetypes/ark2_shared.png")
200                 ImageResource zipShared();
201
202         }
203         
204         /**
205          * The number of files in this folder.
206          */
207         int folderFileCount;
208
209         /**
210          * Total folder size
211          */
212         long folderTotalSize;
213
214         /**
215          * A cache of the files in the list.
216          */
217         private List<File> files;
218
219         /**
220          * The widget's image bundle.
221          */
222         protected final Images images;
223         
224         protected CellTable<File> celltable;
225
226         private final MultiSelectionModel<File> selectionModel;
227
228         Column<File, String> pathColumn;
229
230         protected final List<SortableHeader> allHeaders = new ArrayList<SortableHeader>();
231
232         SortableHeader nameHeader;
233
234         SortableHeader pathHeader;
235
236     protected Pithos app;
237
238     /**
239          * Construct the file list widget. This entails setting up the widget
240          * layout, fetching the number of files in the current folder from the
241          * server and filling the local file cache of displayed files with data from
242          * the server, as well.
243          *
244          * @param _images
245          */
246         public FileList(final Pithos _app, Images _images) {
247         app = _app;
248                 images = _images;
249
250         final CellTable.Resources resources = GWT.create(TableResources.class);
251
252         ProvidesKey<File> keyProvider = new ProvidesKey<File>(){
253
254                         @Override
255                         public Object getKey(File item) {
256                                 return item.getUri();
257                         }
258                 };
259
260                 celltable = new CellTable<File>(10, resources, keyProvider);
261         celltable.setWidth("100%");
262         celltable.setStyleName("pithos-List");
263
264                 Column<File, ImageResource> status = new Column<File, ImageResource>(new ImageResourceCell() {
265                     @Override
266                 public boolean handlesSelection() {
267                     return false;
268                 }
269                 })
270         {
271                  @Override
272                  public ImageResource getValue(File entity) {
273                      return getFileIcon(entity);
274                  }
275
276                         @Override
277                         public String getCellStyleNames(Context context, File object) {
278                                 if (!object.getPermissions().isEmpty() && !object.isPublished())
279                                         return ((TableStyle) resources.cellTableStyle()).cellTableFirstColumnShared();
280                                 return super.getCellStyleNames(context, object);
281                         }
282             };
283             celltable.addColumn(status,"");
284
285         final Column<File,SafeHtml> nameColumn = new Column<File,SafeHtml>(new SafeHtmlCell()) {
286
287                         @Override
288                         public SafeHtml getValue(File object) {
289                                 SafeHtmlBuilder sb = new SafeHtmlBuilder();
290                                 sb.append(Templates.INSTANCE.filenameSpan(object.getName()));
291                                 if (object.getContentType() != null && (object.getContentType().endsWith("png") || object.getContentType().endsWith("gif") || object.getContentType().endsWith("jpeg"))) {
292                                 sb.appendHtmlConstant("&nbsp;")
293                       .append(Templates.INSTANCE.viewLink(app.getApiPath() + object.getOwner() + object.getUri(), object.getName()));
294                                 }
295                                 
296                                 return sb.toSafeHtml();
297                         }
298                         
299                 };
300         celltable.addColumn(nameColumn, nameHeader = new SortableHeader("Name", "name"));
301                 allHeaders.add(nameHeader);
302                 nameHeader.setUpdater(new FileValueUpdater(nameHeader));
303                 nameHeader.setSorted(true);
304                 nameHeader.setReverseSort(true);
305
306                 celltable.redrawHeaders();
307                 
308                 pathColumn = new Column<File, String>(new TextCell()) {
309
310                         @Override
311                         public String getValue(File f) {
312                                 String path;
313                                 if (!app.getSelectedTree().equals(app.mysharedTreeView)) {
314                                         path = f.getParent().getPrefix();
315                                         if (path.length() == 0)
316                                                 path = "/";
317                                 }
318                                 else {
319                                         path = f.getPath();
320                                         if (path.lastIndexOf("/") != -1)
321                                                 path = path.substring(0, path.lastIndexOf("/"));
322                                         else
323                                                 path = "/";
324                                 }
325                                 return path;
326                         }
327                 };
328                 pathHeader = new SortableHeader("Path", "path");
329                 celltable.addColumn(pathColumn, pathHeader);
330                 allHeaders.add(pathHeader);
331                 pathHeader.setUpdater(new FileValueUpdater(pathHeader));
332                 
333         Column<File,String> aColumn = new Column<File,String>(new TextCell()) {
334                         @Override
335                         public String getValue(File object) {
336                                 return object.getSizeAsString();
337                         }
338                 };
339         SortableHeader aheader = new SortableHeader("Size", "size");
340         celltable.addColumn(aColumn, aheader);
341                 allHeaders.add(aheader);
342                 aheader.setUpdater(new FileValueUpdater(aheader));
343
344         aColumn = new Column<File,String>(new TextCell()) {
345                         @Override
346                         public String getValue(File object) {
347                                 return object.getLastModified() != null ? formatter.format(object.getLastModified()) : "";
348                         }
349                 };
350         aheader = new SortableHeader("Last Modified", "date");
351                 celltable.addColumn(aColumn, aheader);
352                 allHeaders.add(aheader);
353                 aheader.setUpdater(new FileValueUpdater(aheader));
354                
355                 provider.addDataDisplay(celltable);
356
357                 VerticalPanel vp = new VerticalPanel();
358                 vp.setWidth("100%");
359                 vp.addStyleName("pithos-FileListContainer");
360
361         vp.add(celltable);
362
363                 vp.setCellWidth(celltable, "100%");
364         vp.addHandler(new ContextMenuHandler() {
365             @Override
366             public void onContextMenu(final ContextMenuEvent event) {
367                 final TreeView tree = app.getSelectedTree();
368                 if (tree != null) {
369                         final int x = event.getNativeEvent().getClientX();
370                         final int y = event.getNativeEvent().getClientY();
371                         final Folder selectedFolder = app.getSelection();
372                         app.scheduleFolderHeadCommand(selectedFolder, new Command() {
373                                                 
374                                                 @Override
375                                                 public void execute() {
376                                                         final List<File> selectedFiles = getSelectedFiles();
377                                                         Iterator<File> iter = selectedFiles.iterator();
378                                                         iterateFilesHeadCommand(iter, new Command() {
379                                                                 
380                                                                 @Override
381                                                                 public void execute() {
382                                                         FileContextMenu contextMenu = new FileContextMenu(app, images, tree, selectedFolder, selectedFiles);
383                                                         contextMenu.setPopupPosition(x, y);
384                                                         contextMenu.show();
385                                                                 }
386                                                         });
387                                                 }
388                                         });
389                 }
390             }
391         }, ContextMenuEvent.getType());
392                 initWidget(vp);
393
394                 selectionModel = new MultiSelectionModel<File>(keyProvider);
395                 selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
396                         
397                         @Override
398                         public void onSelectionChange(SelectionChangeEvent event) {
399                                 app.showRelevantToolbarButtons();
400                         }
401                 });
402                 
403                 celltable.setSelectionModel(selectionModel, PithosSelectionEventManager.<File> createDefaultManager());
404 //              celltable.setPageSize(Pithos.VISIBLE_FILE_COUNT);
405                 
406                 sinkEvents(Event.ONCONTEXTMENU);
407 //              sinkEvents(Event.ONMOUSEUP);
408 //              sinkEvents(Event.ONMOUSEDOWN);
409 //              sinkEvents(Event.ONCLICK);
410 //              sinkEvents(Event.ONKEYDOWN);
411                 sinkEvents(Event.ONDBLCLICK);
412                 Pithos.preventIESelection();
413         }
414
415         public List<File> getSelectedFiles() {
416         return new ArrayList<File>(selectionModel.getSelectedSet());
417         }
418         
419         @Override
420         public void onBrowserEvent(Event event) {
421
422 //              if (files == null || files.size() == 0) {
423 //                      if (DOM.eventGetType(event) == Event.ONCONTEXTMENU && getSelectedFiles().size() == 0) {
424 //                              contextMenu = new FileContextMenu(images, false, true);
425 //                contextMenu.show();
426 //                              event.preventDefault();
427 //                              event.cancelBubble(true);
428 //                      }
429 //                      return;
430 //              }
431 //              if (DOM.eventGetType(event) == Event.ONCONTEXTMENU && getSelectedFiles().size() != 0) {
432 //                      GWT.log("*****GOING TO SHOW CONTEXT MENU ****", null);
433 //                      contextMenu =  new FileContextMenu(images, false, false);
434 //                      contextMenu = contextMenu.onEvent(event);
435 //                      event.cancelBubble(true);
436 //                      event.preventDefault();
437 //              } else if (DOM.eventGetType(event) == Event.ONCONTEXTMENU && getSelectedFiles().size() == 0) {
438 //                      contextMenu = new FileContextMenu(images, false, true);
439 //                      contextMenu = contextMenu.onEmptyEvent(event);
440 //                      event.cancelBubble(true);
441 //                      event.preventDefault();
442 //              } else 
443                 if (DOM.eventGetType(event) == Event.ONDBLCLICK)
444                         if (getSelectedFiles().size() == 1) {
445                                 File file = getSelectedFiles().get(0);
446                                 Window.open(app.getApiPath() + file.getOwner() + file.getUri(), "_blank", "");
447                                 event.preventDefault();
448                                 return;
449                         }
450                 super.onBrowserEvent(event);
451         }
452
453         /**
454          * Update the display of the file list.
455          */
456         void update() {
457                 showCellTable();
458         }
459
460         /**
461          * Return the proper icon based on the MIME type of the file.
462          *
463          * @param file
464          * @return the icon
465          */
466         protected ImageResource getFileIcon(File file) {
467                 String mimetype = file.getContentType();
468                 boolean published = file.isPublished();
469                 if (mimetype == null)
470                         return published ? images.documentShared() : images.document();
471                 mimetype = mimetype.toLowerCase();
472                 if (mimetype.startsWith("application/pdf"))
473                         return published ? images.pdfShared() : images.pdf();
474                 else if (mimetype.endsWith("excel"))
475                         return published ? images.spreadsheetShared() : images.spreadsheet();
476                 else if (mimetype.endsWith("msword"))
477                         return published ? images.wordprocessorShared() : images.wordprocessor();
478                 else if (mimetype.endsWith("powerpoint"))
479                         return published ? images.presentationShared() : images.presentation();
480                 else if (mimetype.startsWith("application/zip") ||
481                                         mimetype.startsWith("application/gzip") ||
482                                         mimetype.startsWith("application/x-gzip") ||
483                                         mimetype.startsWith("application/x-tar") ||
484                                         mimetype.startsWith("application/x-gtar"))
485                         return published ? images.zipShared() : images.zip();
486                 else if (mimetype.startsWith("text/html"))
487                         return published ? images.htmlShared() : images.html();
488                 else if (mimetype.startsWith("text/plain"))
489                         return published ? images.txtShared() : images.txt();
490                 else if (mimetype.startsWith("image/"))
491                         return published ? images.imageShared() : images.image();
492                 else if (mimetype.startsWith("video/"))
493                         return published ? images.videoShared() : images.video();
494                 else if (mimetype.startsWith("audio/"))
495                         return published ? images.audioShared() : images.audio();
496                 return published ? images.documentShared() : images.document();
497         }
498
499         /**
500          * Fill the file cache with data.
501          */
502         public void setFiles(final List<File> _files) {
503                 if (!app.getSelectedTree().equals(app.mysharedTreeView)) {
504                         if (celltable.getColumnIndex(pathColumn) != -1)
505                                 celltable.removeColumn(pathColumn);
506                 }
507                 else {
508                         if (celltable.getColumnIndex(pathColumn) == -1)
509                                 celltable.insertColumn(2, pathColumn, pathHeader);
510                 }
511                 files = new ArrayList<File>();
512         for (File fres : _files) {
513                         files.add(fres);
514         }
515         
516                 folderFileCount = files.size();
517                 
518                 for (SortableHeader header : allHeaders) {
519                         if (header.isSorted())
520                                 sortFiles(header.getProperty(), header.getReverseSort());
521                 }
522                 
523                 List<File> previousSelection = getSelectedFiles(); //Keep the previous selection
524
525                 provider.getList().clear();
526         provider.setList(files);
527         selectionModel.clear();
528         for (File f : files) {
529                 if (previousSelection.contains(f))
530                         selectionModel.setSelected(f, true);
531         }
532         
533         app.showFolderStatistics(folderFileCount);
534         celltable.setPageSize(folderFileCount);
535         }
536
537         /**
538          * Does the list contains the requested filename
539          *
540          * @param fileName
541          * @return true/false
542          */
543         public boolean contains(String fileName) {
544                 for (int i = 0; i < files.size(); i++)
545                         if (files.get(i).getName().equals(fileName))
546                                 return true;
547                 return false;
548         }
549
550         public void clearSelectedRows() {
551                 Iterator<File> it = selectionModel.getSelectedSet().iterator();
552                 while(it.hasNext()){
553                         selectionModel.setSelected(it.next(),false);
554                 }
555         }
556         
557         /**
558          *
559          */
560         public void selectAllRows() {
561                 Iterator<File> it = provider.getList().iterator();
562                 while(it.hasNext()){
563                         selectionModel.setSelected(it.next(),true);
564                 }
565         }
566
567         protected void sortFiles(final String sortingProperty, final boolean sortingType){
568                 Collections.sort(files, new Comparator<File>() {
569
570             @Override
571             public int compare(File arg0, File arg1) {
572                     if (sortingType){
573                             if (sortingProperty.equals("version")) {
574                                     return arg0.getVersion() - arg1.getVersion();
575                             } else if (sortingProperty.equals("owner")) {
576                                     return arg0.getOwner().compareTo(arg1.getOwner());
577                             } else if (sortingProperty.equals("date")) {
578                                         if (arg0.getLastModified() != null && arg1.getLastModified() != null)
579                                                 return arg0.getLastModified().compareTo(arg1.getLastModified());
580                                         return 0;
581                             } else if (sortingProperty.equals("size")) {
582                                     return (int) (arg0.getBytes() - arg1.getBytes());
583                             } else if (sortingProperty.equals("name")) {
584                                     return arg0.getName().compareTo(arg1.getName());
585                             } else if (sortingProperty.equals("path")) {
586                                     return arg0.getUri().compareTo(arg1.getUri());
587                             } else {
588                                     return arg0.getName().compareTo(arg1.getName());
589                             }
590                     }
591                     else if (sortingProperty.equals("version")) {
592                             
593                             return arg1.getVersion() - arg0.getVersion();
594                     } else if (sortingProperty.equals("owner")) {
595                             
596                             return arg1.getOwner().compareTo(arg0.getOwner());
597                     } else if (sortingProperty.equals("date")) {
598                             
599                             return arg1.getLastModified().compareTo(arg0.getLastModified());
600                     } else if (sortingProperty.equals("size")) {
601                             return (int) (arg1.getBytes() - arg0.getBytes());
602                     } else if (sortingProperty.equals("name")) {
603                             
604                             return arg1.getName().compareTo(arg0.getName());
605                     } else if (sortingProperty.equals("path")) {
606                             
607                             return arg1.getUri().compareTo(arg0.getUri());
608                     } else {
609                             
610                             return arg1.getName().compareTo(arg0.getName());
611                     }
612             }
613
614                 });
615         }
616         
617         final class FileValueUpdater implements ValueUpdater<String>{
618                 private SortableHeader header;
619                 /**
620                  * 
621                  */
622                 public FileValueUpdater(SortableHeader header) {
623                         this.header=header;
624                 }
625                 @Override
626                 public void update(String value) {
627                         header.setSorted(true);
628                         header.toggleReverseSort();
629
630                 for (SortableHeader otherHeader : allHeaders) {
631                   if (otherHeader != header) {
632                     otherHeader.setSorted(false);
633                     otherHeader.setReverseSort(true);
634                   }
635                 }
636                 celltable.redrawHeaders();
637                 sortFiles(header.getProperty(), header.getReverseSort());
638                 FileList.this.update();                 
639                 }
640                 
641         }
642
643         /**
644          * Shows the files in the cellTable 
645      */
646         private void showCellTable(){
647                 provider.setList(files);
648                 
649                 provider.refresh();
650                 
651                 //celltable.redraw();
652                 celltable.redrawHeaders();              
653         }
654         
655         void iterateFilesHeadCommand(final Iterator<File> iter, final Command callback) {
656                 if (iter.hasNext()) {
657                         File f = iter.next();
658                         app.scheduleFileHeadCommand(f, new Command() {
659                                 
660                                 @Override
661                                 public void execute() {
662                                         iterateFilesHeadCommand(iter, callback);
663                                 }
664                         });
665                 }
666                 else if (callback != null)
667                         callback.execute();
668         }
669
670         public void selectByUrl(List<String> selectedUrls) {
671                 Set<File> previous = selectionModel.getSelectedSet();
672                 for (File f : previous)
673                         selectionModel.setSelected(f, false);
674                 
675                 int i = 0;
676                 boolean scrolled = false;
677                 for (File f : files) {
678                         if (selectedUrls.contains(app.getApiPath() + f.getOwner() + f.getUri())) {
679                                 selectionModel.setSelected(f, true);
680                                 if (!scrolled) {
681                                         celltable.getRowElement(i).getCells().getItem(0).scrollIntoView();
682                                         scrolled = true;
683                                 }
684                         }
685                         i++;
686                 }
687         }
688 }