Statistics
| Branch: | Tag: | Revision:

root / src / gr / grnet / pithos / web / client / FileList.java @ 60a94150

History | View | Annotate | Download (22 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
                                                        Iterator<FileFolderResource> iter = selectedFiles.iterator();
381
                                                        iterateFilesHeadCommand(iter, new Command() {
382
                                                                
383
                                                                @Override
384
                                                                public void execute() {
385
                                                        FileContextMenu contextMenu = new FileContextMenu(app, images, tree, selectedFolder, selectedFiles);
386
                                                        contextMenu.setPopupPosition(x, y);
387
                                                        contextMenu.show();
388
                                                                }
389
                                                        });
390
                                                }
391
                                        });
392
                    }
393
            }
394
        }, ContextMenuEvent.getType());
395
                initWidget(vp);
396

    
397
                selectionModel = new MultiSelectionModel<FileFolderResource>(keyProvider);
398
                selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
399
                        
400
                        @Override
401
                        public void onSelectionChange(SelectionChangeEvent event) {
402
                                app.showRelevantToolbarButtons();
403
                        }
404
                });
405
                
406
                celltable.setSelectionModel(selectionModel, PithosSelectionEventManager.<FileFolderResource> createDefaultManager());
407
                
408
                sinkEvents(Event.ONCONTEXTMENU);
409
                sinkEvents(Event.ONDBLCLICK);
410
                Pithos.preventIESelection();
411
        }
412

    
413
        public List<FileFolderResource> getSelectedFiles() {
414
        return new ArrayList<FileFolderResource>(selectionModel.getSelectedSet());
415
        }
416
        
417
        @Override
418
        public void onBrowserEvent(Event event) {
419

    
420
                if (DOM.eventGetType(event) == Event.ONDBLCLICK)
421
                        if (getSelectedFiles().size() == 1) {
422
                                FileFolderResource res = getSelectedFiles().get(0);
423
                                if (res instanceof File) {
424
                                        File file = (File) res;
425
                                        Window.open(app.getApiPath() + file.getOwner() + file.getUri(), "_blank", "");
426
                                        event.preventDefault();
427
                                }
428
                                else {
429
                                        Folder f = (Folder) res;
430
                                        app.getFolderTreeView().setSelection(f);
431
                                }
432
                                return;
433
                        }
434
                super.onBrowserEvent(event);
435
        }
436

    
437
        /**
438
         * Update the display of the file list.
439
         */
440
        void update() {
441
                showCellTable();
442
        }
443

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

    
487
        /**
488
         * Fill the file cache with data.
489
         */
490
        public void setFiles(final List<FileFolderResource> _files) {
491
                if (!app.getSelectedTree().equals(app.mysharedTreeView)) {
492
                        if (celltable.getColumnIndex(pathColumn) != -1)
493
                                celltable.removeColumn(pathColumn);
494
                }
495
                else {
496
                        if (celltable.getColumnIndex(pathColumn) == -1)
497
                                celltable.insertColumn(2, pathColumn, pathHeader);
498
                }
499
                files = new ArrayList<FileFolderResource>();
500
            for (FileFolderResource fres : _files) {
501
                        files.add(fres);
502
            }
503
            
504
                folderFileCount = files.size();
505
                
506
                for (SortableHeader header : allHeaders) {
507
                        if (header.isSorted())
508
                                sortFiles(header.getProperty(), header.getReverseSort());
509
                }
510
                
511
                List<FileFolderResource> previousSelection = getSelectedFiles(); //Keep the previous selection
512

    
513
                provider.getList().clear();
514
        provider.setList(files);
515
        selectionModel.clear();
516
            for (FileFolderResource f : files) {
517
                    if (previousSelection.contains(f))
518
                            selectionModel.setSelected(f, true);
519
            }
520
        
521
        app.showFolderStatistics(folderFileCount);
522
        celltable.setPageSize(folderFileCount);
523
        }
524

    
525
        /**
526
         * Does the list contains the requested filename
527
         *
528
         * @param fileName
529
         * @return true/false
530
         */
531
        public boolean contains(String fileName) {
532
                for (int i = 0; i < files.size(); i++)
533
                        if (files.get(i).getName().equals(fileName))
534
                                return true;
535
                return false;
536
        }
537

    
538
        public void clearSelectedRows() {
539
                Iterator<FileFolderResource> it = selectionModel.getSelectedSet().iterator();
540
                while(it.hasNext()){
541
                        selectionModel.setSelected(it.next(),false);
542
                }
543
        }
544
        
545
        /**
546
         *
547
         */
548
        public void selectAllRows() {
549
                Iterator<FileFolderResource> it = provider.getList().iterator();
550
                while(it.hasNext()){
551
                        selectionModel.setSelected(it.next(),true);
552
                }
553
        }
554

    
555
        protected void sortFiles(final String sortingProperty,
556
                        final boolean sortingType) {
557
                Collections.sort(files, new Comparator<FileFolderResource>() {
558

    
559
                        @Override
560
                        public int compare(FileFolderResource arg0, FileFolderResource arg1) {
561
                                if (arg0 instanceof Folder && arg1 instanceof File)
562
                                        return -1;
563
                                if (sortingType) {
564
                                        if (arg0 instanceof Folder && arg1 instanceof File)
565
                                                return -1;
566
                                        else if (arg0 instanceof File && arg1 instanceof Folder)
567
                                                return 1;
568
                                        else if (arg0 instanceof Folder && arg1 instanceof Folder)
569
                                                return arg0.getName().compareTo(arg1.getName());
570
                                        if (sortingProperty.equals("date")) {
571
                                                if (arg0.getLastModified() != null
572
                                                                && arg1.getLastModified() != null)
573
                                                        return arg0.getLastModified().compareTo(
574
                                                                        arg1.getLastModified());
575
                                                return 0;
576
                                        } else if (sortingProperty.equals("size")) {
577
                                                return (int) (arg0.getBytes() - arg1.getBytes());
578
                                        } else if (sortingProperty.equals("name")) {
579
                                                return arg0.getName().compareTo(arg1.getName());
580
                                        } else if (sortingProperty.equals("path")) {
581
                                                return arg0.getUri().compareTo(arg1.getUri());
582
                                        } else {
583
                                                return arg0.getName().compareTo(arg1.getName());
584
                                        }
585
                                } else if (arg0 instanceof Folder && arg1 instanceof File)
586
                                        return -1;
587
                                else if (arg0 instanceof File && arg1 instanceof Folder)
588
                                        return 1;
589
                                else if (arg0 instanceof Folder && arg1 instanceof Folder)
590
                                        return arg1.getName().compareTo(arg0.getName());
591

    
592
                                else if (sortingProperty.equals("date")) {
593

    
594
                                        return arg1.getLastModified().compareTo(
595
                                                        arg0.getLastModified());
596
                                } else if (sortingProperty.equals("size")) {
597
                                        return (int) (arg1.getBytes() - arg0.getBytes());
598
                                } else if (sortingProperty.equals("name")) {
599

    
600
                                        return arg1.getName().compareTo(arg0.getName());
601
                                } else if (sortingProperty.equals("path")) {
602

    
603
                                        return arg1.getUri().compareTo(arg0.getUri());
604
                                } else {
605

    
606
                                        return arg1.getName().compareTo(arg0.getName());
607
                                }
608
                        }
609

    
610
                });
611
        }
612
        
613
        final class FileValueUpdater implements ValueUpdater<String>{
614
                private SortableHeader header;
615
                /**
616
                 * 
617
                 */
618
                public FileValueUpdater(SortableHeader header) {
619
                        this.header=header;
620
                }
621
                @Override
622
                public void update(String value) {
623
                        header.setSorted(true);
624
                        header.toggleReverseSort();
625

    
626
                for (SortableHeader otherHeader : allHeaders) {
627
                  if (otherHeader != header) {
628
                    otherHeader.setSorted(false);
629
                    otherHeader.setReverseSort(true);
630
                  }
631
                }
632
                celltable.redrawHeaders();
633
                sortFiles(header.getProperty(), header.getReverseSort());
634
                FileList.this.update();                        
635
                }
636
                
637
        }
638

    
639
        /**
640
         * Shows the files in the cellTable 
641
     */
642
        private void showCellTable(){
643
                provider.setList(files);
644
                
645
                provider.refresh();
646
                
647
                //celltable.redraw();
648
                celltable.redrawHeaders();                
649
        }
650
        
651
        void iterateFilesHeadCommand(final Iterator<FileFolderResource> iter, final Command callback) {
652
                if (iter.hasNext()) {
653
                        FileFolderResource res = iter.next();
654
                        if (res instanceof File) {
655
                                File f = (File) res;
656
                                app.scheduleFileHeadCommand(f, new Command() {
657
                                        
658
                                        @Override
659
                                        public void execute() {
660
                                                iterateFilesHeadCommand(iter, callback);
661
                                        }
662
                                });
663
                        }
664
                }
665
                else if (callback != null)
666
                        callback.execute();
667
        }
668

    
669
        public void selectByUrl(List<String> selectedUrls) {
670
                Set<FileFolderResource> previous = selectionModel.getSelectedSet();
671
                for (FileFolderResource res : previous)
672
                        selectionModel.setSelected(res, false);
673
                
674
                int i = 0;
675
                boolean scrolled = false;
676
                for (FileFolderResource res : files) {
677
                        if (res instanceof File) {
678
                                File f = (File) res;
679
                                if (selectedUrls.contains(app.getApiPath() + f.getOwner() + f.getUri())) {
680
                                        selectionModel.setSelected(f, true);
681
                                        if (!scrolled) {
682
                                                celltable.getRowElement(i).getCells().getItem(0).scrollIntoView();
683
                                                scrolled = true;
684
                                        }
685
                                }
686
                        }
687
                        i++;
688
                }
689
        }
690
}