-/*\r
- * Copyright 2007, 2008, 2009 Electronic Business Systems Ltd.\r
- *\r
- * This file is part of GSS.\r
- *\r
- * GSS is free software: you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation, either version 3 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * GSS is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with GSS. If not, see <http://www.gnu.org/licenses/>.\r
- */\r
-package gr.ebs.gss.client;\r
-\r
-import gr.ebs.gss.client.dnd.DnDFocusPanel;\r
-import gr.ebs.gss.client.dnd.DnDTreeItem;\r
-import gr.ebs.gss.client.rest.GetCommand;\r
-import gr.ebs.gss.client.rest.MultipleHeadCommand;\r
-import gr.ebs.gss.client.rest.RestCommand;\r
-import gr.ebs.gss.client.rest.RestException;\r
-import gr.ebs.gss.client.rest.resource.FileResource;\r
-import gr.ebs.gss.client.rest.resource.FolderResource;\r
-import gr.ebs.gss.client.rest.resource.OtherUserResource;\r
-import gr.ebs.gss.client.rest.resource.SharedResource;\r
-import gr.ebs.gss.client.rest.resource.TrashResource;\r
-import gr.ebs.gss.client.rest.resource.UserResource;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collections;\r
-import java.util.Comparator;\r
-import java.util.List;\r
-\r
-import com.google.gwt.core.client.GWT;\r
-import com.google.gwt.http.client.URL;\r
-import com.google.gwt.i18n.client.DateTimeFormat;\r
-import com.google.gwt.user.client.DOM;\r
-import com.google.gwt.user.client.DeferredCommand;\r
-import com.google.gwt.user.client.Event;\r
-import com.google.gwt.user.client.IncrementalCommand;\r
-import com.google.gwt.user.client.Window;\r
-import com.google.gwt.user.client.ui.AbstractImagePrototype;\r
-import com.google.gwt.user.client.ui.ClickListener;\r
-import com.google.gwt.user.client.ui.Composite;\r
-import com.google.gwt.user.client.ui.Grid;\r
-import com.google.gwt.user.client.ui.HTML;\r
-import com.google.gwt.user.client.ui.HasHorizontalAlignment;\r
-import com.google.gwt.user.client.ui.HorizontalPanel;\r
-import com.google.gwt.user.client.ui.SourcesTableEvents;\r
-import com.google.gwt.user.client.ui.TableListener;\r
-import com.google.gwt.user.client.ui.TreeItem;\r
-import com.google.gwt.user.client.ui.Widget;\r
-\r
-/**\r
- * A composite that displays the list of files in a particular folder.\r
- */\r
-public class FileList extends Composite implements TableListener, ClickListener {\r
-\r
- private HTML prevButton = new HTML("<a href='javascript:;'>< Previous</a>", true);\r
-\r
- private HTML nextButton = new HTML("<a href='javascript:;'>Next ></a>", true);\r
-\r
- private String showingStats = "";\r
-\r
- private int startIndex = 0;\r
-\r
- /**\r
- * A constant that denotes the completion of an IncrementalCommand.\r
- */\r
- public static final boolean DONE = false;\r
-\r
- private boolean clickControl = false;\r
-\r
- private boolean clickShift = false;\r
-\r
- private int firstShift = -1;\r
-\r
- private ArrayList<Integer> selectedRows = new ArrayList<Integer>();\r
-\r
- /**\r
- * The context menu for the selected file.\r
- */\r
- final DnDFocusPanel contextMenu;\r
-\r
- /**\r
- * Specifies that the images available for this composite will be the ones\r
- * available in FileContextMenu.\r
- */\r
- public interface Images extends FileContextMenu.Images, Folders.Images {\r
-\r
- @Resource("gr/ebs/gss/resources/blank.gif")\r
- AbstractImagePrototype blank();\r
-\r
- @Resource("gr/ebs/gss/resources/asc.png")\r
- AbstractImagePrototype asc();\r
-\r
- @Resource("gr/ebs/gss/resources/desc.png")\r
- AbstractImagePrototype desc();\r
-\r
- @Resource("gr/ebs/gss/resources/mimetypes/document_shared.png")\r
- AbstractImagePrototype documentShared();\r
-\r
- @Resource("gr/ebs/gss/resources/mimetypes/kcmfontinst.png")\r
- AbstractImagePrototype wordprocessor();\r
-\r
- @Resource("gr/ebs/gss/resources/mimetypes/log.png")\r
- AbstractImagePrototype spreadsheet();\r
-\r
- @Resource("gr/ebs/gss/resources/mimetypes/kpresenter_kpr.png")\r
- AbstractImagePrototype presentation();\r
-\r
- @Resource("gr/ebs/gss/resources/mimetypes/acroread.png")\r
- AbstractImagePrototype pdf();\r
-\r
- @Resource("gr/ebs/gss/resources/mimetypes/image.png")\r
- AbstractImagePrototype image();\r
-\r
- @Resource("gr/ebs/gss/resources/mimetypes/video2.png")\r
- AbstractImagePrototype video();\r
-\r
- @Resource("gr/ebs/gss/resources/mimetypes/knotify.png")\r
- AbstractImagePrototype audio();\r
-\r
- @Resource("gr/ebs/gss/resources/mimetypes/html.png")\r
- AbstractImagePrototype html();\r
-\r
- @Resource("gr/ebs/gss/resources/mimetypes/txt.png")\r
- AbstractImagePrototype txt();\r
-\r
- @Resource("gr/ebs/gss/resources/mimetypes/ark2.png")\r
- AbstractImagePrototype zip();\r
-\r
- @Resource("gr/ebs/gss/resources/mimetypes/kcmfontinst_shared.png")\r
- AbstractImagePrototype wordprocessorShared();\r
-\r
- @Resource("gr/ebs/gss/resources/mimetypes/log_shared.png")\r
- AbstractImagePrototype spreadsheetShared();\r
-\r
- @Resource("gr/ebs/gss/resources/mimetypes/kpresenter_kpr_shared.png")\r
- AbstractImagePrototype presentationShared();\r
-\r
- @Resource("gr/ebs/gss/resources/mimetypes/acroread_shared.png")\r
- AbstractImagePrototype pdfShared();\r
-\r
- @Resource("gr/ebs/gss/resources/mimetypes/image_shared.png")\r
- AbstractImagePrototype imageShared();\r
-\r
- @Resource("gr/ebs/gss/resources/mimetypes/video2_shared.png")\r
- AbstractImagePrototype videoShared();\r
-\r
- @Resource("gr/ebs/gss/resources/mimetypes/knotify_shared.png")\r
- AbstractImagePrototype audioShared();\r
-\r
- @Resource("gr/ebs/gss/resources/mimetypes/html_shared.png")\r
- AbstractImagePrototype htmlShared();\r
-\r
- @Resource("gr/ebs/gss/resources/mimetypes/txt_shared.png")\r
- AbstractImagePrototype txtShared();\r
-\r
- @Resource("gr/ebs/gss/resources/mimetypes/ark2_shared.png")\r
- AbstractImagePrototype zipShared();\r
-\r
- }\r
-\r
- /**\r
- * A label with the number of files in this folder.\r
- */\r
- private HTML countLabel = new HTML();\r
-\r
- /**\r
- * The table widget with the file list.\r
- */\r
- private Grid table = new Grid(GSS.VISIBLE_FILE_COUNT + 1, 8);\r
-\r
- /**\r
- * The navigation bar for paginating the results.\r
- */\r
- private HorizontalPanel navBar = new HorizontalPanel();\r
-\r
- /**\r
- * The number of files in this folder.\r
- */\r
- int folderFileCount;\r
-\r
- /**\r
- * Total folder size\r
- */\r
- long folderTotalSize;\r
-\r
- /**\r
- * A cache of the files in the list.\r
- */\r
- private List<FileResource> files;\r
-\r
- /**\r
- * The widget's image bundle.\r
- */\r
- private final Images images;\r
-\r
- private String sortingProperty = "name";\r
-\r
- private boolean sortingType = true;\r
-\r
- private HTML nameLabel;\r
-\r
- private HTML versionLabel;\r
-\r
- private HTML sizeLabel;\r
-\r
- private HTML dateLabel;\r
-\r
- private HTML ownerLabel;\r
-\r
- private HTML pathLabel;\r
-\r
- /**\r
- * Construct the file list widget. This entails setting up the widget\r
- * layout, fetching the number of files in the current folder from the\r
- * server and filling the local file cache of displayed files with data from\r
- * the server, as well.\r
- *\r
- * @param _images\r
- */\r
- public FileList(Images _images) {\r
- images = _images;\r
-\r
- prevButton.addClickListener(this);\r
- nextButton.addClickListener(this);\r
-\r
- contextMenu = new DnDFocusPanel(new HTML(images.fileContextMenu().getHTML()));\r
- contextMenu.addClickListener(new FileContextMenu(images, false, false));\r
- GSS.get().getDragController().makeDraggable(contextMenu);\r
-\r
- // Setup the table.\r
- table.setCellSpacing(0);\r
- table.setCellPadding(2);\r
- table.setWidth("100%");\r
-\r
- // Hook up events.\r
- table.addTableListener(this);\r
-\r
- // Create the 'navigation' bar at the upper-right.\r
- HorizontalPanel innerNavBar = new HorizontalPanel();\r
- innerNavBar.setStyleName("gss-ListNavBar");\r
- innerNavBar.setSpacing(8);\r
- innerNavBar.add(prevButton);\r
- innerNavBar.add(countLabel);\r
- innerNavBar.add(nextButton);\r
- navBar.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);\r
- navBar.add(innerNavBar);\r
- navBar.setWidth("100%");\r
-\r
- initWidget(table);\r
- setStyleName("gss-List");\r
-\r
- initTable();\r
- DeferredCommand.addCommand(new IncrementalCommand() {\r
-\r
- public boolean execute() {\r
- return fetchRootFolder();\r
- }\r
- });\r
- sinkEvents(Event.ONCONTEXTMENU);\r
- sinkEvents(Event.ONMOUSEUP);\r
- sinkEvents(Event.ONCLICK);\r
- sinkEvents(Event.ONKEYDOWN);\r
- sinkEvents(Event.ONDBLCLICK);\r
- GSS.preventIESelection();\r
- }\r
-\r
- public void onClick(Widget sender) {\r
- if (sender == nextButton) {\r
- // Move forward a page.\r
- clearSelectedRows();\r
- startIndex += GSS.VISIBLE_FILE_COUNT;\r
- if (startIndex >= folderFileCount)\r
- startIndex -= GSS.VISIBLE_FILE_COUNT;\r
- else\r
- update();\r
- } else if (sender == prevButton) {\r
- clearSelectedRows();\r
- // Move back a page.\r
- startIndex -= GSS.VISIBLE_FILE_COUNT;\r
- if (startIndex < 0)\r
- startIndex = 0;\r
- else\r
- update();\r
- }\r
- }\r
-\r
- @Override\r
- public void onBrowserEvent(Event event) {\r
- if (files == null || files.size() == 0) {\r
- if (DOM.eventGetType(event) == Event.ONCONTEXTMENU && selectedRows.size() == 0) {\r
- FileContextMenu fm = new FileContextMenu(images, false, true);\r
- fm.onEmptyEvent(event);\r
- }\r
- return;\r
- }\r
- if (DOM.eventGetType(event) == Event.ONCONTEXTMENU && selectedRows.size() != 0) {\r
- FileContextMenu fm = new FileContextMenu(images, false, false);\r
- fm.onEvent(event);\r
- } else if (DOM.eventGetType(event) == Event.ONCONTEXTMENU && selectedRows.size() == 0) {\r
- FileContextMenu fm = new FileContextMenu(images, false, true);\r
- fm.onEmptyEvent(event);\r
- } else if (DOM.eventGetType(event) == Event.ONDBLCLICK)\r
- if (getSelectedFiles().size() == 1) {\r
- GSS app = GSS.get();\r
- FileResource file = getSelectedFiles().get(0);\r
- String dateString = RestCommand.getDate();\r
- String resource = file.getUri().substring(app.getApiPath().length() - 1, file.getUri().length());\r
- String sig = app.getCurrentUserResource().getUsername() + " " +\r
- RestCommand.calculateSig("GET", dateString, resource,\r
- RestCommand.base64decode(app.getToken()));\r
- Window.open(file.getUri() + "?Authorization=" + URL.encodeComponent(sig) + "&Date=" + URL.encodeComponent(dateString), "_blank", "");\r
- event.preventDefault();\r
- return;\r
- }\r
- if (DOM.eventGetType(event) == Event.ONCLICK) {\r
- if (DOM.eventGetCtrlKey(event))\r
- clickControl = true;\r
- else\r
- clickControl = false;\r
- if (DOM.eventGetShiftKey(event)) {\r
- clickShift = true;\r
- if (selectedRows.size() == 1)\r
- firstShift = selectedRows.get(0) - startIndex;\r
- event.preventDefault();\r
- } else {\r
- clickShift = false;\r
- firstShift = -1;\r
- event.preventDefault();\r
- }\r
- }\r
- super.onBrowserEvent(event);\r
- }\r
-\r
- /**\r
- * Retrieve the root folder for the current user.\r
- *\r
- * @return true if the retrieval was successful\r
- */\r
- protected boolean fetchRootFolder() {\r
- UserResource user = GSS.get().getCurrentUserResource();\r
- if (user == null)\r
- return !DONE;\r
- // Update cache and clear selection.\r
- updateFileCache(true);\r
- return DONE;\r
- }\r
-\r
- public void onCellClicked(SourcesTableEvents sender, int row, int cell) {\r
- // Select the row that was clicked (-1 to account for header row).\r
- if (row > folderFileCount)\r
- return;\r
- if (clickShift) {\r
- GWT.log("Row is: " + row + " fs: " + firstShift, null);\r
- if (firstShift == -1)\r
- firstShift = row;\r
- else if (row > firstShift) {\r
- clearSelectedRows();\r
- for (int i = firstShift; i < row; i++) {\r
- selectedRows.add(startIndex + i);\r
- styleRow(i, true);\r
- }\r
- GSS.get().setCurrentSelection(getSelectedFiles());\r
- contextMenu.setFiles(getSelectedFiles());\r
- makeRowDraggable(row);\r
- } else if (row != -1 && row == firstShift) {\r
- selectedRows.add(row - 1);\r
- styleRow(row, true);\r
- styleRow(row - 1, true);\r
- GSS.get().setCurrentSelection(getSelectedFiles());\r
- contextMenu.setFiles(getSelectedFiles());\r
- makeRowDraggable(row);\r
- } else if (row < firstShift) {\r
- GWT.log("Row is:" + row + " fs:" + firstShift, null);\r
- clearSelectedRows();\r
-\r
- for (int i = firstShift; i >= row - 1; i--) {\r
- selectedRows.add(startIndex + i);\r
- styleRow(i, true);\r
- }\r
- GSS.get().setCurrentSelection(getSelectedFiles());\r
- makeRowDraggable(row);\r
- contextMenu.setFiles(getSelectedFiles());\r
- }\r
- } else if (row > 0)\r
- selectRow(row - 1);\r
- }\r
-\r
- /**\r
- * Initializes the table so that it contains enough rows for a full page of\r
- * files.\r
- */\r
- private void initTable() {\r
- nameLabel = new HTML("Name");\r
- nameLabel.addClickListener(new ClickListener() {\r
-\r
- public void onClick(Widget sender) {\r
- sortFiles("name");\r
- update();\r
- }\r
-\r
- });\r
- versionLabel = new HTML("Version");\r
- versionLabel.addClickListener(new ClickListener() {\r
-\r
- public void onClick(Widget sender) {\r
- sortFiles("version");\r
- update();\r
- }\r
-\r
- });\r
- sizeLabel = new HTML("Size");\r
- sizeLabel.addClickListener(new ClickListener() {\r
-\r
- public void onClick(Widget sender) {\r
- sortFiles("size");\r
- update();\r
- }\r
-\r
- });\r
- dateLabel = new HTML("Date");\r
- dateLabel.addClickListener(new ClickListener() {\r
-\r
- public void onClick(Widget sender) {\r
- sortFiles("date");\r
- update();\r
- }\r
-\r
- });\r
- ownerLabel = new HTML("Owner");\r
- ownerLabel.addClickListener(new ClickListener() {\r
-\r
- public void onClick(Widget sender) {\r
- sortFiles("owner");\r
- update();\r
- }\r
-\r
- });\r
- pathLabel = new HTML("Path");\r
- pathLabel.addClickListener(new ClickListener() {\r
-\r
- public void onClick(Widget sender) {\r
- sortFiles("path");\r
- update();\r
- }\r
-\r
- });\r
- // Create the header row.\r
- table.setText(0, 0, "");\r
- table.setWidget(0, 1, nameLabel);\r
- table.setWidget(0, 2, ownerLabel);\r
- table.setWidget(0, 3, pathLabel);\r
- table.setWidget(0, 4, versionLabel);\r
- table.setWidget(0, 5, sizeLabel);\r
- table.setWidget(0, 6, dateLabel);\r
- table.setWidget(0, 7, navBar);\r
- table.getRowFormatter().setStyleName(0, "gss-ListHeader");\r
-\r
- // Initialize the rest of the rows.\r
- for (int i = 1; i < GSS.VISIBLE_FILE_COUNT + 1; ++i) {\r
- table.setText(i, 0, "");\r
- table.setText(i, 1, "");\r
- table.setText(i, 2, "");\r
- table.setText(i, 3, "");\r
- table.setText(i, 4, "");\r
- table.setText(i, 5, "");\r
- table.setText(i, 6, "");\r
- table.setText(i, 7, "");\r
- table.getCellFormatter().setWordWrap(i, 0, false);\r
- table.getCellFormatter().setWordWrap(i, 1, false);\r
- table.getCellFormatter().setWordWrap(i, 2, false);\r
- table.getCellFormatter().setWordWrap(i, 3, false);\r
- table.getCellFormatter().setWordWrap(i, 4, false);\r
- table.getCellFormatter().setWordWrap(i, 5, false);\r
- table.getCellFormatter().setWordWrap(i, 6, false);\r
- table.getCellFormatter().setWordWrap(i, 7, false);\r
- table.getCellFormatter().setHorizontalAlignment(i, 4, HasHorizontalAlignment.ALIGN_CENTER);\r
- }\r
- prevButton.setVisible(false);\r
- nextButton.setVisible(false);\r
- }\r
-\r
- /**\r
- * Selects the given row (relative to the current page).\r
- *\r
- * @param row the row to be selected\r
- */\r
- private void selectRow(final int row) {\r
- if (row < folderFileCount) {\r
- if (clickControl)\r
- if (selectedRows.contains(row)) {\r
- int i = selectedRows.indexOf(startIndex + row);\r
- selectedRows.remove(i);\r
- styleRow(row, false);\r
- } else {\r
- selectedRows.add(startIndex + row);\r
- styleRow(row, true);\r
- }\r
- else if (selectedRows.size() == 1 && selectedRows.contains(row)){\r
- clearSelectedRows();\r
- return;\r
- }\r
- else {\r
- clearSelectedRows();\r
- selectedRows.add(startIndex + row);\r
- styleRow(row, true);\r
- }\r
- if (selectedRows.size() == 1)\r
- GSS.get().setCurrentSelection(files.get(selectedRows.get(0)));\r
- else if(selectedRows.size() == 0)\r
- GSS.get().setCurrentSelection(null);\r
- else\r
- GSS.get().setCurrentSelection(getSelectedFiles());\r
- contextMenu.setFiles(getSelectedFiles());\r
- makeRowDraggable(row+1);\r
- }\r
- }\r
-\r
- public List<FileResource> getSelectedFiles() {\r
- List<FileResource> result = new ArrayList();\r
- for (int i : selectedRows)\r
- result.add(files.get(i));\r
- return result;\r
- }\r
-\r
- /**\r
- * Make the specified row look like selected or not, according to the\r
- * <code>selected</code> flag.\r
- *\r
- * @param row\r
- * @param selected\r
- */\r
- void styleRow(final int row, final boolean selected) {\r
- if (row != -1 && row >= 0)\r
- if (selected)\r
- table.getRowFormatter().addStyleName(row + 1, "gss-SelectedRow");\r
- else\r
- table.getRowFormatter().removeStyleName(row + 1, "gss-SelectedRow");\r
- }\r
-\r
- /**\r
- * Update the display of the file list.\r
- */\r
- void update() {\r
- int count = folderFileCount;\r
- int max = startIndex + GSS.VISIBLE_FILE_COUNT;\r
- if (max > count)\r
- max = count;\r
- folderTotalSize = 0;\r
-\r
- // Show the selected files.\r
- int i = 1;\r
- for (; i < GSS.VISIBLE_FILE_COUNT + 1; ++i) {\r
- // Don't read past the end.\r
- // if (i > folderFileCount)\r
- // break;\r
- if (startIndex + i > folderFileCount)\r
- break;\r
- // Add a new row to the table, then set each of its columns to the\r
- // proper values.\r
- FileResource file = files.get(startIndex + i - 1);\r
- table.setWidget(i, 0, getFileIcon(file).createImage());\r
- table.getRowFormatter().addStyleName(i, "gss-fileRow");\r
-\r
- //add view image link for image files\r
- if (file.getContentType().startsWith("image/"))\r
- table.setHTML(i, 1, file.getName() + " <a href='" +\r
- GSS.get().getTopPanel().getFileMenu().getDownloadURL(file) +\r
- "' title='" + file.getName() + "' rel='lytebox' " +\r
- "onclick='myLytebox.start(this, false, false)'>" +\r
- "(view)" + "</a>");\r
- else\r
- table.setHTML(i, 1, file.getName());\r
- table.setText(i, 2, file.getOwner());\r
- table.setText(i, 3, file.getPath());\r
- table.setText(i, 4, String.valueOf(file.getVersion()));\r
- table.setText(i, 5, String.valueOf(file.getFileSizeAsString()));\r
- final DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a");\r
- table.setText(i, 6, formatter.format(file.getCreationDate()));\r
- folderTotalSize += file.getContentLength();\r
- }\r
-\r
- // Clear any remaining slots.\r
- for (; i < GSS.VISIBLE_FILE_COUNT + 1; ++i) {\r
- table.setHTML(i, 0, " ");\r
- table.setHTML(i, 1, " ");\r
- table.setHTML(i, 2, " ");\r
- table.setHTML(i, 3, " ");\r
- table.setHTML(i, 4, " ");\r
- table.setHTML(i, 5, " ");\r
- table.setHTML(i, 6, " ");\r
- table.setHTML(i, 7, " ");\r
- }\r
-\r
- if (folderFileCount == 0) {\r
- showingStats = "no files";\r
- prevButton.setVisible(false);\r
- nextButton.setVisible(false);\r
- } else if (folderFileCount < GSS.VISIBLE_FILE_COUNT) {\r
- if (folderFileCount == 1)\r
- showingStats = "1 file";\r
- else\r
- showingStats = folderFileCount + " files";\r
- showingStats += " (" + FileResource.getFileSizeAsString(folderTotalSize) + ")";\r
- prevButton.setVisible(false);\r
- nextButton.setVisible(false);\r
- } else {\r
- showingStats = "" + (startIndex + 1) + " - " + max + " of " + count + " files" + " (" + FileResource.getFileSizeAsString(folderTotalSize) + ")";\r
- prevButton.setVisible(startIndex != 0);\r
- nextButton.setVisible(startIndex + GSS.VISIBLE_FILE_COUNT < count);\r
- }\r
- updateCurrentlyShowingStats();\r
-\r
- }\r
-\r
- /**\r
- * Return the proper icon based on the MIME type of the file.\r
- *\r
- * @param file\r
- * @return the icon\r
- */\r
- private AbstractImagePrototype getFileIcon(FileResource file) {\r
- String mimetype = file.getContentType();\r
- boolean shared = file.isShared();\r
- if (mimetype == null)\r
- return shared ? images.documentShared() : images.document();\r
- mimetype = mimetype.toLowerCase();\r
- if (mimetype.startsWith("application/pdf"))\r
- return shared ? images.pdfShared() : images.pdf();\r
- else if (mimetype.endsWith("excel"))\r
- return shared ? images.spreadsheetShared() : images.spreadsheet();\r
- else if (mimetype.endsWith("msword"))\r
- return shared ? images.wordprocessorShared() : images.wordprocessor();\r
- else if (mimetype.endsWith("powerpoint"))\r
- return shared ? images.presentationShared() : images.presentation();\r
- else if (mimetype.startsWith("application/zip") ||\r
- mimetype.startsWith("application/gzip") ||\r
- mimetype.startsWith("application/x-gzip") ||\r
- mimetype.startsWith("application/x-tar") ||\r
- mimetype.startsWith("application/x-gtar"))\r
- return shared ? images.zipShared() : images.zip();\r
- else if (mimetype.startsWith("text/html"))\r
- return shared ? images.htmlShared() : images.html();\r
- else if (mimetype.startsWith("text/plain"))\r
- return shared ? images.txtShared() : images.txt();\r
- else if (mimetype.startsWith("image/"))\r
- return shared ? images.imageShared() : images.image();\r
- else if (mimetype.startsWith("video/"))\r
- return shared ? images.videoShared() : images.video();\r
- else if (mimetype.startsWith("audio/"))\r
- return shared ? images.audioShared() : images.audio();\r
- return shared ? images.documentShared() : images.document();\r
- }\r
-\r
- /**\r
- * Update status panel with currently showing file stats.\r
- */\r
- public void updateCurrentlyShowingStats() {\r
- GSS.get().getStatusPanel().updateCurrentlyShowing(showingStats);\r
- }\r
-\r
- /**\r
- * Adjust the height of the table by adding and removing rows as necessary.\r
- *\r
- * @param newHeight the new height to reach\r
- */\r
- void resizeTableHeight(final int newHeight) {\r
- GWT.log("Panel: " + newHeight + ", parent: " + table.getParent().getOffsetHeight(), null);\r
- // Fill the rest with empty slots.\r
- if (newHeight > table.getOffsetHeight())\r
- while (newHeight > table.getOffsetHeight()) {\r
- table.resizeRows(table.getRowCount() + 1);\r
- GWT.log("Table: " + table.getOffsetHeight() + ", rows: " + table.getRowCount(), null);\r
- }\r
- else\r
- while (newHeight < table.getOffsetHeight()) {\r
- table.resizeRows(table.getRowCount() - 1);\r
- GWT.log("Table: " + table.getOffsetHeight() + ", rows: " + table.getRowCount(), null);\r
- }\r
- }\r
-\r
- public void updateFileCache(boolean updateSelectedFolder, final boolean clearSelection) {\r
- if (!updateSelectedFolder && !GSS.get().getFolders().getTrashItem().equals(GSS.get().getFolders().getCurrent()))\r
- updateFileCache(clearSelection);\r
- else if (GSS.get().getFolders().getCurrent() != null) {\r
- final DnDTreeItem folderItem = (DnDTreeItem) GSS.get().getFolders().getCurrent();\r
- if (folderItem.getFolderResource() != null) {\r
- update();\r
- GetCommand<FolderResource> gf = new GetCommand<FolderResource>(FolderResource.class, folderItem.getFolderResource().getUri()) {\r
-\r
- @Override\r
- public void onComplete() {\r
- folderItem.setUserObject(getResult());\r
- if(GSS.get().getFolders().isFileItem(folderItem)){\r
- String[] filePaths = new String[folderItem.getFolderResource().getFilePaths().size()];\r
- int c=0;\r
- for(String fpath : folderItem.getFolderResource().getFilePaths()){\r
- filePaths[c] = fpath + "?" + Math.random();\r
- c++;\r
- }\r
- MultipleHeadCommand<FileResource> getFiles = new MultipleHeadCommand<FileResource>(FileResource.class, filePaths){\r
-\r
- @Override\r
- public void onComplete(){\r
- List<FileResource> result = getResult();\r
- //remove random from path\r
- for(FileResource r : result){\r
- String p = r.getUri();\r
- int indexOfQuestionMark = p.lastIndexOf('?');\r
- if(indexOfQuestionMark>0)\r
- r.setUri(p.substring(0, indexOfQuestionMark));\r
- }\r
- folderItem.getFolderResource().setFiles(result);\r
- updateFileCache(clearSelection);\r
- }\r
-\r
- @Override\r
- public void onError(String p, Throwable throwable) {\r
- if(throwable instanceof RestException)\r
- GSS.get().displayError("Unable to retrieve file details:"+((RestException)throwable).getHttpStatusText());\r
- }\r
-\r
- @Override\r
- public void onError(Throwable t) {\r
- GWT.log("", t);\r
- GSS.get().displayError("Unable to fetch files for folder " + folderItem.getFolderResource().getName());\r
- }\r
-\r
- };\r
- DeferredCommand.addCommand(getFiles);\r
- }\r
- else\r
- updateFileCache(clearSelection);\r
- }\r
-\r
- @Override\r
- public void onError(Throwable t) {\r
- GWT.log("", t);\r
- GSS.get().displayError("Unable to fetch folder " + folderItem.getFolderResource().getName());\r
- }\r
- };\r
- DeferredCommand.addCommand(gf);\r
- } else if (folderItem.getTrashResource() != null) {\r
- GetCommand<TrashResource> gt = new GetCommand<TrashResource>(TrashResource.class, folderItem.getTrashResource().getUri()) {\r
-\r
- @Override\r
- public void onComplete() {\r
- folderItem.setUserObject(getResult());\r
- updateFileCache(clearSelection);\r
- }\r
-\r
- @Override\r
- public void onError(Throwable t) {\r
- if (t instanceof RestException && (((RestException) t).getHttpStatusCode() == 204 || ((RestException) t).getHttpStatusCode() == 1223)) {\r
- folderItem.setUserObject(new TrashResource(folderItem.getTrashResource().getUri()));\r
- updateFileCache(clearSelection);\r
- } else {\r
- GWT.log("", t);\r
- GSS.get().displayError("Unable to fetch trash resource");\r
- }\r
- }\r
- };\r
- DeferredCommand.addCommand(gt);\r
- } else if (folderItem.getSharedResource() != null) {\r
- GetCommand<SharedResource> gt = new GetCommand<SharedResource>(SharedResource.class, folderItem.getSharedResource().getUri()) {\r
-\r
- @Override\r
- public void onComplete() {\r
- folderItem.setUserObject(getResult());\r
- updateFileCache(clearSelection);\r
- }\r
-\r
- @Override\r
- public void onError(Throwable t) {\r
- GWT.log("", t);\r
- GSS.get().displayError("Unable to fetch My Shares resource");\r
- }\r
- };\r
- DeferredCommand.addCommand(gt);\r
- } else if (folderItem.getOtherUserResource() != null) {\r
- GetCommand<OtherUserResource> gt = new GetCommand<OtherUserResource>(OtherUserResource.class, folderItem.getOtherUserResource().getUri()) {\r
-\r
- @Override\r
- public void onComplete() {\r
- folderItem.setUserObject(getResult());\r
- updateFileCache(clearSelection);\r
- }\r
-\r
- @Override\r
- public void onError(Throwable t) {\r
- GWT.log("", t);\r
- GSS.get().displayError("Unable to fetch My Shares resource");\r
- }\r
- };\r
- DeferredCommand.addCommand(gt);\r
- }\r
- } else\r
- updateFileCache(clearSelection);\r
- }\r
-\r
- /**\r
- * Update the file cache with data from the server.\r
- *\r
- * @param userId the ID of the current user\r
- */\r
- private void updateFileCache(boolean clearSelection) {\r
- if (clearSelection)\r
- clearSelectedRows();\r
- clearLabels();\r
- sortingProperty = "name";\r
- nameLabel.setHTML("Name " + images.desc().getHTML());\r
- sortingType = true;\r
- startIndex = 0;\r
- final TreeItem folderItem = GSS.get().getFolders().getCurrent();\r
- // Validation.\r
- if (folderItem == null || GSS.get().getFolders().isOthersShared(folderItem)) {\r
- setFiles(new ArrayList<FileResource>());\r
- update();\r
- return;\r
- }\r
- if (folderItem instanceof DnDTreeItem) {\r
- DnDTreeItem dnd = (DnDTreeItem) folderItem;\r
- if (dnd.getFolderResource() != null) {\r
- if (GSS.get().getFolders().isTrashItem(dnd))\r
- setFiles(new ArrayList<FileResource>());\r
- else\r
- setFiles(dnd.getFolderResource().getFiles());\r
-\r
- } else if (dnd.getTrashResource() != null)\r
- setFiles(dnd.getTrashResource().getFiles());\r
- else if (dnd.getSharedResource() != null)\r
- setFiles(dnd.getSharedResource().getFiles());\r
- else if (dnd.getOtherUserResource() != null)\r
- setFiles(dnd.getOtherUserResource().getFiles());\r
- else\r
- setFiles(dnd.getFolderResource().getFiles());\r
-\r
- update();\r
- }\r
- }\r
-\r
- /**\r
- * Fill the file cache with data.\r
- */\r
- public void setFiles(final List<FileResource> _files) {\r
- if (_files.size() > 0 && !GSS.get().getFolders().isTrash(GSS.get().getFolders().getCurrent())) {\r
- files = new ArrayList<FileResource>();\r
- for (FileResource fres : _files)\r
- if (!fres.isDeleted())\r
- files.add(fres);\r
- } else\r
- files = _files;\r
- Collections.sort(files, new Comparator<FileResource>() {\r
-\r
- public int compare(FileResource arg0, FileResource arg1) {\r
- return arg0.getName().compareTo(arg1.getName());\r
- }\r
-\r
- });\r
- folderFileCount = files.size();\r
- }\r
-\r
- private void sortFiles(final String sortProperty) {\r
- if (sortProperty.equals(sortingProperty))\r
- sortingType = !sortingType;\r
- else {\r
- sortingProperty = sortProperty;\r
- sortingType = true;\r
- }\r
- clearLabels();\r
- clearSelectedRows();\r
- if (files == null || files.size() == 0)\r
- return;\r
- Collections.sort(files, new Comparator<FileResource>() {\r
-\r
- public int compare(FileResource arg0, FileResource arg1) {\r
- if (sortingType)\r
- if (sortProperty.equals("version")) {\r
- versionLabel.setHTML("Version " + images.desc().getHTML());\r
- return new Integer(arg0.getVersion()).compareTo(new Integer(arg1.getVersion()));\r
- } else if (sortProperty.equals("owner")) {\r
- ownerLabel.setHTML("Owner " + images.desc().getHTML());\r
- return new Integer(arg0.getOwner()).compareTo(new Integer(arg1.getOwner()));\r
- } else if (sortProperty.equals("date")) {\r
- dateLabel.setHTML("Date " + images.desc().getHTML());\r
- return arg0.getCreationDate().compareTo(arg1.getCreationDate());\r
- } else if (sortProperty.equals("size")) {\r
- sizeLabel.setHTML("Size " + images.desc().getHTML());\r
- return new Long(arg0.getContentLength()).compareTo(new Long(arg1.getContentLength()));\r
- } else if (sortProperty.equals("name")) {\r
- nameLabel.setHTML("Name " + images.desc().getHTML());\r
- return arg0.getName().compareTo(arg1.getName());\r
- } else if (sortProperty.equals("path")) {\r
- pathLabel.setHTML("Path " + images.desc().getHTML());\r
- return arg0.getUri().compareTo(arg1.getUri());\r
- } else {\r
- nameLabel.setHTML("Name " + images.desc().getHTML());\r
- return arg0.getName().compareTo(arg1.getName());\r
- }\r
- else if (sortProperty.equals("version")) {\r
- versionLabel.setHTML("Version " + images.asc().getHTML());\r
- return new Integer(arg1.getVersion()).compareTo(new Integer(arg0.getVersion()));\r
- } else if (sortProperty.equals("owner")) {\r
- ownerLabel.setHTML("Owner " + images.asc().getHTML());\r
- return new Integer(arg1.getOwner()).compareTo(new Integer(arg0.getOwner()));\r
- } else if (sortProperty.equals("date")) {\r
- dateLabel.setHTML("Date " + images.asc().getHTML());\r
- return arg1.getCreationDate().compareTo(arg0.getCreationDate());\r
- } else if (sortProperty.equals("size")) {\r
- sizeLabel.setHTML("Size " + images.asc().getHTML());\r
- return new Long(arg1.getContentLength()).compareTo(new Long(arg0.getContentLength()));\r
- } else if (sortProperty.equals("name")) {\r
- nameLabel.setHTML("Name " + images.asc().getHTML());\r
- return arg1.getName().compareTo(arg0.getName());\r
- } else if (sortProperty.equals("path")) {\r
- pathLabel.setHTML("Path " + images.asc().getHTML());\r
- return arg1.getUri().compareTo(arg0.getUri());\r
- } else {\r
- nameLabel.setHTML("Name " + images.asc().getHTML());\r
- return arg1.getName().compareTo(arg0.getName());\r
- }\r
- }\r
-\r
- });\r
- }\r
-\r
- private void clearLabels() {\r
- nameLabel.setText("Name");\r
- versionLabel.setText("Version");\r
- sizeLabel.setText("Size");\r
- dateLabel.setText("Date");\r
- ownerLabel.setText("Owner");\r
- pathLabel.setText("Path");\r
- }\r
-\r
- /**\r
- * Retrieve the table.\r
- *\r
- * @return the table\r
- */\r
- Grid getTable() {\r
- return table;\r
- }\r
-\r
- /**\r
- * Does the list contains the requested filename\r
- *\r
- * @param fileName\r
- * @return true/false\r
- */\r
- public boolean contains(String fileName) {\r
- for (int i = 0; i < files.size(); i++)\r
- if (files.get(i).getName().equals(fileName))\r
- return true;\r
- return false;\r
- }\r
-\r
- public void clearSelectedRows() {\r
- for (int r : selectedRows) {\r
- int row = r - startIndex;\r
- styleRow(row, false);\r
- }\r
- selectedRows.clear();\r
- Object sel = GSS.get().getCurrentSelection();\r
- if (sel instanceof FileResource || sel instanceof List)\r
- GSS.get().setCurrentSelection(null);\r
- }\r
-\r
- /**\r
- *\r
- */\r
- public void selectAllRows() {\r
- clearSelectedRows();\r
- int count = folderFileCount;\r
- if (count == 0)\r
- return;\r
- int max = startIndex + GSS.VISIBLE_FILE_COUNT;\r
- if (max > count)\r
- max = count;\r
- int i = 1;\r
- for (; i < GSS.VISIBLE_FILE_COUNT + 1; ++i) {\r
- // Don't read past the end.\r
- // if (i > folderFileCount)\r
- // break;\r
- if (startIndex + i > folderFileCount)\r
- break;\r
- selectedRows.add(startIndex + i - 1);\r
- styleRow(i - 1, true);\r
- }\r
- GSS.get().setCurrentSelection(getSelectedFiles());\r
- contextMenu.setFiles(getSelectedFiles());\r
- makeRowDraggable(i-1);\r
-\r
- }\r
-\r
- private void makeRowDraggable(int row){\r
- int contextRow = getWidgetRow(contextMenu, table);\r
- if (contextRow != -1)\r
- table.setWidget(contextRow, 0, getFileIcon(files.get(contextRow - 1)).createImage());\r
- contextMenu.setWidget(new HTML(getFileIcon(files.get(row - 1)).getHTML()));\r
- table.setWidget(row, 0, contextMenu);\r
- }\r
-\r
- private int getWidgetRow(Widget widget, Grid grid) {\r
- for (int row = 0; row < grid.getRowCount(); row++)\r
- for (int col = 0; col < grid.getCellCount(row); col++) {\r
- Widget w = table.getWidget(row, col);\r
- if (w == widget)\r
- return row;\r
- }\r
- return -1;\r
- }\r
-\r
-}\r
+/*
+ * Copyright 2007, 2008, 2009 Electronic Business Systems Ltd.
+ *
+ * This file is part of GSS.
+ *
+ * GSS is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GSS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GSS. If not, see <http://www.gnu.org/licenses/>.
+ */
+package gr.ebs.gss.client;
+
+import static com.google.gwt.query.client.GQuery.$;
+import gr.ebs.gss.client.rest.GetCommand;
+import gr.ebs.gss.client.rest.RestCommand;
+import gr.ebs.gss.client.rest.resource.FileResource;
+import gr.ebs.gss.client.rest.resource.RestResource;
+import gr.ebs.gss.client.rest.resource.RestResourceWrapper;
+import gr.ebs.gss.client.rest.resource.SharedResource;
+import gr.ebs.gss.client.rest.resource.TrashResource;
+import gr.ebs.gss.client.rest.resource.UserResource;
+import gr.ebs.gss.client.rest.resource.UserSearchResource;
+import gwtquery.plugins.draggable.client.DraggableOptions;
+import gwtquery.plugins.draggable.client.StopDragException;
+import gwtquery.plugins.draggable.client.DraggableOptions.DragFunction;
+import gwtquery.plugins.draggable.client.DraggableOptions.RevertOption;
+import gwtquery.plugins.draggable.client.events.DragContext;
+import gwtquery.plugins.draggable.client.events.DragStartEvent;
+import gwtquery.plugins.draggable.client.events.DragStopEvent;
+import gwtquery.plugins.draggable.client.events.DragStartEvent.DragStartEventHandler;
+import gwtquery.plugins.draggable.client.events.DragStopEvent.DragStopEventHandler;
+import gwtquery.plugins.droppable.client.gwt.DragAndDropCellTable;
+import gwtquery.plugins.droppable.client.gwt.DragAndDropColumn;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
+
+import com.google.gwt.cell.client.AbstractCell;
+import com.google.gwt.cell.client.ImageResourceCell;
+import com.google.gwt.cell.client.SafeHtmlCell;
+import com.google.gwt.cell.client.TextCell;
+import com.google.gwt.cell.client.ValueUpdater;
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.core.client.Scheduler;
+import com.google.gwt.core.client.Scheduler.RepeatingCommand;
+import com.google.gwt.dom.client.Style.Cursor;
+import com.google.gwt.http.client.URL;
+import com.google.gwt.i18n.client.DateTimeFormat;
+import com.google.gwt.resources.client.ClientBundle;
+import com.google.gwt.resources.client.ImageResource;
+import com.google.gwt.safehtml.client.SafeHtmlTemplates;
+import com.google.gwt.safehtml.shared.SafeHtml;
+import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
+import com.google.gwt.safehtml.shared.SafeHtmlUtils;
+import com.google.gwt.user.cellview.client.CellTable;
+import com.google.gwt.user.cellview.client.Column;
+import com.google.gwt.user.cellview.client.TextColumn;
+import com.google.gwt.user.cellview.client.HasKeyboardSelectionPolicy.KeyboardSelectionPolicy;
+import com.google.gwt.user.client.DOM;
+import com.google.gwt.user.client.DeferredCommand;
+import com.google.gwt.user.client.Event;
+import com.google.gwt.user.client.Window;
+import com.google.gwt.user.client.ui.AbstractImagePrototype;
+import com.google.gwt.user.client.ui.Composite;
+import com.google.gwt.user.client.ui.HTML;
+import com.google.gwt.user.client.ui.HasHorizontalAlignment;
+import com.google.gwt.user.client.ui.HorizontalPanel;
+import com.google.gwt.user.client.ui.VerticalPanel;
+import com.google.gwt.view.client.MultiSelectionModel;
+import com.google.gwt.view.client.ProvidesKey;
+import com.google.gwt.view.client.SelectionChangeEvent;
+import com.google.gwt.view.client.SelectionChangeEvent.Handler;
+
+/**
+ * A composite that displays the list of files in a particular folder.
+ */
+public class FileList extends Composite {
+
+ interface TableResources extends DragAndDropCellTable.Resources {
+ @Source({CellTable.Style.DEFAULT_CSS, "GssCellTable.css"})
+ TableStyle cellTableStyle();
+ }
+
+ static interface Templates extends SafeHtmlTemplates {
+ Templates INSTANCE = GWT.create(Templates.class);
+
+ @Template("<div id='dragHelper' style='border:1px solid black; background-color:#ffffff; color:black; width:150px;z-index:100'></div>")
+ SafeHtml outerHelper();
+ }
+
+
+ /**
+ * The styles applied to the table.
+ */
+ interface TableStyle extends CellTable.Style {
+ }
+
+ private String showingStats = "";
+
+ private int startIndex = 0;
+
+ /**
+ * A constant that denotes the completion of an IncrementalCommand.
+ */
+ public static final boolean DONE = false;
+
+
+
+ private final DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a");
+
+ /**
+ * Specifies that the images available for this composite will be the ones
+ * available in FileContextMenu.
+ */
+ public interface Images extends ClientBundle,FileContextMenu.Images, CellTreeView.Images {
+
+ @Source("gr/ebs/gss/resources/blank.gif")
+ ImageResource blank();
+
+ @Source("gr/ebs/gss/resources/asc.png")
+ ImageResource asc();
+
+ @Source("gr/ebs/gss/resources/desc.png")
+ ImageResource desc();
+
+ @Source("gr/ebs/gss/resources/mimetypes/document_shared.png")
+ ImageResource documentShared();
+
+ @Source("gr/ebs/gss/resources/mimetypes/kcmfontinst.png")
+ ImageResource wordprocessor();
+
+ @Source("gr/ebs/gss/resources/mimetypes/log.png")
+ ImageResource spreadsheet();
+
+ @Source("gr/ebs/gss/resources/mimetypes/kpresenter_kpr.png")
+ ImageResource presentation();
+
+ @Source("gr/ebs/gss/resources/mimetypes/acroread.png")
+ ImageResource pdf();
+
+ @Source("gr/ebs/gss/resources/mimetypes/image.png")
+ ImageResource image();
+
+ @Source("gr/ebs/gss/resources/mimetypes/video2.png")
+ ImageResource video();
+
+ @Source("gr/ebs/gss/resources/mimetypes/knotify.png")
+ ImageResource audio();
+
+ @Source("gr/ebs/gss/resources/mimetypes/html.png")
+ ImageResource html();
+
+ @Source("gr/ebs/gss/resources/mimetypes/txt.png")
+ ImageResource txt();
+
+ @Source("gr/ebs/gss/resources/mimetypes/ark2.png")
+ ImageResource zip();
+
+ @Source("gr/ebs/gss/resources/mimetypes/kcmfontinst_shared.png")
+ ImageResource wordprocessorShared();
+
+ @Source("gr/ebs/gss/resources/mimetypes/log_shared.png")
+ ImageResource spreadsheetShared();
+
+ @Source("gr/ebs/gss/resources/mimetypes/kpresenter_kpr_shared.png")
+ ImageResource presentationShared();
+
+ @Source("gr/ebs/gss/resources/mimetypes/acroread_shared.png")
+ ImageResource pdfShared();
+
+ @Source("gr/ebs/gss/resources/mimetypes/image_shared.png")
+ ImageResource imageShared();
+
+ @Source("gr/ebs/gss/resources/mimetypes/video2_shared.png")
+ ImageResource videoShared();
+
+ @Source("gr/ebs/gss/resources/mimetypes/knotify_shared.png")
+ ImageResource audioShared();
+
+ @Source("gr/ebs/gss/resources/mimetypes/html_shared.png")
+ ImageResource htmlShared();
+
+ @Source("gr/ebs/gss/resources/mimetypes/txt_shared.png")
+ ImageResource txtShared();
+
+ @Source("gr/ebs/gss/resources/mimetypes/ark2_shared.png")
+ ImageResource zipShared();
+
+ }
+
+ DragStopEventHandler dragStop = new DragStopEventHandler() {
+
+ @Override
+ public void onDragStop(DragStopEvent event) {
+ GWT.log("DRAG STOPPED");
+
+ }
+ };
+
+ private static class ContactCell extends AbstractCell<gr.ebs.gss.client.rest.resource.FileResource> {
+
+ /**
+ * The html of the image used for contacts.
+ *
+ */
+ private final String imageHtml;
+
+ public ContactCell(ImageResource image) {
+ this.imageHtml = AbstractImagePrototype.create(image).getHTML();
+ }
+
+
+
+
+
+ @Override
+ public void render(Context context, FileResource value, SafeHtmlBuilder sb) {
+ // Value can be null, so do a null check..
+ if (value == null) {
+ return;
+ }
+
+ sb.appendHtmlConstant("<table>");
+
+ // Add the contact image.
+ sb.appendHtmlConstant("<tr><td rowspan='3'>");
+ sb.appendHtmlConstant(imageHtml);
+ sb.appendHtmlConstant("</td>");
+
+ // Add the name and address.
+ DisplayHelper.log("value.getName()");
+ sb.appendHtmlConstant("<td style='font-size:95%;' id='"+value.getName()+"'>");
+ sb.appendEscaped(value.getName());
+ sb.appendHtmlConstant("</td></tr><tr><td>");
+ sb.appendEscaped(value.getFileSizeAsString());
+ sb.appendHtmlConstant("</td></tr></table>");
+ }
+
+
+ }
+ /**
+ * Retrieve the celltable.
+ *
+ * @return the celltable
+ */
+ public DragAndDropCellTable<FileResource> getCelltable() {
+ return celltable;
+ }
+ /**
+ * A label with the number of files in this folder.
+ */
+ private HTML countLabel = new HTML();
+
+ /**
+ * The table widget with the file list.
+ */
+ //private FileTable table = new FileTable(GSS.VISIBLE_FILE_COUNT + 1, 8);
+
+ /**
+ * The navigation bar for paginating the results.
+ */
+ private HorizontalPanel navBar = new HorizontalPanel();
+
+ /**
+ * The number of files in this folder.
+ */
+ int folderFileCount;
+
+ /**
+ * Total folder size
+ */
+ long folderTotalSize;
+
+ /**
+ * A cache of the files in the list.
+ */
+ private List<FileResource> files;
+
+ /**
+ * The widget's image bundle.
+ */
+ private final Images images;
+ VerticalPanel panel;
+
+ private FileContextMenu menuShowing;
+ private DragAndDropCellTable<FileResource> celltable;
+ private final MultiSelectionModel<FileResource> selectionModel;
+ private final List<SortableHeader> allHeaders = new ArrayList<SortableHeader>();
+ SortableHeader nameHeader;
+ /**
+ * Construct the file list widget. This entails setting up the widget
+ * layout, fetching the number of files in the current folder from the
+ * server and filling the local file cache of displayed files with data from
+ * the server, as well.
+ *
+ * @param _images
+ */
+ public FileList(Images _images) {
+ images = _images;
+ DragAndDropCellTable.Resources resources = GWT.create(TableResources.class);
+
+
+ // Create the 'navigation' bar at the upper-right.
+ HorizontalPanel innerNavBar = new HorizontalPanel();
+ innerNavBar.setStyleName("gss-ListNavBar");
+ innerNavBar.setSpacing(8);
+ innerNavBar.add(countLabel);
+ navBar.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_RIGHT);
+ navBar.add(innerNavBar);
+ navBar.setWidth("100%");
+ ProvidesKey<FileResource> keyProvider = new ProvidesKey<FileResource>(){
+
+ @Override
+ public Object getKey(FileResource item) {
+ return item.getUri();
+ }
+
+ };
+ final DragAndDropColumn<FileResource,SafeHtml> nameColumn = new DragAndDropColumn<FileResource,SafeHtml>(new SafeHtmlCell()) {
+
+
+ @Override
+ public SafeHtml getValue(FileResource object) {
+ SafeHtmlBuilder sb = new SafeHtmlBuilder();
+ if (object.getContentType().endsWith("png") || object.getContentType().endsWith("gif") || object.getContentType().endsWith("jpeg") ){
+ sb.appendHtmlConstant("<span id='fileList."+ object.getName() +"'>");
+ sb.appendEscaped(object.getName());
+ sb.appendHtmlConstant("</span>");
+ sb.appendHtmlConstant(" <a href='" +
+ GSS.get().getTopPanel().getFileMenu().getDownloadURL(object) +
+ "' title='" + object.getOwner() + " : " + object.getPath() + object.getName() +
+ "' rel='lytebox[mnf]' " +
+ "onclick='myLytebox.start(this, false, false); return false;'>" +
+ "(view)" + "</a>");
+
+
+ }
+ else{
+ sb.appendHtmlConstant("<span id='fileList."+ object.getName() +"'>");
+ sb.appendEscaped(object.getName());
+ sb.appendHtmlConstant("</span>");
+ }
+ return sb.toSafeHtml();
+ }
+
+
+ };
+ initDragOperation(nameColumn);
+ celltable = new DragAndDropCellTable<FileResource>(100,resources,keyProvider){
+ @Override
+ protected void onBrowserEvent2(Event event) {
+ /*if (DOM.eventGetType((Event) event) == Event.ONMOUSEDOWN && DOM.eventGetButton((Event) event) == NativeEvent.BUTTON_RIGHT){
+ fireClickEvent((Element) event.getEventTarget().cast());
+ }*/
+ super.onBrowserEvent2(event);
+ }
+ };
+
+ celltable.addDragStopHandler(dragStop);
+ celltable.addDragStartHandler(new DragStartEventHandler() {
+
+ public void onDragStart(DragStartEvent event) {
+ FileResource value = event.getDraggableData();
+ com.google.gwt.dom.client.Element helper = event.getHelper();
+ SafeHtmlBuilder sb = new SafeHtmlBuilder();
+ sb.appendHtmlConstant("<b>");
+ DisplayHelper.log(value.getName());
+ sb.appendEscaped(value.getName());
+ sb.appendHtmlConstant("</b>");
+ helper.setInnerHTML(sb.toSafeHtml().asString());
+
+ }
+ });
+ Column<FileResource, ImageResource> status = new Column<FileResource, ImageResource>(new ImageResourceCell()) {
+ @Override
+ public ImageResource getValue(FileResource entity) {
+ return getFileIcon(entity);
+ }
+ };
+ celltable.addColumn(status,"");
+
+
+ celltable.addColumn(nameColumn,nameHeader = new SortableHeader("Name"));
+ allHeaders.add(nameHeader);
+ nameHeader.setSorted(true);
+ nameHeader.toggleReverseSort();
+ nameHeader.setUpdater(new FileValueUpdater(nameHeader, "name"));
+ celltable.redrawHeaders();
+ SortableHeader aheader;
+ celltable.addColumn(new TextColumn<FileResource>() {
+ @Override
+ public String getValue(FileResource object) {
+ return GSS.get().findUserFullName(object.getOwner());
+ }
+ },aheader = new SortableHeader("Owner"));
+ allHeaders.add(aheader);
+ aheader.setUpdater(new FileValueUpdater(aheader, "owner"));
+ celltable.addColumn(new TextColumn<FileResource>() {
+ @Override
+ public String getValue(FileResource object) {
+ // TODO Auto-generated method stub
+ return object.getPath();
+ }
+ },aheader = new SortableHeader("Path"));
+ allHeaders.add(aheader);
+ aheader.setUpdater(new FileValueUpdater(aheader, "path"));
+ celltable.addColumn(new TextColumn<FileResource>() {
+ @Override
+ public String getValue(FileResource object) {
+ // TODO Auto-generated method stub
+ return object.getVersion().toString();
+ }
+ },aheader = new SortableHeader("Version"));
+ allHeaders.add(aheader);
+ aheader.setUpdater(new FileValueUpdater(aheader, "version"));
+ celltable.addColumn(new TextColumn<FileResource>() {
+ @Override
+ public String getValue(FileResource object) {
+ // TODO Auto-generated method stub
+ return object.getFileSizeAsString();
+ }
+ },aheader = new SortableHeader("Size"));
+ allHeaders.add(aheader);
+ aheader.setUpdater(new FileValueUpdater(aheader, "size"));
+ celltable.addColumn(new TextColumn<FileResource>() {
+ @Override
+ public String getValue(FileResource object) {
+ return formatter.format(object.getModificationDate());
+ }
+ },aheader = new SortableHeader("Last Modified"));
+ allHeaders.add(aheader);
+ aheader.setUpdater(new FileValueUpdater(aheader, "date"));
+
+ initWidget(celltable);
+ setStyleName("gss-List");
+ selectionModel = new MultiSelectionModel<FileResource>();
+
+
+ Handler selectionHandler = new SelectionChangeEvent.Handler() {
+ @Override
+ public void onSelectionChange(com.google.gwt.view.client.SelectionChangeEvent event) {
+ if(getSelectedFiles().size()==1)
+ GSS.get().setCurrentSelection(getSelectedFiles().get(0));
+ else
+ GSS.get().setCurrentSelection(getSelectedFiles());
+ //contextMenu.setFiles(getSelectedFiles());
+ }
+ };
+ selectionModel.addSelectionChangeHandler(selectionHandler);
+
+ celltable.setSelectionModel(selectionModel,GSSSelectionEventManager.<FileResource>createDefaultManager());
+ celltable.setPageSize(GSS.VISIBLE_FILE_COUNT);
+ celltable.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
+ Scheduler.get().scheduleIncremental(new RepeatingCommand() {
+
+ @Override
+ public boolean execute() {
+ return fetchRootFolder();
+ }
+ });
+ sinkEvents(Event.ONCONTEXTMENU);
+ sinkEvents(Event.ONMOUSEUP);
+ sinkEvents(Event.ONMOUSEDOWN);
+ sinkEvents(Event.ONCLICK);
+ sinkEvents(Event.ONKEYDOWN);
+ sinkEvents(Event.ONDBLCLICK);
+ GSS.preventIESelection();
+ }
+
+ //public native void fireClickEvent(Element element) /*-{
+ // var evObj = $doc.createEvent('MouseEvents');
+ //evObj.initEvent('click', true, true);
+ //element.dispatchEvent(evObj);
+ //}-*/;
+
+ public List<FileResource> getSelectedFiles() {
+ return new ArrayList<FileResource>(selectionModel.getSelectedSet());
+ }
+
+ private void initDragOperation(DragAndDropColumn<?, ?> column) {
+
+ // retrieve draggableOptions on the column
+ DraggableOptions draggableOptions = column.getDraggableOptions();
+ // use template to construct the helper. The content of the div will be set
+ // after
+ draggableOptions.setHelper($(Templates.INSTANCE.outerHelper().asString()));
+ //draggableOptions.setZIndex(100);
+ // opacity of the helper
+ draggableOptions.setAppendTo("body");
+ //draggableOptions.setOpacity((float) 0.8);
+ draggableOptions.setContainment("document");
+ // cursor to use during the drag operation
+ draggableOptions.setCursor(Cursor.MOVE);
+ // set the revert option
+ draggableOptions.setRevert(RevertOption.ON_INVALID_DROP);
+ // prevents dragging when user click on the category drop-down list
+ draggableOptions.setCancel("select");
+
+ draggableOptions.setOnBeforeDragStart(new DragFunction() {
+
+ @Override
+ public void f(DragContext context) {
+ FileResource value = context.getDraggableData();
+ if(!selectionModel.isSelected(value)){
+ throw new StopDragException();
+ }
+
+ }
+ });
+ }
+
+ public void showContextMenu(Event event){
+ menuShowing = new FileContextMenu(images, false, true);
+ menuShowing=menuShowing.onEmptyEvent(event);
+ }
+ @Override
+ public void onBrowserEvent(Event event) {
+
+ if (files == null || files.size() == 0) {
+ if (DOM.eventGetType(event) == Event.ONCONTEXTMENU && getSelectedFiles().size() == 0) {
+ menuShowing = new FileContextMenu(images, false, true);
+ menuShowing=menuShowing.onEmptyEvent(event);
+ event.preventDefault();
+ event.cancelBubble(true);
+ }
+ return;
+ }
+ if (DOM.eventGetType(event) == Event.ONCONTEXTMENU && getSelectedFiles().size() != 0) {
+ GWT.log("*****GOING TO SHOW CONTEXT MENU ****", null);
+ menuShowing = new FileContextMenu(images, false, false);
+ menuShowing=menuShowing.onEvent(event);
+ event.cancelBubble(true);
+ event.preventDefault();
+ } else if (DOM.eventGetType(event) == Event.ONCONTEXTMENU && getSelectedFiles().size() == 0) {
+ menuShowing = new FileContextMenu(images, false, true);
+ menuShowing=menuShowing.onEmptyEvent(event);
+ event.cancelBubble(true);
+ event.preventDefault();
+ } else if (DOM.eventGetType(event) == Event.ONDBLCLICK)
+ if (getSelectedFiles().size() == 1) {
+ GSS app = GSS.get();
+ FileResource file = getSelectedFiles().get(0);
+ String dateString = RestCommand.getDate();
+ String resource = file.getUri().substring(app.getApiPath().length() - 1, file.getUri().length());
+ String sig = app.getCurrentUserResource().getUsername() + " " +
+ RestCommand.calculateSig("GET", dateString, resource,
+ RestCommand.base64decode(app.getToken()));
+ Window.open(file.getUri() + "?Authorization=" + URL.encodeComponent(sig) + "&Date=" + URL.encodeComponent(dateString), "_blank", "");
+ event.preventDefault();
+ return;
+ }
+ super.onBrowserEvent(event);
+ }
+
+ /**
+ * Retrieve the root folder for the current user.
+ *
+ * @return true if the retrieval was successful
+ */
+ protected boolean fetchRootFolder() {
+ UserResource user = GSS.get().getCurrentUserResource();
+ if (user == null)
+ return !DONE;
+ // Update cache and clear selection.
+ updateFileCache(true);
+ return DONE;
+ }
+
+
+ /**
+ * Update the display of the file list.
+ */
+ void update(boolean sort) {
+ int count = folderFileCount;
+ int max = startIndex + GSS.VISIBLE_FILE_COUNT;
+ if (max > count)
+ max = count;
+ folderTotalSize = 0;
+
+ copyListAndContinue(files);
+ for(FileResource f : files){
+ folderTotalSize += f.getContentLength();
+ }
+ if (folderFileCount == 0) {
+ showingStats = "no files";
+ } else if (folderFileCount < GSS.VISIBLE_FILE_COUNT) {
+ if (folderFileCount == 1)
+ showingStats = "1 file";
+ else
+ showingStats = folderFileCount + " files";
+ showingStats += " (" + FileResource.getFileSizeAsString(folderTotalSize) + ")";
+ } else {
+ showingStats = "" + (startIndex + 1) + " - " + max + " of " + count + " files" + " (" + FileResource.getFileSizeAsString(folderTotalSize) + ")";
+ }
+ updateCurrentlyShowingStats();
+
+ }
+
+ /**
+ * Return the proper icon based on the MIME type of the file.
+ *
+ * @param file
+ * @return the icon
+ */
+ private ImageResource getFileIcon(FileResource file) {
+ String mimetype = file.getContentType();
+ boolean shared = false;
+ //TODO: FETCH USER OF OTHER FOLDER ITEM
+ //if(GSS.get().getTreeView().getSelection()!=null && (GSS.get().getTreeView().getSelection() instanceof OtherUserResource || GSS.get().getTreeView().getSelection() instanceof OthersFolderResource))
+ /*Folders folders = GSS.get().getFolders();
+ if(folders.getCurrent() != null && folders.isOthersSharedItem(folders.getCurrent())){
+ DnDTreeItem otherUser = (DnDTreeItem) folders.getUserOfSharedItem(folders.getCurrent());
+ if(otherUser==null)
+ shared = false;
+ else{
+ String uname = otherUser.getOtherUserResource().getUsername();
+ if(uname==null)
+ uname = ((DnDTreeItem)folders.getSharesItem()).getOthersResource().getUsernameOfUri(otherUser.getOtherUserResource().getUri());
+ if(uname != null)
+ shared = file.isShared();
+ }
+ }
+ else*/
+ shared = file.isShared();
+ if (mimetype == null)
+ return shared ? images.documentShared() : images.document();
+ mimetype = mimetype.toLowerCase();
+ if (mimetype.startsWith("application/pdf"))
+ return shared ? images.pdfShared() : images.pdf();
+ else if (mimetype.endsWith("excel"))
+ return shared ? images.spreadsheetShared() : images.spreadsheet();
+ else if (mimetype.endsWith("msword"))
+ return shared ? images.wordprocessorShared() : images.wordprocessor();
+ else if (mimetype.endsWith("powerpoint"))
+ return shared ? images.presentationShared() : images.presentation();
+ else if (mimetype.startsWith("application/zip") ||
+ mimetype.startsWith("application/gzip") ||
+ mimetype.startsWith("application/x-gzip") ||
+ mimetype.startsWith("application/x-tar") ||
+ mimetype.startsWith("application/x-gtar"))
+ return shared ? images.zipShared() : images.zip();
+ else if (mimetype.startsWith("text/html"))
+ return shared ? images.htmlShared() : images.html();
+ else if (mimetype.startsWith("text/plain"))
+ return shared ? images.txtShared() : images.txt();
+ else if (mimetype.startsWith("image/"))
+ return shared ? images.imageShared() : images.image();
+ else if (mimetype.startsWith("video/"))
+ return shared ? images.videoShared() : images.video();
+ else if (mimetype.startsWith("audio/"))
+ return shared ? images.audioShared() : images.audio();
+ return shared ? images.documentShared() : images.document();
+ }
+
+ /**
+ * Update status panel with currently showing file stats.
+ */
+ public void updateCurrentlyShowingStats() {
+ GSS.get().getStatusPanel().updateCurrentlyShowing(showingStats);
+ }
+
+ public void updateFileCache(boolean updateSelectedFolder, final boolean clearSelection) {
+ updateFileCache(updateSelectedFolder, clearSelection, null);
+ }
+
+ public void updateFileCache(boolean updateSelectedFolder, final boolean clearSelection, final String newFilename) {
+ if (!updateSelectedFolder && !GSS.get().getTreeView().getSelection().equals(GSS.get().getTreeView().getTrash()))
+ updateFileCache(clearSelection);
+ else if (GSS.get().getTreeView().getSelection() != null) {
+ update(true);
+ }
+ updateFileCache(clearSelection);
+ }
+
+
+ private void updateFileCache(boolean clearSelection) {
+ updateFileCache(clearSelection, null);
+ }
+
+ /**
+ * Update the file cache with data from the server.
+ *
+ * @param newFilename the new name of the previously selected file,
+ * if a rename operation has taken place
+ */
+ private void updateFileCache(boolean clearSelection, String newFilename) {
+ if (clearSelection)
+ clearSelectedRows();
+ startIndex = 0;
+ final RestResource folderItem = GSS.get().getTreeView().getSelection();
+ // Validation.
+ if (folderItem == null || folderItem.equals(GSS.get().getTreeView().getOthers())) {
+ setFiles(new ArrayList<FileResource>());
+ update(true);
+ return;
+ }
+ if (folderItem instanceof RestResourceWrapper) {
+ setFiles(((RestResourceWrapper) folderItem).getResource().getFiles());
+ update(true);
+ }
+ if (folderItem instanceof SharedResource) {
+ setFiles(((SharedResource) folderItem).getFiles());
+ update(true);
+ }
+ if (folderItem instanceof TrashResource) {
+ setFiles(((TrashResource) folderItem).getFiles());
+ update(true);
+ }
+ }
+
+ /**
+ * Fill the file cache with data.
+ */
+ public void setFiles(final List<FileResource> _files) {
+ if (_files.size() > 0 && ! (GSS.get().getTreeView().getSelection() instanceof TrashResource)) {
+ files = new ArrayList<FileResource>();
+ for (FileResource fres : _files)
+ if (!fres.isDeleted())
+ files.add(fres);
+ }
+ else
+ files = _files;
+ Collections.sort(files, new Comparator<FileResource>() {
+
+ @Override
+ public int compare(FileResource arg0, FileResource arg1) {
+ return arg0.getName().compareTo(arg1.getName());
+ }
+
+ });
+ folderFileCount = files.size();
+ }
+
+
+
+
+ /**
+ * Does the list contains the requested filename
+ *
+ * @param fileName
+ * @return true/false
+ */
+ public boolean contains(String fileName) {
+ for (int i = 0; i < files.size(); i++)
+ if (files.get(i).getName().equals(fileName))
+ return true;
+ return false;
+ }
+
+ public void clearSelectedRows() {
+ Iterator<FileResource> it = selectionModel.getSelectedSet().iterator();
+ while(it.hasNext()){
+ selectionModel.setSelected(it.next(),false);
+ }
+ }
+
+ /**
+ *
+ */
+ public void selectAllRows() {
+ Iterator<FileResource> it = selectionModel.getSelectedSet().iterator();
+ while(it.hasNext()){
+ selectionModel.setSelected(it.next(),true);
+ }
+
+
+ }
+
+
+ private void sortFiles(final String sortingProperty, final boolean sortingType){
+ Collections.sort(files, new Comparator<FileResource>() {
+
+ @Override
+ public int compare(FileResource arg0, FileResource arg1) {
+ AbstractImagePrototype descPrototype = AbstractImagePrototype.create(images.desc());
+ AbstractImagePrototype ascPrototype = AbstractImagePrototype.create(images.asc());
+ if (sortingType){
+ if (sortingProperty.equals("version")) {
+ return arg0.getVersion().compareTo(arg1.getVersion());
+ } else if (sortingProperty.equals("owner")) {
+ return arg0.getOwner().compareTo(arg1.getOwner());
+ } else if (sortingProperty.equals("date")) {
+ return arg0.getModificationDate().compareTo(arg1.getModificationDate());
+ } else if (sortingProperty.equals("size")) {
+ return arg0.getContentLength().compareTo(arg1.getContentLength());
+ } else if (sortingProperty.equals("name")) {
+ return arg0.getName().compareTo(arg1.getName());
+ } else if (sortingProperty.equals("path")) {
+ return arg0.getUri().compareTo(arg1.getUri());
+ } else {
+ return arg0.getName().compareTo(arg1.getName());
+ }
+ }
+ else if (sortingProperty.equals("version")) {
+
+ return arg1.getVersion().compareTo(arg0.getVersion());
+ } else if (sortingProperty.equals("owner")) {
+
+ return arg1.getOwner().compareTo(arg0.getOwner());
+ } else if (sortingProperty.equals("date")) {
+
+ return arg1.getModificationDate().compareTo(arg0.getModificationDate());
+ } else if (sortingProperty.equals("size")) {
+
+ return arg1.getContentLength().compareTo(arg0.getContentLength());
+ } else if (sortingProperty.equals("name")) {
+
+ return arg1.getName().compareTo(arg0.getName());
+ } else if (sortingProperty.equals("path")) {
+
+ return arg1.getUri().compareTo(arg0.getUri());
+ } else {
+
+ return arg1.getName().compareTo(arg0.getName());
+ }
+ }
+
+ });
+ }
+
+ final class FileValueUpdater implements ValueUpdater<String>{
+ private String property;
+ private SortableHeader header;
+ /**
+ *
+ */
+ public FileValueUpdater(SortableHeader header,String property) {
+ this.property=property;
+ this.header=header;
+ }
+ @Override
+ public void update(String value) {
+ header.setSorted(true);
+ header.toggleReverseSort();
+
+ for (SortableHeader otherHeader : allHeaders) {
+ if (otherHeader != header) {
+ otherHeader.setSorted(false);
+ otherHeader.setReverseSort(true);
+ }
+ }
+ celltable.redrawHeaders();
+ sortFiles(property, header.getReverseSort());
+ FileList.this.update(true);
+ }
+
+ }
+ /**
+ * Creates a new ArrayList<FileResources> from the given files ArrayList
+ * in order that the input files remain untouched
+ * and continues to find user's full names of each FileResource element
+ * in the new ArrayList
+ *
+ * @param filesInput
+ */
+ private void copyListAndContinue(List<FileResource> filesInput){
+ List<FileResource> copiedFiles = new ArrayList<FileResource>();
+ for(FileResource file : filesInput) {
+ copiedFiles.add(file);
+ }
+ handleFullNames(copiedFiles);
+ }
+
+ /**
+ * Examines whether or not the user's full name exists in the
+ * userFullNameMap in the GSS.java for every element of the input list.
+ * If the user's full name does not exist in the map then a command is being made.
+ *
+ * @param filesInput
+ */
+ private void handleFullNames(List<FileResource> filesInput){
+ if(filesInput.size() == 0){
+ showCellTable();
+ return;
+ }
+
+ if(GSS.get().findUserFullName(filesInput.get(0).getOwner()) == null){
+ findFullNameAndUpdate(filesInput);
+ return;
+ }
+
+ if(filesInput.size() >= 1){
+ filesInput.remove(filesInput.get(0));
+ if(filesInput.isEmpty()){
+ showCellTable();
+ }else{
+ handleFullNames(filesInput);
+ }
+ }
+ }
+
+ /**
+ * Makes a command to search for full name from a given username.
+ * Only after the completion of the command the celltable is shown
+ * or the search for the next full name continues.
+ *
+ * @param filesInput
+ */
+ private void findFullNameAndUpdate(final List<FileResource> filesInput){
+ String aUserName = filesInput.get(0).getOwner();
+ String path = GSS.get().getApiPath() + "users/" + aUserName;
+
+ GetCommand<UserSearchResource> gg = new GetCommand<UserSearchResource>(UserSearchResource.class, path, false,null) {
+ @Override
+ public void onComplete() {
+ final UserSearchResource result = getResult();
+ for (UserResource user : result.getUsers()){
+ String username = user.getUsername();
+ String userFullName = user.getName();
+ GSS.get().putUserToMap(username, userFullName);
+ if(filesInput.size() >= 1){
+ filesInput.remove(filesInput.get(0));
+ if(filesInput.isEmpty()){
+ showCellTable();
+ }else{
+ handleFullNames(filesInput);
+ }
+ }
+ }
+ }
+ @Override
+ public void onError(Throwable t) {
+ GWT.log("", t);
+ GSS.get().displayError("Unable to fetch user's full name from the given username " + filesInput.get(0).getOwner());
+ if(filesInput.size() >= 1){
+ filesInput.remove(filesInput.get(0));
+ handleFullNames(filesInput);
+ }
+ }
+ };
+ DeferredCommand.addCommand(gg);
+
+ }
+ /**
+ * Shows the files in the cellTable
+ */
+
+ private void showCellTable(){
+ celltable.setRowCount(files.size());
+ celltable.setRowData(0,files);
+ celltable.redrawHeaders();
+ }
+
+
+}