-/*\r
- * Copyright 2007, 2008, 2009, 2010 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.commands.EmptyTrashCommand;\r
-import gr.ebs.gss.client.commands.NewFolderCommand;\r
-import gr.ebs.gss.client.commands.PropertiesCommand;\r
-import gr.ebs.gss.client.commands.RefreshCommand;\r
-import gr.ebs.gss.client.commands.UploadFileCommand;\r
-import gr.ebs.gss.client.rest.RestCommand;\r
-import gr.ebs.gss.client.rest.resource.FileResource;\r
-import gr.ebs.gss.client.rest.resource.GroupUserResource;\r
-\r
-import java.util.List;\r
-\r
-import com.google.gwt.event.dom.client.ClickEvent;\r
-import com.google.gwt.event.dom.client.ClickHandler;\r
-import com.google.gwt.http.client.URL;\r
-import com.google.gwt.resources.client.ClientBundle;\r
-import com.google.gwt.resources.client.ImageResource;\r
-import com.google.gwt.user.client.Command;\r
-import com.google.gwt.user.client.ui.AbstractImagePrototype;\r
-import com.google.gwt.user.client.ui.MenuBar;\r
-import com.google.gwt.user.client.ui.PopupPanel;\r
-import com.google.gwt.user.client.ui.TreeItem;\r
-\r
-/**\r
- * The 'File' menu implementation.\r
- */\r
-public class FileMenu extends PopupPanel implements ClickHandler {\r
-\r
- /**\r
- * The widget's images.\r
- */\r
- private final Images images;\r
-\r
- /**\r
- * An image bundle for this widgets images.\r
- */\r
- public interface Images extends ClientBundle,FilePropertiesDialog.Images {\r
-\r
- @Source("gr/ebs/gss/resources/folder_new.png")\r
- ImageResource folderNew();\r
-\r
- @Source("gr/ebs/gss/resources/folder_outbox.png")\r
- ImageResource fileUpdate();\r
-\r
- @Source("gr/ebs/gss/resources/view_text.png")\r
- ImageResource viewText();\r
-\r
- @Source("gr/ebs/gss/resources/folder_inbox.png")\r
- ImageResource download();\r
-\r
- @Source("gr/ebs/gss/resources/trashcan_empty.png")\r
- ImageResource emptyTrash();\r
-\r
- @Source("gr/ebs/gss/resources/internet.png")\r
- ImageResource sharing();\r
-\r
- @Source("gr/ebs/gss/resources/refresh.png")\r
- ImageResource refresh();\r
-}\r
-\r
- final MenuBar contextMenu = new MenuBar(true);\r
-\r
- /**\r
- * The widget's constructor.\r
- *\r
- * @param _images the image bundle passed on by the parent object\r
- */\r
- public FileMenu(final Images _images) {\r
- // The popup's constructor's argument is a boolean specifying that it\r
- // auto-close itself when the user clicks outside of it.\r
- super(true);\r
- setAnimationEnabled(true);\r
- images = _images;\r
- add(contextMenu);\r
-\r
- }\r
-\r
- @Override\r
- public void onClick(ClickEvent event) {\r
- final FileMenu menu = new FileMenu(images);\r
- final int left = event.getRelativeElement().getAbsoluteLeft();\r
- final int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight();\r
- menu.setPopupPosition(left, top);\r
- menu.show();\r
-\r
- }\r
-\r
-\r
- /**\r
- * Do some validation before downloading a file.\r
- */\r
- void preDownloadCheck() {\r
- Object selection = GSS.get().getCurrentSelection();\r
- if (selection == null || !(selection instanceof FileResource)) {\r
- GSS.get().displayError("You have to select a file first");\r
- return;\r
- }\r
- }\r
-\r
- /**\r
- * Create a download link for the respective menu item, if the currently\r
- * selected object is a file.\r
- *\r
- * @param link a String array with two elements that is modified so that the\r
- * first position contains the opening tag and the second one the\r
- * closing tag\r
- * @param forceDownload If true, link will be such that browser should ask for filename\r
- * and save location\r
- */\r
- void createDownloadLink(String[] link, boolean forceDownload) {\r
- String downloadURL = getDownloadURL();\r
- if (!downloadURL.isEmpty()) {\r
- link[0] = "<a class='hidden-link' href='" + downloadURL\r
- + (forceDownload ? "&dl=1" : "") + "' target='_blank'>";\r
- link[1] = "</a>";\r
- }\r
- }\r
-\r
- public String getDownloadURL() {\r
- GSS app = GSS.get();\r
- Object selection = app.getCurrentSelection();\r
- if (selection != null && selection instanceof FileResource) {\r
- FileResource file = (FileResource) selection;\r
- return getDownloadURL(file);\r
- }\r
- return "";\r
- }\r
-\r
- public String getDownloadURL(FileResource file) {\r
- GSS app = GSS.get();\r
- if (file != null) {\r
- String dateString = RestCommand.getDate();\r
- String resource = file.getUri().substring(app.getApiPath().length()-1,file.getUri().length());\r
- String sig = app.getCurrentUserResource().getUsername()+" "+RestCommand.calculateSig("GET", dateString, resource, RestCommand.base64decode(app.getToken()));\r
- return file.getUri() + "?Authorization=" + URL.encodeComponent(sig) + "&Date="+URL.encodeComponent(dateString);\r
- }\r
- return "";\r
- }\r
-\r
- public MenuBar createMenu() {\r
- contextMenu.clearItems();\r
- contextMenu.setAutoOpen(false);\r
- final Command downloadCmd = new Command() {\r
-\r
- public void execute() {\r
- hide();\r
- preDownloadCheck();\r
- }\r
- };\r
- Folders folders = GSS.get().getFolders();\r
- TreeItem selectedItem = folders.getCurrent();\r
- boolean downloadVisible = GSS.get().getCurrentSelection() != null && GSS.get().getCurrentSelection() instanceof FileResource;\r
- boolean propertiesVisible = !(selectedItem != null && (folders.isTrash(selectedItem) || folders.isMyShares(selectedItem) || folders.isOthersShared(selectedItem) || selectedItem.getUserObject() instanceof GroupUserResource || GSS.get().getCurrentSelection() instanceof List));\r
- boolean newFolderVisible = !(selectedItem != null && (folders.isTrash(selectedItem) || folders.isTrashItem(selectedItem) || folders.isMyShares(selectedItem)|| folders.isOthersShared(selectedItem)));\r
- boolean uploadVisible = !(selectedItem != null && (folders.isTrash(selectedItem) || folders.isTrashItem(selectedItem)|| folders.isMyShares(selectedItem)|| folders.isOthersShared(selectedItem)));\r
- if(newFolderVisible)\r
- contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.folderNew()).getHTML() + " New Folder</span>", true, new NewFolderCommand(this, images));\r
- if(uploadVisible)\r
- contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this));\r
- if (downloadVisible) {\r
- String[] link = {"", ""};\r
- createDownloadLink(link, false);\r
- contextMenu.addItem("<span>" + link[0] + AbstractImagePrototype.create(images.download()).getHTML() + " Download" + link[1] + "</span>", true, downloadCmd);\r
- createDownloadLink(link, true);\r
- contextMenu.addItem("<span>" + link[0] + AbstractImagePrototype.create(images.download()).getHTML() + " Save As" + link[1] + "</span>", true, downloadCmd);\r
- }\r
- contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.emptyTrash()).getHTML() + " Empty Trash</span>", true, new EmptyTrashCommand(this));\r
- contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images));\r
- contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.sharing()).getHTML() + " Sharing</span>", true, new PropertiesCommand(this, images, 1))\r
- .setVisible(propertiesVisible);\r
- contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.viewText()).getHTML() + " Properties</span>", true, new PropertiesCommand(this, images, 0))\r
- .setVisible(propertiesVisible);\r
- return contextMenu;\r
- }\r
-\r
-}\r
+/*
+ * Copyright 2007, 2008, 2009, 2010 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 gr.ebs.gss.client.commands.EmptyTrashCommand;
+import gr.ebs.gss.client.commands.NewFolderCommand;
+import gr.ebs.gss.client.commands.PropertiesCommand;
+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.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.MenuBar;
+import com.google.gwt.user.client.ui.PopupPanel;
+import com.google.gwt.user.client.ui.TreeItem;
+
+/**
+ * The 'File' menu implementation.
+ */
+public class FileMenu extends PopupPanel implements ClickHandler {
+
+ /**
+ * The widget's images.
+ */
+ private final Images images;
+
+ /**
+ * An image bundle for this widgets images.
+ */
+ public interface Images extends ClientBundle,FilePropertiesDialog.Images {
+
+ @Source("gr/ebs/gss/resources/folder_new.png")
+ ImageResource folderNew();
+
+ @Source("gr/ebs/gss/resources/folder_outbox.png")
+ ImageResource fileUpdate();
+
+ @Source("gr/ebs/gss/resources/view_text.png")
+ ImageResource viewText();
+
+ @Override
+ @Source("gr/ebs/gss/resources/folder_inbox.png")
+ ImageResource download();
+
+ @Source("gr/ebs/gss/resources/trashcan_empty.png")
+ ImageResource emptyTrash();
+
+ @Source("gr/ebs/gss/resources/internet.png")
+ ImageResource sharing();
+
+ @Source("gr/ebs/gss/resources/refresh.png")
+ ImageResource refresh();
+}
+
+ final MenuBar contextMenu = new MenuBar(true);
+
+ /**
+ * The widget's constructor.
+ *
+ * @param _images the image bundle passed on by the parent object
+ */
+ public FileMenu(final Images _images) {
+ // The popup's constructor's argument is a boolean specifying that it
+ // auto-close itself when the user clicks outside of it.
+ super(true);
+ setAnimationEnabled(true);
+ images = _images;
+ add(contextMenu);
+
+ }
+
+ @Override
+ public void onClick(ClickEvent event) {
+ final FileMenu menu = new FileMenu(images);
+ 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.
+ */
+ void preDownloadCheck() {
+ Object selection = GSS.get().getCurrentSelection();
+ if (selection == null || !(selection instanceof FileResource)) {
+ GSS.get().displayError("You have to select a file first");
+ return;
+ }
+ }
+
+ /**
+ * Create a download link for the respective menu item, if the currently
+ * selected object is a file.
+ *
+ * @param link a String array with two elements that is modified so that the
+ * first position contains the opening tag and the second one the
+ * closing tag
+ * @param forceDownload If true, link will be such that browser should ask for filename
+ * and save location
+ */
+ void createDownloadLink(String[] link, boolean forceDownload) {
+ String downloadURL = getDownloadURL();
+ if (!downloadURL.isEmpty()) {
+ link[0] = "<a class='hidden-link' href='" + downloadURL
+ + (forceDownload ? "&dl=1" : "") + "' target='_blank'>";
+ link[1] = "</a>";
+ }
+ }
+
+ 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()));
+ return file.getUri() + "?Authorization=" + URL.encodeComponent(sig) + "&Date="+URL.encodeComponent(dateString);
+ }
+ return "";
+ }
+
+ public MenuBar createMenu() {
+ contextMenu.clearItems();
+ contextMenu.setAutoOpen(false);
+ final Command downloadCmd = new Command() {
+
+ @Override
+ public void execute() {
+ hide();
+ preDownloadCheck();
+ }
+ };
+ Folders folders = GSS.get().getFolders();
+ TreeItem selectedItem = folders.getCurrent();
+ boolean downloadVisible = GSS.get().getCurrentSelection() != null && GSS.get().getCurrentSelection() instanceof FileResource;
+ boolean propertiesVisible = !(selectedItem != null && (folders.isTrash(selectedItem) || folders.isMyShares(selectedItem) || folders.isOthersShared(selectedItem) || selectedItem.getUserObject() instanceof GroupUserResource || GSS.get().getCurrentSelection() instanceof List));
+ boolean newFolderVisible = !(selectedItem != null && (folders.isTrash(selectedItem) || folders.isTrashItem(selectedItem) || folders.isMyShares(selectedItem)|| folders.isOthersShared(selectedItem)));
+ boolean uploadVisible = !(selectedItem != null && (folders.isTrash(selectedItem) || folders.isTrashItem(selectedItem)|| folders.isMyShares(selectedItem)|| folders.isOthersShared(selectedItem)));
+ if(newFolderVisible)
+ contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.folderNew()).getHTML() + " New Folder</span>", true, new NewFolderCommand(this, images));
+ if(uploadVisible)
+ contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this));
+ if (downloadVisible) {
+ String[] link = {"", ""};
+ createDownloadLink(link, false);
+ contextMenu.addItem("<span>" + link[0] + AbstractImagePrototype.create(images.download()).getHTML() + " Download" + link[1] + "</span>", true, downloadCmd);
+ createDownloadLink(link, true);
+ contextMenu.addItem("<span>" + link[0] + AbstractImagePrototype.create(images.download()).getHTML() + " Save As" + link[1] + "</span>", true, downloadCmd);
+ }
+ contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.emptyTrash()).getHTML() + " Empty Trash</span>", true, new EmptyTrashCommand(this));
+ contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images));
+ contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.sharing()).getHTML() + " Sharing</span>", true, new PropertiesCommand(this, images, 1))
+ .setVisible(propertiesVisible);
+ contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.viewText()).getHTML() + " Properties</span>", true, new PropertiesCommand(this, images, 0))
+ .setVisible(propertiesVisible);
+ return contextMenu;
+ }
+
+}