2 * Copyright 2007, 2008, 2009 Electronic Business Systems Ltd.
4 * This file is part of GSS.
6 * GSS is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GSS is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GSS. If not, see <http://www.gnu.org/licenses/>.
19 package gr.ebs.gss.client;
22 import gr.ebs.gss.client.rest.GetCommand;
23 import gr.ebs.gss.client.rest.MultipleHeadCommand;
24 import gr.ebs.gss.client.rest.RestCommand;
25 import gr.ebs.gss.client.rest.RestException;
26 import gr.ebs.gss.client.rest.resource.FileResource;
27 import gr.ebs.gss.client.rest.resource.FolderResource;
28 import gr.ebs.gss.client.rest.resource.OtherUserResource;
29 import gr.ebs.gss.client.rest.resource.RestResource;
30 import gr.ebs.gss.client.rest.resource.SharedResource;
31 import gr.ebs.gss.client.rest.resource.TrashResource;
32 import gr.ebs.gss.client.rest.resource.UserResource;
33 import gr.ebs.gss.client.rest.resource.UserSearchResource;
35 import java.util.ArrayList;
36 import java.util.Collections;
37 import java.util.Comparator;
38 import java.util.Iterator;
39 import java.util.List;
41 import com.google.gwt.cell.client.ImageResourceCell;
42 import com.google.gwt.cell.client.ValueUpdater;
43 import com.google.gwt.core.client.GWT;
44 import com.google.gwt.core.client.Scheduler;
45 import com.google.gwt.core.client.Scheduler.RepeatingCommand;
46 import com.google.gwt.dom.client.Element;
47 import com.google.gwt.dom.client.NativeEvent;
48 import com.google.gwt.http.client.URL;
49 import com.google.gwt.i18n.client.DateTimeFormat;
50 import com.google.gwt.resources.client.ClientBundle;
51 import com.google.gwt.resources.client.ImageResource;
52 import com.google.gwt.user.cellview.client.CellTable;
53 import com.google.gwt.user.cellview.client.Column;
54 import com.google.gwt.user.cellview.client.TextColumn;
55 import com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy.KeyboardSelectionPolicy;
56 import com.google.gwt.user.client.DOM;
57 import com.google.gwt.user.client.DeferredCommand;
58 import com.google.gwt.user.client.Event;
59 import com.google.gwt.user.client.Window;
60 import com.google.gwt.user.client.ui.AbstractImagePrototype;
61 import com.google.gwt.user.client.ui.Composite;
62 import com.google.gwt.user.client.ui.Grid;
63 import com.google.gwt.user.client.ui.HTML;
64 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
65 import com.google.gwt.user.client.ui.HorizontalPanel;
66 import com.google.gwt.user.client.ui.TreeItem;
67 import com.google.gwt.user.client.ui.VerticalPanel;
68 import com.google.gwt.user.client.ui.Widget;
69 import com.google.gwt.view.client.DefaultSelectionEventManager;
70 import com.google.gwt.view.client.MultiSelectionModel;
71 import com.google.gwt.view.client.ProvidesKey;
72 import com.google.gwt.view.client.SelectionChangeEvent;
73 import com.google.gwt.view.client.SelectionChangeEvent.Handler;
76 * A composite that displays the list of files in a particular folder.
78 public class FileList extends Composite {
80 interface TableResources extends CellTable.Resources {
81 @Source({CellTable.Style.DEFAULT_CSS, "GssCellTable.css"})
82 TableStyle cellTableStyle();
86 * The styles applied to the table.
88 interface TableStyle extends CellTable.Style {
91 private String showingStats = "";
93 private int startIndex = 0;
96 * A constant that denotes the completion of an IncrementalCommand.
98 public static final boolean DONE = false;
102 private final DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a");
105 * Specifies that the images available for this composite will be the ones
106 * available in FileContextMenu.
108 public interface Images extends ClientBundle,FileContextMenu.Images, CellTreeView.Images {
110 @Source("gr/ebs/gss/resources/blank.gif")
111 ImageResource blank();
113 @Source("gr/ebs/gss/resources/asc.png")
116 @Source("gr/ebs/gss/resources/desc.png")
117 ImageResource desc();
119 @Source("gr/ebs/gss/resources/mimetypes/document_shared.png")
120 ImageResource documentShared();
122 @Source("gr/ebs/gss/resources/mimetypes/kcmfontinst.png")
123 ImageResource wordprocessor();
125 @Source("gr/ebs/gss/resources/mimetypes/log.png")
126 ImageResource spreadsheet();
128 @Source("gr/ebs/gss/resources/mimetypes/kpresenter_kpr.png")
129 ImageResource presentation();
131 @Source("gr/ebs/gss/resources/mimetypes/acroread.png")
134 @Source("gr/ebs/gss/resources/mimetypes/image.png")
135 ImageResource image();
137 @Source("gr/ebs/gss/resources/mimetypes/video2.png")
138 ImageResource video();
140 @Source("gr/ebs/gss/resources/mimetypes/knotify.png")
141 ImageResource audio();
143 @Source("gr/ebs/gss/resources/mimetypes/html.png")
144 ImageResource html();
146 @Source("gr/ebs/gss/resources/mimetypes/txt.png")
149 @Source("gr/ebs/gss/resources/mimetypes/ark2.png")
152 @Source("gr/ebs/gss/resources/mimetypes/kcmfontinst_shared.png")
153 ImageResource wordprocessorShared();
155 @Source("gr/ebs/gss/resources/mimetypes/log_shared.png")
156 ImageResource spreadsheetShared();
158 @Source("gr/ebs/gss/resources/mimetypes/kpresenter_kpr_shared.png")
159 ImageResource presentationShared();
161 @Source("gr/ebs/gss/resources/mimetypes/acroread_shared.png")
162 ImageResource pdfShared();
164 @Source("gr/ebs/gss/resources/mimetypes/image_shared.png")
165 ImageResource imageShared();
167 @Source("gr/ebs/gss/resources/mimetypes/video2_shared.png")
168 ImageResource videoShared();
170 @Source("gr/ebs/gss/resources/mimetypes/knotify_shared.png")
171 ImageResource audioShared();
173 @Source("gr/ebs/gss/resources/mimetypes/html_shared.png")
174 ImageResource htmlShared();
176 @Source("gr/ebs/gss/resources/mimetypes/txt_shared.png")
177 ImageResource txtShared();
179 @Source("gr/ebs/gss/resources/mimetypes/ark2_shared.png")
180 ImageResource zipShared();
185 * Retrieve the celltable.
187 * @return the celltable
189 public CellTable<FileResource> getCelltable() {
193 * A label with the number of files in this folder.
195 private HTML countLabel = new HTML();
198 * The table widget with the file list.
200 //private FileTable table = new FileTable(GSS.VISIBLE_FILE_COUNT + 1, 8);
203 * The navigation bar for paginating the results.
205 private HorizontalPanel navBar = new HorizontalPanel();
208 * The number of files in this folder.
215 long folderTotalSize;
218 * A cache of the files in the list.
220 private List<FileResource> files;
223 * The widget's image bundle.
225 private final Images images;
228 private FileContextMenu menuShowing;
229 private CellTable<FileResource> celltable;
230 private final MultiSelectionModel<FileResource> selectionModel;
231 private final List<SortableHeader> allHeaders = new ArrayList<SortableHeader>();
232 SortableHeader nameHeader;
234 * Construct the file list widget. This entails setting up the widget
235 * layout, fetching the number of files in the current folder from the
236 * server and filling the local file cache of displayed files with data from
237 * the server, as well.
241 public FileList(Images _images) {
243 CellTable.Resources resources = GWT.create(TableResources.class);
246 // Create the 'navigation' bar at the upper-right.
247 HorizontalPanel innerNavBar = new HorizontalPanel();
248 innerNavBar.setStyleName("gss-ListNavBar");
249 innerNavBar.setSpacing(8);
250 innerNavBar.add(countLabel);
251 navBar.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
252 navBar.add(innerNavBar);
253 navBar.setWidth("100%");
254 ProvidesKey<FileResource> keyProvider = new ProvidesKey<FileResource>(){
257 public Object getKey(FileResource item) {
258 return item.getUri();
262 final TextColumn<FileResource> nameColumn = new TextColumn<FileResource>() {
265 public String getValue(FileResource object) {
266 // TODO Auto-generated method stub
267 return object.getName();
272 celltable = new CellTable<FileResource>(100,resources,keyProvider){
274 protected void onBrowserEvent2(Event event) {
275 /*if (DOM.eventGetType((Event) event) == Event.ONMOUSEDOWN && DOM.eventGetButton((Event) event) == NativeEvent.BUTTON_RIGHT){
276 fireClickEvent((Element) event.getEventTarget().cast());
278 GWT.log("event in celltable:"+event.getType());
279 super.onBrowserEvent2(event);
283 Column<FileResource, ImageResource> status = new Column<FileResource, ImageResource>(new ImageResourceCell()) {
285 public ImageResource getValue(FileResource entity) {
286 return getFileIcon(entity);
289 celltable.addColumn(status,"");
292 celltable.addColumn(nameColumn,nameHeader = new SortableHeader("Name"));
293 allHeaders.add(nameHeader);
294 nameHeader.setSorted(true);
295 nameHeader.toggleReverseSort();
296 nameHeader.setUpdater(new FileValueUpdater(nameHeader, "name"));
297 celltable.redrawHeaders();
298 SortableHeader aheader;
299 celltable.addColumn(new TextColumn<FileResource>() {
301 public String getValue(FileResource object) {
302 return GSS.get().findUserFullName(object.getOwner());
304 },aheader = new SortableHeader("Owner"));
305 allHeaders.add(aheader);
306 aheader.setUpdater(new FileValueUpdater(aheader, "owner"));
307 celltable.addColumn(new TextColumn<FileResource>() {
309 public String getValue(FileResource object) {
310 // TODO Auto-generated method stub
311 return object.getPath();
313 },aheader = new SortableHeader("Path"));
314 allHeaders.add(aheader);
315 aheader.setUpdater(new FileValueUpdater(aheader, "path"));
316 celltable.addColumn(new TextColumn<FileResource>() {
318 public String getValue(FileResource object) {
319 // TODO Auto-generated method stub
320 return object.getVersion().toString();
322 },aheader = new SortableHeader("Version"));
323 allHeaders.add(aheader);
324 aheader.setUpdater(new FileValueUpdater(aheader, "version"));
325 celltable.addColumn(new TextColumn<FileResource>() {
327 public String getValue(FileResource object) {
328 // TODO Auto-generated method stub
329 return object.getFileSizeAsString();
331 },aheader = new SortableHeader("Size"));
332 allHeaders.add(aheader);
333 aheader.setUpdater(new FileValueUpdater(aheader, "size"));
334 celltable.addColumn(new TextColumn<FileResource>() {
336 public String getValue(FileResource object) {
337 return formatter.format(object.getModificationDate());
339 },aheader = new SortableHeader("Last Modified"));
340 allHeaders.add(aheader);
341 aheader.setUpdater(new FileValueUpdater(aheader, "date"));
343 initWidget(celltable);
344 setStyleName("gss-List");
345 selectionModel = new MultiSelectionModel<FileResource>();
348 Handler selectionHandler = new SelectionChangeEvent.Handler() {
350 public void onSelectionChange(com.google.gwt.view.client.SelectionChangeEvent event) {
351 if(getSelectedFiles().size()==1)
352 GSS.get().setCurrentSelection(getSelectedFiles().get(0));
354 GSS.get().setCurrentSelection(getSelectedFiles());
355 //contextMenu.setFiles(getSelectedFiles());
358 selectionModel.addSelectionChangeHandler(selectionHandler);
360 celltable.setSelectionModel(selectionModel,GSSSelectionEventManager.<FileResource>createDefaultManager());
361 celltable.setPageSize(GSS.VISIBLE_FILE_COUNT);
362 celltable.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
363 Scheduler.get().scheduleIncremental(new RepeatingCommand() {
366 public boolean execute() {
367 return fetchRootFolder();
370 sinkEvents(Event.ONCONTEXTMENU);
371 sinkEvents(Event.ONMOUSEUP);
372 sinkEvents(Event.ONMOUSEDOWN);
373 sinkEvents(Event.ONCLICK);
374 sinkEvents(Event.ONKEYDOWN);
375 sinkEvents(Event.ONDBLCLICK);
376 GSS.preventIESelection();
379 //public native void fireClickEvent(Element element) /*-{
380 // var evObj = $doc.createEvent('MouseEvents');
381 //evObj.initEvent('click', true, true);
382 //element.dispatchEvent(evObj);
385 public List<FileResource> getSelectedFiles() {
386 return new ArrayList<FileResource>(selectionModel.getSelectedSet());
392 public void onBrowserEvent(Event event) {
394 if (files == null || files.size() == 0) {
395 if (DOM.eventGetType(event) == Event.ONCONTEXTMENU && getSelectedFiles().size() == 0) {
396 menuShowing = new FileContextMenu(images, false, true);
397 menuShowing=menuShowing.onEmptyEvent(event);
401 if (DOM.eventGetType(event) == Event.ONCONTEXTMENU && getSelectedFiles().size() != 0) {
402 GWT.log("*****GOING TO SHOW CONTEXT MENU ****", null);
403 menuShowing = new FileContextMenu(images, false, false);
404 menuShowing=menuShowing.onEvent(event);
405 } else if (DOM.eventGetType(event) == Event.ONCONTEXTMENU && getSelectedFiles().size() == 0) {
406 menuShowing = new FileContextMenu(images, false, true);
407 menuShowing=menuShowing.onEmptyEvent(event);
408 } else if (DOM.eventGetType(event) == Event.ONDBLCLICK)
409 if (getSelectedFiles().size() == 1) {
411 FileResource file = getSelectedFiles().get(0);
412 String dateString = RestCommand.getDate();
413 String resource = file.getUri().substring(app.getApiPath().length() - 1, file.getUri().length());
414 String sig = app.getCurrentUserResource().getUsername() + " " +
415 RestCommand.calculateSig("GET", dateString, resource,
416 RestCommand.base64decode(app.getToken()));
417 Window.open(file.getUri() + "?Authorization=" + URL.encodeComponent(sig) + "&Date=" + URL.encodeComponent(dateString), "_blank", "");
418 event.preventDefault();
421 super.onBrowserEvent(event);
425 * Retrieve the root folder for the current user.
427 * @return true if the retrieval was successful
429 protected boolean fetchRootFolder() {
430 UserResource user = GSS.get().getCurrentUserResource();
433 // Update cache and clear selection.
434 updateFileCache(true);
442 * Make the specified row look like selected or not, according to the
443 * <code>selected</code> flag.
448 void styleRow(final int row, final boolean selected) {
453 * Update the display of the file list.
455 void update(boolean sort) {
456 int count = folderFileCount;
457 int max = startIndex + GSS.VISIBLE_FILE_COUNT;
462 copyListAndContinue(files);
464 if (folderFileCount == 0) {
465 showingStats = "no files";
466 } else if (folderFileCount < GSS.VISIBLE_FILE_COUNT) {
467 if (folderFileCount == 1)
468 showingStats = "1 file";
470 showingStats = folderFileCount + " files";
471 showingStats += " (" + FileResource.getFileSizeAsString(folderTotalSize) + ")";
473 showingStats = "" + (startIndex + 1) + " - " + max + " of " + count + " files" + " (" + FileResource.getFileSizeAsString(folderTotalSize) + ")";
475 updateCurrentlyShowingStats();
480 * Return the proper icon based on the MIME type of the file.
485 private ImageResource getFileIcon(FileResource file) {
486 String mimetype = file.getContentType();
487 boolean shared = false;
488 /*Folders folders = GSS.get().getFolders();
489 if(folders.getCurrent() != null && folders.isOthersSharedItem(folders.getCurrent())){
490 DnDTreeItem otherUser = (DnDTreeItem) folders.getUserOfSharedItem(folders.getCurrent());
494 String uname = otherUser.getOtherUserResource().getUsername();
496 uname = ((DnDTreeItem)folders.getSharesItem()).getOthersResource().getUsernameOfUri(otherUser.getOtherUserResource().getUri());
498 shared = file.isShared();
502 shared = file.isShared();
503 if (mimetype == null)
504 return shared ? images.documentShared() : images.document();
505 mimetype = mimetype.toLowerCase();
506 if (mimetype.startsWith("application/pdf"))
507 return shared ? images.pdfShared() : images.pdf();
508 else if (mimetype.endsWith("excel"))
509 return shared ? images.spreadsheetShared() : images.spreadsheet();
510 else if (mimetype.endsWith("msword"))
511 return shared ? images.wordprocessorShared() : images.wordprocessor();
512 else if (mimetype.endsWith("powerpoint"))
513 return shared ? images.presentationShared() : images.presentation();
514 else if (mimetype.startsWith("application/zip") ||
515 mimetype.startsWith("application/gzip") ||
516 mimetype.startsWith("application/x-gzip") ||
517 mimetype.startsWith("application/x-tar") ||
518 mimetype.startsWith("application/x-gtar"))
519 return shared ? images.zipShared() : images.zip();
520 else if (mimetype.startsWith("text/html"))
521 return shared ? images.htmlShared() : images.html();
522 else if (mimetype.startsWith("text/plain"))
523 return shared ? images.txtShared() : images.txt();
524 else if (mimetype.startsWith("image/"))
525 return shared ? images.imageShared() : images.image();
526 else if (mimetype.startsWith("video/"))
527 return shared ? images.videoShared() : images.video();
528 else if (mimetype.startsWith("audio/"))
529 return shared ? images.audioShared() : images.audio();
530 return shared ? images.documentShared() : images.document();
534 * Update status panel with currently showing file stats.
536 public void updateCurrentlyShowingStats() {
537 GSS.get().getStatusPanel().updateCurrentlyShowing(showingStats);
541 * Adjust the height of the table by adding and removing rows as necessary.
543 * @param newHeight the new height to reach
545 //void resizeTableHeight(final int newHeight) {
546 /*GWT.log("Panel: " + newHeight + ", parent: " + table.getParent().getOffsetHeight(), null);
547 // Fill the rest with empty slots.
548 if (newHeight > table.getOffsetHeight())
549 while (newHeight > table.getOffsetHeight()) {
550 table.resizeRows(table.getRowCount() + 1);
551 GWT.log("Table: " + table.getOffsetHeight() + ", rows: " + table.getRowCount(), null);
554 while (newHeight < table.getOffsetHeight()) {
555 table.resizeRows(table.getRowCount() - 1);
556 GWT.log("Table: " + table.getOffsetHeight() + ", rows: " + table.getRowCount(), null);
560 public void updateFileCache(boolean updateSelectedFolder, final boolean clearSelection) {
561 updateFileCache(updateSelectedFolder, clearSelection, null);
564 public void updateFileCache(boolean updateSelectedFolder, final boolean clearSelection, final String newFilename) {
565 if (!updateSelectedFolder && !GSS.get().getTreeView().getSelection().equals(GSS.get().getTreeView().getTrash()))
566 updateFileCache(clearSelection);
567 else if (GSS.get().getTreeView().getSelection() != null) {
568 final RestResource selectedResource = GSS.get().getTreeView().getSelection();
569 if (selectedResource instanceof FolderResource) {
574 updateFileCache(clearSelection);
578 private void updateFileCache(boolean clearSelection) {
579 updateFileCache(clearSelection, null);
583 * Update the file cache with data from the server.
585 * @param newFilename the new name of the previously selected file,
586 * if a rename operation has taken place
588 private void updateFileCache(boolean clearSelection, String newFilename) {
592 final RestResource folderItem = GSS.get().getTreeView().getSelection();
594 if (folderItem == null || folderItem.equals(GSS.get().getTreeView().getOthers())) {
595 setFiles(new ArrayList<FileResource>());
599 if (folderItem instanceof FolderResource) {
600 setFiles(((FolderResource) folderItem).getFiles());
603 if (folderItem instanceof SharedResource) {
604 setFiles(((SharedResource) folderItem).getFiles());
607 if (folderItem instanceof TrashResource) {
608 setFiles(((TrashResource) folderItem).getFiles());
614 * Fill the file cache with data.
616 public void setFiles(final List<FileResource> _files) {
617 /*if (_files.size() > 0 && !GSS.get().getFolders().isTrash(GSS.get().getFolders().getCurrent())) {
618 files = new ArrayList<FileResource>();
619 for (FileResource fres : _files)
620 if (!fres.isDeleted())
624 Collections.sort(files, new Comparator<FileResource>() {
627 public int compare(FileResource arg0, FileResource arg1) {
628 return arg0.getName().compareTo(arg1.getName());
632 folderFileCount = files.size();
639 * Does the list contains the requested filename
644 public boolean contains(String fileName) {
645 for (int i = 0; i < files.size(); i++)
646 if (files.get(i).getName().equals(fileName))
651 public void clearSelectedRows() {
652 Iterator<FileResource> it = selectionModel.getSelectedSet().iterator();
654 selectionModel.setSelected(it.next(),false);
657 /*for (int r : selectedRows) {
658 int row = r - startIndex;
659 styleRow(row, false);
660 makeRowNotDraggable(row+1);
662 selectedRows.clear();
663 Object sel = GSS.get().getCurrentSelection();
664 if (sel instanceof FileResource || sel instanceof List)
665 GSS.get().setCurrentSelection(null);
666 if(menuShowing != null && menuShowing.isShowing()){
675 public void selectAllRows() {
676 /*clearSelectedRows();
677 int count = folderFileCount;
680 int max = startIndex + GSS.VISIBLE_FILE_COUNT;
684 for (; i < GSS.VISIBLE_FILE_COUNT + 1; ++i) {
685 // Don't read past the end.
686 // if (i > folderFileCount)
688 if (startIndex + i > folderFileCount)
690 selectedRows.add(startIndex + i - 1);
691 styleRow(i - 1, true);
694 GSS.get().setCurrentSelection(getSelectedFiles());
695 contextMenu.setFiles(getSelectedFiles());*/
700 private void makeRowDraggable(int row){
701 /* int contextRow = getWidgetRow(contextMenu, table);
702 if (contextRow != -1)
703 table.setWidget(contextRow, 0, getFileIcon(files.get(contextRow - 1)).createImage());
704 contextMenu.setWidget(new HTML(getFileIcon(files.get(row - 1)).getHTML()));
705 table.setWidget(row, 0, contextMenu);
706 //for(int i=1;i<table.getCellCount(row);i++)
707 //GSS.get().getDragController().makeDraggable(table.getWidget(row, i));
708 table.setWidget(row, 1, new DnDSimpleFocusPanel(table.getWidget(row, 1)));
709 ((DnDSimpleFocusPanel)table.getWidget(row, 1)).setFiles(getSelectedFiles());
710 GSS.get().getDragController().makeDraggable(table.getWidget(row, 1));*/
712 private void makeRowNotDraggable(int row){
713 /*if(table.getWidget(row, 1) instanceof DnDSimpleFocusPanel){
714 ((DnDSimpleFocusPanel)table.getWidget(row, 1)).setFiles(null);
715 GSS.get().getDragController().makeNotDraggable(table.getWidget(row, 1));
716 table.setWidget(row, 1, new DnDSimpleFocusPanel(((DnDSimpleFocusPanel)table.getWidget(row, 1)).getWidget()));
722 private int getWidgetRow(Widget widget, Grid grid) {
723 /*for (int row = 0; row < grid.getRowCount(); row++)
724 for (int col = 0; col < grid.getCellCount(row); col++) {
725 Widget w = table.getWidget(row, col);
733 private void sortFiles(final String sortingProperty, final boolean sortingType){
734 Collections.sort(files, new Comparator<FileResource>() {
737 public int compare(FileResource arg0, FileResource arg1) {
738 AbstractImagePrototype descPrototype = AbstractImagePrototype.create(images.desc());
739 AbstractImagePrototype ascPrototype = AbstractImagePrototype.create(images.asc());
741 if (sortingProperty.equals("version")) {
742 return arg0.getVersion().compareTo(arg1.getVersion());
743 } else if (sortingProperty.equals("owner")) {
744 return arg0.getOwner().compareTo(arg1.getOwner());
745 } else if (sortingProperty.equals("date")) {
746 return arg0.getModificationDate().compareTo(arg1.getModificationDate());
747 } else if (sortingProperty.equals("size")) {
748 return arg0.getContentLength().compareTo(arg1.getContentLength());
749 } else if (sortingProperty.equals("name")) {
750 return arg0.getName().compareTo(arg1.getName());
751 } else if (sortingProperty.equals("path")) {
752 return arg0.getUri().compareTo(arg1.getUri());
754 return arg0.getName().compareTo(arg1.getName());
757 else if (sortingProperty.equals("version")) {
759 return arg1.getVersion().compareTo(arg0.getVersion());
760 } else if (sortingProperty.equals("owner")) {
762 return arg1.getOwner().compareTo(arg0.getOwner());
763 } else if (sortingProperty.equals("date")) {
765 return arg1.getModificationDate().compareTo(arg0.getModificationDate());
766 } else if (sortingProperty.equals("size")) {
768 return arg1.getContentLength().compareTo(arg0.getContentLength());
769 } else if (sortingProperty.equals("name")) {
771 return arg1.getName().compareTo(arg0.getName());
772 } else if (sortingProperty.equals("path")) {
774 return arg1.getUri().compareTo(arg0.getUri());
777 return arg1.getName().compareTo(arg0.getName());
784 final class FileValueUpdater implements ValueUpdater<String>{
785 private String property;
786 private SortableHeader header;
790 public FileValueUpdater(SortableHeader header,String property) {
791 this.property=property;
795 public void update(String value) {
796 header.setSorted(true);
797 header.toggleReverseSort();
799 for (SortableHeader otherHeader : allHeaders) {
800 if (otherHeader != header) {
801 otherHeader.setSorted(false);
802 otherHeader.setReverseSort(true);
805 celltable.redrawHeaders();
806 sortFiles(property, header.getReverseSort());
807 FileList.this.update(true);
812 * Creates a new ArrayList<FileResources> from the given files ArrayList
813 * in order that the input files remain untouched
814 * and continues to find user's full names of each FileResource element
815 * in the new ArrayList
819 private void copyListAndContinue(List<FileResource> filesInput){
820 List<FileResource> copiedFiles = new ArrayList<FileResource>();
821 for(FileResource file : filesInput) {
822 copiedFiles.add(file);
824 handleFullNames(copiedFiles);
828 * Examines whether or not the user's full name exists in the
829 * userFullNameMap in the GSS.java for every element of the input list.
830 * If the user's full name does not exist in the map then a command is being made.
834 private void handleFullNames(List<FileResource> filesInput){
835 if(filesInput.size() == 0){
840 if(GSS.get().findUserFullName(filesInput.get(0).getOwner()) == null){
841 findFullNameAndUpdate(filesInput);
845 if(filesInput.size() >= 1){
846 filesInput.remove(filesInput.get(0));
847 if(filesInput.isEmpty()){
850 handleFullNames(filesInput);
856 * Makes a command to search for full name from a given username.
857 * Only after the completion of the command the celltable is shown
858 * or the search for the next full name continues.
862 private void findFullNameAndUpdate(final List<FileResource> filesInput){
863 String aUserName = filesInput.get(0).getOwner();
864 String path = GSS.get().getApiPath() + "users/" + aUserName;
866 GetCommand<UserSearchResource> gg = new GetCommand<UserSearchResource>(UserSearchResource.class, path, false,null) {
868 public void onComplete() {
869 final UserSearchResource result = getResult();
870 for (UserResource user : result.getUsers()){
871 String username = user.getUsername();
872 String userFullName = user.getName();
873 GSS.get().putUserToMap(username, userFullName);
874 if(filesInput.size() >= 1){
875 filesInput.remove(filesInput.get(0));
876 if(filesInput.isEmpty()){
879 handleFullNames(filesInput);
885 public void onError(Throwable t) {
887 GSS.get().displayError("Unable to fetch user's full name from the given username " + filesInput.get(0).getOwner());
888 if(filesInput.size() >= 1){
889 filesInput.remove(filesInput.get(0));
890 handleFullNames(filesInput);
894 DeferredCommand.addCommand(gg);
898 * Shows the files in the cellTable
901 private void showCellTable(){
902 celltable.setRowCount(files.size());
903 celltable.setRowData(0,files);
904 celltable.redrawHeaders();