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