Statistics
| Branch: | Tag: | Revision:

root / src / gr / grnet / pithos / web / client / FileList.java @ 9a849658

History | View | Annotate | Download (22.2 kB)

1
/*
2
 * Copyright 2011-2013 GRNET S.A. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or
5
 * without modification, are permitted provided that the following
6
 * conditions are met:
7
 *
8
 *   1. Redistributions of source code must retain the above
9
 *      copyright notice, this list of conditions and the following
10
 *      disclaimer.
11
 *
12
 *   2. Redistributions in binary form must reproduce the above
13
 *      copyright notice, this list of conditions and the following
14
 *      disclaimer in the documentation and/or other materials
15
 *      provided with the distribution.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
 * POSSIBILITY OF SUCH DAMAGE.
29
 *
30
 * The views and conclusions contained in the software and
31
 * documentation are those of the authors and should not be
32
 * interpreted as representing official policies, either expressed
33
 * or implied, of GRNET S.A.
34
 */
35

    
36
package gr.grnet.pithos.web.client;
37

    
38
import com.google.gwt.cell.client.Cell.Context;
39
import com.google.gwt.cell.client.ImageResourceCell;
40
import com.google.gwt.cell.client.SafeHtmlCell;
41
import com.google.gwt.cell.client.TextCell;
42
import com.google.gwt.cell.client.ValueUpdater;
43
import com.google.gwt.core.client.GWT;
44
import com.google.gwt.event.dom.client.ContextMenuEvent;
45
import com.google.gwt.event.dom.client.ContextMenuHandler;
46
import com.google.gwt.i18n.client.DateTimeFormat;
47
import com.google.gwt.resources.client.ImageResource;
48
import com.google.gwt.resources.client.ImageResource.ImageOptions;
49
import com.google.gwt.resources.client.ImageResource.RepeatStyle;
50
import com.google.gwt.safehtml.client.SafeHtmlTemplates;
51
import com.google.gwt.safehtml.shared.SafeHtml;
52
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
53
import com.google.gwt.user.cellview.client.CellTable;
54
import com.google.gwt.user.cellview.client.Column;
55
import com.google.gwt.user.client.Command;
56
import com.google.gwt.user.client.DOM;
57
import com.google.gwt.user.client.Event;
58
import com.google.gwt.user.client.Window;
59
import com.google.gwt.user.client.ui.Composite;
60
import com.google.gwt.user.client.ui.VerticalPanel;
61
import com.google.gwt.view.client.ListDataProvider;
62
import com.google.gwt.view.client.MultiSelectionModel;
63
import com.google.gwt.view.client.ProvidesKey;
64
import com.google.gwt.view.client.SelectionChangeEvent;
65
import gr.grnet.pithos.web.client.foldertree.File;
66
import gr.grnet.pithos.web.client.foldertree.Folder;
67
import gr.grnet.pithos.web.client.foldertree.FolderTreeView;
68

    
69
import java.util.*;
70

    
71
/**
72
 * A composite that displays the list of files in a particular folder.
73
 */
74
public class FileList extends Composite {
75

    
76
        ListDataProvider<File> provider = new ListDataProvider<File>();
77

    
78
    /**
79
       * The styles applied to the table.
80
       */
81
    interface TableStyle extends CellTable.Style {
82
            String cellTableFirstColumnShared();
83
    }
84

    
85
        interface TableResources extends CellTable.Resources {
86
            @Override
87
                @Source({CellTable.Style.DEFAULT_CSS, "PithosCellTable.css"})
88
            TableStyle cellTableStyle();
89
            
90
            @Source("share.png")
91
            @ImageOptions(repeatStyle = RepeatStyle.None)
92
            ImageResource cellTableSharedIcon();
93
        }
94
        
95
        static interface Templates extends SafeHtmlTemplates {
96
            Templates INSTANCE = GWT.create(Templates.class);
97

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

    
101
        @Template("<span id='{0}'>{0}</span>")
102
        public SafeHtml filenameSpan(String filename);
103

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

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

    
110
        @Template("<span id='{0}' class='{1}'>{2}</span>")
111
        public SafeHtml spanWithIdAndClass(String id, String cssClass, String content);
112
        }
113

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

    
116
        /**
117
         * Specifies that the images available for this composite will be the ones
118
         * available in FileContextMenu.
119
         */
120
        public interface Images extends FolderTreeView.Images {
121

    
122
                @Source("gr/grnet/pithos/resources/blank.gif")
123
                ImageResource blank();
124

    
125
                @Source("gr/grnet/pithos/resources/asc.png")
126
                ImageResource asc();
127

    
128
                @Source("gr/grnet/pithos/resources/desc.png")
129
                ImageResource desc();
130

    
131
                @Source("gr/grnet/pithos/resources/mimetypes/document_shared.png")
132
                ImageResource documentShared();
133

    
134
                @Source("gr/grnet/pithos/resources/mimetypes/kcmfontinst.png")
135
                ImageResource wordprocessor();
136

    
137
                @Source("gr/grnet/pithos/resources/mimetypes/log.png")
138
                ImageResource spreadsheet();
139

    
140
                @Source("gr/grnet/pithos/resources/mimetypes/kpresenter_kpr.png")
141
                ImageResource presentation();
142

    
143
                @Source("gr/grnet/pithos/resources/mimetypes/acroread.png")
144
                ImageResource pdf();
145

    
146
                @Source("gr/grnet/pithos/resources/mimetypes/image.png")
147
                ImageResource image();
148

    
149
                @Source("gr/grnet/pithos/resources/mimetypes/video2.png")
150
                ImageResource video();
151

    
152
                @Source("gr/grnet/pithos/resources/mimetypes/knotify.png")
153
                ImageResource audio();
154

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

    
158
                @Source("gr/grnet/pithos/resources/mimetypes/txt.png")
159
                ImageResource txt();
160

    
161
                @Source("gr/grnet/pithos/resources/mimetypes/ark2.png")
162
                ImageResource zip();
163

    
164
                @Source("gr/grnet/pithos/resources/mimetypes/kcmfontinst_shared.png")
165
                ImageResource wordprocessorShared();
166

    
167
                @Source("gr/grnet/pithos/resources/mimetypes/log_shared.png")
168
                ImageResource spreadsheetShared();
169

    
170
                @Source("gr/grnet/pithos/resources/mimetypes/kpresenter_kpr_shared.png")
171
                ImageResource presentationShared();
172

    
173
                @Source("gr/grnet/pithos/resources/mimetypes/acroread_shared.png")
174
                ImageResource pdfShared();
175

    
176
                @Source("gr/grnet/pithos/resources/mimetypes/image_shared.png")
177
                ImageResource imageShared();
178

    
179
                @Source("gr/grnet/pithos/resources/mimetypes/video2_shared.png")
180
                ImageResource videoShared();
181

    
182
                @Source("gr/grnet/pithos/resources/mimetypes/knotify_shared.png")
183
                ImageResource audioShared();
184

    
185
                @Source("gr/grnet/pithos/resources/mimetypes/html_shared.png")
186
                ImageResource htmlShared();
187

    
188
                @Source("gr/grnet/pithos/resources/mimetypes/txt_shared.png")
189
                ImageResource txtShared();
190

    
191
                @Source("gr/grnet/pithos/resources/mimetypes/ark2_shared.png")
192
                ImageResource zipShared();
193

    
194
        }
195
        
196
        /**
197
         * The number of files in this folder.
198
         */
199
        int folderFileCount;
200

    
201
        /**
202
         * Total folder size
203
         */
204
        long folderTotalSize;
205

    
206
        /**
207
         * A cache of the files in the list.
208
         */
209
        private List<File> files;
210

    
211
        /**
212
         * The widget's image bundle.
213
         */
214
        protected final Images images;
215
        
216
        protected CellTable<File> celltable;
217

    
218
        private final MultiSelectionModel<File> selectionModel;
219

    
220
        Column<File, String> pathColumn;
221

    
222
        protected final List<SortableHeader> allHeaders = new ArrayList<SortableHeader>();
223

    
224
        SortableHeader nameHeader;
225

    
226
        SortableHeader pathHeader;
227

    
228
    protected Pithos app;
229

    
230
    /**
231
         * Construct the file list widget. This entails setting up the widget
232
         * layout, fetching the number of files in the current folder from the
233
         * server and filling the local file cache of displayed files with data from
234
         * the server, as well.
235
         *
236
         * @param _images
237
         */
238
        public FileList(final Pithos _app, Images _images) {
239
        app = _app;
240
                images = _images;
241

    
242
        final CellTable.Resources resources = GWT.create(TableResources.class);
243

    
244
        ProvidesKey<File> keyProvider = new ProvidesKey<File>(){
245

    
246
                        @Override
247
                        public Object getKey(File item) {
248
                                return item.getUri();
249
                        }
250
                };
251

    
252
                celltable = new CellTable<File>(10, resources, keyProvider);
253
        celltable.setWidth("100%");
254
        celltable.setStyleName("pithos-List");
255

    
256
                Column<File, ImageResource> status = new Column<File, ImageResource>(new ImageResourceCell() {
257
                    @Override
258
                public boolean handlesSelection() {
259
                    return false;
260
                }
261
                }) {
262
            @Override
263
                 public ImageResource getValue(File entity) {
264
                     return getFileIcon(entity);
265
                 }
266

    
267
                        @Override
268
                        public String getCellStyleNames(Context context, File object) {
269
                                if (!object.getPermissions().isEmpty() && !object.isPublished())
270
                                        return ((TableStyle) resources.cellTableStyle()).cellTableFirstColumnShared();
271
                                return super.getCellStyleNames(context, object);
272
                        }
273
            };
274
            celltable.addColumn(status,"");
275

    
276
        final Column<File,SafeHtml> nameColumn = new Column<File,SafeHtml>(new SafeHtmlCell()) {
277

    
278
                        @Override
279
                        public SafeHtml getValue(File object) {
280
                                SafeHtmlBuilder sb = new SafeHtmlBuilder();
281
                                sb.append(Templates.INSTANCE.filenameSpan(object.getName()));
282

    
283
                final String contentType = object.getContentType();
284
                if(contentType != null)
285
                if(contentType.endsWith("png") ||
286
                   contentType.endsWith("gif") ||
287
                   contentType.endsWith("jpeg")) {
288

    
289
                    sb.appendHtmlConstant("&nbsp;").
290
                       append(Templates.INSTANCE.viewLink(Pithos.getFileViewURL(object), object.getName()));
291
                }
292

    
293
                                return sb.toSafeHtml();
294
                        }
295
                        
296
                };
297
        celltable.addColumn(nameColumn, nameHeader = new SortableHeader("Name", "name"));
298
                allHeaders.add(nameHeader);
299
                nameHeader.setUpdater(new FileValueUpdater(nameHeader));
300
                nameHeader.setSorted(true);
301
                nameHeader.setReverseSort(true);
302

    
303
                celltable.redrawHeaders();
304
                
305
                pathColumn = new Column<File, String>(new TextCell()) {
306

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

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

    
354
                VerticalPanel vp = new VerticalPanel();
355
                vp.setWidth("100%");
356
                vp.addStyleName("pithos-FileListContainer");
357

    
358
        vp.add(celltable);
359

    
360
                vp.setCellWidth(celltable, "100%");
361
        vp.addHandler(new ContextMenuHandler() {
362
            @Override
363
            public void onContextMenu(final ContextMenuEvent event) {
364
                    final TreeView tree = app.getSelectedTree();
365
                    if (tree != null) {
366
                        final int x = event.getNativeEvent().getClientX();
367
                        final int y = event.getNativeEvent().getClientY();
368
                        final Folder selectedFolder = app.getSelection();
369
                    Pithos.LOG("FileList::ContextMenuHandler::onContextMenu(), selectedFolder=", selectedFolder);
370
                        app.scheduleFolderHeadCommand(selectedFolder, new Command() {
371
                                                
372
                                                @Override
373
                                                public void execute() {
374
                                                        final List<File> selectedFiles = getSelectedFiles();
375
                            Pithos.LOG("FileList::ContextMenuHandler::onContextMenu()::scheduledHEAD(), selectedFolder=", selectedFolder);
376
                            Pithos.LOG("FileList::ContextMenuHandler::onContextMenu()::scheduledHEAD(), ", selectedFiles.size(), " selectedFiles");
377
                            for(File selectedFile : selectedFiles) {
378
                                Pithos.LOG("FileList::ContextMenuHandler::onContextMenu()::scheduledHEAD(), selectedFile: ", selectedFile);
379
                            }
380
                            Iterator<File> 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<File>(keyProvider);
398
                selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
399
                        
400
                        @Override
401
                        public void onSelectionChange(SelectionChangeEvent event) {
402
                Pithos.LOG("FileList::selectionModel::onSelectionChange(", event, ")");
403
                                app.showRelevantToolbarButtons();
404
                        }
405
                });
406
                
407
                celltable.setSelectionModel(selectionModel, PithosSelectionEventManager.<File> createDefaultManager());
408
                
409
                sinkEvents(Event.ONCONTEXTMENU);
410
                sinkEvents(Event.ONDBLCLICK);
411
                Pithos.preventIESelection();
412
        }
413

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

    
421
                if (DOM.eventGetType(event) == Event.ONDBLCLICK)
422
                        if (getSelectedFiles().size() == 1) {
423
                                File file = getSelectedFiles().get(0);
424
                                Window.open(Pithos.getFileViewURL(file), "_blank", "");
425
                                event.preventDefault();
426
                                return;
427
                        }
428
                super.onBrowserEvent(event);
429
        }
430

    
431
        /**
432
         * Update the display of the file list.
433
         */
434
        void update() {
435
                showCellTable();
436
        }
437

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

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

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

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

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

    
545
        protected void sortFiles(final String sortingProperty, final boolean sortingType){
546
                Collections.sort(files, new Comparator<File>() {
547

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

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

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

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

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