Fixed various warnings
[pithos-web-client] / src / gr / grnet / pithos / web / client / FileContextMenu.java
index bfbb369..03abed3 100644 (file)
@@ -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;
@@ -49,6 +50,7 @@ import java.util.List;
 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;
@@ -96,7 +98,7 @@ public class FileContextMenu extends PopupPanel {
                @Source("gr/grnet/pithos/resources/doc_versions.png")
                ImageResource versions();
 
-               @Source("gr/grnet/pithos/resources/group.png")
+               @Source("gr/grnet/pithos/resources/groups22.png")
                ImageResource sharing();
 
                @Source("gr/grnet/pithos/resources/border_remove.png")
@@ -117,7 +119,7 @@ public class FileContextMenu extends PopupPanel {
         @Source("gr/grnet/pithos/resources/folder_inbox.png")
         ImageResource download();
 
-        @Source("gr/grnet/pithos/resources/trashcan_empty.png")
+        @Source("gr/grnet/pithos/resources/trash.png")
         ImageResource emptyTrash();
 
         @Source("gr/grnet/pithos/resources/refresh.png")
@@ -178,62 +180,78 @@ public class FileContextMenu extends PopupPanel {
         *
         * @param newImages the image bundle passed on by the parent object
         */
-       public FileContextMenu(final Pithos app, Images newImages, Folder selectedFolder, List<File> selectedFiles, boolean isTrash) {
+       public FileContextMenu(final Pithos app, Images newImages, TreeView selectedTree, Folder selectedFolder, final List<File> 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);
                setAnimationEnabled(true);
                images = newImages;
         MenuBar contextMenu = new MenuBar(true);
-
-        if (app.getClipboard().hasFiles()) {
-            pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.paste()).getHTML() + "&nbsp;Paste</span>", true, new PasteCommand(app, 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("<span>" + AbstractImagePrototype.create(images.paste()).getHTML() + "&nbsp;Paste</span>", true, new PasteCommand(app, this, selectedFolder));
+                               contextMenu.addItem(pasteItem);
+                       }
+               
+                       if (canWrite) {
+                               MenuItem upload = new MenuItem("<span>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(app, this, selectedFolder));
+                               contextMenu.addItem(upload);
+                       }
+                       if (isFolderTreeSelected) {
+                                       cutItem = new MenuItem("<span id='fileContextMenu.cut'>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + "&nbsp;Cut</span>", true, new CutCommand(app, this, selectedFiles));
+                           contextMenu.addItem(cutItem);
+                       }
+               
+               
+                       if (isFolderTreeSelected) {
+                                       trashItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(app, this, selectedFiles));
+                           contextMenu.addItem(trashItem);
+                       }
+                   }
+                   else {
+                               MenuItem restore = new MenuItem("<span>" + AbstractImagePrototype.create(images.versions()).getHTML() + "&nbsp;Restore</span>", true, new RestoreTrashCommand(app, this, selectedFiles));
+                               contextMenu.addItem(restore);
+                   }
+        }
+               copyItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + "&nbsp;Copy</span>", true, new CopyCommand(app, this, selectedFiles));
+        contextMenu.addItem(copyItem);
 
-        MenuItem upload = new MenuItem("<span>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(app, this, selectedFolder));
-        contextMenu.addItem(upload);
-
-//        MenuItem refresh = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
-//        contextMenu.addItem(refresh);
-
-//             if (isTrash) {
-//                     MenuItem restore = new MenuItem("<span>" + AbstractImagePrototype.create(images.versions()).getHTML() + "&nbsp;Restore</span>", true, new RestoreTrashCommand(this));
-//                     contextMenu.addItem(restore);
-//
-//                     MenuItem delete = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, null, images));
-//                     contextMenu.addItem(delete);
-//             } else {
-                       cutItem = new MenuItem("<span id='fileContextMenu.cut'>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + "&nbsp;Cut</span>", true, new CutCommand(app, this, selectedFiles));
-            contextMenu.addItem(cutItem);
-
-                       copyItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + "&nbsp;Copy</span>", true, new CopyCommand(app, this, selectedFiles));
-            contextMenu.addItem(copyItem);
-
-                       trashItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(app, this, selectedFiles));
-            contextMenu.addItem(trashItem);
-
+        if (isFolderTreeSelected) {
                        deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(app, this, selectedFiles, MessagePanel.images));
-            contextMenu.addItem(deleteItem);
-
-//                     sharingItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + "&nbsp;Sharing</span>", true, new PropertiesCommand(this, images, 1));
-//            contextMenu.addItem(sharingItem);
-
-            contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(app, this, selectedFiles, images, 0)));
+               contextMenu.addItem(deleteItem);
+        }
 
-            if (!selectedFiles.isEmpty())
-                           contextMenu.addItem(new MenuItem("<span><a class='hidden-link' href='" + app.getApiPath() + app.getUsername() + selectedFiles.get(0).getUri() + "?X-Auth-Token=" + app.getToken() + "' target='_blank'>" + AbstractImagePrototype.create(newImages.download()).getHTML() + " Download</a></span>", true, (Command) null));
+        if (selectedFolder != null && !selectedFolder.isInTrash()) {
+               if (isFolderTreeSelected && selectedFiles.size() == 1) {
+                       contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(app, this, selectedFiles, PropertiesCommand.PROPERTIES)));
+                       contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + "&nbsp;Sharing</span>", true, new PropertiesCommand(app, this, selectedFiles, PropertiesCommand.PERMISSIONS)));
+                       contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.versions()).getHTML() + "&nbsp;Versions</span>", true, new PropertiesCommand(app, this, selectedFiles, PropertiesCommand.VERSIONS)));
+               }
 
-                       MenuItem unSelect = new MenuItem("<span>" + AbstractImagePrototype.create(images.unselectAll()).getHTML() + "&nbsp;Unselect</span>", true, new Command() {
-                @Override
-                public void execute() {
-                    hide();
-                    app.getFileList().clearSelectedRows();
-                }
-            });
-                       contextMenu.addItem(unSelect);
+        }
+           contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.download()).getHTML() + "&nbsp;Download</span>", true, new Command() {
+                       
+                       @Override
+                       public void execute() {
+                               for (File f : selectedFiles)
+                                       Window.open(app.getApiPath() + f.getOwner() + f.getUri() + "?X-Auth-Token=" + app.getToken(), "_blank", "");
+                       }
+               }));
 
-//             }
                add(contextMenu);
        }
 }