X-Git-Url: https://code.grnet.gr/git/pithos/blobdiff_plain/c357d641c831d43f7e7ff6c81ebe070368e17605..f7c2e76a8fce86128ce8224b4ab8d1a6bbee6592:/src/gr/ebs/gss/client/FileMenu.java
diff --git a/src/gr/ebs/gss/client/FileMenu.java b/src/gr/ebs/gss/client/FileMenu.java
index 08a2e4a..c486447 100644
--- a/src/gr/ebs/gss/client/FileMenu.java
+++ b/src/gr/ebs/gss/client/FileMenu.java
@@ -25,22 +25,25 @@ import gr.ebs.gss.client.commands.RefreshCommand;
import gr.ebs.gss.client.commands.UploadFileCommand;
import gr.ebs.gss.client.rest.RestCommand;
import gr.ebs.gss.client.rest.resource.FileResource;
-import gr.ebs.gss.client.rest.resource.FolderResource;
import gr.ebs.gss.client.rest.resource.GroupUserResource;
+import java.util.List;
+
+import com.google.gwt.event.dom.client.ClickEvent;
+import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.http.client.URL;
+import com.google.gwt.resources.client.ClientBundle;
+import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.AbstractImagePrototype;
-import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.MenuBar;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.TreeItem;
-import com.google.gwt.user.client.ui.Widget;
/**
* The 'File' menu implementation.
*/
-public class FileMenu extends PopupPanel implements ClickListener {
+public class FileMenu extends PopupPanel implements ClickHandler {
/**
* The widget's images.
@@ -50,28 +53,28 @@ public class FileMenu extends PopupPanel implements ClickListener {
/**
* An image bundle for this widgets images.
*/
- public interface Images extends FilePropertiesDialog.Images {
+ public interface Images extends ClientBundle,FilePropertiesDialog.Images {
- @Resource("gr/ebs/gss/resources/folder_new.png")
- AbstractImagePrototype folderNew();
+ @Source("gr/ebs/gss/resources/folder_new.png")
+ ImageResource folderNew();
- @Resource("gr/ebs/gss/resources/folder_outbox.png")
- AbstractImagePrototype fileUpdate();
+ @Source("gr/ebs/gss/resources/folder_outbox.png")
+ ImageResource fileUpdate();
- @Resource("gr/ebs/gss/resources/view_text.png")
- AbstractImagePrototype viewText();
+ @Source("gr/ebs/gss/resources/view_text.png")
+ ImageResource viewText();
- @Resource("gr/ebs/gss/resources/folder_inbox.png")
- AbstractImagePrototype download();
+ @Source("gr/ebs/gss/resources/folder_inbox.png")
+ ImageResource download();
- @Resource("gr/ebs/gss/resources/trashcan_empty.png")
- AbstractImagePrototype emptyTrash();
+ @Source("gr/ebs/gss/resources/trashcan_empty.png")
+ ImageResource emptyTrash();
- @Resource("gr/ebs/gss/resources/internet.png")
- AbstractImagePrototype sharing();
+ @Source("gr/ebs/gss/resources/internet.png")
+ ImageResource sharing();
- @Resource("gr/ebs/gss/resources/refresh.png")
- AbstractImagePrototype refresh();
+ @Source("gr/ebs/gss/resources/refresh.png")
+ ImageResource refresh();
}
final MenuBar contextMenu = new MenuBar(true);
@@ -91,15 +94,17 @@ public class FileMenu extends PopupPanel implements ClickListener {
}
- public void onClick(final Widget sender) {
+ @Override
+ public void onClick(ClickEvent event) {
final FileMenu menu = new FileMenu(images);
- final int left = sender.getAbsoluteLeft();
- final int top = sender.getAbsoluteTop() + sender.getOffsetHeight();
+ final int left = event.getRelativeElement().getAbsoluteLeft();
+ final int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight();
menu.setPopupPosition(left, top);
-
menu.show();
+
}
+
/**
* Do some validation before downloading a file.
*/
@@ -122,17 +127,33 @@ public class FileMenu extends PopupPanel implements ClickListener {
* and save location
*/
void createDownloadLink(String[] link, boolean forceDownload) {
+ String downloadURL = getDownloadURL();
+ if (!downloadURL.isEmpty()) {
+ link[0] = "";
+ link[1] = "";
+ }
+ }
+
+ public String getDownloadURL() {
GSS app = GSS.get();
Object selection = app.getCurrentSelection();
if (selection != null && selection instanceof FileResource) {
FileResource file = (FileResource) selection;
+ return getDownloadURL(file);
+ }
+ return "";
+ }
+
+ public String getDownloadURL(FileResource file) {
+ GSS app = GSS.get();
+ if (file != null) {
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()));
- link[0] = "";
- link[1] = "";
+ return file.getUri() + "?Authorization=" + URL.encodeComponent(sig) + "&Date="+URL.encodeComponent(dateString);
}
+ return "";
}
public MenuBar createMenu() {
@@ -148,24 +169,25 @@ public class FileMenu extends PopupPanel implements ClickListener {
Folders folders = GSS.get().getFolders();
TreeItem selectedItem = folders.getCurrent();
boolean downloadVisible = GSS.get().getCurrentSelection() != null && GSS.get().getCurrentSelection() instanceof FileResource;
- boolean uploadVisible = GSS.get().getFolders().getCurrent().getUserObject() instanceof FolderResource;
- boolean propertiesNotVisible = selectedItem != null && (folders.isTrash(selectedItem) || folders.isMyShares(selectedItem) || folders.isOthersShared(selectedItem) || selectedItem.getUserObject() instanceof GroupUserResource);
- contextMenu.addItem("" + images.folderNew().getHTML() + " New Folder", true, new NewFolderCommand(this, images));
- contextMenu.addItem("" + images.fileUpdate().getHTML() + " Upload", true, new UploadFileCommand(this));
+ boolean propertiesVisible = !(selectedItem != null && (folders.isTrash(selectedItem) || folders.isMyShares(selectedItem) || folders.isOthersShared(selectedItem) || selectedItem.getUserObject() instanceof GroupUserResource || GSS.get().getCurrentSelection() instanceof List));
+ contextMenu.addItem("" + AbstractImagePrototype.create(images.folderNew()).getHTML() + " New Folder", true, new NewFolderCommand(this, images));
+ contextMenu.addItem("" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + " Upload", true, new UploadFileCommand(this));
if (downloadVisible) {
String[] link = {"", ""};
createDownloadLink(link, false);
- contextMenu.addItem("" + link[0] + images.download().getHTML() + " Download" + link[1] + "", true, downloadCmd);
+ contextMenu.addItem("" + link[0] + AbstractImagePrototype.create(images.download()).getHTML() + " Download" + link[1] + "", true, downloadCmd);
createDownloadLink(link, true);
- contextMenu.addItem("" + link[0] + images.download().getHTML() + " Save file as" + link[1] + "", true, downloadCmd);
+ contextMenu.addItem("" + link[0] + AbstractImagePrototype.create(images.download()).getHTML() + " Save As" + link[1] + "", true, downloadCmd);
}
- contextMenu.addItem("" + images.emptyTrash().getHTML() + " Empty Trash", true, new EmptyTrashCommand(this));
- contextMenu.addItem("" + images.refresh().getHTML() + " Refresh", true, new RefreshCommand(this, images));
- contextMenu.addItem("" + images.sharing().getHTML() + " Sharing", true, new PropertiesCommand(this, images, 1))
- .setVisible(!propertiesNotVisible);
- contextMenu.addItem("" + images.viewText().getHTML() + " Properties", true, new PropertiesCommand(this, images, 0))
- .setVisible(!propertiesNotVisible);
+ contextMenu.addItem("" + AbstractImagePrototype.create(images.emptyTrash()).getHTML() + " Empty Trash", true, new EmptyTrashCommand(this));
+ contextMenu.addItem("" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh", true, new RefreshCommand(this, images));
+ contextMenu.addItem("" + AbstractImagePrototype.create(images.sharing()).getHTML() + " Sharing", true, new PropertiesCommand(this, images, 1))
+ .setVisible(propertiesVisible);
+ contextMenu.addItem("" + AbstractImagePrototype.create(images.viewText()).getHTML() + " Properties", true, new PropertiesCommand(this, images, 0))
+ .setVisible(propertiesVisible);
return contextMenu;
}
+
+
}