2 * Copyright 2011 GRNET S.A. All rights reserved.
4 * Redistribution and use in source and binary forms, with or
5 * without modification, are permitted provided that the following
8 * 1. Redistributions of source code must retain the above
9 * copyright notice, this list of conditions and the following
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.
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.
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.
36 package gr.grnet.pithos.web.client;
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.$;
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;
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;
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.Event;
82 import com.google.gwt.user.client.ui.AbstractImagePrototype;
83 import com.google.gwt.user.client.ui.Button;
84 import com.google.gwt.user.client.ui.Composite;
85 import com.google.gwt.user.client.ui.HorizontalPanel;
86 import com.google.gwt.user.client.ui.VerticalPanel;
87 import com.google.gwt.view.client.ListDataProvider;
88 import com.google.gwt.view.client.MultiSelectionModel;
89 import com.google.gwt.view.client.ProvidesKey;
90 import com.google.gwt.view.client.SelectionChangeEvent;
91 import com.google.gwt.view.client.SelectionChangeEvent.Handler;
94 * A composite that displays the list of files in a particular folder.
96 public class FileList extends Composite {
98 ListDataProvider<File> provider = new ListDataProvider<File>();
101 * The styles applied to the table.
103 interface TableStyle extends CellTable.Style {
106 interface TableResources extends DragAndDropCellTable.Resources {
107 @Source({CellTable.Style.DEFAULT_CSS, "GssCellTable.css"})
108 TableStyle cellTableStyle();
111 static interface Templates extends SafeHtmlTemplates {
112 Templates INSTANCE = GWT.create(Templates.class);
114 @Template("<div id='dragHelper' style='border:1px solid black; background-color:#ffffff; color:black; width:150px;z-index:100'></div>")
115 SafeHtml outerHelper();
117 @Template("<span id='{0}'>{0}</span>")
118 public SafeHtml filenameSpan(String filename);
120 @Template("<a href='{0}' title='{1}' rel='lytebox[mnf]' onclick='myLytebox.start(this, false, false); return false;'>(view)</a>")
121 public SafeHtml viewLink(String link, String title);
123 @Template("<table><tr><td rowspan='3'>{0}</td><td style='font-size:95%;' id='{1}'>{1}</td></tr><tr><td>{2}</td></tr></table>")
124 public SafeHtml rendelContactCell(String imageHtml, String name, String fileSize);
126 @Template("<span id='{0}' class='{1}'>{2}</span>")
127 public SafeHtml spanWithIdAndClass(String id, String cssClass, String content);
130 private String showingStats = "";
132 private int startIndex = 0;
135 * A constant that denotes the completion of an IncrementalCommand.
137 public static final boolean DONE = false;
139 private final DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a");
142 * Specifies that the images available for this composite will be the ones
143 * available in FileContextMenu.
145 public interface Images extends ClientBundle,FileContextMenu.Images, CellTreeView.Images {
147 @Source("gr/grnet/pithos/resources/blank.gif")
148 ImageResource blank();
150 @Source("gr/grnet/pithos/resources/asc.png")
153 @Source("gr/grnet/pithos/resources/desc.png")
154 ImageResource desc();
156 @Source("gr/grnet/pithos/resources/mimetypes/document_shared.png")
157 ImageResource documentShared();
159 @Source("gr/grnet/pithos/resources/mimetypes/kcmfontinst.png")
160 ImageResource wordprocessor();
162 @Source("gr/grnet/pithos/resources/mimetypes/log.png")
163 ImageResource spreadsheet();
165 @Source("gr/grnet/pithos/resources/mimetypes/kpresenter_kpr.png")
166 ImageResource presentation();
168 @Source("gr/grnet/pithos/resources/mimetypes/acroread.png")
171 @Source("gr/grnet/pithos/resources/mimetypes/image.png")
172 ImageResource image();
174 @Source("gr/grnet/pithos/resources/mimetypes/video2.png")
175 ImageResource video();
177 @Source("gr/grnet/pithos/resources/mimetypes/knotify.png")
178 ImageResource audio();
180 @Source("gr/grnet/pithos/resources/mimetypes/html.png")
181 ImageResource html();
183 @Source("gr/grnet/pithos/resources/mimetypes/txt.png")
186 @Source("gr/grnet/pithos/resources/mimetypes/ark2.png")
189 @Source("gr/grnet/pithos/resources/mimetypes/kcmfontinst_shared.png")
190 ImageResource wordprocessorShared();
192 @Source("gr/grnet/pithos/resources/mimetypes/log_shared.png")
193 ImageResource spreadsheetShared();
195 @Source("gr/grnet/pithos/resources/mimetypes/kpresenter_kpr_shared.png")
196 ImageResource presentationShared();
198 @Source("gr/grnet/pithos/resources/mimetypes/acroread_shared.png")
199 ImageResource pdfShared();
201 @Source("gr/grnet/pithos/resources/mimetypes/image_shared.png")
202 ImageResource imageShared();
204 @Source("gr/grnet/pithos/resources/mimetypes/video2_shared.png")
205 ImageResource videoShared();
207 @Source("gr/grnet/pithos/resources/mimetypes/knotify_shared.png")
208 ImageResource audioShared();
210 @Source("gr/grnet/pithos/resources/mimetypes/html_shared.png")
211 ImageResource htmlShared();
213 @Source("gr/grnet/pithos/resources/mimetypes/txt_shared.png")
214 ImageResource txtShared();
216 @Source("gr/grnet/pithos/resources/mimetypes/ark2_shared.png")
217 ImageResource zipShared();
222 * The number of files in this folder.
229 long folderTotalSize;
232 * A cache of the files in the list.
234 private List<File> files;
237 * The widget's image bundle.
239 private final Images images;
241 private DragAndDropCellTable<File> celltable;
243 private final MultiSelectionModel<File> selectionModel;
245 private final List<SortableHeader> allHeaders = new ArrayList<SortableHeader>();
247 SortableHeader nameHeader;
249 GssSimplePager pagerBottom;
251 GssSimplePager pagerTop;
253 Button uploadButtonBottom;
255 Button uploadButtonTop;
257 FolderTreeView treeView;
260 * Construct the file list widget. This entails setting up the widget
261 * layout, fetching the number of files in the current folder from the
262 * server and filling the local file cache of displayed files with data from
263 * the server, as well.
267 public FileList(Images _images, FolderTreeView _treeView) {
269 this.treeView = _treeView;
271 DragAndDropCellTable.Resources resources = GWT.create(TableResources.class);
273 ProvidesKey<File> keyProvider = new ProvidesKey<File>(){
276 public Object getKey(File item) {
277 return item.getUri();
281 celltable = new DragAndDropCellTable<File>(Pithos.VISIBLE_FILE_COUNT, resources, keyProvider);
282 celltable.setWidth("100%");
283 celltable.setStyleName("pithos-List");
285 DragAndDropColumn<File, ImageResource> status = new DragAndDropColumn<File, ImageResource>(new ImageResourceCell() {
287 public boolean handlesSelection() {
293 public ImageResource getValue(File entity) {
294 return getFileIcon(entity);
297 celltable.addColumn(status,"");
298 initDragOperation(status);
300 final DragAndDropColumn<File,SafeHtml> nameColumn = new DragAndDropColumn<File,SafeHtml>(new SafeHtmlCell()) {
303 public SafeHtml getValue(File object) {
304 SafeHtmlBuilder sb = new SafeHtmlBuilder();
305 sb.append(Templates.INSTANCE.filenameSpan(object.getName()));
306 if (object.getContentType().endsWith("png") || object.getContentType().endsWith("gif") || object.getContentType().endsWith("jpeg")) {
307 sb.appendHtmlConstant(" ")
308 .append(Templates.INSTANCE.viewLink(object.getUri(), object.getOwner() + " : " + object.getPath() + object.getName()));
311 return sb.toSafeHtml();
315 initDragOperation(nameColumn);
316 celltable.addColumn(nameColumn, nameHeader = new SortableHeader("Name"));
317 allHeaders.add(nameHeader);
318 nameHeader.setUpdater(new FileValueUpdater(nameHeader, "name"));
320 celltable.redrawHeaders();
322 DragAndDropColumn<File,String> aColumn = new DragAndDropColumn<File, String>(new TextCell()) {
324 public String getValue(File object) {
325 return object.getOwner();
328 SortableHeader aheader = new SortableHeader("Owner");
329 celltable.addColumn(aColumn, aheader);
330 initDragOperation(aColumn);
331 allHeaders.add(aheader);
332 aheader.setUpdater(new FileValueUpdater(aheader, "owner"));
334 aColumn = new DragAndDropColumn<File,String>(new TextCell()) {
336 public String getValue(File object) {
337 return object.getPath();
340 aheader = new SortableHeader("Path");
341 celltable.addColumn(aColumn, aheader);
342 initDragOperation(aColumn);
343 allHeaders.add(aheader);
344 aheader.setUpdater(new FileValueUpdater(aheader, "path"));
346 aColumn = new DragAndDropColumn<File,String>(new TextCell()) {
348 public String getValue(File object) {
349 return String.valueOf(object.getVersion());
352 aheader = new SortableHeader("Version");
353 celltable.addColumn(aColumn, aheader);
354 initDragOperation(aColumn);
355 allHeaders.add(aheader);
356 aheader.setUpdater(new FileValueUpdater(aheader, "version"));
358 aColumn = new DragAndDropColumn<File,String>(new TextCell()) {
360 public String getValue(File object) {
361 // TODO Auto-generated method stub
362 return object.getSizeAsString();
365 aheader = new SortableHeader("Size");
366 celltable.addColumn(aColumn, aheader);
367 initDragOperation(aColumn);
368 allHeaders.add(aheader);
369 aheader.setUpdater(new FileValueUpdater(aheader, "size"));
371 aColumn = new DragAndDropColumn<File,String>(new TextCell()) {
373 public String getValue(File object) {
374 return formatter.format(object.getLastModified());
377 aheader = new SortableHeader("Last Modified");
378 celltable.addColumn(aColumn, aheader);
379 allHeaders.add(aheader);
380 aheader.setUpdater(new FileValueUpdater(aheader, "date"));
382 provider.addDataDisplay(celltable);
384 celltable.addDragStopHandler(new DragStopEventHandler() {
387 public void onDragStop(DragStopEvent event) {
388 GWT.log("DRAG STOPPED");
391 celltable.addDragStartHandler(new DragStartEventHandler() {
393 public void onDragStart(DragStartEvent event) {
394 FileResource value = event.getDraggableData();
396 com.google.gwt.dom.client.Element helper = event.getHelper();
397 SafeHtmlBuilder sb = new SafeHtmlBuilder();
398 sb.appendHtmlConstant("<b>");
399 DisplayHelper.log(value.getName());
400 if(getSelectedFiles().size()==1)
401 sb.appendEscaped(value.getName());
403 sb.appendEscaped(getSelectedFiles().size()+" files");
404 sb.appendHtmlConstant("</b>");
405 helper.setInnerHTML(sb.toSafeHtml().asString());
409 VerticalPanel vp = new VerticalPanel();
412 pagerTop = new GssSimplePager(GssSimplePager.TextLocation.CENTER);
413 pagerTop.setVisible(false);
414 pagerTop.setDisplay(celltable);
415 uploadButtonTop = new Button("<span id='topMenu.file.upload'>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + " Upload</span>");
416 uploadButtonTop.addClickHandler(new ClickHandler() {
419 public void onClick(ClickEvent event) {
420 new UploadFileCommand(null, treeView.getSelection()).execute();
423 HorizontalPanel topPanel = new HorizontalPanel();
424 topPanel.add(pagerTop);
425 topPanel.add(uploadButtonTop);
430 pagerBottom = new GssSimplePager(GssSimplePager.TextLocation.CENTER);
431 pagerBottom.setVisible(false);
432 pagerBottom.setDisplay(celltable);
433 uploadButtonBottom=new Button("<span id='topMenu.file.upload'>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + " Upload</span>");
434 uploadButtonBottom.addClickHandler(new ClickHandler() {
437 public void onClick(ClickEvent event) {
438 new UploadFileCommand(null, treeView.getSelection()).execute();
441 HorizontalPanel bottomPanel = new HorizontalPanel();
442 bottomPanel.add(pagerBottom);
443 bottomPanel.add(uploadButtonBottom);
446 vp.setCellWidth(celltable, "100%");
447 vp.addHandler(new ContextMenuHandler() {
449 public void onContextMenu(ContextMenuEvent event) {
450 Folder selectedFolder = treeView.getSelection();
451 if (!selectedFolder.isTrash()) {
452 FileContextMenu contextMenu = new FileContextMenu(images, selectedFolder, getSelectedFiles(), false);
453 int x = event.getNativeEvent().getClientX();
454 int y = event.getNativeEvent().getClientY();
455 contextMenu.setPopupPosition(x, y);
459 }, ContextMenuEvent.getType());
462 selectionModel = new MultiSelectionModel<File>(keyProvider);
464 Handler selectionHandler = new SelectionChangeEvent.Handler() {
466 public void onSelectionChange(SelectionChangeEvent event) {
467 if(getSelectedFiles().size() == 1)
468 Pithos.get().setCurrentSelection(getSelectedFiles().get(0));
470 Pithos.get().setCurrentSelection(getSelectedFiles());
473 selectionModel.addSelectionChangeHandler(selectionHandler);
475 celltable.setSelectionModel(selectionModel, GSSSelectionEventManager.<File> createDefaultManager());
476 celltable.setPageSize(Pithos.VISIBLE_FILE_COUNT);
478 sinkEvents(Event.ONCONTEXTMENU);
479 // sinkEvents(Event.ONMOUSEUP);
480 // sinkEvents(Event.ONMOUSEDOWN);
481 // sinkEvents(Event.ONCLICK);
482 // sinkEvents(Event.ONKEYDOWN);
483 // sinkEvents(Event.ONDBLCLICK);
484 Pithos.preventIESelection();
487 public List<File> getSelectedFiles() {
488 return new ArrayList<File>(selectionModel.getSelectedSet());
491 private void initDragOperation(DragAndDropColumn<?, ?> column) {
492 // retrieve draggableOptions on the column
493 DraggableOptions draggableOptions = column.getDraggableOptions();
494 // use template to construct the helper. The content of the div will be set
496 draggableOptions.setHelper($(Templates.INSTANCE.outerHelper().asString()));
497 //draggableOptions.setZIndex(100);
498 // opacity of the helper
499 draggableOptions.setAppendTo("body");
500 //draggableOptions.setOpacity((float) 0.8);
501 draggableOptions.setContainment("document");
502 // cursor to use during the drag operation
503 draggableOptions.setCursor(Cursor.MOVE);
504 // set the revert option
505 draggableOptions.setRevert(RevertOption.ON_INVALID_DROP);
506 // prevents dragging when user click on the category drop-down list
507 draggableOptions.setCancel("select");
508 draggableOptions.setOnBeforeDragStart(new DragFunction() {
510 public void f(DragContext context) {
511 File value = context.getDraggableData();
512 if (!selectionModel.isSelected(value)) {
513 throw new StopDragException();
520 // public void onBrowserEvent(Event event) {
522 // if (files == null || files.size() == 0) {
523 // if (DOM.eventGetType(event) == Event.ONCONTEXTMENU && getSelectedFiles().size() == 0) {
524 // contextMenu = new FileContextMenu(images, false, true);
525 // contextMenu.show();
526 // event.preventDefault();
527 // event.cancelBubble(true);
531 // if (DOM.eventGetType(event) == Event.ONCONTEXTMENU && getSelectedFiles().size() != 0) {
532 // GWT.log("*****GOING TO SHOW CONTEXT MENU ****", null);
533 // contextMenu = new FileContextMenu(images, false, false);
534 // contextMenu = contextMenu.onEvent(event);
535 // event.cancelBubble(true);
536 // event.preventDefault();
537 // } else if (DOM.eventGetType(event) == Event.ONCONTEXTMENU && getSelectedFiles().size() == 0) {
538 // contextMenu = new FileContextMenu(images, false, true);
539 // contextMenu = contextMenu.onEmptyEvent(event);
540 // event.cancelBubble(true);
541 // event.preventDefault();
542 // } else if (DOM.eventGetType(event) == Event.ONDBLCLICK)
543 // if (getSelectedFiles().size() == 1) {
544 // Pithos app = Pithos.get();
545 // File file = getSelectedFiles().get(0);
546 // Window.open(file.getUri(), "_blank", "");
547 // event.preventDefault();
550 // super.onBrowserEvent(event);
554 * Update the display of the file list.
556 void update(boolean sort) {
557 int count = folderFileCount;
558 int max = startIndex + Pithos.VISIBLE_FILE_COUNT;
564 folderTotalSize += f.getBytes();
566 if (folderFileCount == 0) {
567 showingStats = "no files";
568 } else if (folderFileCount < Pithos.VISIBLE_FILE_COUNT) {
569 if (folderFileCount == 1)
570 showingStats = "1 file";
572 showingStats = folderFileCount + " files";
573 showingStats += " (" + FileResource.getFileSizeAsString(folderTotalSize) + ")";
575 showingStats = "" + (startIndex + 1) + " - " + max + " of " + count + " files" + " (" + FileResource.getFileSizeAsString(folderTotalSize) + ")";
578 updateCurrentlyShowingStats();
583 * Return the proper icon based on the MIME type of the file.
588 private ImageResource getFileIcon(File file) {
589 String mimetype = file.getContentType();
590 boolean shared = file.isShared();
591 if (mimetype == null)
592 return shared ? images.documentShared() : images.document();
593 mimetype = mimetype.toLowerCase();
594 if (mimetype.startsWith("application/pdf"))
595 return shared ? images.pdfShared() : images.pdf();
596 else if (mimetype.endsWith("excel"))
597 return shared ? images.spreadsheetShared() : images.spreadsheet();
598 else if (mimetype.endsWith("msword"))
599 return shared ? images.wordprocessorShared() : images.wordprocessor();
600 else if (mimetype.endsWith("powerpoint"))
601 return shared ? images.presentationShared() : images.presentation();
602 else if (mimetype.startsWith("application/zip") ||
603 mimetype.startsWith("application/gzip") ||
604 mimetype.startsWith("application/x-gzip") ||
605 mimetype.startsWith("application/x-tar") ||
606 mimetype.startsWith("application/x-gtar"))
607 return shared ? images.zipShared() : images.zip();
608 else if (mimetype.startsWith("text/html"))
609 return shared ? images.htmlShared() : images.html();
610 else if (mimetype.startsWith("text/plain"))
611 return shared ? images.txtShared() : images.txt();
612 else if (mimetype.startsWith("image/"))
613 return shared ? images.imageShared() : images.image();
614 else if (mimetype.startsWith("video/"))
615 return shared ? images.videoShared() : images.video();
616 else if (mimetype.startsWith("audio/"))
617 return shared ? images.audioShared() : images.audio();
618 return shared ? images.documentShared() : images.document();
622 * Update status panel with currently showing file stats.
624 public void updateCurrentlyShowingStats() {
625 Pithos.get().getStatusPanel().updateCurrentlyShowing(showingStats);
629 * Fill the file cache with data.
631 public void setFiles(final List<File> _files) {
632 files = new ArrayList<File>();
633 for (File fres : _files)
634 if (!fres.isInTrash())
636 Collections.sort(files, new Comparator<File>() {
639 public int compare(File arg0, File arg1) {
640 return arg0.getName().compareTo(arg1.getName());
644 folderFileCount = files.size();
646 nameHeader.setSorted(true);
647 nameHeader.toggleReverseSort();
648 for (SortableHeader otherHeader : allHeaders) {
649 if (otherHeader != nameHeader) {
650 otherHeader.setSorted(false);
651 otherHeader.setReverseSort(true);
655 if(files.size() > Pithos.VISIBLE_FILE_COUNT){
656 pagerBottom.setVisible(true);
657 pagerTop.setVisible(true);
660 pagerTop.setVisible(false);
661 pagerBottom.setVisible(false);
663 Folder selectedItem = treeView.getSelection();
665 provider.setList(files);
669 * Does the list contains the requested filename
674 public boolean contains(String fileName) {
675 for (int i = 0; i < files.size(); i++)
676 if (files.get(i).getName().equals(fileName))
681 public void clearSelectedRows() {
682 Iterator<File> it = selectionModel.getSelectedSet().iterator();
684 selectionModel.setSelected(it.next(),false);
692 public void selectAllRows() {
693 Iterator<File> it = provider.getList().iterator();
695 selectionModel.setSelected(it.next(),true);
702 private void sortFiles(final String sortingProperty, final boolean sortingType){
703 Collections.sort(files, new Comparator<File>() {
706 public int compare(File arg0, File arg1) {
707 AbstractImagePrototype descPrototype = AbstractImagePrototype.create(images.desc());
708 AbstractImagePrototype ascPrototype = AbstractImagePrototype.create(images.asc());
710 if (sortingProperty.equals("version")) {
711 return arg0.getVersion() - arg1.getVersion();
712 } else if (sortingProperty.equals("owner")) {
713 return arg0.getOwner().compareTo(arg1.getOwner());
714 } else if (sortingProperty.equals("date")) {
715 return arg0.getLastModified().compareTo(arg1.getLastModified());
716 } else if (sortingProperty.equals("size")) {
717 return (int) (arg0.getBytes() - arg1.getBytes());
718 } else if (sortingProperty.equals("name")) {
719 return arg0.getName().compareTo(arg1.getName());
720 } else if (sortingProperty.equals("path")) {
721 return arg0.getUri().compareTo(arg1.getUri());
723 return arg0.getName().compareTo(arg1.getName());
726 else if (sortingProperty.equals("version")) {
728 return arg1.getVersion() - arg0.getVersion();
729 } else if (sortingProperty.equals("owner")) {
731 return arg1.getOwner().compareTo(arg0.getOwner());
732 } else if (sortingProperty.equals("date")) {
734 return arg1.getLastModified().compareTo(arg0.getLastModified());
735 } else if (sortingProperty.equals("size")) {
736 return (int) (arg1.getBytes() - arg0.getBytes());
737 } else if (sortingProperty.equals("name")) {
739 return arg1.getName().compareTo(arg0.getName());
740 } else if (sortingProperty.equals("path")) {
742 return arg1.getUri().compareTo(arg0.getUri());
745 return arg1.getName().compareTo(arg0.getName());
752 final class FileValueUpdater implements ValueUpdater<String>{
753 private String property;
754 private SortableHeader header;
758 public FileValueUpdater(SortableHeader header,String property) {
759 this.property=property;
763 public void update(String value) {
764 header.setSorted(true);
765 header.toggleReverseSort();
767 for (SortableHeader otherHeader : allHeaders) {
768 if (otherHeader != header) {
769 otherHeader.setSorted(false);
770 otherHeader.setReverseSort(true);
773 celltable.redrawHeaders();
774 sortFiles(property, header.getReverseSort());
775 FileList.this.update(true);
781 * Shows the files in the cellTable
783 private void showCellTable(){
784 if(files.size()> Pithos.VISIBLE_FILE_COUNT){
785 pagerBottom.setVisible(true);
786 pagerTop.setVisible(true);
789 pagerTop.setVisible(false);
790 pagerBottom.setVisible(false);
792 provider.setList(files);
796 //celltable.redraw();
797 celltable.redrawHeaders();
800 public void showTrash() {
801 uploadButtonBottom.setVisible(false);
802 uploadButtonTop.setVisible(false);
805 public void showFiles() {
806 uploadButtonBottom.setVisible(true);
807 uploadButtonTop.setVisible(true);