Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (21.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.Folder;
40
import gr.grnet.pithos.web.client.foldertree.FolderTreeView;
41

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

    
49
import com.google.gwt.cell.client.Cell.Context;
50
import com.google.gwt.cell.client.ImageResourceCell;
51
import com.google.gwt.cell.client.SafeHtmlCell;
52
import com.google.gwt.cell.client.TextCell;
53
import com.google.gwt.cell.client.ValueUpdater;
54
import com.google.gwt.core.client.GWT;
55
import com.google.gwt.event.dom.client.ContextMenuEvent;
56
import com.google.gwt.event.dom.client.ContextMenuHandler;
57
import com.google.gwt.http.client.URL;
58
import com.google.gwt.i18n.client.DateTimeFormat;
59
import com.google.gwt.resources.client.ImageResource;
60
import com.google.gwt.resources.client.ClientBundle.Source;
61
import com.google.gwt.resources.client.ImageResource.ImageOptions;
62
import com.google.gwt.resources.client.ImageResource.RepeatStyle;
63
import com.google.gwt.safehtml.client.SafeHtmlTemplates;
64
import com.google.gwt.safehtml.shared.SafeHtml;
65
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
66
import com.google.gwt.user.cellview.client.CellTable;
67
import com.google.gwt.user.cellview.client.Column;
68
import com.google.gwt.user.client.Command;
69
import com.google.gwt.user.client.DOM;
70
import com.google.gwt.user.client.Event;
71
import com.google.gwt.user.client.Window;
72
import com.google.gwt.user.client.ui.Composite;
73
import com.google.gwt.user.client.ui.VerticalPanel;
74
import com.google.gwt.view.client.ListDataProvider;
75
import com.google.gwt.view.client.MultiSelectionModel;
76
import com.google.gwt.view.client.ProvidesKey;
77
import com.google.gwt.view.client.SelectionChangeEvent;
78

    
79
/**
80
 * A composite that displays the list of files in a particular folder.
81
 */
82
public class FileList extends Composite {
83

    
84
        ListDataProvider<File> provider = new ListDataProvider<File>();
85

    
86
    /**
87
       * The styles applied to the table.
88
       */
89
    interface TableStyle extends CellTable.Style {
90
            String cellTableFirstColumnShared();
91
    }
92

    
93
        interface TableResources extends CellTable.Resources {
94
            @Override
95
                @Source({CellTable.Style.DEFAULT_CSS, "PithosCellTable.css"})
96
            TableStyle cellTableStyle();
97
            
98
            @Source("share.png")
99
            @ImageOptions(repeatStyle = RepeatStyle.None)
100
            ImageResource cellTableSharedIcon();
101
        }
102
        
103
        static interface Templates extends SafeHtmlTemplates {
104
            Templates INSTANCE = GWT.create(Templates.class);
105

    
106
            @Template("<div id='dragHelper' style='border:1px solid black; background-color:#ffffff; color:black; width:150px;z-index:100'></div>")
107
            SafeHtml outerHelper();
108

    
109
        @Template("<span id='{0}'>{0}</span>")
110
        public SafeHtml filenameSpan(String filename);
111

    
112
        @Template("<a href='{0}' title='{1}' rel='lytebox[mnf]' onclick='myLytebox.start(this, false, false); return false;'>(view)</a>")
113
        public SafeHtml viewLink(String link, String title);
114

    
115
        @Template("<table><tr><td rowspan='3'>{0}</td><td style='font-size:95%;' id='{1}'>{1}</td></tr><tr><td>{2}</td></tr></table>")
116
        public SafeHtml rendelContactCell(String imageHtml, String name, String fileSize);
117

    
118
        @Template("<span id='{0}' class='{1}'>{2}</span>")
119
        public SafeHtml spanWithIdAndClass(String id, String cssClass, String content);
120
        }
121

    
122
        protected final DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a");
123

    
124
        /**
125
         * Specifies that the images available for this composite will be the ones
126
         * available in FileContextMenu.
127
         */
128
        public interface Images extends FolderTreeView.Images {
129

    
130
                @Source("gr/grnet/pithos/resources/blank.gif")
131
                ImageResource blank();
132

    
133
                @Source("gr/grnet/pithos/resources/asc.png")
134
                ImageResource asc();
135

    
136
                @Source("gr/grnet/pithos/resources/desc.png")
137
                ImageResource desc();
138

    
139
                @Source("gr/grnet/pithos/resources/mimetypes/document_shared.png")
140
                ImageResource documentShared();
141

    
142
                @Source("gr/grnet/pithos/resources/mimetypes/kcmfontinst.png")
143
                ImageResource wordprocessor();
144

    
145
                @Source("gr/grnet/pithos/resources/mimetypes/log.png")
146
                ImageResource spreadsheet();
147

    
148
                @Source("gr/grnet/pithos/resources/mimetypes/kpresenter_kpr.png")
149
                ImageResource presentation();
150

    
151
                @Source("gr/grnet/pithos/resources/mimetypes/acroread.png")
152
                ImageResource pdf();
153

    
154
                @Source("gr/grnet/pithos/resources/mimetypes/image.png")
155
                ImageResource image();
156

    
157
                @Source("gr/grnet/pithos/resources/mimetypes/video2.png")
158
                ImageResource video();
159

    
160
                @Source("gr/grnet/pithos/resources/mimetypes/knotify.png")
161
                ImageResource audio();
162

    
163
                @Source("gr/grnet/pithos/resources/mimetypes/html.png")
164
                ImageResource html();
165

    
166
                @Source("gr/grnet/pithos/resources/mimetypes/txt.png")
167
                ImageResource txt();
168

    
169
                @Source("gr/grnet/pithos/resources/mimetypes/ark2.png")
170
                ImageResource zip();
171

    
172
                @Source("gr/grnet/pithos/resources/mimetypes/kcmfontinst_shared.png")
173
                ImageResource wordprocessorShared();
174

    
175
                @Source("gr/grnet/pithos/resources/mimetypes/log_shared.png")
176
                ImageResource spreadsheetShared();
177

    
178
                @Source("gr/grnet/pithos/resources/mimetypes/kpresenter_kpr_shared.png")
179
                ImageResource presentationShared();
180

    
181
                @Source("gr/grnet/pithos/resources/mimetypes/acroread_shared.png")
182
                ImageResource pdfShared();
183

    
184
                @Source("gr/grnet/pithos/resources/mimetypes/image_shared.png")
185
                ImageResource imageShared();
186

    
187
                @Source("gr/grnet/pithos/resources/mimetypes/video2_shared.png")
188
                ImageResource videoShared();
189

    
190
                @Source("gr/grnet/pithos/resources/mimetypes/knotify_shared.png")
191
                ImageResource audioShared();
192

    
193
                @Source("gr/grnet/pithos/resources/mimetypes/html_shared.png")
194
                ImageResource htmlShared();
195

    
196
                @Source("gr/grnet/pithos/resources/mimetypes/txt_shared.png")
197
                ImageResource txtShared();
198

    
199
                @Source("gr/grnet/pithos/resources/mimetypes/ark2_shared.png")
200
                ImageResource zipShared();
201

    
202
        }
203
        
204
        /**
205
         * The number of files in this folder.
206
         */
207
        int folderFileCount;
208

    
209
        /**
210
         * Total folder size
211
         */
212
        long folderTotalSize;
213

    
214
        /**
215
         * A cache of the files in the list.
216
         */
217
        private List<File> files;
218

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

    
226
        private final MultiSelectionModel<File> selectionModel;
227

    
228
        Column<File, String> pathColumn;
229

    
230
        protected final List<SortableHeader> allHeaders = new ArrayList<SortableHeader>();
231

    
232
        SortableHeader nameHeader;
233

    
234
        SortableHeader pathHeader;
235

    
236
    protected Pithos app;
237

    
238
    /**
239
         * Construct the file list widget. This entails setting up the widget
240
         * layout, fetching the number of files in the current folder from the
241
         * server and filling the local file cache of displayed files with data from
242
         * the server, as well.
243
         *
244
         * @param _images
245
         */
246
        public FileList(final Pithos _app, Images _images) {
247
        app = _app;
248
                images = _images;
249

    
250
        final CellTable.Resources resources = GWT.create(TableResources.class);
251

    
252
        ProvidesKey<File> keyProvider = new ProvidesKey<File>(){
253

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

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

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

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

    
285
        final Column<File,SafeHtml> nameColumn = new Column<File,SafeHtml>(new SafeHtmlCell()) {
286

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

    
306
                celltable.redrawHeaders();
307
                
308
                pathColumn = new Column<File, String>(new TextCell()) {
309

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

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

    
357
                VerticalPanel vp = new VerticalPanel();
358
                vp.setWidth("100%");
359
                vp.addStyleName("pithos-FileListContainer");
360

    
361
        vp.add(celltable);
362

    
363
                vp.setCellWidth(celltable, "100%");
364
        vp.addHandler(new ContextMenuHandler() {
365
            @Override
366
            public void onContextMenu(final ContextMenuEvent event) {
367
                    final TreeView tree = app.getSelectedTree();
368
                    if (tree != null) {
369
                        final int x = event.getNativeEvent().getClientX();
370
                        final int y = event.getNativeEvent().getClientY();
371
                        final Folder selectedFolder = app.getSelection();
372
                        app.scheduleFolderHeadCommand(selectedFolder, new Command() {
373
                                                
374
                                                @Override
375
                                                public void execute() {
376
                                                        final List<File> selectedFiles = getSelectedFiles();
377
                                                        Iterator<File> iter = selectedFiles.iterator();
378
                                                        iterateFilesHeadCommand(iter, new Command() {
379
                                                                
380
                                                                @Override
381
                                                                public void execute() {
382
                                                        FileContextMenu contextMenu = new FileContextMenu(app, images, tree, selectedFolder, selectedFiles);
383
                                                        contextMenu.setPopupPosition(x, y);
384
                                                        contextMenu.show();
385
                                                                }
386
                                                        });
387
                                                }
388
                                        });
389
                    }
390
            }
391
        }, ContextMenuEvent.getType());
392
                initWidget(vp);
393

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

    
410
        public List<File> getSelectedFiles() {
411
        return new ArrayList<File>(selectionModel.getSelectedSet());
412
        }
413
        
414
        @Override
415
        public void onBrowserEvent(Event event) {
416

    
417
                if (DOM.eventGetType(event) == Event.ONDBLCLICK)
418
                        if (getSelectedFiles().size() == 1) {
419
                                File file = getSelectedFiles().get(0);
420
                                Window.open(app.getApiPath() + file.getOwner() + file.getUri(), "_blank", "");
421
                                event.preventDefault();
422
                                return;
423
                        }
424
                super.onBrowserEvent(event);
425
        }
426

    
427
        /**
428
         * Update the display of the file list.
429
         */
430
        void update() {
431
                showCellTable();
432
        }
433

    
434
        /**
435
         * Return the proper icon based on the MIME type of the file.
436
         *
437
         * @param file
438
         * @return the icon
439
         */
440
        protected ImageResource getFileIcon(File file) {
441
                String mimetype = file.getContentType();
442
                boolean published = file.isPublished();
443
                if (mimetype == null)
444
                        return published ? images.documentShared() : images.document();
445
                mimetype = mimetype.toLowerCase();
446
                if (mimetype.startsWith("application/pdf"))
447
                        return published ? images.pdfShared() : images.pdf();
448
                else if (mimetype.endsWith("excel"))
449
                        return published ? images.spreadsheetShared() : images.spreadsheet();
450
                else if (mimetype.endsWith("msword"))
451
                        return published ? images.wordprocessorShared() : images.wordprocessor();
452
                else if (mimetype.endsWith("powerpoint"))
453
                        return published ? images.presentationShared() : images.presentation();
454
                else if (mimetype.startsWith("application/zip") ||
455
                                        mimetype.startsWith("application/gzip") ||
456
                                        mimetype.startsWith("application/x-gzip") ||
457
                                        mimetype.startsWith("application/x-tar") ||
458
                                        mimetype.startsWith("application/x-gtar"))
459
                        return published ? images.zipShared() : images.zip();
460
                else if (mimetype.startsWith("text/html"))
461
                        return published ? images.htmlShared() : images.html();
462
                else if (mimetype.startsWith("text/plain"))
463
                        return published ? images.txtShared() : images.txt();
464
                else if (mimetype.startsWith("image/"))
465
                        return published ? images.imageShared() : images.image();
466
                else if (mimetype.startsWith("video/"))
467
                        return published ? images.videoShared() : images.video();
468
                else if (mimetype.startsWith("audio/"))
469
                        return published ? images.audioShared() : images.audio();
470
                return published ? images.documentShared() : images.document();
471
        }
472

    
473
        /**
474
         * Fill the file cache with data.
475
         */
476
        public void setFiles(final List<File> _files) {
477
                if (!app.getSelectedTree().equals(app.mysharedTreeView)) {
478
                        if (celltable.getColumnIndex(pathColumn) != -1)
479
                                celltable.removeColumn(pathColumn);
480
                }
481
                else {
482
                        if (celltable.getColumnIndex(pathColumn) == -1)
483
                                celltable.insertColumn(2, pathColumn, pathHeader);
484
                }
485
                files = new ArrayList<File>();
486
            for (File fres : _files) {
487
                        files.add(fres);
488
            }
489
            
490
                folderFileCount = files.size();
491
                
492
                for (SortableHeader header : allHeaders) {
493
                        if (header.isSorted())
494
                                sortFiles(header.getProperty(), header.getReverseSort());
495
                }
496
                
497
                List<File> previousSelection = getSelectedFiles(); //Keep the previous selection
498

    
499
                provider.getList().clear();
500
        provider.setList(files);
501
        selectionModel.clear();
502
            for (File f : files) {
503
                    if (previousSelection.contains(f))
504
                            selectionModel.setSelected(f, true);
505
            }
506
        
507
        app.showFolderStatistics(folderFileCount);
508
        celltable.setPageSize(folderFileCount);
509
        }
510

    
511
        /**
512
         * Does the list contains the requested filename
513
         *
514
         * @param fileName
515
         * @return true/false
516
         */
517
        public boolean contains(String fileName) {
518
                for (int i = 0; i < files.size(); i++)
519
                        if (files.get(i).getName().equals(fileName))
520
                                return true;
521
                return false;
522
        }
523

    
524
        public void clearSelectedRows() {
525
                Iterator<File> it = selectionModel.getSelectedSet().iterator();
526
                while(it.hasNext()){
527
                        selectionModel.setSelected(it.next(),false);
528
                }
529
        }
530
        
531
        /**
532
         *
533
         */
534
        public void selectAllRows() {
535
                Iterator<File> it = provider.getList().iterator();
536
                while(it.hasNext()){
537
                        selectionModel.setSelected(it.next(),true);
538
                }
539
        }
540

    
541
        protected void sortFiles(final String sortingProperty, final boolean sortingType){
542
                Collections.sort(files, new Comparator<File>() {
543

    
544
            @Override
545
            public int compare(File arg0, File arg1) {
546
                    if (sortingType){
547
                            if (sortingProperty.equals("version")) {
548
                                    return arg0.getVersion() - arg1.getVersion();
549
                            } else if (sortingProperty.equals("owner")) {
550
                                    return arg0.getOwner().compareTo(arg1.getOwner());
551
                            } else if (sortingProperty.equals("date")) {
552
                                            if (arg0.getLastModified() != null && arg1.getLastModified() != null)
553
                                                    return arg0.getLastModified().compareTo(arg1.getLastModified());
554
                                            return 0;
555
                            } else if (sortingProperty.equals("size")) {
556
                                    return (int) (arg0.getBytes() - arg1.getBytes());
557
                            } else if (sortingProperty.equals("name")) {
558
                                    return arg0.getName().compareTo(arg1.getName());
559
                            } else if (sortingProperty.equals("path")) {
560
                                    return arg0.getUri().compareTo(arg1.getUri());
561
                            } else {
562
                                    return arg0.getName().compareTo(arg1.getName());
563
                            }
564
                    }
565
                    else if (sortingProperty.equals("version")) {
566
                            
567
                            return arg1.getVersion() - arg0.getVersion();
568
                    } else if (sortingProperty.equals("owner")) {
569
                            
570
                            return arg1.getOwner().compareTo(arg0.getOwner());
571
                    } else if (sortingProperty.equals("date")) {
572
                            
573
                            return arg1.getLastModified().compareTo(arg0.getLastModified());
574
                    } else if (sortingProperty.equals("size")) {
575
                            return (int) (arg1.getBytes() - arg0.getBytes());
576
                    } else if (sortingProperty.equals("name")) {
577
                            
578
                            return arg1.getName().compareTo(arg0.getName());
579
                    } else if (sortingProperty.equals("path")) {
580
                            
581
                            return arg1.getUri().compareTo(arg0.getUri());
582
                    } else {
583
                            
584
                            return arg1.getName().compareTo(arg0.getName());
585
                    }
586
            }
587

    
588
                });
589
        }
590
        
591
        final class FileValueUpdater implements ValueUpdater<String>{
592
                private SortableHeader header;
593
                /**
594
                 * 
595
                 */
596
                public FileValueUpdater(SortableHeader header) {
597
                        this.header=header;
598
                }
599
                @Override
600
                public void update(String value) {
601
                        header.setSorted(true);
602
                        header.toggleReverseSort();
603

    
604
                for (SortableHeader otherHeader : allHeaders) {
605
                  if (otherHeader != header) {
606
                    otherHeader.setSorted(false);
607
                    otherHeader.setReverseSort(true);
608
                  }
609
                }
610
                celltable.redrawHeaders();
611
                sortFiles(header.getProperty(), header.getReverseSort());
612
                FileList.this.update();                        
613
                }
614
                
615
        }
616

    
617
        /**
618
         * Shows the files in the cellTable 
619
     */
620
        private void showCellTable(){
621
                provider.setList(files);
622
                
623
                provider.refresh();
624
                
625
                //celltable.redraw();
626
                celltable.redrawHeaders();                
627
        }
628
        
629
        void iterateFilesHeadCommand(final Iterator<File> iter, final Command callback) {
630
                if (iter.hasNext()) {
631
                        File f = iter.next();
632
                        app.scheduleFileHeadCommand(f, new Command() {
633
                                
634
                                @Override
635
                                public void execute() {
636
                                        iterateFilesHeadCommand(iter, callback);
637
                                }
638
                        });
639
                }
640
                else if (callback != null)
641
                        callback.execute();
642
        }
643

    
644
        public void selectByUrl(List<String> selectedUrls) {
645
                Set<File> previous = selectionModel.getSelectedSet();
646
                for (File f : previous)
647
                        selectionModel.setSelected(f, false);
648
                
649
                int i = 0;
650
                boolean scrolled = false;
651
                for (File f : files) {
652
                        if (selectedUrls.contains(app.getApiPath() + f.getOwner() + f.getUri())) {
653
                                selectionModel.setSelected(f, true);
654
                                if (!scrolled) {
655
                                        celltable.getRowElement(i).getCells().getItem(0).scrollIntoView();
656
                                        scrolled = true;
657
                                }
658
                        }
659
                        i++;
660
                }
661
        }
662
}