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;
21 import static com.google.gwt.query.client.GQuery.$;
22 import gr.ebs.gss.client.rest.GetCommand;
23 import gr.ebs.gss.client.rest.RestCommand;
24 import gr.ebs.gss.client.rest.resource.FileResource;
25 import gr.ebs.gss.client.rest.resource.RestResource;
26 import gr.ebs.gss.client.rest.resource.RestResourceWrapper;
27 import gr.ebs.gss.client.rest.resource.SharedResource;
28 import gr.ebs.gss.client.rest.resource.TrashResource;
29 import gr.ebs.gss.client.rest.resource.UserResource;
30 import gr.ebs.gss.client.rest.resource.UserSearchResource;
31 import gwtquery.plugins.draggable.client.DraggableOptions;
32 import gwtquery.plugins.draggable.client.StopDragException;
33 import gwtquery.plugins.draggable.client.DraggableOptions.DragFunction;
34 import gwtquery.plugins.draggable.client.DraggableOptions.RevertOption;
35 import gwtquery.plugins.draggable.client.events.DragContext;
36 import gwtquery.plugins.draggable.client.events.DragStartEvent;
37 import gwtquery.plugins.draggable.client.events.DragStopEvent;
38 import gwtquery.plugins.draggable.client.events.DragStartEvent.DragStartEventHandler;
39 import gwtquery.plugins.draggable.client.events.DragStopEvent.DragStopEventHandler;
40 import gwtquery.plugins.droppable.client.gwt.DragAndDropCellTable;
41 import gwtquery.plugins.droppable.client.gwt.DragAndDropColumn;
43 import java.util.ArrayList;
44 import java.util.Collections;
45 import java.util.Comparator;
46 import java.util.Iterator;
47 import java.util.List;
49 import com.google.gwt.cell.client.AbstractCell;
50 import com.google.gwt.cell.client.ImageResourceCell;
51 import com.google.gwt.cell.client.SafeHtmlCell;
52 import com.google.gwt.cell.client.TextCell;
53 import com.google.gwt.cell.client.ValueUpdater;
54 import com.google.gwt.core.client.GWT;
55 import com.google.gwt.core.client.Scheduler;
56 import com.google.gwt.core.client.Scheduler.RepeatingCommand;
57 import com.google.gwt.dom.client.Style.Cursor;
58 import com.google.gwt.http.client.URL;
59 import com.google.gwt.i18n.client.DateTimeFormat;
60 import com.google.gwt.resources.client.ClientBundle;
61 import com.google.gwt.resources.client.ImageResource;
62 import com.google.gwt.safehtml.client.SafeHtmlTemplates;
63 import com.google.gwt.safehtml.shared.SafeHtml;
64 import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
65 import com.google.gwt.safehtml.shared.SafeHtmlUtils;
66 import com.google.gwt.user.cellview.client.CellTable;
67 import com.google.gwt.user.cellview.client.Column;
68 import com.google.gwt.user.cellview.client.TextColumn;
69 import com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy.KeyboardSelectionPolicy;
70 import com.google.gwt.user.client.DOM;
71 import com.google.gwt.user.client.DeferredCommand;
72 import com.google.gwt.user.client.Event;
73 import com.google.gwt.user.client.Window;
74 import com.google.gwt.user.client.ui.AbstractImagePrototype;
75 import com.google.gwt.user.client.ui.Composite;
76 import com.google.gwt.user.client.ui.HTML;
77 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
78 import com.google.gwt.user.client.ui.HorizontalPanel;
79 import com.google.gwt.user.client.ui.VerticalPanel;
80 import com.google.gwt.view.client.MultiSelectionModel;
81 import com.google.gwt.view.client.ProvidesKey;
82 import com.google.gwt.view.client.SelectionChangeEvent;
83 import com.google.gwt.view.client.SelectionChangeEvent.Handler;
86 * A composite that displays the list of files in a particular folder.
88 public class FileList extends Composite {
90 interface TableResources extends DragAndDropCellTable.Resources {
91 @Source({CellTable.Style.DEFAULT_CSS, "GssCellTable.css"})
92 TableStyle cellTableStyle();
95 static interface Templates extends SafeHtmlTemplates {
96 Templates INSTANCE = GWT.create(Templates.class);
98 @Template("<div id='dragHelper' style='border:1px solid black; background-color:#ffffff; color:black; width:150px;z-index:100'></div>")
99 SafeHtml outerHelper();
104 * The styles applied to the table.
106 interface TableStyle extends CellTable.Style {
109 private String showingStats = "";
111 private int startIndex = 0;
114 * A constant that denotes the completion of an IncrementalCommand.
116 public static final boolean DONE = false;
120 private final DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a");
123 * Specifies that the images available for this composite will be the ones
124 * available in FileContextMenu.
126 public interface Images extends ClientBundle,FileContextMenu.Images, CellTreeView.Images {
128 @Source("gr/ebs/gss/resources/blank.gif")
129 ImageResource blank();
131 @Source("gr/ebs/gss/resources/asc.png")
134 @Source("gr/ebs/gss/resources/desc.png")
135 ImageResource desc();
137 @Source("gr/ebs/gss/resources/mimetypes/document_shared.png")
138 ImageResource documentShared();
140 @Source("gr/ebs/gss/resources/mimetypes/kcmfontinst.png")
141 ImageResource wordprocessor();
143 @Source("gr/ebs/gss/resources/mimetypes/log.png")
144 ImageResource spreadsheet();
146 @Source("gr/ebs/gss/resources/mimetypes/kpresenter_kpr.png")
147 ImageResource presentation();
149 @Source("gr/ebs/gss/resources/mimetypes/acroread.png")
152 @Source("gr/ebs/gss/resources/mimetypes/image.png")
153 ImageResource image();
155 @Source("gr/ebs/gss/resources/mimetypes/video2.png")
156 ImageResource video();
158 @Source("gr/ebs/gss/resources/mimetypes/knotify.png")
159 ImageResource audio();
161 @Source("gr/ebs/gss/resources/mimetypes/html.png")
162 ImageResource html();
164 @Source("gr/ebs/gss/resources/mimetypes/txt.png")
167 @Source("gr/ebs/gss/resources/mimetypes/ark2.png")
170 @Source("gr/ebs/gss/resources/mimetypes/kcmfontinst_shared.png")
171 ImageResource wordprocessorShared();
173 @Source("gr/ebs/gss/resources/mimetypes/log_shared.png")
174 ImageResource spreadsheetShared();
176 @Source("gr/ebs/gss/resources/mimetypes/kpresenter_kpr_shared.png")
177 ImageResource presentationShared();
179 @Source("gr/ebs/gss/resources/mimetypes/acroread_shared.png")
180 ImageResource pdfShared();
182 @Source("gr/ebs/gss/resources/mimetypes/image_shared.png")
183 ImageResource imageShared();
185 @Source("gr/ebs/gss/resources/mimetypes/video2_shared.png")
186 ImageResource videoShared();
188 @Source("gr/ebs/gss/resources/mimetypes/knotify_shared.png")
189 ImageResource audioShared();
191 @Source("gr/ebs/gss/resources/mimetypes/html_shared.png")
192 ImageResource htmlShared();
194 @Source("gr/ebs/gss/resources/mimetypes/txt_shared.png")
195 ImageResource txtShared();
197 @Source("gr/ebs/gss/resources/mimetypes/ark2_shared.png")
198 ImageResource zipShared();
202 DragStopEventHandler dragStop = new DragStopEventHandler() {
205 public void onDragStop(DragStopEvent event) {
206 GWT.log("DRAG STOPPED");
211 private static class ContactCell extends AbstractCell<gr.ebs.gss.client.rest.resource.FileResource> {
214 * The html of the image used for contacts.
217 private final String imageHtml;
219 public ContactCell(ImageResource image) {
220 this.imageHtml = AbstractImagePrototype.create(image).getHTML();
228 public void render(Context context, FileResource value, SafeHtmlBuilder sb) {
229 // Value can be null, so do a null check..
234 sb.appendHtmlConstant("<table>");
236 // Add the contact image.
237 sb.appendHtmlConstant("<tr><td rowspan='3'>");
238 sb.appendHtmlConstant(imageHtml);
239 sb.appendHtmlConstant("</td>");
241 // Add the name and address.
242 sb.appendHtmlConstant("<td style='font-size:95%;'>");
243 sb.appendEscaped(value.getName());
244 sb.appendHtmlConstant("</td></tr><tr><td>");
245 sb.appendEscaped(value.getFileSizeAsString());
246 sb.appendHtmlConstant("</td></tr></table>");
252 * Retrieve the celltable.
254 * @return the celltable
256 public DragAndDropCellTable<FileResource> getCelltable() {
260 * A label with the number of files in this folder.
262 private HTML countLabel = new HTML();
265 * The table widget with the file list.
267 //private FileTable table = new FileTable(GSS.VISIBLE_FILE_COUNT + 1, 8);
270 * The navigation bar for paginating the results.
272 private HorizontalPanel navBar = new HorizontalPanel();
275 * The number of files in this folder.
282 long folderTotalSize;
285 * A cache of the files in the list.
287 private List<FileResource> files;
290 * The widget's image bundle.
292 private final Images images;
295 private FileContextMenu menuShowing;
296 private DragAndDropCellTable<FileResource> celltable;
297 private final MultiSelectionModel<FileResource> selectionModel;
298 private final List<SortableHeader> allHeaders = new ArrayList<SortableHeader>();
299 SortableHeader nameHeader;
301 * Construct the file list widget. This entails setting up the widget
302 * layout, fetching the number of files in the current folder from the
303 * server and filling the local file cache of displayed files with data from
304 * the server, as well.
308 public FileList(Images _images) {
310 DragAndDropCellTable.Resources resources = GWT.create(TableResources.class);
313 // Create the 'navigation' bar at the upper-right.
314 HorizontalPanel innerNavBar = new HorizontalPanel();
315 innerNavBar.setStyleName("gss-ListNavBar");
316 innerNavBar.setSpacing(8);
317 innerNavBar.add(countLabel);
318 navBar.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
319 navBar.add(innerNavBar);
320 navBar.setWidth("100%");
321 ProvidesKey<FileResource> keyProvider = new ProvidesKey<FileResource>(){
324 public Object getKey(FileResource item) {
325 return item.getUri();
329 final DragAndDropColumn<FileResource,SafeHtml> nameColumn = new DragAndDropColumn<FileResource,SafeHtml>(new SafeHtmlCell()) {
333 public SafeHtml getValue(FileResource object) {
334 SafeHtmlBuilder sb = new SafeHtmlBuilder();
335 if (object.getContentType().endsWith("png") || object.getContentType().endsWith("gif") || object.getContentType().endsWith("jpeg") ){
337 sb.appendEscaped(object.getName());
338 sb.appendHtmlConstant(" <a href='" +
339 GSS.get().getTopPanel().getFileMenu().getDownloadURL(object) +
340 "' title='" + object.getOwner() + " : " + object.getPath() + object.getName() +
341 "' rel='lytebox[mnf]' " +
342 "onclick='myLytebox.start(this, false, false); return false;'>" +
348 sb.appendEscaped(object.getName());
349 return sb.toSafeHtml();
354 initDragOperation(nameColumn);
355 celltable = new DragAndDropCellTable<FileResource>(100,resources,keyProvider){
357 protected void onBrowserEvent2(Event event) {
358 /*if (DOM.eventGetType((Event) event) == Event.ONMOUSEDOWN && DOM.eventGetButton((Event) event) == NativeEvent.BUTTON_RIGHT){
359 fireClickEvent((Element) event.getEventTarget().cast());
361 super.onBrowserEvent2(event);
365 celltable.addDragStopHandler(dragStop);
366 celltable.addDragStartHandler(new DragStartEventHandler() {
368 public void onDragStart(DragStartEvent event) {
369 FileResource value = event.getDraggableData();
370 com.google.gwt.dom.client.Element helper = event.getHelper();
371 SafeHtmlBuilder sb = new SafeHtmlBuilder();
372 sb.appendHtmlConstant("<b>");
373 sb.appendEscaped(value.getName());
374 sb.appendHtmlConstant("</b>");
375 helper.setInnerHTML(sb.toSafeHtml().asString());
379 Column<FileResource, ImageResource> status = new Column<FileResource, ImageResource>(new ImageResourceCell()) {
381 public ImageResource getValue(FileResource entity) {
382 return getFileIcon(entity);
385 celltable.addColumn(status,"");
388 celltable.addColumn(nameColumn,nameHeader = new SortableHeader("Name"));
389 allHeaders.add(nameHeader);
390 nameHeader.setSorted(true);
391 nameHeader.toggleReverseSort();
392 nameHeader.setUpdater(new FileValueUpdater(nameHeader, "name"));
393 celltable.redrawHeaders();
394 SortableHeader aheader;
395 celltable.addColumn(new TextColumn<FileResource>() {
397 public String getValue(FileResource object) {
398 return GSS.get().findUserFullName(object.getOwner());
400 },aheader = new SortableHeader("Owner"));
401 allHeaders.add(aheader);
402 aheader.setUpdater(new FileValueUpdater(aheader, "owner"));
403 celltable.addColumn(new TextColumn<FileResource>() {
405 public String getValue(FileResource object) {
406 // TODO Auto-generated method stub
407 return object.getPath();
409 },aheader = new SortableHeader("Path"));
410 allHeaders.add(aheader);
411 aheader.setUpdater(new FileValueUpdater(aheader, "path"));
412 celltable.addColumn(new TextColumn<FileResource>() {
414 public String getValue(FileResource object) {
415 // TODO Auto-generated method stub
416 return object.getVersion().toString();
418 },aheader = new SortableHeader("Version"));
419 allHeaders.add(aheader);
420 aheader.setUpdater(new FileValueUpdater(aheader, "version"));
421 celltable.addColumn(new TextColumn<FileResource>() {
423 public String getValue(FileResource object) {
424 // TODO Auto-generated method stub
425 return object.getFileSizeAsString();
427 },aheader = new SortableHeader("Size"));
428 allHeaders.add(aheader);
429 aheader.setUpdater(new FileValueUpdater(aheader, "size"));
430 celltable.addColumn(new TextColumn<FileResource>() {
432 public String getValue(FileResource object) {
433 return formatter.format(object.getModificationDate());
435 },aheader = new SortableHeader("Last Modified"));
436 allHeaders.add(aheader);
437 aheader.setUpdater(new FileValueUpdater(aheader, "date"));
439 initWidget(celltable);
440 setStyleName("gss-List");
441 selectionModel = new MultiSelectionModel<FileResource>();
444 Handler selectionHandler = new SelectionChangeEvent.Handler() {
446 public void onSelectionChange(com.google.gwt.view.client.SelectionChangeEvent event) {
447 if(getSelectedFiles().size()==1)
448 GSS.get().setCurrentSelection(getSelectedFiles().get(0));
450 GSS.get().setCurrentSelection(getSelectedFiles());
451 //contextMenu.setFiles(getSelectedFiles());
454 selectionModel.addSelectionChangeHandler(selectionHandler);
456 celltable.setSelectionModel(selectionModel,GSSSelectionEventManager.<FileResource>createDefaultManager());
457 celltable.setPageSize(GSS.VISIBLE_FILE_COUNT);
458 celltable.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
459 Scheduler.get().scheduleIncremental(new RepeatingCommand() {
462 public boolean execute() {
463 return fetchRootFolder();
466 sinkEvents(Event.ONCONTEXTMENU);
467 sinkEvents(Event.ONMOUSEUP);
468 sinkEvents(Event.ONMOUSEDOWN);
469 sinkEvents(Event.ONCLICK);
470 sinkEvents(Event.ONKEYDOWN);
471 sinkEvents(Event.ONDBLCLICK);
472 GSS.preventIESelection();
475 //public native void fireClickEvent(Element element) /*-{
476 // var evObj = $doc.createEvent('MouseEvents');
477 //evObj.initEvent('click', true, true);
478 //element.dispatchEvent(evObj);
481 public List<FileResource> getSelectedFiles() {
482 return new ArrayList<FileResource>(selectionModel.getSelectedSet());
485 private void initDragOperation(DragAndDropColumn<?, ?> column) {
487 // retrieve draggableOptions on the column
488 DraggableOptions draggableOptions = column.getDraggableOptions();
489 // use template to construct the helper. The content of the div will be set
491 draggableOptions.setHelper($(Templates.INSTANCE.outerHelper().asString()));
492 //draggableOptions.setZIndex(100);
493 // opacity of the helper
494 draggableOptions.setAppendTo("body");
495 //draggableOptions.setOpacity((float) 0.8);
496 draggableOptions.setContainment("document");
497 // cursor to use during the drag operation
498 draggableOptions.setCursor(Cursor.MOVE);
499 // set the revert option
500 draggableOptions.setRevert(RevertOption.ON_INVALID_DROP);
501 // prevents dragging when user click on the category drop-down list
502 draggableOptions.setCancel("select");
504 draggableOptions.setOnBeforeDragStart(new DragFunction() {
507 public void f(DragContext context) {
508 FileResource value = context.getDraggableData();
509 if(!selectionModel.isSelected(value)){
510 throw new StopDragException();
519 public void onBrowserEvent(Event event) {
521 if (files == null || files.size() == 0) {
522 if (DOM.eventGetType(event) == Event.ONCONTEXTMENU && getSelectedFiles().size() == 0) {
523 menuShowing = new FileContextMenu(images, false, true);
524 menuShowing=menuShowing.onEmptyEvent(event);
528 if (DOM.eventGetType(event) == Event.ONCONTEXTMENU && getSelectedFiles().size() != 0) {
529 GWT.log("*****GOING TO SHOW CONTEXT MENU ****", null);
530 menuShowing = new FileContextMenu(images, false, false);
531 menuShowing=menuShowing.onEvent(event);
532 } else if (DOM.eventGetType(event) == Event.ONCONTEXTMENU && getSelectedFiles().size() == 0) {
533 menuShowing = new FileContextMenu(images, false, true);
534 menuShowing=menuShowing.onEmptyEvent(event);
535 } else if (DOM.eventGetType(event) == Event.ONDBLCLICK)
536 if (getSelectedFiles().size() == 1) {
538 FileResource file = getSelectedFiles().get(0);
539 String dateString = RestCommand.getDate();
540 String resource = file.getUri().substring(app.getApiPath().length() - 1, file.getUri().length());
541 String sig = app.getCurrentUserResource().getUsername() + " " +
542 RestCommand.calculateSig("GET", dateString, resource,
543 RestCommand.base64decode(app.getToken()));
544 Window.open(file.getUri() + "?Authorization=" + URL.encodeComponent(sig) + "&Date=" + URL.encodeComponent(dateString), "_blank", "");
545 event.preventDefault();
548 super.onBrowserEvent(event);
552 * Retrieve the root folder for the current user.
554 * @return true if the retrieval was successful
556 protected boolean fetchRootFolder() {
557 UserResource user = GSS.get().getCurrentUserResource();
560 // Update cache and clear selection.
561 updateFileCache(true);
567 * Update the display of the file list.
569 void update(boolean sort) {
570 int count = folderFileCount;
571 int max = startIndex + GSS.VISIBLE_FILE_COUNT;
576 copyListAndContinue(files);
577 for(FileResource f : files){
578 folderTotalSize += f.getContentLength();
580 if (folderFileCount == 0) {
581 showingStats = "no files";
582 } else if (folderFileCount < GSS.VISIBLE_FILE_COUNT) {
583 if (folderFileCount == 1)
584 showingStats = "1 file";
586 showingStats = folderFileCount + " files";
587 showingStats += " (" + FileResource.getFileSizeAsString(folderTotalSize) + ")";
589 showingStats = "" + (startIndex + 1) + " - " + max + " of " + count + " files" + " (" + FileResource.getFileSizeAsString(folderTotalSize) + ")";
591 updateCurrentlyShowingStats();
596 * Return the proper icon based on the MIME type of the file.
601 private ImageResource getFileIcon(FileResource file) {
602 String mimetype = file.getContentType();
603 boolean shared = false;
604 //TODO: FETCH USER OF OTHER FOLDER ITEM
605 //if(GSS.get().getTreeView().getSelection()!=null && (GSS.get().getTreeView().getSelection() instanceof OtherUserResource || GSS.get().getTreeView().getSelection() instanceof OthersFolderResource))
606 /*Folders folders = GSS.get().getFolders();
607 if(folders.getCurrent() != null && folders.isOthersSharedItem(folders.getCurrent())){
608 DnDTreeItem otherUser = (DnDTreeItem) folders.getUserOfSharedItem(folders.getCurrent());
612 String uname = otherUser.getOtherUserResource().getUsername();
614 uname = ((DnDTreeItem)folders.getSharesItem()).getOthersResource().getUsernameOfUri(otherUser.getOtherUserResource().getUri());
616 shared = file.isShared();
620 shared = file.isShared();
621 if (mimetype == null)
622 return shared ? images.documentShared() : images.document();
623 mimetype = mimetype.toLowerCase();
624 if (mimetype.startsWith("application/pdf"))
625 return shared ? images.pdfShared() : images.pdf();
626 else if (mimetype.endsWith("excel"))
627 return shared ? images.spreadsheetShared() : images.spreadsheet();
628 else if (mimetype.endsWith("msword"))
629 return shared ? images.wordprocessorShared() : images.wordprocessor();
630 else if (mimetype.endsWith("powerpoint"))
631 return shared ? images.presentationShared() : images.presentation();
632 else if (mimetype.startsWith("application/zip") ||
633 mimetype.startsWith("application/gzip") ||
634 mimetype.startsWith("application/x-gzip") ||
635 mimetype.startsWith("application/x-tar") ||
636 mimetype.startsWith("application/x-gtar"))
637 return shared ? images.zipShared() : images.zip();
638 else if (mimetype.startsWith("text/html"))
639 return shared ? images.htmlShared() : images.html();
640 else if (mimetype.startsWith("text/plain"))
641 return shared ? images.txtShared() : images.txt();
642 else if (mimetype.startsWith("image/"))
643 return shared ? images.imageShared() : images.image();
644 else if (mimetype.startsWith("video/"))
645 return shared ? images.videoShared() : images.video();
646 else if (mimetype.startsWith("audio/"))
647 return shared ? images.audioShared() : images.audio();
648 return shared ? images.documentShared() : images.document();
652 * Update status panel with currently showing file stats.
654 public void updateCurrentlyShowingStats() {
655 GSS.get().getStatusPanel().updateCurrentlyShowing(showingStats);
658 public void updateFileCache(boolean updateSelectedFolder, final boolean clearSelection) {
659 updateFileCache(updateSelectedFolder, clearSelection, null);
662 public void updateFileCache(boolean updateSelectedFolder, final boolean clearSelection, final String newFilename) {
663 if (!updateSelectedFolder && !GSS.get().getTreeView().getSelection().equals(GSS.get().getTreeView().getTrash()))
664 updateFileCache(clearSelection);
665 else if (GSS.get().getTreeView().getSelection() != null) {
668 updateFileCache(clearSelection);
672 private void updateFileCache(boolean clearSelection) {
673 updateFileCache(clearSelection, null);
677 * Update the file cache with data from the server.
679 * @param newFilename the new name of the previously selected file,
680 * if a rename operation has taken place
682 private void updateFileCache(boolean clearSelection, String newFilename) {
686 final RestResource folderItem = GSS.get().getTreeView().getSelection();
688 if (folderItem == null || folderItem.equals(GSS.get().getTreeView().getOthers())) {
689 setFiles(new ArrayList<FileResource>());
693 if (folderItem instanceof RestResourceWrapper) {
694 setFiles(((RestResourceWrapper) folderItem).getResource().getFiles());
697 if (folderItem instanceof SharedResource) {
698 setFiles(((SharedResource) folderItem).getFiles());
701 if (folderItem instanceof TrashResource) {
702 setFiles(((TrashResource) folderItem).getFiles());
708 * Fill the file cache with data.
710 public void setFiles(final List<FileResource> _files) {
711 if (_files.size() > 0 && ! (GSS.get().getTreeView().getSelection() instanceof TrashResource)) {
712 files = new ArrayList<FileResource>();
713 for (FileResource fres : _files)
714 if (!fres.isDeleted())
719 Collections.sort(files, new Comparator<FileResource>() {
722 public int compare(FileResource arg0, FileResource arg1) {
723 return arg0.getName().compareTo(arg1.getName());
727 folderFileCount = files.size();
734 * Does the list contains the requested filename
739 public boolean contains(String fileName) {
740 for (int i = 0; i < files.size(); i++)
741 if (files.get(i).getName().equals(fileName))
746 public void clearSelectedRows() {
747 Iterator<FileResource> it = selectionModel.getSelectedSet().iterator();
749 selectionModel.setSelected(it.next(),false);
756 public void selectAllRows() {
757 Iterator<FileResource> it = selectionModel.getSelectedSet().iterator();
759 selectionModel.setSelected(it.next(),true);
766 private void sortFiles(final String sortingProperty, final boolean sortingType){
767 Collections.sort(files, new Comparator<FileResource>() {
770 public int compare(FileResource arg0, FileResource arg1) {
771 AbstractImagePrototype descPrototype = AbstractImagePrototype.create(images.desc());
772 AbstractImagePrototype ascPrototype = AbstractImagePrototype.create(images.asc());
774 if (sortingProperty.equals("version")) {
775 return arg0.getVersion().compareTo(arg1.getVersion());
776 } else if (sortingProperty.equals("owner")) {
777 return arg0.getOwner().compareTo(arg1.getOwner());
778 } else if (sortingProperty.equals("date")) {
779 return arg0.getModificationDate().compareTo(arg1.getModificationDate());
780 } else if (sortingProperty.equals("size")) {
781 return arg0.getContentLength().compareTo(arg1.getContentLength());
782 } else if (sortingProperty.equals("name")) {
783 return arg0.getName().compareTo(arg1.getName());
784 } else if (sortingProperty.equals("path")) {
785 return arg0.getUri().compareTo(arg1.getUri());
787 return arg0.getName().compareTo(arg1.getName());
790 else if (sortingProperty.equals("version")) {
792 return arg1.getVersion().compareTo(arg0.getVersion());
793 } else if (sortingProperty.equals("owner")) {
795 return arg1.getOwner().compareTo(arg0.getOwner());
796 } else if (sortingProperty.equals("date")) {
798 return arg1.getModificationDate().compareTo(arg0.getModificationDate());
799 } else if (sortingProperty.equals("size")) {
801 return arg1.getContentLength().compareTo(arg0.getContentLength());
802 } else if (sortingProperty.equals("name")) {
804 return arg1.getName().compareTo(arg0.getName());
805 } else if (sortingProperty.equals("path")) {
807 return arg1.getUri().compareTo(arg0.getUri());
810 return arg1.getName().compareTo(arg0.getName());
817 final class FileValueUpdater implements ValueUpdater<String>{
818 private String property;
819 private SortableHeader header;
823 public FileValueUpdater(SortableHeader header,String property) {
824 this.property=property;
828 public void update(String value) {
829 header.setSorted(true);
830 header.toggleReverseSort();
832 for (SortableHeader otherHeader : allHeaders) {
833 if (otherHeader != header) {
834 otherHeader.setSorted(false);
835 otherHeader.setReverseSort(true);
838 celltable.redrawHeaders();
839 sortFiles(property, header.getReverseSort());
840 FileList.this.update(true);
845 * Creates a new ArrayList<FileResources> from the given files ArrayList
846 * in order that the input files remain untouched
847 * and continues to find user's full names of each FileResource element
848 * in the new ArrayList
852 private void copyListAndContinue(List<FileResource> filesInput){
853 List<FileResource> copiedFiles = new ArrayList<FileResource>();
854 for(FileResource file : filesInput) {
855 copiedFiles.add(file);
857 handleFullNames(copiedFiles);
861 * Examines whether or not the user's full name exists in the
862 * userFullNameMap in the GSS.java for every element of the input list.
863 * If the user's full name does not exist in the map then a command is being made.
867 private void handleFullNames(List<FileResource> filesInput){
868 if(filesInput.size() == 0){
873 if(GSS.get().findUserFullName(filesInput.get(0).getOwner()) == null){
874 findFullNameAndUpdate(filesInput);
878 if(filesInput.size() >= 1){
879 filesInput.remove(filesInput.get(0));
880 if(filesInput.isEmpty()){
883 handleFullNames(filesInput);
889 * Makes a command to search for full name from a given username.
890 * Only after the completion of the command the celltable is shown
891 * or the search for the next full name continues.
895 private void findFullNameAndUpdate(final List<FileResource> filesInput){
896 String aUserName = filesInput.get(0).getOwner();
897 String path = GSS.get().getApiPath() + "users/" + aUserName;
899 GetCommand<UserSearchResource> gg = new GetCommand<UserSearchResource>(UserSearchResource.class, path, false,null) {
901 public void onComplete() {
902 final UserSearchResource result = getResult();
903 for (UserResource user : result.getUsers()){
904 String username = user.getUsername();
905 String userFullName = user.getName();
906 GSS.get().putUserToMap(username, userFullName);
907 if(filesInput.size() >= 1){
908 filesInput.remove(filesInput.get(0));
909 if(filesInput.isEmpty()){
912 handleFullNames(filesInput);
918 public void onError(Throwable t) {
920 GSS.get().displayError("Unable to fetch user's full name from the given username " + filesInput.get(0).getOwner());
921 if(filesInput.size() >= 1){
922 filesInput.remove(filesInput.get(0));
923 handleFullNames(filesInput);
927 DeferredCommand.addCommand(gg);
931 * Shows the files in the cellTable
934 private void showCellTable(){
935 celltable.setRowCount(files.size());
936 celltable.setRowData(0,files);
937 celltable.redrawHeaders();