2 * Copyright 2007, 2008, 2009 Electronic Business Systems Ltd.
\r
4 * This file is part of GSS.
\r
6 * GSS is free software: you can redistribute it and/or modify
\r
7 * it under the terms of the GNU General Public License as published by
\r
8 * the Free Software Foundation, either version 3 of the License, or
\r
9 * (at your option) any later version.
\r
11 * GSS is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with GSS. If not, see <http://www.gnu.org/licenses/>.
\r
19 package gr.ebs.gss.client;
\r
21 import gr.ebs.gss.client.dnd.DnDFocusPanel;
\r
22 import gr.ebs.gss.client.dnd.DnDTreeItem;
\r
23 import gr.ebs.gss.client.rest.AbstractRestCommand;
\r
24 import gr.ebs.gss.client.rest.ExecuteGet;
\r
25 import gr.ebs.gss.client.rest.RestException;
\r
26 import gr.ebs.gss.client.rest.resource.FileResource;
\r
27 import gr.ebs.gss.client.rest.resource.FolderResource;
\r
28 import gr.ebs.gss.client.rest.resource.OtherUserResource;
\r
29 import gr.ebs.gss.client.rest.resource.SharedResource;
\r
30 import gr.ebs.gss.client.rest.resource.TrashResource;
\r
31 import gr.ebs.gss.client.rest.resource.UserResource;
\r
33 import java.util.ArrayList;
\r
34 import java.util.Collections;
\r
35 import java.util.Comparator;
\r
36 import java.util.List;
\r
38 import com.google.gwt.core.client.GWT;
\r
39 import com.google.gwt.http.client.URL;
\r
40 import com.google.gwt.i18n.client.DateTimeFormat;
\r
41 import com.google.gwt.user.client.DOM;
\r
42 import com.google.gwt.user.client.DeferredCommand;
\r
43 import com.google.gwt.user.client.Event;
\r
44 import com.google.gwt.user.client.IncrementalCommand;
\r
45 import com.google.gwt.user.client.Window;
\r
46 import com.google.gwt.user.client.ui.AbstractImagePrototype;
\r
47 import com.google.gwt.user.client.ui.ClickListener;
\r
48 import com.google.gwt.user.client.ui.Composite;
\r
49 import com.google.gwt.user.client.ui.Grid;
\r
50 import com.google.gwt.user.client.ui.HTML;
\r
51 import com.google.gwt.user.client.ui.HasHorizontalAlignment;
\r
52 import com.google.gwt.user.client.ui.HorizontalPanel;
\r
53 import com.google.gwt.user.client.ui.SourcesTableEvents;
\r
54 import com.google.gwt.user.client.ui.TableListener;
\r
55 import com.google.gwt.user.client.ui.TreeItem;
\r
56 import com.google.gwt.user.client.ui.Widget;
\r
59 * A composite that displays the list of files in a particular folder.
\r
61 public class FileList extends Composite implements TableListener, ClickListener {
\r
63 private HTML prevButton = new HTML("<a href='javascript:;'>< Previous</a>", true);
\r
65 private HTML nextButton = new HTML("<a href='javascript:;'>Next ></a>", true);
\r
67 private String showingStats = "";
\r
69 private int startIndex = 0;
\r
72 * A constant that denotes the completion of an IncrementalCommand.
\r
74 public static final boolean DONE = false;
\r
76 private boolean clickControl = false;
\r
78 private boolean clickShift = false;
\r
80 private int firstShift = -1;
\r
82 private ArrayList<Integer> selectedRows = new ArrayList<Integer>();
\r
85 * The context menu for the selected file.
\r
87 final DnDFocusPanel contextMenu;
\r
90 * Specifies that the images available for this composite will be the ones
\r
91 * available in FileContextMenu.
\r
93 public interface Images extends FileContextMenu.Images, Folders.Images {
\r
95 @Resource("gr/ebs/gss/resources/blank.gif")
\r
96 AbstractImagePrototype blank();
\r
98 @Resource("gr/ebs/gss/resources/asc.png")
\r
99 AbstractImagePrototype asc();
\r
101 @Resource("gr/ebs/gss/resources/desc.png")
\r
102 AbstractImagePrototype desc();
\r
106 * A label with the number of files in this folder.
\r
108 private HTML countLabel = new HTML();
\r
111 * The table widget with the file list.
\r
113 private Grid table = new Grid(GSS.VISIBLE_FILE_COUNT + 1, 8);
\r
116 * The navigation bar for paginating the results.
\r
118 private HorizontalPanel navBar = new HorizontalPanel();
\r
121 * The number of files in this folder.
\r
123 int folderFileCount;
\r
126 * Total folder size
\r
128 long folderTotalSize;
\r
131 * A cache of the files in the list.
\r
133 private List<FileResource> files;
\r
137 * The widget's image bundle.
\r
139 private final Images images;
\r
141 private String sortingProperty = "name";
\r
143 private boolean sortingType = true;
\r
145 private HTML nameLabel;
\r
147 private HTML versionLabel;
\r
149 private HTML sizeLabel;
\r
151 private HTML dateLabel;
\r
153 private HTML ownerLabel;
\r
155 private HTML pathLabel;
\r
158 * Construct the file list widget. This entails setting up the widget
\r
159 * layout, fetching the number of files in the current folder from the
\r
160 * server and filling the local file cache of displayed files with data from
\r
161 * the server, as well.
\r
165 public FileList(final Images _images) {
\r
168 prevButton.addClickListener(this);
\r
169 nextButton.addClickListener(this);
\r
171 contextMenu = new DnDFocusPanel(new HTML(images.fileContextMenu().getHTML()));
\r
172 contextMenu.addClickListener(new FileContextMenu(images, false, false));
\r
173 GSS.get().getDragController().makeDraggable(contextMenu);
\r
176 // Setup the table.
\r
177 table.setCellSpacing(0);
\r
178 table.setCellPadding(2);
\r
179 table.setWidth("100%");
\r
182 table.addTableListener(this);
\r
184 // Create the 'navigation' bar at the upper-right.
\r
185 final HorizontalPanel innerNavBar = new HorizontalPanel();
\r
186 innerNavBar.setStyleName("gss-ListNavBar");
\r
187 innerNavBar.setSpacing(8);
\r
188 innerNavBar.add(prevButton);
\r
189 innerNavBar.add(countLabel);
\r
190 innerNavBar.add(nextButton);
\r
191 navBar.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
\r
192 navBar.add(innerNavBar);
\r
193 navBar.setWidth("100%");
\r
196 setStyleName("gss-List");
\r
199 DeferredCommand.addCommand(new IncrementalCommand() {
\r
201 public boolean execute() {
\r
202 return fetchRootFolder();
\r
205 sinkEvents(Event.ONCONTEXTMENU);
\r
206 sinkEvents(Event.ONMOUSEUP);
\r
207 sinkEvents(Event.ONCLICK);
\r
208 sinkEvents(Event.ONKEYDOWN);
\r
209 sinkEvents(Event.ONDBLCLICK);
\r
210 preventIESelection();
\r
213 public void onClick(Widget sender) {
\r
214 if (sender == nextButton) {
\r
215 // Move forward a page.
\r
216 clearSelectedRows();
\r
217 startIndex += GSS.VISIBLE_FILE_COUNT;
\r
218 if (startIndex >= folderFileCount)
\r
219 startIndex -= GSS.VISIBLE_FILE_COUNT;
\r
222 } else if (sender == prevButton) {
\r
223 clearSelectedRows();
\r
224 // Move back a page.
\r
225 startIndex -= GSS.VISIBLE_FILE_COUNT;
\r
226 if (startIndex < 0)
\r
233 public void onBrowserEvent(Event event) {
\r
234 if (files == null || files.size() == 0){
\r
235 if(DOM.eventGetType(event) == Event.ONCONTEXTMENU && selectedRows.size() == 0){
\r
236 FileContextMenu fm = new FileContextMenu(images, false, true);
\r
237 fm.onEmptyEvent(event);
\r
241 if (DOM.eventGetType(event) == Event.ONCONTEXTMENU && selectedRows.size() != 0) {
\r
242 FileContextMenu fm = new FileContextMenu(images, false, false);
\r
243 fm.onClick(contextMenu);
\r
245 else if(DOM.eventGetType(event) == Event.ONCONTEXTMENU && selectedRows.size() == 0){
\r
246 FileContextMenu fm = new FileContextMenu(images, false, true);
\r
247 fm.onEmptyEvent(event);
\r
249 else if (DOM.eventGetType(event) == Event.ONDBLCLICK)
\r
250 if(getSelectedFiles().size() == 1){
\r
251 FileResource file = getSelectedFiles().get(0);
\r
252 String dateString = AbstractRestCommand.getDate();
\r
253 String resource = file.getPath().substring(GSS.GSS_REST_PATH.length()-1,file.getPath().length());
\r
254 String sig = GSS.get().getCurrentUserResource().getUsername()+" "+AbstractRestCommand.calculateSig("GET", dateString, resource, AbstractRestCommand.base64decode(GSS.get().getToken()));
\r
255 Window.open(file.getPath() + "?Authorization=" + URL.encodeComponent(sig) + "&Date="+URL.encodeComponent(dateString), "_blank", "");
\r
257 if (DOM.eventGetType(event) == Event.ONCLICK) {
\r
258 if (DOM.eventGetCtrlKey(event))
\r
259 clickControl = true;
\r
261 clickControl = false;
\r
262 if (DOM.eventGetShiftKey(event)) {
\r
264 if (selectedRows.size() == 1)
\r
265 firstShift = selectedRows.get(0) - startIndex;
\r
266 event.preventDefault();
\r
268 clickShift = false;
\r
270 event.preventDefault();
\r
275 super.onBrowserEvent(event);
\r
279 * Retrieve the root folder for the current user.
\r
281 * @return true if the retrieval was successful
\r
283 protected boolean fetchRootFolder() {
\r
284 UserResource user = GSS.get().getCurrentUserResource();
\r
294 * @see com.google.gwt.user.client.ui.TableListener#onCellClicked(com.google.gwt.user.client.ui.SourcesTableEvents,
\r
297 public void onCellClicked(@SuppressWarnings("unused") SourcesTableEvents sender, int row, @SuppressWarnings("unused") int cell) {
\r
298 // Select the row that was clicked (-1 to account for header row).
\r
299 if (row > folderFileCount)
\r
302 GWT.log("ROW is:" + row + " fs:" + firstShift, null);
\r
303 if (firstShift == -1)
\r
305 else if (row > firstShift) {
\r
306 clearSelectedRows();
\r
307 for (int i = firstShift; i < row; i++) {
\r
308 selectedRows.add(startIndex + i);
\r
311 GSS.get().setCurrentSelection(getSelectedFiles());
\r
312 contextMenu.setFiles(getSelectedFiles());
\r
313 table.setWidget(row, 0, contextMenu);
\r
314 } else if (row != -1 && row == firstShift) {
\r
315 selectedRows.add(row);
\r
316 selectedRows.add(row - 1);
\r
317 styleRow(row, true);
\r
318 styleRow(row - 1, true);
\r
319 } else if (row < firstShift) {
\r
320 GWT.log("ROW is:" + row + " fs:" + firstShift, null);
\r
321 clearSelectedRows();
\r
323 for (int i = firstShift; i >= row - 1; i--) {
\r
324 selectedRows.add(startIndex + i);
\r
327 GSS.get().setCurrentSelection(getSelectedFiles());
\r
328 table.setWidget(row, 0, contextMenu);
\r
329 contextMenu.setFiles(getSelectedFiles());
\r
332 } else if (row > 0)
\r
333 selectRow(row - 1);
\r
338 * Initializes the table so that it contains enough rows for a full page of
\r
341 private void initTable() {
\r
343 nameLabel = new HTML("Name");
\r
344 nameLabel.addClickListener(new ClickListener() {
\r
346 public void onClick(Widget sender) {
\r
353 versionLabel = new HTML("Version");
\r
354 versionLabel.addClickListener(new ClickListener() {
\r
356 public void onClick(Widget sender) {
\r
357 sortFiles("version");
\r
363 sizeLabel = new HTML("Size");
\r
364 sizeLabel.addClickListener(new ClickListener() {
\r
366 public void onClick(Widget sender) {
\r
373 dateLabel = new HTML("Date");
\r
374 dateLabel.addClickListener(new ClickListener() {
\r
376 public void onClick(Widget sender) {
\r
383 ownerLabel = new HTML("Owner");
\r
384 ownerLabel.addClickListener(new ClickListener() {
\r
386 public void onClick(Widget sender) {
\r
387 sortFiles("owner");
\r
393 pathLabel = new HTML("Path");
\r
394 pathLabel.addClickListener(new ClickListener() {
\r
396 public void onClick(Widget sender) {
\r
403 // Create the header row.
\r
404 table.setText(0, 0, "");
\r
405 table.setWidget(0, 1, nameLabel);
\r
406 table.setWidget(0, 2, ownerLabel);
\r
407 table.setWidget(0, 3, pathLabel);
\r
408 table.setWidget(0, 4, versionLabel);
\r
409 table.setWidget(0, 5, sizeLabel);
\r
410 table.setWidget(0, 6, dateLabel);
\r
411 table.setWidget(0, 7, navBar);
\r
412 table.getRowFormatter().setStyleName(0, "gss-ListHeader");
\r
414 // Initialize the rest of the rows.
\r
415 for (int i = 1; i < GSS.VISIBLE_FILE_COUNT + 1; ++i) {
\r
416 table.setText(i, 0, "");
\r
417 table.setText(i, 1, "");
\r
418 table.setText(i, 2, "");
\r
419 table.setText(i, 3, "");
\r
420 table.setText(i, 4, "");
\r
421 table.setText(i, 5, "");
\r
422 table.setText(i, 6, "");
\r
423 table.setText(i, 7, "");
\r
424 table.getCellFormatter().setWordWrap(i, 0, false);
\r
425 table.getCellFormatter().setWordWrap(i, 1, false);
\r
426 table.getCellFormatter().setWordWrap(i, 2, false);
\r
427 table.getCellFormatter().setWordWrap(i, 3, false);
\r
428 table.getCellFormatter().setWordWrap(i, 4, false);
\r
429 table.getCellFormatter().setWordWrap(i, 5, false);
\r
430 table.getCellFormatter().setWordWrap(i, 6, false);
\r
431 table.getCellFormatter().setWordWrap(i, 7, false);
\r
432 table.getCellFormatter().setHorizontalAlignment(i, 4, HasHorizontalAlignment.ALIGN_CENTER);
\r
434 prevButton.setVisible(false);
\r
435 nextButton.setVisible(false);
\r
440 * Selects the given row (relative to the current page).
\r
442 * @param row the row to be selected
\r
444 private void selectRow(final int row) {
\r
445 if (row < folderFileCount) {
\r
447 if (selectedRows.contains(row)) {
\r
448 int i = selectedRows.indexOf(startIndex + row);
\r
449 selectedRows.remove(i);
\r
450 styleRow(row, false);
\r
452 for (int r : selectedRows) {
\r
453 int prow = r - startIndex;
\r
454 table.setWidget(prow + 1, 0, images.document().createImage());
\r
456 selectedRows.add(startIndex + row);
\r
457 styleRow(row, true);
\r
461 clearSelectedRows();
\r
462 selectedRows.add(startIndex + row);
\r
463 styleRow(row, true);
\r
465 if (selectedRows.size() == 1)
\r
466 GSS.get().setCurrentSelection(files.get(selectedRows.get(0)));
\r
468 GSS.get().setCurrentSelection(getSelectedFiles());
\r
469 contextMenu.setFiles(getSelectedFiles());
\r
470 table.setWidget(row + 1, 0, contextMenu);
\r
476 public List<FileResource> getSelectedFiles() {
\r
477 List<FileResource> result = new ArrayList();
\r
478 for (int i : selectedRows)
\r
479 result.add(files.get(i));
\r
484 * Make the specified row look like selected or not, according to the
\r
485 * <code>selected</code> flag.
\r
490 void styleRow(final int row, final boolean selected) {
\r
491 if (row != -1 && row >= 0)
\r
493 table.getRowFormatter().addStyleName(row + 1, "gss-SelectedRow");
\r
495 table.getRowFormatter().removeStyleName(row + 1, "gss-SelectedRow");
\r
499 * Update the display of the file list.
\r
502 int count = folderFileCount;
\r
503 int max = startIndex + GSS.VISIBLE_FILE_COUNT;
\r
506 folderTotalSize = 0;
\r
508 // Show the selected files.
\r
510 for (; i < GSS.VISIBLE_FILE_COUNT + 1; ++i) {
\r
511 // Don't read past the end.
\r
512 // if (i > folderFileCount)
\r
514 if (startIndex + i > folderFileCount)
\r
516 // Add a new row to the table, then set each of its columns to the
\r
518 table.setWidget(i, 0, images.document().createImage());
\r
519 FileResource fileHeader = files.get(startIndex + i - 1);
\r
520 table.getRowFormatter().addStyleName(i, "gss-fileRow");
\r
522 table.setHTML(i, 1, fileHeader.getName());
\r
523 table.setText(i, 2, fileHeader.getOwner());
\r
524 table.setText(i, 3, URL.decodeComponent(fileHeader.getPath().substring(GSS.GSS_REST_PATH.length()+fileHeader.getOwner().length()+6,fileHeader.getPath().length()-fileHeader.getName().length())));
\r
525 table.setText(i, 4, String.valueOf(fileHeader.getVersion()));
\r
526 table.setText(i, 5, String.valueOf(fileHeader.getFileSizeAsString()));
\r
527 final DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a");
\r
528 table.setText(i, 6, formatter.format(fileHeader.getCreationDate()));
\r
529 folderTotalSize += fileHeader.getContentLength();
\r
532 // Clear any remaining slots.
\r
533 for (; i < GSS.VISIBLE_FILE_COUNT + 1; ++i) {
\r
534 table.setHTML(i, 0, " ");
\r
535 table.setHTML(i, 1, " ");
\r
536 table.setHTML(i, 2, " ");
\r
537 table.setHTML(i, 3, " ");
\r
538 table.setHTML(i, 4, " ");
\r
539 table.setHTML(i, 5, " ");
\r
540 table.setHTML(i, 6, " ");
\r
541 table.setHTML(i, 7, " ");
\r
544 if (folderFileCount == 0) {
\r
545 showingStats = "no files";
\r
546 prevButton.setVisible(false);
\r
547 nextButton.setVisible(false);
\r
548 } else if (folderFileCount < GSS.VISIBLE_FILE_COUNT) {
\r
549 showingStats = folderFileCount + " files" + " (" + FileResource.getFileSizeAsString(folderTotalSize) + ")";
\r
550 prevButton.setVisible(false);
\r
551 nextButton.setVisible(false);
\r
553 showingStats = "" + (startIndex + 1) + " - " + max + " of " + count + " files" + " (" + FileResource.getFileSizeAsString(folderTotalSize) + ")";
\r
554 prevButton.setVisible(startIndex != 0);
\r
555 nextButton.setVisible(startIndex + GSS.VISIBLE_FILE_COUNT < count);
\r
557 updateCurrentlyShowingStats();
\r
562 * update status panel with currently showing file stats
\r
564 public void updateCurrentlyShowingStats() {
\r
565 GSS.get().getStatusPanel().updateCurrentlyShowing(showingStats);
\r
569 * Adjust the height of the table by adding and removing rows as necessary.
\r
571 * @param newHeight the new height to reach
\r
573 void resizeTableHeight(final int newHeight) {
\r
574 GWT.log("Panel: " + newHeight + ", parent: " + table.getParent().getOffsetHeight(), null);
\r
575 // Fill the rest with empty slots.
\r
576 if (newHeight > table.getOffsetHeight())
\r
577 while (newHeight > table.getOffsetHeight()) {
\r
578 // table.setHTML(table.getRowCount(), 5, " ");
\r
579 table.resizeRows(table.getRowCount() + 1);
\r
580 GWT.log("Table: " + table.getOffsetHeight() + ", rows: " + table.getRowCount(), null);
\r
583 while (newHeight < table.getOffsetHeight()) {
\r
584 // table.setHTML(table.getRowCount(), 5, " ");
\r
585 table.resizeRows(table.getRowCount() - 1);
\r
586 GWT.log("Table: " + table.getOffsetHeight() + ", rows: " + table.getRowCount(), null);
\r
590 public void updateFileCache(boolean updateSelectedFolder) {
\r
591 if (!updateSelectedFolder && !GSS.get().getFolders().getTrashItem().equals(GSS.get().getFolders().getCurrent()))
\r
593 else if(GSS.get().getFolders().getCurrent() != null){
\r
594 final DnDTreeItem folderItem = (DnDTreeItem) GSS.get().getFolders().getCurrent();
\r
595 if (folderItem.getFolderResource() != null) {
\r
597 ExecuteGet<FolderResource> gf = new ExecuteGet<FolderResource>(FolderResource.class, folderItem.getFolderResource().getPath()) {
\r
599 public void onComplete() {
\r
600 folderItem.setUserObject(getResult());
\r
605 public void onError(Throwable t) {
\r
607 GSS.get().displayError("Unable to fetch folder " + folderItem.getFolderResource().getName());
\r
610 DeferredCommand.addCommand(gf);
\r
612 else if(folderItem.getTrashResource() != null){
\r
613 ExecuteGet<TrashResource> gt = new ExecuteGet<TrashResource>(TrashResource.class, folderItem.getTrashResource().getPath()){
\r
615 public void onComplete() {
\r
616 folderItem.setUserObject(getResult());
\r
621 public void onError(Throwable t) {
\r
622 if(t instanceof RestException && (((RestException)t).getHttpStatusCode() == 204 ||((RestException)t).getHttpStatusCode() == 1223 )){
\r
623 folderItem.setUserObject(new TrashResource(folderItem.getTrashResource().getPath()));
\r
628 GSS.get().displayError("Unable to fetch trash resource");
\r
632 DeferredCommand.addCommand(gt);
\r
634 else if(folderItem.getSharedResource() != null){
\r
635 ExecuteGet<SharedResource> gt = new ExecuteGet<SharedResource>(SharedResource.class, folderItem.getSharedResource().getPath()){
\r
637 public void onComplete() {
\r
638 folderItem.setUserObject(getResult());
\r
643 public void onError(Throwable t) {
\r
646 GSS.get().displayError("Unable to fetch My Shares resource");
\r
650 DeferredCommand.addCommand(gt);
\r
652 else if(folderItem.getOtherUserResource() != null){
\r
653 ExecuteGet<OtherUserResource> gt = new ExecuteGet<OtherUserResource>(OtherUserResource.class, folderItem.getOtherUserResource().getPath()){
\r
655 public void onComplete() {
\r
656 folderItem.setUserObject(getResult());
\r
661 public void onError(Throwable t) {
\r
664 GSS.get().displayError("Unable to fetch My Shares resource");
\r
668 DeferredCommand.addCommand(gt);
\r
677 * Update the file cache with data from the server.
\r
679 * @param userId the ID of the current user
\r
681 private void updateFileCache() {
\r
683 clearSelectedRows();
\r
685 sortingProperty = "name";
\r
686 nameLabel.setHTML("Name " + images.desc().getHTML());
\r
687 sortingType = true;
\r
689 final TreeItem folderItem = GSS.get().getFolders().getCurrent();
\r
691 if (folderItem == null || GSS.get().getFolders().isOthersShared(folderItem)) {
\r
692 setFiles(new ArrayList<FileResource>());
\r
696 if (folderItem instanceof DnDTreeItem) {
\r
697 DnDTreeItem dnd = (DnDTreeItem) folderItem;
\r
698 if (dnd.getFolderResource() != null) {
\r
699 if (GSS.get().getFolders().isTrashItem(dnd))
\r
700 setFiles(new ArrayList<FileResource>());
\r
702 setFiles(dnd.getFolderResource().getFiles());
\r
704 } else if (dnd.getTrashResource() != null)
\r
705 setFiles(dnd.getTrashResource().getFiles());
\r
706 else if (dnd.getSharedResource() != null)
\r
707 setFiles(dnd.getSharedResource().getFiles());
\r
708 else if (dnd.getOtherUserResource() != null)
\r
709 setFiles(dnd.getOtherUserResource().getFiles());
\r
711 setFiles(dnd.getFolderResource().getFiles());
\r
718 * Fill the file cache with data.
\r
721 * @param filePaths the files to set
\r
723 public void setFiles(final List<FileResource> _files) {
\r
724 if(_files.size() >0 && !GSS.get().getFolders().isTrash(GSS.get().getFolders().getCurrent())){
\r
725 files = new ArrayList<FileResource>();
\r
726 for(FileResource fres : _files)
\r
727 if(!fres.isDeleted())
\r
732 Collections.sort(files, new Comparator<FileResource>() {
\r
734 public int compare(FileResource arg0, FileResource arg1) {
\r
735 return arg0.getName().compareTo(arg1.getName());
\r
740 folderFileCount = files.size();
\r
743 private void sortFiles(final String sortProperty) {
\r
744 if (sortProperty.equals(sortingProperty))
\r
745 sortingType = !sortingType;
\r
747 sortingProperty = sortProperty;
\r
748 sortingType = true;
\r
751 clearSelectedRows();
\r
752 if (files == null || files.size() == 0)
\r
754 Collections.sort(files, new Comparator<FileResource>() {
\r
756 public int compare(FileResource arg0, FileResource arg1) {
\r
758 if (sortProperty.equals("version")) {
\r
759 versionLabel.setHTML("Version " + images.desc().getHTML());
\r
760 return new Integer(arg0.getVersion()).compareTo(new Integer(arg1.getVersion()));
\r
761 } else if (sortProperty.equals("owner")) {
\r
762 ownerLabel.setHTML("Owner " + images.desc().getHTML());
\r
763 return new Integer(arg0.getOwner()).compareTo(new Integer(arg1.getOwner()));
\r
764 } else if (sortProperty.equals("date")) {
\r
765 dateLabel.setHTML("Date " + images.desc().getHTML());
\r
766 return arg0.getCreationDate().compareTo(arg1.getCreationDate());
\r
767 } else if (sortProperty.equals("size")) {
\r
768 sizeLabel.setHTML("Size " + images.desc().getHTML());
\r
769 return new Long(arg0.getContentLength()).compareTo(new Long(arg1.getContentLength()));
\r
770 } else if (sortProperty.equals("name")) {
\r
771 nameLabel.setHTML("Name " + images.desc().getHTML());
\r
772 return arg0.getName().compareTo(arg1.getName());
\r
773 } else if (sortProperty.equals("path")) {
\r
774 pathLabel.setHTML("Path " + images.desc().getHTML());
\r
775 return arg0.getPath().compareTo(arg1.getPath());
\r
777 nameLabel.setHTML("Name " + images.desc().getHTML());
\r
778 return arg0.getName().compareTo(arg1.getName());
\r
780 else if (sortProperty.equals("version")) {
\r
781 versionLabel.setHTML("Version " + images.asc().getHTML());
\r
782 return new Integer(arg1.getVersion()).compareTo(new Integer(arg0.getVersion()));
\r
783 } else if (sortProperty.equals("owner")) {
\r
784 ownerLabel.setHTML("Owner " + images.asc().getHTML());
\r
785 return new Integer(arg1.getOwner()).compareTo(new Integer(arg0.getOwner()));
\r
786 } else if (sortProperty.equals("date")) {
\r
787 dateLabel.setHTML("Date " + images.asc().getHTML());
\r
788 return arg1.getCreationDate().compareTo(arg0.getCreationDate());
\r
789 } else if (sortProperty.equals("size")) {
\r
790 sizeLabel.setHTML("Size " + images.asc().getHTML());
\r
791 return new Long(arg1.getContentLength()).compareTo(new Long(arg0.getContentLength()));
\r
792 } else if (sortProperty.equals("name")) {
\r
793 nameLabel.setHTML("Name " + images.asc().getHTML());
\r
794 return arg1.getName().compareTo(arg0.getName());
\r
795 } else if (sortProperty.equals("path")) {
\r
796 pathLabel.setHTML("Path " + images.asc().getHTML());
\r
797 return arg1.getPath().compareTo(arg0.getPath());
\r
799 nameLabel.setHTML("Name " + images.asc().getHTML());
\r
800 return arg1.getName().compareTo(arg0.getName());
\r
807 private void clearLabels() {
\r
808 nameLabel.setText("Name");
\r
809 versionLabel.setText("Version");
\r
810 sizeLabel.setText("Size");
\r
811 dateLabel.setText("Date");
\r
812 ownerLabel.setText("Owner");
\r
813 pathLabel.setText("Path");
\r
817 * Retrieve the table.
\r
819 * @return the table
\r
826 * Does the list contains the requested filename
\r
829 * @return true/false
\r
831 public boolean contains(String fileName) {
\r
832 for (int i = 0; i < files.size(); i++)
\r
833 if (files.get(i).getName().equals(fileName))
\r
838 public void clearSelectedRows() {
\r
839 for (int r : selectedRows) {
\r
840 int row = r - startIndex;
\r
841 styleRow(row, false);
\r
842 table.setWidget(row + 1, 0, images.document().createImage());
\r
844 selectedRows.clear();
\r
845 Object sel = GSS.get().getCurrentSelection();
\r
846 if (sel instanceof FileResource || sel instanceof List)
\r
847 GSS.get().setCurrentSelection(null);
\r
850 public static native void preventIESelection() /*-{
\r
851 $doc.body.onselectstart = function () { return false; };
\r
854 public static native void enableIESelection() /*-{
\r
855 if ($doc.body.onselectstart != null)
\r
856 $doc.body.onselectstart = null;
\r
862 public void selectAllRows() {
\r
863 clearSelectedRows();
\r
864 int count = folderFileCount;
\r
867 int max = startIndex + GSS.VISIBLE_FILE_COUNT;
\r
871 for (; i < GSS.VISIBLE_FILE_COUNT + 1; ++i) {
\r
872 // Don't read past the end.
\r
873 // if (i > folderFileCount)
\r
875 if (startIndex + i > folderFileCount)
\r
877 selectedRows.add(startIndex + i - 1);
\r
878 styleRow(i - 1, true);
\r
880 GSS.get().setCurrentSelection(getSelectedFiles());
\r
881 contextMenu.setFiles(getSelectedFiles());
\r
882 table.setWidget(i - 1, 0, contextMenu);
\r