X-Git-Url: https://code.grnet.gr/git/pithos/blobdiff_plain/e0324db343ee6607062db0776a1edb565625d155..f25aa622850d7dc2675950425e36c91ab263d2d5:/src/gr/ebs/gss/client/FileList.java
diff --git a/src/gr/ebs/gss/client/FileList.java b/src/gr/ebs/gss/client/FileList.java
index c525b72..a3bedc9 100644
--- a/src/gr/ebs/gss/client/FileList.java
+++ b/src/gr/ebs/gss/client/FileList.java
@@ -18,18 +18,22 @@
*/
package gr.ebs.gss.client;
-import gr.ebs.gss.client.dnd.DnDSimpleFocusPanel;
-import gr.ebs.gss.client.dnd.DnDTreeItem;
+import static com.google.gwt.query.client.GQuery.$;
import gr.ebs.gss.client.rest.GetCommand;
-import gr.ebs.gss.client.rest.MultipleHeadCommand;
import gr.ebs.gss.client.rest.RestCommand;
-import gr.ebs.gss.client.rest.RestException;
import gr.ebs.gss.client.rest.resource.FileResource;
import gr.ebs.gss.client.rest.resource.FolderResource;
-import gr.ebs.gss.client.rest.resource.OtherUserResource;
+import gr.ebs.gss.client.rest.resource.RestResource;
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.DraggableOptions.RevertOption;
+import gwtquery.plugins.draggable.client.events.DragStartEvent;
+import gwtquery.plugins.draggable.client.events.DragStartEvent.DragStartEventHandler;
+import gwtquery.plugins.droppable.client.gwt.DragAndDropCellTable;
+import gwtquery.plugins.droppable.client.gwt.DragAndDropColumn;
import java.util.ArrayList;
import java.util.Collections;
@@ -37,17 +41,21 @@ 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.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.Element;
-import com.google.gwt.dom.client.NativeEvent;
+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.user.cellview.client.CellTable;
import com.google.gwt.user.cellview.client.Column;
import com.google.gwt.user.cellview.client.TextColumn;
@@ -62,9 +70,8 @@ import com.google.gwt.user.client.ui.Grid;
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.TreeItem;
+import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
-import com.google.gwt.view.client.DefaultSelectionEventManager;
import com.google.gwt.view.client.MultiSelectionModel;
import com.google.gwt.view.client.ProvidesKey;
import com.google.gwt.view.client.SelectionChangeEvent;
@@ -75,7 +82,25 @@ import com.google.gwt.view.client.SelectionChangeEvent.Handler;
*/
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("
")
+ SafeHtml outerHelper();
+ }
+
+
+ /**
+ * The styles applied to the table.
+ */
+ interface TableStyle extends CellTable.Style {
+ }
+
private String showingStats = "";
private int startIndex = 0;
@@ -85,10 +110,7 @@ public class FileList extends Composite {
*/
public static final boolean DONE = false;
- /**
- * The context menu for the selected file.
- */
- final DnDSimpleFocusPanel contextMenu;
+
private final DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a");
@@ -96,7 +118,7 @@ public class FileList extends Composite {
* Specifies that the images available for this composite will be the ones
* available in FileContextMenu.
*/
- public interface Images extends ClientBundle,FileContextMenu.Images, Folders.Images {
+ public interface Images extends ClientBundle,FileContextMenu.Images, CellTreeView.Images {
@Source("gr/ebs/gss/resources/blank.gif")
ImageResource blank();
@@ -171,7 +193,54 @@ public class FileList extends Composite {
ImageResource zipShared();
}
+ private static class ContactCell extends AbstractCell {
+
+ /**
+ * 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("");
+
+ // Add the contact image.
+ sb.appendHtmlConstant("");
+ sb.appendHtmlConstant(imageHtml);
+ sb.appendHtmlConstant(" | ");
+
+ // Add the name and address.
+ sb.appendHtmlConstant("");
+ sb.appendEscaped(value.getName());
+ sb.appendHtmlConstant(" |
");
+ sb.appendEscaped(value.getFileSizeAsString());
+ sb.appendHtmlConstant(" |
");
+ }
+
+
+ }
+ /**
+ * Retrieve the celltable.
+ *
+ * @return the celltable
+ */
+ public DragAndDropCellTable getCelltable() {
+ return celltable;
+ }
/**
* A label with the number of files in this folder.
*/
@@ -206,10 +275,10 @@ public class FileList extends Composite {
* The widget's image bundle.
*/
private final Images images;
-
+ VerticalPanel panel;
private FileContextMenu menuShowing;
- private CellTable celltable;
+ private DragAndDropCellTable celltable;
private final MultiSelectionModel selectionModel;
private final List allHeaders = new ArrayList();
SortableHeader nameHeader;
@@ -223,14 +292,9 @@ public class FileList extends Composite {
*/
public FileList(Images _images) {
images = _images;
-
+ DragAndDropCellTable.Resources resources = GWT.create(TableResources.class);
- contextMenu = new DnDSimpleFocusPanel(new HTML(AbstractImagePrototype.create(images.fileContextMenu()).getHTML()));
- GSS.get().getDragController().makeDraggable(contextMenu);
-
- // Setup the table.
-
// Create the 'navigation' bar at the upper-right.
HorizontalPanel innerNavBar = new HorizontalPanel();
innerNavBar.setStyleName("gss-ListNavBar");
@@ -247,7 +311,7 @@ public class FileList extends Composite {
}
};
- final TextColumn nameColumn = new TextColumn() {
+ final DragAndDropColumn nameColumn = new DragAndDropColumn(new TextCell()) {
@Override
public String getValue(FileResource object) {
@@ -257,17 +321,37 @@ public class FileList extends Composite {
};
- celltable = new CellTable(keyProvider){
+ initDragOperation(nameColumn);
+ celltable = new DragAndDropCellTable(100,resources,keyProvider){
@Override
protected void onBrowserEvent2(Event event) {
- if (DOM.eventGetType((Event) event) == Event.ONMOUSEDOWN && DOM.eventGetButton((Event) event) == NativeEvent.BUTTON_RIGHT){
+ /*if (DOM.eventGetType((Event) event) == Event.ONMOUSEDOWN && DOM.eventGetButton((Event) event) == NativeEvent.BUTTON_RIGHT){
fireClickEvent((Element) event.getEventTarget().cast());
- }
+ }*/
super.onBrowserEvent2(event);
}
};
-
-
+ celltable.addDragStartHandler(new DragStartEventHandler() {
+
+ public void onDragStart(DragStartEvent event) {
+ FileResource value = event.getDraggableData();
+ if(!selectionModel.isSelected(value)){
+ event.getHelper().removeFromParent();
+ return;
+ }
+
+ com.google.gwt.dom.client.Element helper = event.getHelper();
+
+ SafeHtmlBuilder sb = new SafeHtmlBuilder();
+ // reuse the contact cell to render the inner html of the drag helper.
+ ///new CotactCell(images.blank()).render(new Context(0,0, value), value, sb);
+ sb.appendHtmlConstant("");
+ sb.appendEscaped(value.getName());
+ sb.appendHtmlConstant("");
+ helper.setInnerHTML(sb.toSafeHtml().asString());
+
+ }
+ });
Column status = new Column(new ImageResourceCell()) {
@Override
public ImageResource getValue(FileResource entity) {
@@ -287,8 +371,7 @@ public class FileList extends Composite {
celltable.addColumn(new TextColumn() {
@Override
public String getValue(FileResource object) {
- // TODO Auto-generated method stub
- return object.getOwner();
+ return GSS.get().findUserFullName(object.getOwner());
}
},aheader = new SortableHeader("Owner"));
allHeaders.add(aheader);
@@ -328,6 +411,7 @@ public class FileList extends Composite {
},aheader = new SortableHeader("Last Modified"));
allHeaders.add(aheader);
aheader.setUpdater(new FileValueUpdater(aheader, "date"));
+
initWidget(celltable);
setStyleName("gss-List");
selectionModel = new MultiSelectionModel();
@@ -340,12 +424,12 @@ public class FileList extends Composite {
GSS.get().setCurrentSelection(getSelectedFiles().get(0));
else
GSS.get().setCurrentSelection(getSelectedFiles());
- contextMenu.setFiles(getSelectedFiles());
+ //contextMenu.setFiles(getSelectedFiles());
}
};
selectionModel.addSelectionChangeHandler(selectionHandler);
- celltable.setSelectionModel(selectionModel,DefaultSelectionEventManager.createDefaultManager());
+ celltable.setSelectionModel(selectionModel,GSSSelectionEventManager.createDefaultManager());
celltable.setPageSize(GSS.VISIBLE_FILE_COUNT);
celltable.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
Scheduler.get().scheduleIncremental(new RepeatingCommand() {
@@ -363,16 +447,36 @@ public class FileList extends Composite {
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 native void fireClickEvent(Element element) /*-{
+ // var evObj = $doc.createEvent('MouseEvents');
+ //evObj.initEvent('click', true, true);
+ //element.dispatchEvent(evObj);
+ //}-*/;
public List getSelectedFiles() {
return new ArrayList(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");
+ }
@Override
@@ -446,9 +550,8 @@ public class FileList extends Composite {
max = count;
folderTotalSize = 0;
- celltable.setRowCount(files.size());
- celltable.setRowData(0,files);
- celltable.redrawHeaders();
+ copyListAndContinue(files);
+
if (folderFileCount == 0) {
showingStats = "no files";
} else if (folderFileCount < GSS.VISIBLE_FILE_COUNT) {
@@ -473,7 +576,7 @@ public class FileList extends Composite {
private ImageResource getFileIcon(FileResource file) {
String mimetype = file.getContentType();
boolean shared = false;
- Folders folders = GSS.get().getFolders();
+ /*Folders folders = GSS.get().getFolders();
if(folders.getCurrent() != null && folders.isOthersSharedItem(folders.getCurrent())){
DnDTreeItem otherUser = (DnDTreeItem) folders.getUserOfSharedItem(folders.getCurrent());
if(otherUser==null)
@@ -486,7 +589,7 @@ public class FileList extends Composite {
shared = file.isShared();
}
}
- else
+ else*/
shared = file.isShared();
if (mimetype == null)
return shared ? images.documentShared() : images.document();
@@ -550,146 +653,16 @@ public class FileList extends Composite {
}
public void updateFileCache(boolean updateSelectedFolder, final boolean clearSelection, final String newFilename) {
- if (!updateSelectedFolder && !GSS.get().getFolders().getCurrent().equals(GSS.get().getFolders().getTrashItem()))
+ if (!updateSelectedFolder && !GSS.get().getTreeView().getSelection().equals(GSS.get().getTreeView().getTrash()))
updateFileCache(clearSelection);
- else if (GSS.get().getFolders().getCurrent() != null) {
- final DnDTreeItem folderItem = (DnDTreeItem) GSS.get().getFolders().getCurrent();
- if (folderItem.getFolderResource() != null) {
- if(GSS.get().getFolders().isFileItem(folderItem) || GSS.get().getFolders().isMySharedItem(folderItem) || GSS.get().getFolders().isOthersSharedItem(folderItem) ){
+ else if (GSS.get().getTreeView().getSelection() != null) {
+ final RestResource selectedResource = GSS.get().getTreeView().getSelection();
+ if (selectedResource instanceof FolderResource) {
+
update(true);
- GetCommand gf = new GetCommand(FolderResource.class, folderItem.getFolderResource().getUri(),folderItem.getFolderResource()) {
-
- @Override
- public void onComplete() {
- folderItem.setUserObject(getResult());
- if(GSS.get().getFolders().isFileItem(folderItem)){
- String[] filePaths = new String[folderItem.getFolderResource().getFilePaths().size()];
- int c=0;
- for(String fpath : folderItem.getFolderResource().getFilePaths()){
- filePaths[c] = fpath + "?" + Math.random();
- c++;
- }
- MultipleHeadCommand getFiles = new MultipleHeadCommand(FileResource.class, filePaths, folderItem.getFolderResource().getFileCache()){
-
- @Override
- public void onComplete(){
- List result = getResult();
- //remove random from path
- for(FileResource r : result){
- String p = r.getUri();
- int indexOfQuestionMark = p.lastIndexOf('?');
- if(indexOfQuestionMark>0)
- r.setUri(p.substring(0, indexOfQuestionMark));
- GWT.log("FETCHED:"+r.getLastModifiedSince(), null);
- }
- folderItem.getFolderResource().setFiles(result);
- folderItem.getFolderResource().setFilesExpanded(true);
- updateFileCache(clearSelection, newFilename);
- }
-
- @Override
- public void onError(String p, Throwable throwable) {
- if(throwable instanceof RestException)
- GSS.get().displayError("Unable to retrieve file details:"+((RestException)throwable).getHttpStatusText());
- }
-
- @Override
- public void onError(Throwable t) {
- GWT.log("", t);
- GSS.get().displayError("Unable to fetch files for folder " + folderItem.getFolderResource().getName());
- }
-
- };
- DeferredCommand.addCommand(getFiles);
- }
- else
- updateFileCache(clearSelection, newFilename);
- }
-
- @Override
- public void onError(Throwable t) {
- GWT.log("", t);
- GSS.get().displayError("Unable to fetch folder " + folderItem.getFolderResource().getName());
- }
- };
- DeferredCommand.addCommand(gf);
- }
- }
- else if (folderItem.getTrashResource() != null) {
- GetCommand gt = new GetCommand(TrashResource.class, folderItem.getTrashResource().getUri(), null) {
-
- @Override
- public void onComplete() {
- folderItem.setUserObject(getResult());
- updateFileCache(clearSelection);
- }
-
- @Override
- public void onError(Throwable t) {
- if (t instanceof RestException && (((RestException) t).getHttpStatusCode() == 204 || ((RestException) t).getHttpStatusCode() == 1223)) {
- folderItem.setUserObject(new TrashResource(folderItem.getTrashResource().getUri()));
- updateFileCache(clearSelection);
- } else {
- GWT.log("", t);
- GSS.get().displayError("Unable to fetch trash resource");
- }
- }
- };
- DeferredCommand.addCommand(gt);
- } else if (folderItem.getSharedResource() != null) {
- GetCommand gt = new GetCommand(SharedResource.class, folderItem.getSharedResource().getUri(), null) {
-
- @Override
- public void onComplete() {
- folderItem.setUserObject(getResult());
- for(FileResource r : folderItem.getSharedResource().getFiles()){
- String p = r.getUri();
- int indexOfQuestionMark = p.lastIndexOf('?');
- if(indexOfQuestionMark>0)
- r.setUri(p.substring(0, indexOfQuestionMark));
- GWT.log("FETCHED:"+r.getLastModifiedSince(), null);
- }
- folderItem.getSharedResource().setFilesExpanded(true);
- updateFileCache(clearSelection, newFilename);
-
- }
-
- @Override
- public void onError(Throwable t) {
- GWT.log("", t);
- GSS.get().displayError("Unable to fetch My Shares resource");
- }
- };
- DeferredCommand.addCommand(gt);
- } else if (folderItem.getOtherUserResource() != null) {
- GetCommand gt = new GetCommand(OtherUserResource.class, folderItem.getOtherUserResource().getUri(), null) {
-
- @Override
- public void onComplete() {
- folderItem.setUserObject(getResult());
- //updateFileCache(clearSelection, newFilename);
- for(FileResource r : folderItem.getOtherUserResource().getFiles()){
- String p = r.getUri();
- int indexOfQuestionMark = p.lastIndexOf('?');
- if(indexOfQuestionMark>0)
- r.setUri(p.substring(0, indexOfQuestionMark));
- GWT.log("FETCHED:"+r.getLastModifiedSince(), null);
- }
- folderItem.getOtherUserResource().setFilesExpanded(true);
- updateFileCache(clearSelection, newFilename);
-
- }
-
- @Override
- public void onError(Throwable t) {
- GWT.log("", t);
- GSS.get().displayError("Unable to fetch My Shares resource");
- }
- };
- DeferredCommand.addCommand(gt);
}
- } else
- updateFileCache(clearSelection);
+ }
+ updateFileCache(clearSelection);
}
@@ -707,31 +680,24 @@ public class FileList extends Composite {
if (clearSelection)
clearSelectedRows();
startIndex = 0;
- final TreeItem folderItem = GSS.get().getFolders().getCurrent();
+ final RestResource folderItem = GSS.get().getTreeView().getSelection();
// Validation.
- if (folderItem == null || GSS.get().getFolders().isOthersShared(folderItem)) {
+ if (folderItem == null || folderItem.equals(GSS.get().getTreeView().getOthers())) {
setFiles(new ArrayList());
update(true);
return;
}
- if (folderItem instanceof DnDTreeItem) {
- DnDTreeItem dnd = (DnDTreeItem) folderItem;
- if (dnd.getFolderResource() != null) {
- if (GSS.get().getFolders().isTrashItem(dnd))
- setFiles(new ArrayList());
- else
- setFiles(dnd.getFolderResource().getFiles());
-
- } else if (dnd.getTrashResource() != null)
- setFiles(dnd.getTrashResource().getFiles());
- else if (dnd.getSharedResource() != null)
- setFiles(dnd.getSharedResource().getFiles());
- else if (dnd.getOtherUserResource() != null)
- setFiles(dnd.getOtherUserResource().getFiles());
- else
- setFiles(dnd.getFolderResource().getFiles());
+ if (folderItem instanceof FolderResource) {
+ setFiles(((FolderResource) folderItem).getFiles());
+ update(true);
+ }
+ if (folderItem instanceof SharedResource) {
+ setFiles(((SharedResource) folderItem).getFiles());
+ update(true);
+ }
+ if (folderItem instanceof TrashResource) {
+ setFiles(((TrashResource) folderItem).getFiles());
update(true);
-
}
}
@@ -739,12 +705,12 @@ public class FileList extends Composite {
* Fill the file cache with data.
*/
public void setFiles(final List _files) {
- if (_files.size() > 0 && !GSS.get().getFolders().isTrash(GSS.get().getFolders().getCurrent())) {
+ /*if (_files.size() > 0 && !GSS.get().getFolders().isTrash(GSS.get().getFolders().getCurrent())) {
files = new ArrayList();
for (FileResource fres : _files)
if (!fres.isDeleted())
files.add(fres);
- } else
+ } else*/
files = _files;
Collections.sort(files, new Comparator() {
@@ -933,4 +899,101 @@ public class FileList extends Composite {
}
}
+ /**
+ * Creates a new ArrayList 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 filesInput){
+ List copiedFiles = new ArrayList();
+ 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 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 filesInput){
+ String aUserName = filesInput.get(0).getOwner();
+ String path = GSS.get().getApiPath() + "users/" + aUserName;
+
+ GetCommand gg = new GetCommand(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();
+ }
+
+
}