55ba20704a284ff07d0164b59c140e702308e095
[pithos-web-client] / src / gr / grnet / pithos / web / client / FileList.java
1 /*
2  * Copyright 2011 GRNET S.A. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or
5  * without modification, are permitted provided that the following
6  * conditions are met:
7  *
8  *   1. Redistributions of source code must retain the above
9  *      copyright notice, this list of conditions and the following
10  *      disclaimer.
11  *
12  *   2. Redistributions in binary form must reproduce the above
13  *      copyright notice, this list of conditions and the following
14  *      disclaimer in the documentation and/or other materials
15  *      provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  *
30  * The views and conclusions contained in the software and
31  * documentation are those of the authors and should not be
32  * interpreted as representing official policies, either expressed
33  * or implied, of GRNET S.A.
34  */
35
36 package gr.grnet.pithos.web.client;
37
38 import com.google.gwt.event.dom.client.ContextMenuEvent;
39 import com.google.gwt.event.dom.client.ContextMenuHandler;
40
41 import com.google.gwt.user.cellview.client.Column;
42 import gr.grnet.pithos.web.client.commands.UploadFileCommand;
43 import gr.grnet.pithos.web.client.foldertree.File;
44 import gr.grnet.pithos.web.client.foldertree.Folder;
45 import gr.grnet.pithos.web.client.foldertree.FolderTreeView;
46
47 import java.util.ArrayList;
48 import java.util.Collections;
49 import java.util.Comparator;
50 import java.util.Iterator;
51 import java.util.List;
52
53 import com.google.gwt.cell.client.ImageResourceCell;
54 import com.google.gwt.cell.client.SafeHtmlCell;
55 import com.google.gwt.cell.client.TextCell;
56 import com.google.gwt.cell.client.ValueUpdater;
57 import com.google.gwt.core.client.GWT;
58 import com.google.gwt.dom.client.Style.Cursor;
59 import com.google.gwt.event.dom.client.ClickEvent;
60 import com.google.gwt.event.dom.client.ClickHandler;
61 import com.google.gwt.i18n.client.DateTimeFormat;
62 import com.google.gwt.resources.client.ClientBundle;
63 import com.google.gwt.resources.client.ImageResource;
64 import com.google.gwt.safehtml.client.SafeHtmlTemplates;
65 import com.google.gwt.safehtml.shared.SafeHtml;
66 import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
67 import com.google.gwt.user.cellview.client.CellTable;
68 import com.google.gwt.user.cellview.client.GssSimplePager;
69 import com.google.gwt.user.client.Event;
70 import com.google.gwt.user.client.ui.AbstractImagePrototype;
71 import com.google.gwt.user.client.ui.Button;
72 import com.google.gwt.user.client.ui.Composite;
73 import com.google.gwt.user.client.ui.HorizontalPanel;
74 import com.google.gwt.user.client.ui.VerticalPanel;
75 import com.google.gwt.view.client.ListDataProvider;
76 import com.google.gwt.view.client.MultiSelectionModel;
77 import com.google.gwt.view.client.ProvidesKey;
78 import com.google.gwt.view.client.SelectionChangeEvent;
79 import com.google.gwt.view.client.SelectionChangeEvent.Handler;
80
81 /**
82  * A composite that displays the list of files in a particular folder.
83  */
84 public class FileList extends Composite {
85
86         ListDataProvider<File> provider = new ListDataProvider<File>();
87
88     /**
89        * The styles applied to the table.
90        */
91     interface TableStyle extends CellTable.Style {
92     }
93
94         interface TableResources extends CellTable.Resources {
95             @Source({CellTable.Style.DEFAULT_CSS, "GssCellTable.css"})
96             TableStyle cellTableStyle();
97         }
98         
99         static interface Templates extends SafeHtmlTemplates {
100             Templates INSTANCE = GWT.create(Templates.class);
101
102             @Template("<div id='dragHelper' style='border:1px solid black; background-color:#ffffff; color:black; width:150px;z-index:100'></div>")
103             SafeHtml outerHelper();
104
105         @Template("<span id='{0}'>{0}</span>")
106         public SafeHtml filenameSpan(String filename);
107
108         @Template("<a href='{0}' title='{1}' rel='lytebox[mnf]' onclick='myLytebox.start(this, false, false); return false;'>(view)</a>")
109         public SafeHtml viewLink(String link, String title);
110
111         @Template("<table><tr><td rowspan='3'>{0}</td><td style='font-size:95%;' id='{1}'>{1}</td></tr><tr><td>{2}</td></tr></table>")
112         public SafeHtml rendelContactCell(String imageHtml, String name, String fileSize);
113
114         @Template("<span id='{0}' class='{1}'>{2}</span>")
115         public SafeHtml spanWithIdAndClass(String id, String cssClass, String content);
116         }
117
118     private String showingStats = "";
119
120         private int startIndex = 0;
121
122         /**
123          * A constant that denotes the completion of an IncrementalCommand.
124          */
125         public static final boolean DONE = false;
126
127         private final DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a");
128
129         /**
130          * Specifies that the images available for this composite will be the ones
131          * available in FileContextMenu.
132          */
133         public interface Images extends ClientBundle,FileContextMenu.Images, FolderTreeView.Images {
134
135                 @Source("gr/grnet/pithos/resources/blank.gif")
136                 ImageResource blank();
137
138                 @Source("gr/grnet/pithos/resources/asc.png")
139                 ImageResource asc();
140
141                 @Source("gr/grnet/pithos/resources/desc.png")
142                 ImageResource desc();
143
144                 @Source("gr/grnet/pithos/resources/mimetypes/document_shared.png")
145                 ImageResource documentShared();
146
147                 @Source("gr/grnet/pithos/resources/mimetypes/kcmfontinst.png")
148                 ImageResource wordprocessor();
149
150                 @Source("gr/grnet/pithos/resources/mimetypes/log.png")
151                 ImageResource spreadsheet();
152
153                 @Source("gr/grnet/pithos/resources/mimetypes/kpresenter_kpr.png")
154                 ImageResource presentation();
155
156                 @Source("gr/grnet/pithos/resources/mimetypes/acroread.png")
157                 ImageResource pdf();
158
159                 @Source("gr/grnet/pithos/resources/mimetypes/image.png")
160                 ImageResource image();
161
162                 @Source("gr/grnet/pithos/resources/mimetypes/video2.png")
163                 ImageResource video();
164
165                 @Source("gr/grnet/pithos/resources/mimetypes/knotify.png")
166                 ImageResource audio();
167
168                 @Source("gr/grnet/pithos/resources/mimetypes/html.png")
169                 ImageResource html();
170
171                 @Source("gr/grnet/pithos/resources/mimetypes/txt.png")
172                 ImageResource txt();
173
174                 @Source("gr/grnet/pithos/resources/mimetypes/ark2.png")
175                 ImageResource zip();
176
177                 @Source("gr/grnet/pithos/resources/mimetypes/kcmfontinst_shared.png")
178                 ImageResource wordprocessorShared();
179
180                 @Source("gr/grnet/pithos/resources/mimetypes/log_shared.png")
181                 ImageResource spreadsheetShared();
182
183                 @Source("gr/grnet/pithos/resources/mimetypes/kpresenter_kpr_shared.png")
184                 ImageResource presentationShared();
185
186                 @Source("gr/grnet/pithos/resources/mimetypes/acroread_shared.png")
187                 ImageResource pdfShared();
188
189                 @Source("gr/grnet/pithos/resources/mimetypes/image_shared.png")
190                 ImageResource imageShared();
191
192                 @Source("gr/grnet/pithos/resources/mimetypes/video2_shared.png")
193                 ImageResource videoShared();
194
195                 @Source("gr/grnet/pithos/resources/mimetypes/knotify_shared.png")
196                 ImageResource audioShared();
197
198                 @Source("gr/grnet/pithos/resources/mimetypes/html_shared.png")
199                 ImageResource htmlShared();
200
201                 @Source("gr/grnet/pithos/resources/mimetypes/txt_shared.png")
202                 ImageResource txtShared();
203
204                 @Source("gr/grnet/pithos/resources/mimetypes/ark2_shared.png")
205                 ImageResource zipShared();
206
207         }
208         
209         /**
210          * The number of files in this folder.
211          */
212         int folderFileCount;
213
214         /**
215          * Total folder size
216          */
217         long folderTotalSize;
218
219         /**
220          * A cache of the files in the list.
221          */
222         private List<File> files;
223
224         /**
225          * The widget's image bundle.
226          */
227         private final Images images;
228         
229         private CellTable<File> celltable;
230
231         private final MultiSelectionModel<File> selectionModel;
232
233         private final List<SortableHeader> allHeaders = new ArrayList<SortableHeader>();
234
235         SortableHeader nameHeader;
236
237         GssSimplePager pagerBottom;
238
239         GssSimplePager pagerTop;
240
241         Button uploadButtonBottom;
242
243         Button uploadButtonTop;
244
245     FolderTreeView treeView;
246
247     private Pithos app;
248
249     /**
250          * Construct the file list widget. This entails setting up the widget
251          * layout, fetching the number of files in the current folder from the
252          * server and filling the local file cache of displayed files with data from
253          * the server, as well.
254          *
255          * @param _images
256          */
257         public FileList(final Pithos _app, Images _images, FolderTreeView _treeView) {
258         app = _app;
259                 images = _images;
260         this.treeView = _treeView;
261
262         CellTable.Resources resources = GWT.create(TableResources.class);
263
264         ProvidesKey<File> keyProvider = new ProvidesKey<File>(){
265
266                         @Override
267                         public Object getKey(File item) {
268                                 return item.getUri();
269                         }
270                 };
271
272                 celltable = new CellTable<File>(Pithos.VISIBLE_FILE_COUNT, resources, keyProvider);
273         celltable.setWidth("100%");
274         celltable.setStyleName("pithos-List");
275
276                 Column<File, ImageResource> status = new Column<File, ImageResource>(new ImageResourceCell() {
277                     @Override
278                 public boolean handlesSelection() {
279                     return false;
280                 }
281                 })
282         {
283                  @Override
284                  public ImageResource getValue(File entity) {
285                      return getFileIcon(entity);
286                  }
287             };
288             celltable.addColumn(status,"");
289
290         final Column<File,SafeHtml> nameColumn = new Column<File,SafeHtml>(new SafeHtmlCell()) {
291
292                         @Override
293                         public SafeHtml getValue(File object) {
294                                 SafeHtmlBuilder sb = new SafeHtmlBuilder();
295                 sb.append(Templates.INSTANCE.filenameSpan(object.getName()));
296                                 if (object.getContentType().endsWith("png") || object.getContentType().endsWith("gif") || object.getContentType().endsWith("jpeg")) {
297                                 sb.appendHtmlConstant("&nbsp;")
298                       .append(Templates.INSTANCE.viewLink(object.getUri(), object.getOwner() + " : " + object.getPath() + object.getName()));
299                                 }
300                                 
301                                 return sb.toSafeHtml();
302                         }
303                         
304                 };
305         celltable.addColumn(nameColumn, nameHeader = new SortableHeader("Name"));
306                 allHeaders.add(nameHeader);
307                 nameHeader.setUpdater(new FileValueUpdater(nameHeader, "name"));
308
309                 celltable.redrawHeaders();
310                 
311             Column<File,String> aColumn = new Column<File, String>(new TextCell()) {
312                         @Override
313                         public String getValue(File object) {
314                                 return object.getOwner();
315                         }
316                 };
317         SortableHeader aheader = new SortableHeader("Owner");
318                 celltable.addColumn(aColumn, aheader);
319                 allHeaders.add(aheader);
320         aheader.setUpdater(new FileValueUpdater(aheader, "owner"));
321
322         aColumn = new Column<File,String>(new TextCell()) {
323                         @Override
324                         public String getValue(File object) {
325                                 return object.getPath();
326                         }
327                 };
328         aheader = new SortableHeader("Path");
329                 celltable.addColumn(aColumn, aheader);
330                 allHeaders.add(aheader);
331                 aheader.setUpdater(new FileValueUpdater(aheader, "path"));
332
333         aColumn = new Column<File,String>(new TextCell()) {
334                         @Override
335                         public String getValue(File object) {
336                         return String.valueOf(object.getVersion());
337                         }
338                 };
339         aheader = new SortableHeader("Version");
340                 celltable.addColumn(aColumn, aheader);
341                 allHeaders.add(aheader);
342                 aheader.setUpdater(new FileValueUpdater(aheader, "version"));
343
344         aColumn = new Column<File,String>(new TextCell()) {
345                         @Override
346                         public String getValue(File object) {
347                                 // TODO Auto-generated method stub
348                                 return object.getSizeAsString();
349                         }
350                 };
351         aheader = new SortableHeader("Size");
352         celltable.addColumn(aColumn, aheader);
353                 allHeaders.add(aheader);
354                 aheader.setUpdater(new FileValueUpdater(aheader, "size"));
355
356         aColumn = new Column<File,String>(new TextCell()) {
357                         @Override
358                         public String getValue(File object) {
359                                 return formatter.format(object.getLastModified());
360                         }
361                 };
362         aheader = new SortableHeader("Last Modified");
363                 celltable.addColumn(aColumn, aheader);
364                 allHeaders.add(aheader);
365                 aheader.setUpdater(new FileValueUpdater(aheader, "date"));
366                
367                 provider.addDataDisplay(celltable);
368
369                 VerticalPanel vp = new VerticalPanel();
370                 vp.setWidth("100%");
371
372                 pagerTop = new GssSimplePager(GssSimplePager.TextLocation.CENTER);
373         pagerTop.setVisible(false);
374                 pagerTop.setDisplay(celltable);
375                 uploadButtonTop = new Button("<span id='topMenu.file.upload'>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + "&nbsp;Upload</span>");
376                 uploadButtonTop.addClickHandler(new ClickHandler() {
377                         
378                         @Override
379                         public void onClick(ClickEvent event) {
380                                 new UploadFileCommand(app, null, treeView.getSelection()).execute();
381                         }
382                 });
383                 HorizontalPanel topPanel = new HorizontalPanel();
384                 topPanel.add(pagerTop);
385                 topPanel.add(uploadButtonTop);
386                 vp.add(topPanel);
387
388         vp.add(celltable);
389
390                 pagerBottom = new GssSimplePager(GssSimplePager.TextLocation.CENTER);
391         pagerBottom.setVisible(false);
392                 pagerBottom.setDisplay(celltable);
393                 uploadButtonBottom=new Button("<span id='topMenu.file.upload'>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + "&nbsp;Upload</span>");
394                 uploadButtonBottom.addClickHandler(new ClickHandler() {
395                         
396                         @Override
397                         public void onClick(ClickEvent event) {
398                                 new UploadFileCommand(app, null, treeView.getSelection()).execute();
399                         }
400                 });
401         HorizontalPanel bottomPanel = new HorizontalPanel();
402         bottomPanel.add(pagerBottom);
403                 bottomPanel.add(uploadButtonBottom);
404
405                 vp.add(bottomPanel);
406                 vp.setCellWidth(celltable, "100%");
407         vp.addHandler(new ContextMenuHandler() {
408             @Override
409             public void onContextMenu(ContextMenuEvent event) {
410                 Folder selectedFolder = treeView.getSelection();
411                 if (!selectedFolder.isTrash()) {
412                     FileContextMenu contextMenu = new FileContextMenu(app, images, selectedFolder, getSelectedFiles(), false);
413                     int x = event.getNativeEvent().getClientX();
414                     int y = event.getNativeEvent().getClientY();
415                     contextMenu.setPopupPosition(x, y);
416                     contextMenu.show();
417                 }
418             }
419         }, ContextMenuEvent.getType());
420                 initWidget(vp);
421
422                 selectionModel = new MultiSelectionModel<File>(keyProvider);
423
424                 celltable.setSelectionModel(selectionModel, GSSSelectionEventManager.<File> createDefaultManager());
425                 celltable.setPageSize(Pithos.VISIBLE_FILE_COUNT);
426                 
427                 sinkEvents(Event.ONCONTEXTMENU);
428 //              sinkEvents(Event.ONMOUSEUP);
429 //              sinkEvents(Event.ONMOUSEDOWN);
430 //              sinkEvents(Event.ONCLICK);
431 //              sinkEvents(Event.ONKEYDOWN);
432 //              sinkEvents(Event.ONDBLCLICK);
433                 Pithos.preventIESelection();
434         }
435
436         public List<File> getSelectedFiles() {
437         return new ArrayList<File>(selectionModel.getSelectedSet());
438         }
439         
440 //      @Override
441 //      public void onBrowserEvent(Event event) {
442 //
443 //              if (files == null || files.size() == 0) {
444 //                      if (DOM.eventGetType(event) == Event.ONCONTEXTMENU && getSelectedFiles().size() == 0) {
445 //                              contextMenu = new FileContextMenu(images, false, true);
446 //                contextMenu.show();
447 //                              event.preventDefault();
448 //                              event.cancelBubble(true);
449 //                      }
450 //                      return;
451 //              }
452 //              if (DOM.eventGetType(event) == Event.ONCONTEXTMENU && getSelectedFiles().size() != 0) {
453 //                      GWT.log("*****GOING TO SHOW CONTEXT MENU ****", null);
454 //                      contextMenu =  new FileContextMenu(images, false, false);
455 //                      contextMenu = contextMenu.onEvent(event);
456 //                      event.cancelBubble(true);
457 //                      event.preventDefault();
458 //              } else if (DOM.eventGetType(event) == Event.ONCONTEXTMENU && getSelectedFiles().size() == 0) {
459 //                      contextMenu = new FileContextMenu(images, false, true);
460 //                      contextMenu = contextMenu.onEmptyEvent(event);
461 //                      event.cancelBubble(true);
462 //                      event.preventDefault();
463 //              } else if (DOM.eventGetType(event) == Event.ONDBLCLICK)
464 //                      if (getSelectedFiles().size() == 1) {
465 //                              Pithos app = app;
466 //                              File file = getSelectedFiles().get(0);
467 //                              Window.open(file.getUri(), "_blank", "");
468 //                              event.preventDefault();
469 //                              return;
470 //                      }
471 //              super.onBrowserEvent(event);
472 //      }
473
474         /**
475          * Update the display of the file list.
476          */
477         void update(boolean sort) {
478                 int count = folderFileCount;
479                 int max = startIndex + Pithos.VISIBLE_FILE_COUNT;
480                 if (max > count)
481                         max = count;
482                 folderTotalSize = 0;
483                 
484                 for(File f : files){
485                         folderTotalSize += f.getBytes();
486                 }
487                 if (folderFileCount == 0) {
488                         showingStats = "no files";
489                 } else if (folderFileCount < Pithos.VISIBLE_FILE_COUNT) {
490                         if (folderFileCount == 1)
491                                 showingStats = "1 file";
492                         else
493                                 showingStats = folderFileCount + " files";
494 //                      showingStats += " (" + FileResource.getFileSizeAsString(folderTotalSize) + ")";
495                 } else {
496 //                      showingStats = "" + (startIndex + 1) + " - " + max + " of " + count + " files" + " (" + FileResource.getFileSizeAsString(folderTotalSize) + ")";
497                 }
498                 showCellTable();
499         }
500
501         /**
502          * Return the proper icon based on the MIME type of the file.
503          *
504          * @param file
505          * @return the icon
506          */
507         private ImageResource getFileIcon(File file) {
508                 String mimetype = file.getContentType();
509                 boolean shared = file.isShared();
510                 if (mimetype == null)
511                         return shared ? images.documentShared() : images.document();
512                 mimetype = mimetype.toLowerCase();
513                 if (mimetype.startsWith("application/pdf"))
514                         return shared ? images.pdfShared() : images.pdf();
515                 else if (mimetype.endsWith("excel"))
516                         return shared ? images.spreadsheetShared() : images.spreadsheet();
517                 else if (mimetype.endsWith("msword"))
518                         return shared ? images.wordprocessorShared() : images.wordprocessor();
519                 else if (mimetype.endsWith("powerpoint"))
520                         return shared ? images.presentationShared() : images.presentation();
521                 else if (mimetype.startsWith("application/zip") ||
522                                         mimetype.startsWith("application/gzip") ||
523                                         mimetype.startsWith("application/x-gzip") ||
524                                         mimetype.startsWith("application/x-tar") ||
525                                         mimetype.startsWith("application/x-gtar"))
526                         return shared ? images.zipShared() : images.zip();
527                 else if (mimetype.startsWith("text/html"))
528                         return shared ? images.htmlShared() : images.html();
529                 else if (mimetype.startsWith("text/plain"))
530                         return shared ? images.txtShared() : images.txt();
531                 else if (mimetype.startsWith("image/"))
532                         return shared ? images.imageShared() : images.image();
533                 else if (mimetype.startsWith("video/"))
534                         return shared ? images.videoShared() : images.video();
535                 else if (mimetype.startsWith("audio/"))
536                         return shared ? images.audioShared() : images.audio();
537                 return shared ? images.documentShared() : images.document();
538         }
539
540         /**
541          * Fill the file cache with data.
542          */
543         public void setFiles(final List<File> _files) {
544                 files = new ArrayList<File>();
545         for (File fres : _files)
546                 if (!fres.isInTrash())
547                                 files.add(fres);
548                 Collections.sort(files, new Comparator<File>() {
549
550                         @Override
551                         public int compare(File arg0, File arg1) {
552                                 return arg0.getName().compareTo(arg1.getName());
553                         }
554
555                 });
556                 folderFileCount = files.size();
557                 
558                 nameHeader.setSorted(true);
559                 nameHeader.toggleReverseSort();
560                 for (SortableHeader otherHeader : allHeaders) {
561                 if (otherHeader != nameHeader) {
562                     otherHeader.setSorted(false);
563                     otherHeader.setReverseSort(true);
564                 }
565             }
566
567         if(files.size() > Pithos.VISIBLE_FILE_COUNT){
568             pagerBottom.setVisible(true);
569             pagerTop.setVisible(true);
570         }
571         else{
572             pagerTop.setVisible(false);
573             pagerBottom.setVisible(false);
574         }
575         Folder selectedItem = treeView.getSelection();
576
577         provider.setList(files);
578         selectionModel.clear();
579         }
580
581         /**
582          * Does the list contains the requested filename
583          *
584          * @param fileName
585          * @return true/false
586          */
587         public boolean contains(String fileName) {
588                 for (int i = 0; i < files.size(); i++)
589                         if (files.get(i).getName().equals(fileName))
590                                 return true;
591                 return false;
592         }
593
594         public void clearSelectedRows() {
595                 Iterator<File> it = selectionModel.getSelectedSet().iterator();
596                 while(it.hasNext()){
597                         selectionModel.setSelected(it.next(),false);
598                 }
599         }
600         
601         /**
602          *
603          */
604         public void selectAllRows() {
605                 Iterator<File> it = provider.getList().iterator();
606                 while(it.hasNext()){
607                         selectionModel.setSelected(it.next(),true);
608                 }
609         }
610
611         private void sortFiles(final String sortingProperty, final boolean sortingType){
612                 Collections.sort(files, new Comparator<File>() {
613
614             @Override
615             public int compare(File arg0, File arg1) {
616                     AbstractImagePrototype descPrototype = AbstractImagePrototype.create(images.desc());
617                     AbstractImagePrototype ascPrototype = AbstractImagePrototype.create(images.asc());
618                     if (sortingType){
619                             if (sortingProperty.equals("version")) {
620                                     return arg0.getVersion() - arg1.getVersion();
621                             } else if (sortingProperty.equals("owner")) {
622                                     return arg0.getOwner().compareTo(arg1.getOwner());
623                             } else if (sortingProperty.equals("date")) {
624                                     return arg0.getLastModified().compareTo(arg1.getLastModified());
625                             } else if (sortingProperty.equals("size")) {
626                                     return (int) (arg0.getBytes() - arg1.getBytes());
627                             } else if (sortingProperty.equals("name")) {
628                                     return arg0.getName().compareTo(arg1.getName());
629                             } else if (sortingProperty.equals("path")) {
630                                     return arg0.getUri().compareTo(arg1.getUri());
631                             } else {
632                                     return arg0.getName().compareTo(arg1.getName());
633                             }
634                     }
635                     else if (sortingProperty.equals("version")) {
636                             
637                             return arg1.getVersion() - arg0.getVersion();
638                     } else if (sortingProperty.equals("owner")) {
639                             
640                             return arg1.getOwner().compareTo(arg0.getOwner());
641                     } else if (sortingProperty.equals("date")) {
642                             
643                             return arg1.getLastModified().compareTo(arg0.getLastModified());
644                     } else if (sortingProperty.equals("size")) {
645                             return (int) (arg1.getBytes() - arg0.getBytes());
646                     } else if (sortingProperty.equals("name")) {
647                             
648                             return arg1.getName().compareTo(arg0.getName());
649                     } else if (sortingProperty.equals("path")) {
650                             
651                             return arg1.getUri().compareTo(arg0.getUri());
652                     } else {
653                             
654                             return arg1.getName().compareTo(arg0.getName());
655                     }
656             }
657
658                 });
659         }
660         
661         final class FileValueUpdater implements ValueUpdater<String>{
662                 private String property;
663                 private SortableHeader header;
664                 /**
665                  * 
666                  */
667                 public FileValueUpdater(SortableHeader header,String property) {
668                         this.property=property;
669                         this.header=header;
670                 }
671                 @Override
672                 public void update(String value) {
673                         header.setSorted(true);
674                         header.toggleReverseSort();
675
676                 for (SortableHeader otherHeader : allHeaders) {
677                   if (otherHeader != header) {
678                     otherHeader.setSorted(false);
679                     otherHeader.setReverseSort(true);
680                   }
681                 }
682                 celltable.redrawHeaders();
683                 sortFiles(property, header.getReverseSort());
684                 FileList.this.update(true);                     
685                 }
686                 
687         }
688
689         /**
690          * Shows the files in the cellTable 
691      */
692         private void showCellTable(){
693                 if(files.size()> Pithos.VISIBLE_FILE_COUNT){
694                         pagerBottom.setVisible(true);
695                         pagerTop.setVisible(true);
696                 }
697                 else{
698                         pagerTop.setVisible(false);
699                         pagerBottom.setVisible(false);
700                 }
701                 provider.setList(files);
702                 
703                 provider.refresh();
704                 
705                 //celltable.redraw();
706                 celltable.redrawHeaders();              
707         }
708
709     public void showTrash() {
710         uploadButtonBottom.setVisible(false);
711         uploadButtonTop.setVisible(false);
712     }
713
714     public void showFiles() {
715         uploadButtonBottom.setVisible(true);
716         uploadButtonTop.setVisible(true);
717     }
718 }