Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (27.2 kB)

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

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

    
38
import com.google.gwt.event.dom.client.ContextMenuEvent;
39
import com.google.gwt.event.dom.client.ContextMenuHandler;
40
import static com.google.gwt.query.client.GQuery.$;
41

    
42
import gr.grnet.pithos.web.client.commands.UploadFileCommand;
43
import gr.grnet.pithos.web.client.foldertree.File;
44
import gr.grnet.pithos.web.client.foldertree.Folder;
45
import gr.grnet.pithos.web.client.foldertree.FolderTreeView;
46
import gr.grnet.pithos.web.client.rest.resource.FileResource;
47
import gwtquery.plugins.draggable.client.DraggableOptions;
48
import gwtquery.plugins.draggable.client.StopDragException;
49
import gwtquery.plugins.draggable.client.DraggableOptions.DragFunction;
50
import gwtquery.plugins.draggable.client.DraggableOptions.RevertOption;
51
import gwtquery.plugins.draggable.client.events.DragContext;
52
import gwtquery.plugins.draggable.client.events.DragStartEvent;
53
import gwtquery.plugins.draggable.client.events.DragStopEvent;
54
import gwtquery.plugins.draggable.client.events.DragStartEvent.DragStartEventHandler;
55
import gwtquery.plugins.draggable.client.events.DragStopEvent.DragStopEventHandler;
56
import gwtquery.plugins.droppable.client.gwt.DragAndDropCellTable;
57
import gwtquery.plugins.droppable.client.gwt.DragAndDropColumn;
58

    
59
import java.util.ArrayList;
60
import java.util.Collections;
61
import java.util.Comparator;
62
import java.util.Iterator;
63
import java.util.List;
64

    
65
import com.google.gwt.cell.client.ImageResourceCell;
66
import com.google.gwt.cell.client.SafeHtmlCell;
67
import com.google.gwt.cell.client.TextCell;
68
import com.google.gwt.cell.client.ValueUpdater;
69
import com.google.gwt.core.client.GWT;
70
import com.google.gwt.dom.client.Style.Cursor;
71
import com.google.gwt.event.dom.client.ClickEvent;
72
import com.google.gwt.event.dom.client.ClickHandler;
73
import com.google.gwt.i18n.client.DateTimeFormat;
74
import com.google.gwt.resources.client.ClientBundle;
75
import com.google.gwt.resources.client.ImageResource;
76
import com.google.gwt.safehtml.client.SafeHtmlTemplates;
77
import com.google.gwt.safehtml.shared.SafeHtml;
78
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
79
import com.google.gwt.user.cellview.client.CellTable;
80
import com.google.gwt.user.cellview.client.GssSimplePager;
81
import com.google.gwt.user.client.DOM;
82
import com.google.gwt.user.client.Event;
83
import com.google.gwt.user.client.Window;
84
import com.google.gwt.user.client.ui.AbstractImagePrototype;
85
import com.google.gwt.user.client.ui.Button;
86
import com.google.gwt.user.client.ui.Composite;
87
import com.google.gwt.user.client.ui.HorizontalPanel;
88
import com.google.gwt.user.client.ui.VerticalPanel;
89
import com.google.gwt.view.client.ListDataProvider;
90
import com.google.gwt.view.client.MultiSelectionModel;
91
import com.google.gwt.view.client.ProvidesKey;
92
import com.google.gwt.view.client.SelectionChangeEvent;
93
import com.google.gwt.view.client.SelectionChangeEvent.Handler;
94

    
95
/**
96
 * A composite that displays the list of files in a particular folder.
97
 */
98
public class FileList extends Composite {
99

    
100
        ListDataProvider<File> provider = new ListDataProvider<File>();
101

    
102
    /**
103
       * The styles applied to the table.
104
       */
105
    interface TableStyle extends CellTable.Style {
106
    }
107

    
108
        interface TableResources extends DragAndDropCellTable.Resources {
109
            @Source({CellTable.Style.DEFAULT_CSS, "GssCellTable.css"})
110
            TableStyle cellTableStyle();
111
        }
112
        
113
        static interface Templates extends SafeHtmlTemplates {
114
            Templates INSTANCE = GWT.create(Templates.class);
115

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

    
119
        @Template("<span id='{0}'>{0}</span>")
120
        public SafeHtml filenameSpan(String filename);
121

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

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

    
128
        @Template("<span id='{0}' class='{1}'>{2}</span>")
129
        public SafeHtml spanWithIdAndClass(String id, String cssClass, String content);
130
        }
131

    
132
    private String showingStats = "";
133

    
134
        private int startIndex = 0;
135

    
136
        /**
137
         * A constant that denotes the completion of an IncrementalCommand.
138
         */
139
        public static final boolean DONE = false;
140

    
141
        private final DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a");
142

    
143
        /**
144
         * Specifies that the images available for this composite will be the ones
145
         * available in FileContextMenu.
146
         */
147
        public interface Images extends ClientBundle,FileContextMenu.Images, CellTreeView.Images {
148

    
149
                @Source("gr/grnet/pithos/resources/blank.gif")
150
                ImageResource blank();
151

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
194
                @Source("gr/grnet/pithos/resources/mimetypes/log_shared.png")
195
                ImageResource spreadsheetShared();
196

    
197
                @Source("gr/grnet/pithos/resources/mimetypes/kpresenter_kpr_shared.png")
198
                ImageResource presentationShared();
199

    
200
                @Source("gr/grnet/pithos/resources/mimetypes/acroread_shared.png")
201
                ImageResource pdfShared();
202

    
203
                @Source("gr/grnet/pithos/resources/mimetypes/image_shared.png")
204
                ImageResource imageShared();
205

    
206
                @Source("gr/grnet/pithos/resources/mimetypes/video2_shared.png")
207
                ImageResource videoShared();
208

    
209
                @Source("gr/grnet/pithos/resources/mimetypes/knotify_shared.png")
210
                ImageResource audioShared();
211

    
212
                @Source("gr/grnet/pithos/resources/mimetypes/html_shared.png")
213
                ImageResource htmlShared();
214

    
215
                @Source("gr/grnet/pithos/resources/mimetypes/txt_shared.png")
216
                ImageResource txtShared();
217

    
218
                @Source("gr/grnet/pithos/resources/mimetypes/ark2_shared.png")
219
                ImageResource zipShared();
220

    
221
        }
222
        
223
        /**
224
         * The number of files in this folder.
225
         */
226
        int folderFileCount;
227

    
228
        /**
229
         * Total folder size
230
         */
231
        long folderTotalSize;
232

    
233
        /**
234
         * A cache of the files in the list.
235
         */
236
        private List<File> files;
237

    
238
        /**
239
         * The widget's image bundle.
240
         */
241
        private final Images images;
242
        
243
        private FileContextMenu contextMenu;
244

    
245
        private DragAndDropCellTable<File> celltable;
246

    
247
        private final MultiSelectionModel<File> selectionModel;
248

    
249
        private final List<SortableHeader> allHeaders = new ArrayList<SortableHeader>();
250

    
251
        SortableHeader nameHeader;
252

    
253
        GssSimplePager pagerBottom;
254

    
255
        GssSimplePager pagerTop;
256

    
257
        Button uploadButtonBottom;
258

    
259
        Button uploadButtonTop;
260

    
261
    FolderTreeView treeView;
262

    
263
    /**
264
         * Construct the file list widget. This entails setting up the widget
265
         * layout, fetching the number of files in the current folder from the
266
         * server and filling the local file cache of displayed files with data from
267
         * the server, as well.
268
         *
269
         * @param _images
270
         */
271
        public FileList(Images _images, FolderTreeView _treeView) {
272
                images = _images;
273
        this.treeView = _treeView;
274

    
275
        DragAndDropCellTable.Resources resources = GWT.create(TableResources.class);
276

    
277
        ProvidesKey<File> keyProvider = new ProvidesKey<File>(){
278

    
279
                        @Override
280
                        public Object getKey(File item) {
281
                                return item.getUri();
282
                        }
283
                };
284

    
285
                celltable = new DragAndDropCellTable<File>(GSS.VISIBLE_FILE_COUNT, resources, keyProvider);
286
        celltable.setWidth("100%");
287
        celltable.setStyleName("pithos-List");
288

    
289
                DragAndDropColumn<File, ImageResource> status = new DragAndDropColumn<File, ImageResource>(new ImageResourceCell() {
290
                    @Override
291
                public boolean handlesSelection() {
292
                    return false;
293
                }
294
                })
295
        {
296
                 @Override
297
                 public ImageResource getValue(File entity) {
298
                     return getFileIcon(entity);
299
                 }
300
            };
301
            celltable.addColumn(status,"");
302
            initDragOperation(status);
303

    
304
        final DragAndDropColumn<File,SafeHtml> nameColumn = new DragAndDropColumn<File,SafeHtml>(new SafeHtmlCell()) {
305

    
306
                        @Override
307
                        public SafeHtml getValue(File object) {
308
                                SafeHtmlBuilder sb = new SafeHtmlBuilder();
309
                sb.append(Templates.INSTANCE.filenameSpan(object.getName()));
310
                                if (object.getContentType().endsWith("png") || object.getContentType().endsWith("gif") || object.getContentType().endsWith("jpeg")) {
311
                                sb.appendHtmlConstant("&nbsp;")
312
                      .append(Templates.INSTANCE.viewLink(object.getUri(), object.getOwner() + " : " + object.getPath() + object.getName()));
313
                                }
314
                                
315
                                return sb.toSafeHtml();
316
                        }
317
                        
318
                };
319
        initDragOperation(nameColumn);
320
        celltable.addColumn(nameColumn, nameHeader = new SortableHeader("Name"));
321
                allHeaders.add(nameHeader);
322
                nameHeader.setUpdater(new FileValueUpdater(nameHeader, "name"));
323

    
324
                celltable.redrawHeaders();
325
                
326
            DragAndDropColumn<File,String> aColumn = new DragAndDropColumn<File, String>(new TextCell()) {
327
                        @Override
328
                        public String getValue(File object) {
329
                                return object.getOwner();
330
                        }
331
                };
332
        SortableHeader aheader = new SortableHeader("Owner");
333
                celltable.addColumn(aColumn, aheader);
334
                initDragOperation(aColumn);
335
                allHeaders.add(aheader);
336
        aheader.setUpdater(new FileValueUpdater(aheader, "owner"));
337

    
338
        aColumn = new DragAndDropColumn<File,String>(new TextCell()) {
339
                        @Override
340
                        public String getValue(File object) {
341
                                return object.getPath();
342
                        }
343
                };
344
        aheader = new SortableHeader("Path");
345
                celltable.addColumn(aColumn, aheader);
346
                initDragOperation(aColumn);
347
                allHeaders.add(aheader);
348
                aheader.setUpdater(new FileValueUpdater(aheader, "path"));
349

    
350
        aColumn = new DragAndDropColumn<File,String>(new TextCell()) {
351
                        @Override
352
                        public String getValue(File object) {
353
                            return String.valueOf(object.getVersion());
354
                        }
355
                };
356
        aheader = new SortableHeader("Version");
357
                celltable.addColumn(aColumn, aheader);
358
                initDragOperation(aColumn);
359
                allHeaders.add(aheader);
360
                aheader.setUpdater(new FileValueUpdater(aheader, "version"));
361

    
362
        aColumn = new DragAndDropColumn<File,String>(new TextCell()) {
363
                        @Override
364
                        public String getValue(File object) {
365
                                // TODO Auto-generated method stub
366
                                return object.getSizeAsString();
367
                        }
368
                };
369
        aheader = new SortableHeader("Size");
370
        celltable.addColumn(aColumn, aheader);
371
                initDragOperation(aColumn);
372
                allHeaders.add(aheader);
373
                aheader.setUpdater(new FileValueUpdater(aheader, "size"));
374

    
375
        aColumn = new DragAndDropColumn<File,String>(new TextCell()) {
376
                        @Override
377
                        public String getValue(File object) {
378
                                return formatter.format(object.getLastModified());
379
                        }
380
                };
381
        aheader = new SortableHeader("Last Modified");
382
                celltable.addColumn(aColumn, aheader);
383
                allHeaders.add(aheader);
384
                aheader.setUpdater(new FileValueUpdater(aheader, "date"));
385
               
386
                provider.addDataDisplay(celltable);
387

    
388
                celltable.addDragStopHandler(new DragStopEventHandler() {
389

    
390
                    @Override
391
                    public void onDragStop(DragStopEvent event) {
392
                            GWT.log("DRAG STOPPED");
393
                    }
394
            });
395
                celltable.addDragStartHandler(new DragStartEventHandler() {
396

    
397
                    public void onDragStart(DragStartEvent event) {
398
                        FileResource value = event.getDraggableData();
399
                        
400
                        com.google.gwt.dom.client.Element helper = event.getHelper();
401
                        SafeHtmlBuilder sb = new SafeHtmlBuilder();
402
                        sb.appendHtmlConstant("<b>");
403
                        DisplayHelper.log(value.getName());
404
                        if(getSelectedFiles().size()==1)
405
                                sb.appendEscaped(value.getName());
406
                        else
407
                                sb.appendEscaped(getSelectedFiles().size()+" files");
408
                        sb.appendHtmlConstant("</b>");
409
                        helper.setInnerHTML(sb.toSafeHtml().asString());
410
                    }
411
                });
412

    
413
                VerticalPanel vp = new VerticalPanel();
414
                vp.setWidth("100%");
415

    
416
                pagerTop = new GssSimplePager(GssSimplePager.TextLocation.CENTER);
417
        pagerTop.setVisible(false);
418
                pagerTop.setDisplay(celltable);
419
                uploadButtonTop = new Button("<span id='topMenu.file.upload'>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + "&nbsp;Upload</span>");
420
                uploadButtonTop.addClickHandler(new ClickHandler() {
421
                        
422
                        @Override
423
                        public void onClick(ClickEvent event) {
424
                                new UploadFileCommand(null).execute();
425
                        }
426
                });
427
                HorizontalPanel topPanel = new HorizontalPanel();
428
                topPanel.add(pagerTop);
429
                topPanel.add(uploadButtonTop);
430
                vp.add(topPanel);
431

    
432
        vp.add(celltable);
433

    
434
                pagerBottom = new GssSimplePager(GssSimplePager.TextLocation.CENTER);
435
        pagerBottom.setVisible(false);
436
                pagerBottom.setDisplay(celltable);
437
                uploadButtonBottom=new Button("<span id='topMenu.file.upload'>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + "&nbsp;Upload</span>");
438
                uploadButtonBottom.addClickHandler(new ClickHandler() {
439
                        
440
                        @Override
441
                        public void onClick(ClickEvent event) {
442
                                new UploadFileCommand(null).execute();
443
                        }
444
                });
445
        HorizontalPanel bottomPanel = new HorizontalPanel();
446
        bottomPanel.add(pagerBottom);
447
                bottomPanel.add(uploadButtonBottom);
448

    
449
                vp.add(bottomPanel);
450
                vp.setCellWidth(celltable, "100%");
451
        vp.addHandler(new ContextMenuHandler() {
452
            @Override
453
            public void onContextMenu(ContextMenuEvent event) {
454
                contextMenu = new FileContextMenu(images, treeView.getSelection(), false);
455
                int x = event.getNativeEvent().getClientX();
456
                int y = event.getNativeEvent().getClientY();
457
                contextMenu.setPopupPosition(x, y);
458
                contextMenu.show();
459
            }
460
        }, ContextMenuEvent.getType());
461
                initWidget(vp);
462

    
463
                selectionModel = new MultiSelectionModel<File>(keyProvider);
464

    
465
                 Handler selectionHandler = new SelectionChangeEvent.Handler() {
466
             @Override 
467
             public void onSelectionChange(SelectionChangeEvent event) {
468
                     if(getSelectedFiles().size() == 1)
469
                             GSS.get().setCurrentSelection(getSelectedFiles().get(0));
470
                     else
471
                             GSS.get().setCurrentSelection(getSelectedFiles());
472
             }
473
         };
474
         selectionModel.addSelectionChangeHandler(selectionHandler);
475
         
476
                celltable.setSelectionModel(selectionModel, GSSSelectionEventManager.<File> createDefaultManager());
477
                celltable.setPageSize(GSS.VISIBLE_FILE_COUNT);
478
                
479
                sinkEvents(Event.ONCONTEXTMENU);
480
                sinkEvents(Event.ONMOUSEUP);
481
                sinkEvents(Event.ONMOUSEDOWN);
482
                sinkEvents(Event.ONCLICK);
483
                sinkEvents(Event.ONKEYDOWN);
484
                sinkEvents(Event.ONDBLCLICK);
485
                GSS.preventIESelection();
486
        }
487

    
488
        public List<File> getSelectedFiles() {
489
        return new ArrayList<File>(selectionModel.getSelectedSet());
490
        }
491
        
492
        private void initDragOperation(DragAndDropColumn<?, ?> column) {
493
        // retrieve draggableOptions on the column
494
                DraggableOptions draggableOptions = column.getDraggableOptions();
495
                // use template to construct the helper. The content of the div will be set
496
                // after
497
                draggableOptions.setHelper($(Templates.INSTANCE.outerHelper().asString()));
498
                //draggableOptions.setZIndex(100);
499
                // opacity of the helper
500
                draggableOptions.setAppendTo("body");
501
                //draggableOptions.setOpacity((float) 0.8);
502
                draggableOptions.setContainment("document");
503
                // cursor to use during the drag operation
504
                draggableOptions.setCursor(Cursor.MOVE);
505
                // set the revert option
506
                draggableOptions.setRevert(RevertOption.ON_INVALID_DROP);
507
                // prevents dragging when user click on the category drop-down list
508
                draggableOptions.setCancel("select");
509
            draggableOptions.setOnBeforeDragStart(new DragFunction() {
510
                        @Override
511
                        public void f(DragContext context) {
512
                        File value = context.getDraggableData();
513
                                if (!selectionModel.isSelected(value)) {
514
                                   throw new StopDragException();
515
                        }
516
                        }
517
                });
518
    }
519
        
520
//        @Override
521
//        public void onBrowserEvent(Event event) {
522
//
523
//                if (files == null || files.size() == 0) {
524
//                        if (DOM.eventGetType(event) == Event.ONCONTEXTMENU && getSelectedFiles().size() == 0) {
525
//                                contextMenu = new FileContextMenu(images, false, true);
526
//                contextMenu.show();
527
//                                event.preventDefault();
528
//                                event.cancelBubble(true);
529
//                        }
530
//                        return;
531
//                }
532
//                if (DOM.eventGetType(event) == Event.ONCONTEXTMENU && getSelectedFiles().size() != 0) {
533
//                        GWT.log("*****GOING TO SHOW CONTEXT MENU ****", null);
534
//                        contextMenu =  new FileContextMenu(images, false, false);
535
//                        contextMenu = contextMenu.onEvent(event);
536
//                        event.cancelBubble(true);
537
//                        event.preventDefault();
538
//                } else if (DOM.eventGetType(event) == Event.ONCONTEXTMENU && getSelectedFiles().size() == 0) {
539
//                        contextMenu = new FileContextMenu(images, false, true);
540
//                        contextMenu = contextMenu.onEmptyEvent(event);
541
//                        event.cancelBubble(true);
542
//                        event.preventDefault();
543
//                } else if (DOM.eventGetType(event) == Event.ONDBLCLICK)
544
//                        if (getSelectedFiles().size() == 1) {
545
//                                GSS app = GSS.get();
546
//                                File file = getSelectedFiles().get(0);
547
//                                Window.open(file.getUri(), "_blank", "");
548
//                                event.preventDefault();
549
//                                return;
550
//                        }
551
//                super.onBrowserEvent(event);
552
//        }
553

    
554
        /**
555
         * Update the display of the file list.
556
         */
557
        void update(boolean sort) {
558
                int count = folderFileCount;
559
                int max = startIndex + GSS.VISIBLE_FILE_COUNT;
560
                if (max > count)
561
                        max = count;
562
                folderTotalSize = 0;
563
                
564
                for(File f : files){
565
                        folderTotalSize += f.getBytes();
566
                }
567
                if (folderFileCount == 0) {
568
                        showingStats = "no files";
569
                } else if (folderFileCount < GSS.VISIBLE_FILE_COUNT) {
570
                        if (folderFileCount == 1)
571
                                showingStats = "1 file";
572
                        else
573
                                showingStats = folderFileCount + " files";
574
                        showingStats += " (" + FileResource.getFileSizeAsString(folderTotalSize) + ")";
575
                } else {
576
                        showingStats = "" + (startIndex + 1) + " - " + max + " of " + count + " files" + " (" + FileResource.getFileSizeAsString(folderTotalSize) + ")";
577
                }
578
                showCellTable();
579
                updateCurrentlyShowingStats();
580

    
581
        }
582

    
583
        /**
584
         * Return the proper icon based on the MIME type of the file.
585
         *
586
         * @param file
587
         * @return the icon
588
         */
589
        private ImageResource getFileIcon(File file) {
590
                String mimetype = file.getContentType();
591
                boolean shared = file.isShared();
592
                if (mimetype == null)
593
                        return shared ? images.documentShared() : images.document();
594
                mimetype = mimetype.toLowerCase();
595
                if (mimetype.startsWith("application/pdf"))
596
                        return shared ? images.pdfShared() : images.pdf();
597
                else if (mimetype.endsWith("excel"))
598
                        return shared ? images.spreadsheetShared() : images.spreadsheet();
599
                else if (mimetype.endsWith("msword"))
600
                        return shared ? images.wordprocessorShared() : images.wordprocessor();
601
                else if (mimetype.endsWith("powerpoint"))
602
                        return shared ? images.presentationShared() : images.presentation();
603
                else if (mimetype.startsWith("application/zip") ||
604
                                        mimetype.startsWith("application/gzip") ||
605
                                        mimetype.startsWith("application/x-gzip") ||
606
                                        mimetype.startsWith("application/x-tar") ||
607
                                        mimetype.startsWith("application/x-gtar"))
608
                        return shared ? images.zipShared() : images.zip();
609
                else if (mimetype.startsWith("text/html"))
610
                        return shared ? images.htmlShared() : images.html();
611
                else if (mimetype.startsWith("text/plain"))
612
                        return shared ? images.txtShared() : images.txt();
613
                else if (mimetype.startsWith("image/"))
614
                        return shared ? images.imageShared() : images.image();
615
                else if (mimetype.startsWith("video/"))
616
                        return shared ? images.videoShared() : images.video();
617
                else if (mimetype.startsWith("audio/"))
618
                        return shared ? images.audioShared() : images.audio();
619
                return shared ? images.documentShared() : images.document();
620
        }
621

    
622
        /**
623
         * Update status panel with currently showing file stats.
624
         */
625
        public void updateCurrentlyShowingStats() {
626
                GSS.get().getStatusPanel().updateCurrentlyShowing(showingStats);
627
        }
628
        
629
        /**
630
         * Fill the file cache with data.
631
         */
632
        public void setFiles(final List<File> _files) {
633
                files = new ArrayList<File>();
634
            for (File fres : _files)
635
                    if (!fres.isInTrash())
636
                                files.add(fres);
637
                Collections.sort(files, new Comparator<File>() {
638

    
639
                        @Override
640
                        public int compare(File arg0, File arg1) {
641
                                return arg0.getName().compareTo(arg1.getName());
642
                        }
643

    
644
                });
645
                folderFileCount = files.size();
646
                
647
                nameHeader.setSorted(true);
648
                nameHeader.toggleReverseSort();
649
                for (SortableHeader otherHeader : allHeaders) {
650
                if (otherHeader != nameHeader) {
651
                    otherHeader.setSorted(false);
652
                    otherHeader.setReverseSort(true);
653
                }
654
            }
655

    
656
        if(files.size() > GSS.VISIBLE_FILE_COUNT){
657
            pagerBottom.setVisible(true);
658
            pagerTop.setVisible(true);
659
        }
660
        else{
661
            pagerTop.setVisible(false);
662
            pagerBottom.setVisible(false);
663
        }
664
        Folder selectedItem = treeView.getSelection();
665

    
666
        provider.setList(files);
667
        }
668

    
669
        /**
670
         * Does the list contains the requested filename
671
         *
672
         * @param fileName
673
         * @return true/false
674
         */
675
        public boolean contains(String fileName) {
676
                for (int i = 0; i < files.size(); i++)
677
                        if (files.get(i).getName().equals(fileName))
678
                                return true;
679
                return false;
680
        }
681

    
682
        public void clearSelectedRows() {
683
                Iterator<File> it = selectionModel.getSelectedSet().iterator();
684
                while(it.hasNext()){
685
                        selectionModel.setSelected(it.next(),false);
686
                }
687
        }
688
        
689

    
690
        /**
691
         *
692
         */
693
        public void selectAllRows() {
694
                Iterator<File> it = provider.getList().iterator();
695
                while(it.hasNext()){
696
                        selectionModel.setSelected(it.next(),true);
697
                }
698

    
699

    
700
        }
701

    
702
        
703
        private void sortFiles(final String sortingProperty, final boolean sortingType){
704
                Collections.sort(files, new Comparator<File>() {
705

    
706
            @Override
707
            public int compare(File arg0, File arg1) {
708
                    AbstractImagePrototype descPrototype = AbstractImagePrototype.create(images.desc());
709
                    AbstractImagePrototype ascPrototype = AbstractImagePrototype.create(images.asc());
710
                    if (sortingType){
711
                            if (sortingProperty.equals("version")) {
712
                                    return arg0.getVersion() - arg1.getVersion();
713
                            } else if (sortingProperty.equals("owner")) {
714
                                    return arg0.getOwner().compareTo(arg1.getOwner());
715
                            } else if (sortingProperty.equals("date")) {
716
                                    return arg0.getLastModified().compareTo(arg1.getLastModified());
717
                            } else if (sortingProperty.equals("size")) {
718
                                    return (int) (arg0.getBytes() - arg1.getBytes());
719
                            } else if (sortingProperty.equals("name")) {
720
                                    return arg0.getName().compareTo(arg1.getName());
721
                            } else if (sortingProperty.equals("path")) {
722
                                    return arg0.getUri().compareTo(arg1.getUri());
723
                            } else {
724
                                    return arg0.getName().compareTo(arg1.getName());
725
                            }
726
                    }
727
                    else if (sortingProperty.equals("version")) {
728
                            
729
                            return arg1.getVersion() - arg0.getVersion();
730
                    } else if (sortingProperty.equals("owner")) {
731
                            
732
                            return arg1.getOwner().compareTo(arg0.getOwner());
733
                    } else if (sortingProperty.equals("date")) {
734
                            
735
                            return arg1.getLastModified().compareTo(arg0.getLastModified());
736
                    } else if (sortingProperty.equals("size")) {
737
                            return (int) (arg1.getBytes() - arg0.getBytes());
738
                    } else if (sortingProperty.equals("name")) {
739
                            
740
                            return arg1.getName().compareTo(arg0.getName());
741
                    } else if (sortingProperty.equals("path")) {
742
                            
743
                            return arg1.getUri().compareTo(arg0.getUri());
744
                    } else {
745
                            
746
                            return arg1.getName().compareTo(arg0.getName());
747
                    }
748
            }
749

    
750
                });
751
        }
752
        
753
        final class FileValueUpdater implements ValueUpdater<String>{
754
                private String property;
755
                private SortableHeader header;
756
                /**
757
                 * 
758
                 */
759
                public FileValueUpdater(SortableHeader header,String property) {
760
                        this.property=property;
761
                        this.header=header;
762
                }
763
                @Override
764
                public void update(String value) {
765
                        header.setSorted(true);
766
                        header.toggleReverseSort();
767

    
768
                for (SortableHeader otherHeader : allHeaders) {
769
                  if (otherHeader != header) {
770
                    otherHeader.setSorted(false);
771
                    otherHeader.setReverseSort(true);
772
                  }
773
                }
774
                celltable.redrawHeaders();
775
                sortFiles(property, header.getReverseSort());
776
                FileList.this.update(true);                        
777
                }
778
                
779
        }
780

    
781
        /**
782
         * Shows the files in the cellTable 
783
     */
784
        private void showCellTable(){
785
                if(files.size()>GSS.VISIBLE_FILE_COUNT){
786
                        pagerBottom.setVisible(true);
787
                        pagerTop.setVisible(true);
788
                }
789
                else{
790
                        pagerTop.setVisible(false);
791
                        pagerBottom.setVisible(false);
792
                }
793
                provider.setList(files);
794
                
795
                provider.refresh();
796
                
797
                //celltable.redraw();
798
                celltable.redrawHeaders();                
799
        }
800
}