X-Git-Url: https://code.grnet.gr/git/pithos/blobdiff_plain/6dd67d1c0dd7c9511e764bac47875b63c5bc3f70..dc275351d7946c097450634fd43e1057cdb9d5f1:/web_client/src/gr/grnet/pithos/web/client/FileContextMenu.java diff --git a/web_client/src/gr/grnet/pithos/web/client/FileContextMenu.java b/web_client/src/gr/grnet/pithos/web/client/FileContextMenu.java index 5b32aad..2ad422d 100644 --- a/web_client/src/gr/grnet/pithos/web/client/FileContextMenu.java +++ b/web_client/src/gr/grnet/pithos/web/client/FileContextMenu.java @@ -1,5 +1,36 @@ /* - * Copyright (c) 2011 Greek Research and Technology Network + * Copyright 2011 GRNET S.A. All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * 1. Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and + * documentation are those of the authors and should not be + * interpreted as representing official policies, either expressed + * or implied, of GRNET S.A. */ package gr.grnet.pithos.web.client; @@ -8,25 +39,18 @@ import gr.grnet.pithos.web.client.commands.CutCommand; import gr.grnet.pithos.web.client.commands.DeleteCommand; import gr.grnet.pithos.web.client.commands.PasteCommand; import gr.grnet.pithos.web.client.commands.PropertiesCommand; -import gr.grnet.pithos.web.client.commands.RefreshCommand; import gr.grnet.pithos.web.client.commands.RestoreTrashCommand; import gr.grnet.pithos.web.client.commands.ToTrashCommand; import gr.grnet.pithos.web.client.commands.UploadFileCommand; -import gr.grnet.pithos.web.client.rest.resource.FileResource; -import gr.grnet.pithos.web.client.rest.resource.FolderResource; -import gr.grnet.pithos.web.client.rest.resource.RestResource; -import gr.grnet.pithos.web.client.rest.resource.RestResourceWrapper; -import gr.grnet.pithos.web.client.rest.resource.TrashFolderResource; +import gr.grnet.pithos.web.client.foldertree.File; +import gr.grnet.pithos.web.client.foldertree.Folder; import java.util.List; -import com.google.gwt.event.dom.client.ClickEvent; -import com.google.gwt.event.dom.client.ClickHandler; -import com.google.gwt.event.dom.client.ContextMenuEvent; 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.Event; +import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.AbstractImagePrototype; import com.google.gwt.user.client.ui.MenuBar; import com.google.gwt.user.client.ui.MenuItem; @@ -35,7 +59,7 @@ import com.google.gwt.user.client.ui.PopupPanel; /** * The 'File Context' menu implementation. */ -public class FileContextMenu extends PopupPanel implements ClickHandler { +public class FileContextMenu extends PopupPanel { /** * The widget's images. @@ -66,7 +90,7 @@ public class FileContextMenu extends PopupPanel implements ClickHandler { * The image bundle for this widget's images that reuses images defined in * other menus. */ - public interface Images extends ClientBundle,FileMenu.Images, EditMenu.Images { + public interface Images extends ClientBundle { @Source("gr/grnet/pithos/resources/mimetypes/document.png") ImageResource fileContextMenu(); @@ -74,17 +98,78 @@ public class FileContextMenu extends PopupPanel implements ClickHandler { @Source("gr/grnet/pithos/resources/doc_versions.png") ImageResource versions(); - @Override - @Source("gr/grnet/pithos/resources/group.png") + @Source("gr/grnet/pithos/resources/groups22.png") ImageResource sharing(); - @Override @Source("gr/grnet/pithos/resources/border_remove.png") ImageResource unselectAll(); @Source("gr/grnet/pithos/resources/demo.png") ImageResource viewImage(); -} + + @Source("gr/grnet/pithos/resources/folder_new.png") + ImageResource folderNew(); + + @Source("gr/grnet/pithos/resources/folder_outbox.png") + ImageResource fileUpdate(); + + @Source("gr/grnet/pithos/resources/view_text.png") + ImageResource viewText(); + + @Source("gr/grnet/pithos/resources/folder_inbox.png") + ImageResource download(); + + @Source("gr/grnet/pithos/resources/trash.png") + ImageResource emptyTrash(); + + @Source("gr/grnet/pithos/resources/refresh.png") + ImageResource refresh(); + + /** + * Will bundle the file 'editcut.png' residing in the package + * 'gr.grnet.pithos.web.resources'. + * + * @return the image prototype + */ + @Source("gr/grnet/pithos/resources/editcut.png") + ImageResource cut(); + + /** + * Will bundle the file 'editcopy.png' residing in the package + * 'gr.grnet.pithos.web.resources'. + * + * @return the image prototype + */ + @Source("gr/grnet/pithos/resources/editcopy.png") + ImageResource copy(); + + /** + * Will bundle the file 'editpaste.png' residing in the package + * 'gr.grnet.pithos.web.resources'. + * + * @return the image prototype + */ + @Source("gr/grnet/pithos/resources/editpaste.png") + ImageResource paste(); + + /** + * Will bundle the file 'editdelete.png' residing in the package + * 'gr.grnet.pithos.web.resources'. + * + * @return the image prototype + */ + @Source("gr/grnet/pithos/resources/editdelete.png") + ImageResource delete(); + + /** + * Will bundle the file 'translate.png' residing in the package + * 'gr.grnet.pithos.web.resources'. + * + * @return the image prototype + */ + @Source("gr/grnet/pithos/resources/translate.png") + ImageResource selectAll(); + } public static native String getDate()/*-{ return (new Date()).toUTCString(); @@ -95,249 +180,76 @@ public class FileContextMenu extends PopupPanel implements ClickHandler { * * @param newImages the image bundle passed on by the parent object */ - public FileContextMenu(Images newImages, boolean isTrash, boolean isEmpty) { + public FileContextMenu(final Pithos app, Images newImages, TreeView selectedTree, Folder selectedFolder, final List selectedFiles) { // The popup's constructor's argument is a boolean specifying that it // auto-close itself when the user clicks outside of it. super(true); - GSS gss = GSS.get(); setAnimationEnabled(true); images = newImages; - - // The command that does some validation before downloading a file. - Command downloadCmd = new Command() { - + MenuBar contextMenu = new MenuBar(true); + Boolean[] permissions = null; + boolean canWrite = true; + if (selectedFolder != null) { + permissions = selectedFolder.getPermissions().get(app.getUsername()); + canWrite = selectedFolder.getOwner().equals(app.getUsername()) || (permissions!= null && permissions[1] != null && permissions[1]); + } + else { + for (File f : selectedFiles) { + permissions = f.getPermissions().get(app.getUsername()); + canWrite &= (f.getOwner().equals(app.getUsername()) || (permissions!= null && permissions[1] != null && permissions[1])); + } + } + boolean isFolderTreeSelected = selectedTree.equals(app.getFolderTreeView()); + if (selectedFolder != null) { + if (!selectedFolder.isInTrash()) { + if (canWrite && app.getClipboard().hasFiles()) { + List files = (List) app.getClipboard().getItem(); + pasteItem = new MenuItem("" + AbstractImagePrototype.create(images.paste()).getHTML() + " Paste", true, new PasteCommand(app, this, selectedFolder)); + contextMenu.addItem(pasteItem); + } + + if (canWrite) { + MenuItem upload = new MenuItem("" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + " Upload", true, new UploadFileCommand(app, this, selectedFolder)); + contextMenu.addItem(upload); + } + if (isFolderTreeSelected) { + cutItem = new MenuItem("" + AbstractImagePrototype.create(newImages.cut()).getHTML() + " Cut", true, new CutCommand(app, this, selectedFiles)); + contextMenu.addItem(cutItem); + } + + + if (isFolderTreeSelected) { + trashItem = new MenuItem("" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + " Move to Trash", true, new ToTrashCommand(app, this, selectedFiles)); + contextMenu.addItem(trashItem); + } + } + else { + MenuItem restore = new MenuItem("" + AbstractImagePrototype.create(images.versions()).getHTML() + " Restore", true, new RestoreTrashCommand(app, this, selectedFiles)); + contextMenu.addItem(restore); + } + } + copyItem = new MenuItem("" + AbstractImagePrototype.create(newImages.copy()).getHTML() + " Copy", true, new CopyCommand(app, this, selectedFiles)); + contextMenu.addItem(copyItem); + + if (isFolderTreeSelected) { + deleteItem = new MenuItem("" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete", true, new DeleteCommand(app, this, selectedFiles, MessagePanel.images)); + contextMenu.addItem(deleteItem); + } + + if (selectedFolder != null && !selectedFolder.isInTrash()) { + if (isFolderTreeSelected && selectedFiles.size() == 1) + contextMenu.addItem(new MenuItem("" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Properties", true, new PropertiesCommand(app, this, selectedFiles, images, 0))); + + } + contextMenu.addItem(new MenuItem("" + AbstractImagePrototype.create(newImages.download()).getHTML() + " Download", true, new Command() { + @Override public void execute() { - hide(); - GSS.get().getTopPanel().getFileMenu().preDownloadCheck(); - } - }; - - pasteItem = new MenuItem("" + AbstractImagePrototype.create(newImages.paste()).getHTML() + " Paste", true, new PasteCommand(this)); - pasteItem.getElement().setId("FileContextMenu.paste"); - RestResource sel = GSS.get().getTreeView().getSelection(); - MenuBar contextMenu = new MenuBar(true); - if (isEmpty) { - contextMenu.addItem(pasteItem); - if (sel != null) - /*TODO:CELLTREE - if (GSS.get().getTreeView().isFileItem(GSS.get().getTreeView().getCurrent())) - contextMenu.addItem("" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + " Upload", true, new UploadFileCommand(this)); - else if (GSS.get().getTreeView().isMySharedItem(GSS.get().getTreeView().getCurrent()) || GSS .get() - .getTreeView() - .isOthersSharedItem(GSS .get() - .getTreeView() - .getCurrent())) - if(sel instanceof FolderResource) - contextMenu.addItem("" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + " Upload", true, new UploadFileCommand(this)); - */ - if(sel instanceof RestResourceWrapper && !(sel instanceof TrashFolderResource)){ - MenuItem upload = new MenuItem("" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + " Upload", true, new UploadFileCommand(this)); - upload.getElement().setId("fileContextMenu.upload"); - contextMenu.addItem(upload); + for (File f : selectedFiles) + Window.open(app.getApiPath() + f.getOwner() + f.getUri() + "?X-Auth-Token=" + app.getToken(), "_blank", ""); } - MenuItem refresh = new MenuItem("" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh", true, new RefreshCommand(this, images)); - refresh.getElement().setId("fileContextMenu.refresh"); - contextMenu.addItem(refresh); - - } else if (isTrash) { - MenuItem restore = new MenuItem("" + AbstractImagePrototype.create(newImages.versions()).getHTML() + " Restore", true, new RestoreTrashCommand(this)); - restore.getElement().setId("fileContextMenu.restore"); - contextMenu.addItem(restore); - - MenuItem delete = new MenuItem("" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete", true, new DeleteCommand(this, images)); - delete.getElement().setId("fileContextMenu.delete"); - contextMenu.addItem(delete); - } else { - final Command unselectAllCommand = new Command() { - - @Override - public void execute() { - hide(); - if(GSS.get().isFileListShowing()) - GSS.get().getFileList().clearSelectedRows(); - else if(GSS.get().isSearchResultsShowing()) - GSS.get().getSearchResults().clearSelectedRows(); - } - }; - cutItem = new MenuItem("" + AbstractImagePrototype.create(newImages.cut()).getHTML() + " Cut", true, new CutCommand(this)); - cutItem.getElement().setId("fileContextMenu.cut"); - - copyItem = new MenuItem("" + AbstractImagePrototype.create(newImages.copy()).getHTML() + " Copy", true, new CopyCommand(this)); - copyItem.getElement().setId("fileContextMenu.copy"); - - updateItem = new MenuItem("" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + " Upload", true, new UploadFileCommand(this)); - updateItem.getElement().setId("fileContextMenu.upload"); + })); - trashItem = new MenuItem("" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + " Move to Trash", true, new ToTrashCommand(this)); - trashItem.getElement().setId("fileContextMenu.moveToTrash"); - - deleteItem = new MenuItem("" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete", true, new DeleteCommand(this, images)); - deleteItem.getElement().setId("fileContextMenu.delete"); - - sharingItem = new MenuItem("" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + " Sharing", true, new PropertiesCommand(this, images, 1)); - sharingItem.getElement().setId("fileContextMenu.sharing"); - - propItem = new MenuItem("" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Properties", true, new PropertiesCommand(this, images, 0)); - propItem.getElement().setId("fileContextMenu.properties"); - - - if(sel!=null && sel instanceof FolderResource) - contextMenu.addItem(updateItem); - String[] link = {"", ""}; - gss.getTopPanel().getFileMenu().createDownloadLink(link, false); - downloadItem = new MenuItem("" + link[0] + AbstractImagePrototype.create(newImages.download()).getHTML() + " Download" + link[1] + "", true, downloadCmd); - downloadItem.getElement().setId("fileContextMenu.download"); - contextMenu.addItem(downloadItem); - - gss.getTopPanel().getFileMenu().createDownloadLink(link, true); - saveAsItem = new MenuItem("" + link[0] + AbstractImagePrototype.create(newImages.download()).getHTML() + " Save As" + link[1] + "", true, downloadCmd); - saveAsItem.getElement().setId("fileContextMenu.saveAs"); - contextMenu.addItem(saveAsItem); - contextMenu.addItem(cutItem); - contextMenu.addItem(copyItem); - if(sel!=null && sel instanceof FolderResource) - contextMenu.addItem(pasteItem); - MenuItem unSelect = new MenuItem("" + AbstractImagePrototype.create(images.unselectAll()).getHTML() + " Unselect", true, unselectAllCommand); - unSelect.getElement().setId("fileContextMenu.unSelect"); - contextMenu.addItem(unSelect); - - contextMenu.addItem(trashItem); - contextMenu.addItem(deleteItem); - - MenuItem refresh = new MenuItem("" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh", true, new RefreshCommand(this, images)); - refresh.getElement().setId("fileContextMenu.refresh"); - contextMenu.addItem(refresh); - - contextMenu.addItem(sharingItem); - contextMenu.addItem(propItem); - } add(contextMenu); - if (gss.getClipboard().hasFileItem()) - pasteItem.setVisible(true); - else - pasteItem.setVisible(false); - } - - void onMultipleSelection() { - updateItem.setVisible(false); - downloadItem.setVisible(false); - saveAsItem.setVisible(false); - sharingItem.setVisible(false); } - @Override - public void onClick(ClickEvent event) { - if (GSS.get().getCurrentSelection() != null) - if (GSS.get().getCurrentSelection() instanceof FileResource) { - FileResource res = (FileResource) GSS.get().getCurrentSelection(); - FileContextMenu menu; - if (res.isDeleted()) - menu = new FileContextMenu(images, true, false); - else - menu = new FileContextMenu(images, false, false); - int left = event.getRelativeElement().getAbsoluteLeft(); - int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight(); - menu.setPopupPosition(left, top); - menu.show(); - } else if (GSS.get().getCurrentSelection() instanceof List) { - FileContextMenu menu; - /*TODO: CELLTREE - if (GSS.get().getTreeView().isTrashItem(GSS.get().getTreeView().getCurrent())) - menu = new FileContextMenu(images, true, false); - else { - menu = new FileContextMenu(images, false, false); - menu.onMultipleSelection(); - } - */ - menu = new FileContextMenu(images, false, false); - menu.onMultipleSelection(); - int left = event.getRelativeElement().getAbsoluteLeft(); - int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight(); - menu.setPopupPosition(left, top); - menu.show(); - } - } - - - public void onContextEvent(ContextMenuEvent event) { - if (GSS.get().getCurrentSelection() != null) - if (GSS.get().getCurrentSelection() instanceof FileResource) { - FileResource res = (FileResource) GSS.get().getCurrentSelection(); - FileContextMenu menu; - if (res.isDeleted()) - menu = new FileContextMenu(images, true, false); - else - menu = new FileContextMenu(images, false, false); - int left = event.getNativeEvent().getClientX(); - int top = event.getNativeEvent().getClientY(); - menu.setPopupPosition(left, top); - menu.show(); - - } else if (GSS.get().getCurrentSelection() instanceof List) { - FileContextMenu menu; - /*TODO: CELLTREE - if (GSS.get().getTreeView().isTrashItem(GSS.get().getTreeView().getCurrent())) - menu = new FileContextMenu(images, true, false); - else { - menu = new FileContextMenu(images, false, false); - menu.onMultipleSelection(); - } - */ - int left = event.getNativeEvent().getClientX(); - int top = event.getNativeEvent().getClientY(); - //menu.setPopupPosition(left, top); - //menu.show(); - } - } - - public FileContextMenu onEvent(Event event) { - FileContextMenu menu=null; - if (GSS.get().getCurrentSelection() != null) - if (GSS.get().getCurrentSelection() instanceof FileResource) { - FileResource res = (FileResource) GSS.get().getCurrentSelection(); - - if (res.isDeleted()) - menu = new FileContextMenu(images, true, false); - else - menu = new FileContextMenu(images, false, false); - int left = event.getClientX(); - int top = event.getClientY(); - menu.setPopupPosition(left, top); - menu.show(); - } else if (GSS.get().getCurrentSelection() instanceof List) { - /*TODO: CELLTREE - if (GSS.get().getTreeView().isTrashItem(GSS.get().getTreeView().getSelection())) - menu = new FileContextMenu(images, true, false); - else { - menu = new FileContextMenu(images, false, false); - menu.onMultipleSelection(); - }*/ - menu = new FileContextMenu(images, false, false); - menu.onMultipleSelection(); - int left = event.getClientX(); - int top = event.getClientY(); - menu.setPopupPosition(left, top); - menu.show(); - } - return menu; - } - - public FileContextMenu onEmptyEvent(Event event) { - FileContextMenu menu=null; - /*TODO: CELLTREE - if (GSS.get().getTreeView().isTrashItem(GSS.get().getTreeView().getCurrent())) - menu = new FileContextMenu(images, true, true); - else if(((DnDTreeItem)GSS.get().getTreeView().getCurrent()).getFolderResource() != null) - menu = new FileContextMenu(images, false, true); - else return menu; - */ - menu = new FileContextMenu(images, false, true); - int left = event.getClientX(); - int top = event.getClientY(); - menu.setPopupPosition(left, top); - menu.show(); - return menu; - } - - }