X-Git-Url: https://code.grnet.gr/git/pithos-web-client/blobdiff_plain/749068baa7761f90d9896c1e2a70586afc655a04..d02b08f2e55608496533f32b098406ed1fb289e0:/src/gr/grnet/pithos/web/client/FileContextMenu.java diff --git a/src/gr/grnet/pithos/web/client/FileContextMenu.java b/src/gr/grnet/pithos/web/client/FileContextMenu.java index dfc2060..b19bde5 100644 --- a/src/gr/grnet/pithos/web/client/FileContextMenu.java +++ b/src/gr/grnet/pithos/web/client/FileContextMenu.java @@ -1,5 +1,5 @@ /* - * Copyright 2011 GRNET S.A. All rights reserved. + * Copyright 2011-2012 GRNET S.A. All rights reserved. * * Redistribution and use in source and binary forms, with or * without modification, are permitted provided that the following @@ -39,6 +39,7 @@ 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.RestoreTrashCommand; import gr.grnet.pithos.web.client.commands.ToTrashCommand; import gr.grnet.pithos.web.client.commands.UploadFileCommand; import gr.grnet.pithos.web.client.foldertree.File; @@ -46,9 +47,11 @@ import gr.grnet.pithos.web.client.foldertree.Folder; import java.util.List; +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.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; @@ -88,7 +91,7 @@ public class FileContextMenu extends PopupPanel { * 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(); @@ -96,17 +99,78 @@ public class FileContextMenu extends PopupPanel { @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(); @@ -117,63 +181,78 @@ public class FileContextMenu extends PopupPanel { * * @param newImages the image bundle passed on by the parent object */ - public FileContextMenu(Images newImages, Folder selectedFolder, List selectedFiles, boolean isTrash) { + 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); - Pithos gss = Pithos.get(); setAnimationEnabled(true); images = newImages; MenuBar contextMenu = new MenuBar(true); - - if (Pithos.get().getClipboard().hasFiles()) { - pasteItem = new MenuItem("" + AbstractImagePrototype.create(images.paste()).getHTML() + " Paste", true, new PasteCommand(Pithos.get(), this, selectedFolder)); - contextMenu.addItem(pasteItem); + 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()) { + 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); - MenuItem upload = new MenuItem("" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + " Upload", true, new UploadFileCommand(this, selectedFolder)); - contextMenu.addItem(upload); - -// MenuItem refresh = new MenuItem("" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh", true, new RefreshCommand(this, images)); -// contextMenu.addItem(refresh); - -// if (isTrash) { -// MenuItem restore = new MenuItem("" + AbstractImagePrototype.create(images.versions()).getHTML() + " Restore", true, new RestoreTrashCommand(this)); -// contextMenu.addItem(restore); -// -// MenuItem delete = new MenuItem("" + AbstractImagePrototype.create(images.delete()).getHTML() + " Delete", true, new DeleteCommand(this, null, images)); -// contextMenu.addItem(delete); -// } else { - cutItem = new MenuItem("" + AbstractImagePrototype.create(newImages.cut()).getHTML() + " Cut", true, new CutCommand(Pithos.get(), this, selectedFiles)); - contextMenu.addItem(cutItem); - - copyItem = new MenuItem("" + AbstractImagePrototype.create(newImages.copy()).getHTML() + " Copy", true, new CopyCommand(Pithos.get(), this, selectedFiles)); - contextMenu.addItem(copyItem); - - trashItem = new MenuItem("" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + " Move to Trash", true, new ToTrashCommand(Pithos.get(), this, selectedFiles)); - contextMenu.addItem(trashItem); - - deleteItem = new MenuItem("" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete", true, new DeleteCommand(this, selectedFiles, images)); - contextMenu.addItem(deleteItem); - -// sharingItem = new MenuItem("" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + " Sharing", true, new PropertiesCommand(this, images, 1)); -// contextMenu.addItem(sharingItem); - - contextMenu.addItem(new MenuItem("" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Properties", true, new PropertiesCommand(Pithos.get(), this, selectedFiles, images, 0))); + if (isFolderTreeSelected) { + deleteItem = new MenuItem("" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete", true, new DeleteCommand(app, this, selectedFiles, MessagePanel.images)); + contextMenu.addItem(deleteItem); + } - if (!selectedFiles.isEmpty()) - contextMenu.addItem(new MenuItem("" + AbstractImagePrototype.create(newImages.download()).getHTML() + " Download", true, (Command) null)); + 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, PropertiesCommand.PROPERTIES))); + contextMenu.addItem(new MenuItem("" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + " Sharing", true, new PropertiesCommand(app, this, selectedFiles, PropertiesCommand.PERMISSIONS))); + contextMenu.addItem(new MenuItem("" + AbstractImagePrototype.create(newImages.versions()).getHTML() + " Versions", true, new PropertiesCommand(app, this, selectedFiles, PropertiesCommand.VERSIONS))); + } - MenuItem unSelect = new MenuItem("" + AbstractImagePrototype.create(images.unselectAll()).getHTML() + " Unselect", true, new Command() { - @Override - public void execute() { - hide(); - Pithos.get().getFileList().clearSelectedRows(); - } - }); - contextMenu.addItem(unSelect); + } + contextMenu.addItem(new MenuItem("" + AbstractImagePrototype.create(newImages.download()).getHTML() + " Download", true, new Command() { + + @Override + public void execute() { + for (File f : selectedFiles) + Window.open(app.getApiPath() + f.getOwner() + f.getUri() + "?X-Auth-Token=" + URL.encodeQueryString(app.getToken()), "_blank", ""); + } + })); -// } add(contextMenu); } }