Merge branch 'release-0.15' into debian-release-0.15
[pithos-web-client] / src / gr / grnet / pithos / web / client / FileContextMenu.java
index 6273de7..1399047 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2011-2012 GRNET S.A. All rights reserved.
+ * Copyright 2011-2013 GRNET S.A. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or
  * without modification, are permitted provided that the following
  */
 package gr.grnet.pithos.web.client;
 
-import gr.grnet.pithos.web.client.commands.CopyCommand;
-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;
-import gr.grnet.pithos.web.client.foldertree.Folder;
-
-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;
@@ -55,6 +42,11 @@ import com.google.gwt.user.client.ui.AbstractImagePrototype;
 import com.google.gwt.user.client.ui.MenuBar;
 import com.google.gwt.user.client.ui.MenuItem;
 import com.google.gwt.user.client.ui.PopupPanel;
+import gr.grnet.pithos.web.client.commands.*;
+import gr.grnet.pithos.web.client.foldertree.File;
+import gr.grnet.pithos.web.client.foldertree.Folder;
+
+import java.util.List;
 
 /**
  * The 'File Context' menu implementation.
@@ -169,6 +161,9 @@ public class FileContextMenu extends PopupPanel {
          */
         @Source("gr/grnet/pithos/resources/translate.png")
         ImageResource selectAll();
+        
+        @Source("gr/grnet/pithos/resources/internet.png")
+        ImageResource internet();
     }
 
        public static native String getDate()/*-{
@@ -184,40 +179,43 @@ public class FileContextMenu extends PopupPanel {
                // 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);
         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]);
+               permissions = selectedFolder.getPermissions().get(app.getUserID());
+               canWrite = selectedFolder.getOwnerID().equals(app.getUserID()) || (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]));
+                       permissions = f.getPermissions().get(app.getUserID());
+                       canWrite &= (f.getOwnerID().equals(app.getUserID()) || (permissions!= null && permissions[1] != null && permissions[1]));
                }
         }
         boolean isFolderTreeSelected = selectedTree.equals(app.getFolderTreeView());
+        boolean isMysharedSelected = selectedTree.equals(app.getMySharedTreeView());
+
+        Pithos.LOG("FileContextMenu(), selectedFolder=", selectedFolder);
+        Pithos.LOG("FileContextMenu(), isFolderTreeSelected=", isFolderTreeSelected);
+        Pithos.LOG("FileContextMenu(), isMysharedSelected=", isMysharedSelected);
+
         if (selectedFolder != null) {
                    if (!selectedFolder.isInTrash()) {
-                       if (canWrite && app.getClipboard().hasFiles()) {
+                       if (canWrite && app.getClipboard().hasFiles() && !isMysharedSelected) {
                                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) {
+                       if (isFolderTreeSelected || isMysharedSelected) {
                                        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);
                
-                       if (isFolderTreeSelected) {
+                       if (isFolderTreeSelected || isMysharedSelected) {
                                        trashItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(app, this, selectedFiles));
                            contextMenu.addItem(trashItem);
                        }
@@ -225,21 +223,17 @@ public class FileContextMenu extends PopupPanel {
                    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);
 
-        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);
+                deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(app, this, selectedFiles, MessagePanel.images));
+                contextMenu.addItem(deleteItem);
+                   }
         }
 
         if (selectedFolder != null && !selectedFolder.isInTrash()) {
-               if (isFolderTreeSelected && selectedFiles.size() == 1) {
+               if ((isFolderTreeSelected || isMysharedSelected) && 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)));
+                       contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + "&nbsp;Share</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)));
                }
 
         }
@@ -247,8 +241,9 @@ public class FileContextMenu extends PopupPanel {
                        
                        @Override
                        public void execute() {
-                               for (File f : selectedFiles)
-                                       Window.open(app.getApiPath() + f.getOwner() + f.getUri() + "?X-Auth-Token=" + app.getToken(), "_blank", "");
+                               for (File f : selectedFiles) {
+                    Window.open(Pithos.getFileViewURL(f), "_blank", "");
+                }
                        }
                }));