Statistics
| Branch: | Tag: | Revision:

root / src / gr / grnet / pithos / web / client / FileList.java @ 4c69b354

History | View | Annotate | Download (22.7 kB)

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.FileFolderResource;
40
import gr.grnet.pithos.web.client.foldertree.Folder;
41
import gr.grnet.pithos.web.client.foldertree.FolderTreeView;
42
import gr.grnet.pithos.web.client.foldertree.Resource;
43

    
44
import java.util.ArrayList;
45
import java.util.Collections;
46
import java.util.Comparator;
47
import java.util.Iterator;
48
import java.util.List;
49
import java.util.Set;
50

    
51
import com.google.gwt.cell.client.Cell.Context;
52
import com.google.gwt.cell.client.ImageResourceCell;
53
import com.google.gwt.cell.client.SafeHtmlCell;
54
import com.google.gwt.cell.client.TextCell;
55
import com.google.gwt.cell.client.ValueUpdater;
56
import com.google.gwt.core.client.GWT;
57
import com.google.gwt.event.dom.client.ContextMenuEvent;
58
import com.google.gwt.event.dom.client.ContextMenuHandler;
59
import com.google.gwt.i18n.client.DateTimeFormat;
60
import com.google.gwt.resources.client.ImageResource;
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<FileFolderResource> provider = new ListDataProvider<FileFolderResource>();
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
         * 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<FileFolderResource> files;
217

    
218
        /**
219
         * The widget's image bundle.
220
         */
221
        protected final Images images;
222
        
223
        protected CellTable<FileFolderResource> celltable;
224

    
225
        private final MultiSelectionModel<FileFolderResource> selectionModel;
226

    
227
        Column<FileFolderResource, 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<FileFolderResource> keyProvider = new ProvidesKey<FileFolderResource>(){
252

    
253
                        @Override
254
                        public Object getKey(FileFolderResource item) {
255
                                return item.getUri();
256
                        }
257
                };
258

    
259
                celltable = new CellTable<FileFolderResource>(10, resources, keyProvider);
260
        celltable.setWidth("100%");
261
        celltable.setStyleName("pithos-List");
262

    
263
                Column<FileFolderResource, ImageResource> status = new Column<FileFolderResource, ImageResource>(
264
                                new ImageResourceCell() {
265
                                        @Override
266
                                        public boolean handlesSelection() {
267
                                                return false;
268
                                        }
269
                                }) {
270
                        @Override
271
                        public ImageResource getValue(FileFolderResource entity) {
272
                                return getFileIcon(entity);
273
                        }
274

    
275
                        @Override
276
                        public String getCellStyleNames(Context context, FileFolderResource object) {
277
                                if (object instanceof File) {
278
                                        File f = (File) object;
279
                                        if (!f.getPermissions().isEmpty() && !f.isPublished())
280
                                                return ((TableStyle) resources.cellTableStyle())
281
                                                                .cellTableFirstColumnShared();
282
                                }
283
                                return super.getCellStyleNames(context, object);
284
                        }
285
                };
286
            celltable.addColumn(status,"");
287

    
288
        final Column<FileFolderResource,SafeHtml> nameColumn = new Column<FileFolderResource,SafeHtml>(new SafeHtmlCell()) {
289

    
290
                        @Override
291
                        public SafeHtml getValue(FileFolderResource object) {
292
                                SafeHtmlBuilder sb = new SafeHtmlBuilder();
293
                                sb.append(Templates.INSTANCE.filenameSpan(object.getName()));
294
                                if (object.getContentType() != null && (object.getContentType().endsWith("png") || object.getContentType().endsWith("gif") || object.getContentType().endsWith("jpeg"))) {
295
                                sb.appendHtmlConstant("&nbsp;")
296
                      .append(Templates.INSTANCE.viewLink(app.getApiPath() + object.getOwner() + object.getUri(), object.getName()));
297
                                }
298
                                
299
                                return sb.toSafeHtml();
300
                        }
301
                        
302
                };
303
        celltable.addColumn(nameColumn, nameHeader = new SortableHeader("Name", "name"));
304
                allHeaders.add(nameHeader);
305
                nameHeader.setUpdater(new FileValueUpdater(nameHeader));
306
                nameHeader.setSorted(true);
307
                nameHeader.setReverseSort(true);
308

    
309
                celltable.redrawHeaders();
310
                
311
                pathColumn = new Column<FileFolderResource, String>(new TextCell()) {
312

    
313
                        @Override
314
                        public String getValue(FileFolderResource f) {
315
                                String path;
316
                                if (!app.getSelectedTree().equals(app.mysharedTreeView)) {
317
                                        path = f.getParent().getPrefix();
318
                                        if (path.length() == 0)
319
                                                path = "/";
320
                                }
321
                                else {
322
                                        path = f.getPath();
323
                                        if (path.lastIndexOf("/") != -1)
324
                                                path = path.substring(0, path.lastIndexOf("/"));
325
                                        else
326
                                                path = "/";
327
                                }
328
                                return path;
329
                        }
330
                };
331
                pathHeader = new SortableHeader("Path", "path");
332
                celltable.addColumn(pathColumn, pathHeader);
333
                allHeaders.add(pathHeader);
334
                pathHeader.setUpdater(new FileValueUpdater(pathHeader));
335
                
336
        Column<FileFolderResource,String> aColumn = new Column<FileFolderResource,String>(new TextCell()) {
337
                        @Override
338
                        public String getValue(FileFolderResource object) {
339
                                return object.getSizeAsString();
340
                        }
341
                };
342
        SortableHeader aheader = new SortableHeader("Size", "size");
343
        celltable.addColumn(aColumn, aheader);
344
                allHeaders.add(aheader);
345
                aheader.setUpdater(new FileValueUpdater(aheader));
346

    
347
        aColumn = new Column<FileFolderResource,String>(new TextCell()) {
348
                        @Override
349
                        public String getValue(FileFolderResource object) {
350
                                return object.getLastModified() != null ? formatter.format(object.getLastModified()) : "";
351
                        }
352
                };
353
        aheader = new SortableHeader("Last Modified", "date");
354
                celltable.addColumn(aColumn, aheader);
355
                allHeaders.add(aheader);
356
                aheader.setUpdater(new FileValueUpdater(aheader));
357
               
358
                provider.addDataDisplay(celltable);
359

    
360
                VerticalPanel vp = new VerticalPanel();
361
                vp.setWidth("100%");
362
                vp.addStyleName("pithos-FileListContainer");
363

    
364
        vp.add(celltable);
365

    
366
                vp.setCellWidth(celltable, "100%");
367
        vp.addHandler(new ContextMenuHandler() {
368
            @Override
369
            public void onContextMenu(final ContextMenuEvent event) {
370
                    final TreeView tree = app.getSelectedTree();
371
                    if (tree != null) {
372
                        final int x = event.getNativeEvent().getClientX();
373
                        final int y = event.getNativeEvent().getClientY();
374
                        final Folder selectedFolder = app.getSelection();
375
                        app.scheduleFolderHeadCommand(selectedFolder, new Command() {
376
                                                
377
                                                @Override
378
                                                public void execute() {
379
                                                        final List<FileFolderResource> selectedFiles = getSelectedFiles();
380
                                                        boolean ofSameType = true;
381
                                                        FileFolderResource previous = null;
382
                                                        for (FileFolderResource r : selectedFiles) {
383
                                                                if (previous != null && ((previous instanceof Folder && r instanceof File)) || (r instanceof Folder && previous instanceof File)) {
384
                                                                        ofSameType = false;
385
                                                                        break;
386
                                                                }
387
                                                                previous = r;
388
                                                        }
389
                                                        if (!ofSameType)
390
                                                                return;
391
                                                        if (selectedFiles.get(0) instanceof Folder)
392
                                                                return;
393
                                                        Iterator<FileFolderResource> iter = selectedFiles.iterator();
394
                                                        iterateFileFolderHeadCommand(iter, new Command() {
395
                                                                
396
                                                                @Override
397
                                                                public void execute() {
398
                                                        FileContextMenu contextMenu = new FileContextMenu(app, images, tree, selectedFolder, selectedFiles);
399
                                                        contextMenu.setPopupPosition(x, y);
400
                                                        contextMenu.show();
401
                                                                }
402
                                                        });
403
                                                }
404
                                        });
405
                    }
406
            }
407
        }, ContextMenuEvent.getType());
408
                initWidget(vp);
409

    
410
                selectionModel = new MultiSelectionModel<FileFolderResource>(keyProvider);
411
                selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
412
                        
413
                        @Override
414
                        public void onSelectionChange(SelectionChangeEvent event) {
415
                                app.showRelevantToolbarButtons();
416
                        }
417
                });
418
                
419
                celltable.setSelectionModel(selectionModel, PithosSelectionEventManager.<FileFolderResource> createDefaultManager());
420
                
421
                sinkEvents(Event.ONCONTEXTMENU);
422
                sinkEvents(Event.ONDBLCLICK);
423
                Pithos.preventIESelection();
424
        }
425

    
426
        public List<FileFolderResource> getSelectedFiles() {
427
        return new ArrayList<FileFolderResource>(selectionModel.getSelectedSet());
428
        }
429
        
430
        @Override
431
        public void onBrowserEvent(Event event) {
432

    
433
                if (DOM.eventGetType(event) == Event.ONDBLCLICK)
434
                        if (getSelectedFiles().size() == 1) {
435
                                FileFolderResource res = getSelectedFiles().get(0);
436
                                if (res instanceof File) {
437
                                        File file = (File) res;
438
                                        Window.open(app.getApiPath() + file.getOwner() + file.getUri(), "_blank", "");
439
                                        event.preventDefault();
440
                                }
441
                                else {
442
                                        Folder f = (Folder) res;
443
                                        app.getFolderTreeView().setSelection(f);
444
                                }
445
                                return;
446
                        }
447
                super.onBrowserEvent(event);
448
        }
449

    
450
        /**
451
         * Update the display of the file list.
452
         */
453
        void update() {
454
                showCellTable();
455
        }
456

    
457
        /**
458
         * Return the proper icon based on the MIME type of the file.
459
         *
460
         * @param res
461
         * @return the icon
462
         */
463
        protected ImageResource getFileIcon(Resource res) {
464
                if (res instanceof Folder) {
465
                        return images.folderYellow();
466
                }
467
                File file = (File) res;
468
                String mimetype = file.getContentType();
469
                boolean published = file.isPublished();
470
                if (mimetype == null)
471
                        return published ? images.documentShared() : images.document();
472
                mimetype = mimetype.toLowerCase();
473
                if (mimetype.startsWith("application/pdf"))
474
                        return published ? images.pdfShared() : images.pdf();
475
                else if (mimetype.endsWith("excel"))
476
                        return published ? images.spreadsheetShared() : images.spreadsheet();
477
                else if (mimetype.endsWith("msword"))
478
                        return published ? images.wordprocessorShared() : images.wordprocessor();
479
                else if (mimetype.endsWith("powerpoint"))
480
                        return published ? images.presentationShared() : images.presentation();
481
                else if (mimetype.startsWith("application/zip") ||
482
                                        mimetype.startsWith("application/gzip") ||
483
                                        mimetype.startsWith("application/x-gzip") ||
484
                                        mimetype.startsWith("application/x-tar") ||
485
                                        mimetype.startsWith("application/x-gtar"))
486
                        return published ? images.zipShared() : images.zip();
487
                else if (mimetype.startsWith("text/html"))
488
                        return published ? images.htmlShared() : images.html();
489
                else if (mimetype.startsWith("text/plain"))
490
                        return published ? images.txtShared() : images.txt();
491
                else if (mimetype.startsWith("image/"))
492
                        return published ? images.imageShared() : images.image();
493
                else if (mimetype.startsWith("video/"))
494
                        return published ? images.videoShared() : images.video();
495
                else if (mimetype.startsWith("audio/"))
496
                        return published ? images.audioShared() : images.audio();
497
                return published ? images.documentShared() : images.document();
498
        }
499

    
500
        /**
501
         * Fill the file cache with data.
502
         */
503
        public void setFiles(final List<FileFolderResource> _files) {
504
                if (!app.getSelectedTree().equals(app.mysharedTreeView)) {
505
                        if (celltable.getColumnIndex(pathColumn) != -1)
506
                                celltable.removeColumn(pathColumn);
507
                }
508
                else {
509
                        if (celltable.getColumnIndex(pathColumn) == -1)
510
                                celltable.insertColumn(2, pathColumn, pathHeader);
511
                }
512
                files = new ArrayList<FileFolderResource>();
513
            for (FileFolderResource fres : _files) {
514
                        files.add(fres);
515
            }
516
            
517
                folderFileCount = files.size();
518
                
519
                for (SortableHeader header : allHeaders) {
520
                        if (header.isSorted())
521
                                sortFiles(header.getProperty(), header.getReverseSort());
522
                }
523
                
524
                List<FileFolderResource> previousSelection = getSelectedFiles(); //Keep the previous selection
525

    
526
                provider.getList().clear();
527
        provider.setList(files);
528
        selectionModel.clear();
529
            for (FileFolderResource f : files) {
530
                    if (previousSelection.contains(f))
531
                            selectionModel.setSelected(f, true);
532
            }
533
        
534
        app.showFolderStatistics(folderFileCount);
535
        celltable.setPageSize(folderFileCount);
536
        }
537

    
538
        /**
539
         * Does the list contains the requested filename
540
         *
541
         * @param fileName
542
         * @return true/false
543
         */
544
        public boolean contains(String fileName) {
545
                for (int i = 0; i < files.size(); i++)
546
                        if (files.get(i).getName().equals(fileName))
547
                                return true;
548
                return false;
549
        }
550

    
551
        public void clearSelectedRows() {
552
                Iterator<FileFolderResource> it = selectionModel.getSelectedSet().iterator();
553
                while(it.hasNext()){
554
                        selectionModel.setSelected(it.next(),false);
555
                }
556
        }
557
        
558
        /**
559
         *
560
         */
561
        public void selectAllRows() {
562
                Iterator<FileFolderResource> it = provider.getList().iterator();
563
                while(it.hasNext()){
564
                        selectionModel.setSelected(it.next(),true);
565
                }
566
        }
567

    
568
        protected void sortFiles(final String sortingProperty,
569
                        final boolean sortingType) {
570
                Collections.sort(files, new Comparator<FileFolderResource>() {
571

    
572
                        @Override
573
                        public int compare(FileFolderResource arg0, FileFolderResource arg1) {
574
                                if (arg0 instanceof Folder && arg1 instanceof File)
575
                                        return -1;
576
                                if (sortingType) {
577
                                        if (arg0 instanceof Folder && arg1 instanceof File)
578
                                                return -1;
579
                                        else if (arg0 instanceof File && arg1 instanceof Folder)
580
                                                return 1;
581
                                        else if (arg0 instanceof Folder && arg1 instanceof Folder)
582
                                                return arg0.getName().compareTo(arg1.getName());
583
                                        if (sortingProperty.equals("date")) {
584
                                                if (arg0.getLastModified() != null
585
                                                                && arg1.getLastModified() != null)
586
                                                        return arg0.getLastModified().compareTo(
587
                                                                        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
                                } else if (arg0 instanceof Folder && arg1 instanceof File)
599
                                        return -1;
600
                                else if (arg0 instanceof File && arg1 instanceof Folder)
601
                                        return 1;
602
                                else if (arg0 instanceof Folder && arg1 instanceof Folder)
603
                                        return arg1.getName().compareTo(arg0.getName());
604

    
605
                                else if (sortingProperty.equals("date")) {
606

    
607
                                        return arg1.getLastModified().compareTo(
608
                                                        arg0.getLastModified());
609
                                } else if (sortingProperty.equals("size")) {
610
                                        return (int) (arg1.getBytes() - arg0.getBytes());
611
                                } else if (sortingProperty.equals("name")) {
612

    
613
                                        return arg1.getName().compareTo(arg0.getName());
614
                                } else if (sortingProperty.equals("path")) {
615

    
616
                                        return arg1.getUri().compareTo(arg0.getUri());
617
                                } else {
618

    
619
                                        return arg1.getName().compareTo(arg0.getName());
620
                                }
621
                        }
622

    
623
                });
624
        }
625
        
626
        final class FileValueUpdater implements ValueUpdater<String>{
627
                private SortableHeader header;
628
                /**
629
                 * 
630
                 */
631
                public FileValueUpdater(SortableHeader header) {
632
                        this.header=header;
633
                }
634
                @Override
635
                public void update(String value) {
636
                        header.setSorted(true);
637
                        header.toggleReverseSort();
638

    
639
                for (SortableHeader otherHeader : allHeaders) {
640
                  if (otherHeader != header) {
641
                    otherHeader.setSorted(false);
642
                    otherHeader.setReverseSort(true);
643
                  }
644
                }
645
                celltable.redrawHeaders();
646
                sortFiles(header.getProperty(), header.getReverseSort());
647
                FileList.this.update();                        
648
                }
649
                
650
        }
651

    
652
        /**
653
         * Shows the files in the cellTable 
654
     */
655
        private void showCellTable(){
656
                provider.setList(files);
657
                
658
                provider.refresh();
659
                
660
                //celltable.redraw();
661
                celltable.redrawHeaders();                
662
        }
663
        
664
        void iterateFileFolderHeadCommand(final Iterator<FileFolderResource> iter, final Command callback) {
665
                if (iter.hasNext()) {
666
                        FileFolderResource res = iter.next();
667
                        if (res instanceof File) {
668
                                File f = (File) res;
669
                                app.scheduleFileHeadCommand(f, new Command() {
670
                                        
671
                                        @Override
672
                                        public void execute() {
673
                                                iterateFileFolderHeadCommand(iter, callback);
674
                                        }
675
                                });
676
                        }
677
                        else {
678
                                Folder f = (Folder) res;
679
                                app.scheduleFolderHeadCommand(f, new Command() {
680
                                        
681
                                        @Override
682
                                        public void execute() {
683
                                                iterateFileFolderHeadCommand(iter, callback);
684
                                        }
685
                                });
686
                        }
687
                }
688
                else if (callback != null)
689
                        callback.execute();
690
        }
691

    
692
        public void selectByUrl(List<String> selectedUrls) {
693
                Set<FileFolderResource> previous = selectionModel.getSelectedSet();
694
                for (FileFolderResource res : previous)
695
                        selectionModel.setSelected(res, false);
696
                
697
                int i = 0;
698
                boolean scrolled = false;
699
                for (FileFolderResource res : files) {
700
                        if (res instanceof File) {
701
                                File f = (File) res;
702
                                if (selectedUrls.contains(app.getApiPath() + f.getOwner() + f.getUri())) {
703
                                        selectionModel.setSelected(f, true);
704
                                        if (!scrolled) {
705
                                                celltable.getRowElement(i).getCells().getItem(0).scrollIntoView();
706
                                                scrolled = true;
707
                                        }
708
                                }
709
                        }
710
                        i++;
711
                }
712
        }
713
}