Completed 'Shared by me' file context menu with whatever command is relevant (issue...
[pithos-web-client] / src / gr / grnet / pithos / web / client / ToolsMenu.java
index b45baf7..04356bd 100644 (file)
@@ -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
@@ -54,6 +54,7 @@ import gr.grnet.pithos.web.client.grouptree.User;
 
 import java.util.List;
 
+import com.google.gwt.http.client.URL;
 import com.google.gwt.user.client.Command;
 import com.google.gwt.user.client.Window;
 import com.google.gwt.user.client.ui.AbstractImagePrototype;
@@ -80,7 +81,7 @@ public class ToolsMenu extends PopupPanel {
 
        private MenuItem pasteItem;
 
-       private boolean empty = false;;
+       private boolean empty = true;
        
        /**
         * The widget's constructor.
@@ -99,11 +100,12 @@ public class ToolsMenu extends PopupPanel {
                Boolean[] permissions = folder.getPermissions().get(app.getUsername());
                boolean canWrite = folder.getOwner().equals(app.getUsername()) || (permissions!= null && permissions[1] != null && permissions[1]);
                boolean isFolderTreeSelected = selectedTree.equals(app.getFolderTreeView());
+               boolean isMysharedTreeSelected = app.isMySharedSelected();
                
                if (!folder.isInTrash()) {
                        if (canWrite) {
 
-                               if (isFolderTreeSelected) {
+                               if (isFolderTreeSelected || isMysharedTreeSelected) {
                                        MenuItem cut = null;
                                        if (files != null && !files.isEmpty()) {
                                                        cut = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + "&nbsp;Cut files</span>", true, new CutCommand(app, this, files));
@@ -111,21 +113,25 @@ public class ToolsMenu extends PopupPanel {
                                        else if (!folder.isContainer()) {
                                            cut = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + "&nbsp;Cut folder</span>", true, new CutCommand(app, this, folder));
                                        }
-                                       if (cut != null)
+                                       if (cut != null) {
                                                contextMenu.addItem(cut);
+                                               empty = false;
+                                       }
                                }
                        }
        
                        MenuItem copy = null;
                        if (files != null && !files.isEmpty())
                                copy = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + "&nbsp;Copy files</span>", true, new CopyCommand(app, this, files));
-                       else if (!folder.isContainer())
+                       else if (isFolderTreeSelected && !folder.isContainer())
                                copy = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + "&nbsp;Copy folder</span>", true, new CopyCommand(app, this, folder));
-                       if (copy != null)
+                       if (copy != null) {
                                contextMenu.addItem(copy);
+                               empty = false;
+                       }
                
                        if (canWrite) {
-                               if (!app.getClipboard().isEmpty()) {
+                               if (!isMysharedTreeSelected && !app.getClipboard().isEmpty()) {
                                        Object item = app.getClipboard().getItem();
                                        boolean showPaste = false;
                                        if (item instanceof List) {
@@ -142,10 +148,11 @@ public class ToolsMenu extends PopupPanel {
                                        if (showPaste) {
                                            pasteItem = new MenuItem("<span id = 'folderContextMenu.paste'>" + AbstractImagePrototype.create(newImages.paste()).getHTML() + "&nbsp;Paste</span>", true, new PasteCommand(app, this, folder));
                                            contextMenu.addItem(pasteItem);
+                                               empty = false;
                                        }
                                }
        
-                                   if (isFolderTreeSelected) {
+                                   if (isFolderTreeSelected || isMysharedTreeSelected) {
                                        MenuItem moveToTrash = null;
                                        if (files != null && !files.isEmpty()) {
                                                moveToTrash = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move files to Trash</span>", true, new ToTrashCommand(app, this, files));
@@ -153,8 +160,10 @@ public class ToolsMenu extends PopupPanel {
                                        else if (!folder.isContainer()) {
                                                moveToTrash = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move folder to Trash</span>", true, new ToTrashCommand(app, this, folder));
                                        }
-                                       if (moveToTrash != null)
+                                       if (moveToTrash != null) {
                                                contextMenu.addItem(moveToTrash);
+                                               empty = false;
+                                       }
                                
                                        MenuItem delete = null;
                                        if (files != null && !files.isEmpty()) {
@@ -162,17 +171,23 @@ public class ToolsMenu extends PopupPanel {
                                        }
                                        else if (!folder.isContainer())
                                                delete = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete folder</span>", true, new DeleteCommand(app, this, folder, MessagePanel.images));
-                                       if (delete != null)
+                                       if (delete != null) {
                                                contextMenu.addItem(delete);
-                               
+                                               empty = false;
+                                       }
+                                   }
+                                   if (isFolderTreeSelected || isMysharedTreeSelected) {
                                        if (files != null && files.size() == 1) {
                                                contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;File properties</span>", true, new PropertiesCommand(app, this, files, PropertiesCommand.PROPERTIES)));
                                                contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.group()).getHTML() + "&nbsp;Sharing</span>", true, new PropertiesCommand(app, this, files, PropertiesCommand.PERMISSIONS)));
-                                               contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.versions()).getHTML() + "&nbsp;Versions</span>", true, new PropertiesCommand(app, this, files, PropertiesCommand.VERSIONS)));
+                                               contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.internet()).getHTML() + "&nbsp;Publish</span>", true, new PropertiesCommand(app, this, files, PropertiesCommand.PUBLISH)));
+                                               contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.versions()).getHTML() + "&nbsp;Versions</span>", true, new PropertiesCommand(app, this, files, PropertiesCommand.VERSIONS)));
+                                               empty = false;
                                        }
                                        else if (!folder.isContainer()) {
                                                contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Folder properties</span>", true, new PropertiesCommand(app, this, folder, PropertiesCommand.PROPERTIES)));
                                                contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + "&nbsp;Folder sharing</span>", true, new PropertiesCommand(app, this, folder, PropertiesCommand.PERMISSIONS)));
+                                               empty = false;
                                        }
                                    }
                                if (files != null && !files.isEmpty()) {
@@ -181,9 +196,10 @@ public class ToolsMenu extends PopupPanel {
                                                        @Override
                                                        public void execute() {
                                                        for (File f: files)
-                                                               Window.open(app.getApiPath() + f.getOwner() + f.getUri() + "?X-Auth-Token=" + app.getToken(), "_blank", "");
+                                                               Window.open(app.getApiPath() + f.getOwner() + f.getUri(), "_blank", "");
                                                        }
                                                }));
+                                       empty = false;
                                }
                        }
                }
@@ -195,13 +211,15 @@ public class ToolsMenu extends PopupPanel {
                                else
                                        restore = new MenuItem("<span>" + AbstractImagePrototype.create(images.versions()).getHTML() + "&nbsp;Restore</span>", true, new RestoreTrashCommand(app, this, folder));
                                contextMenu.addItem(restore);
-       
+
                                MenuItem delete = new MenuItem("<span id = 'folderContextMenu.delete'>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(app, this, folder, MessagePanel.images));
                                contextMenu.addItem(delete);
+                               empty = false;
                        }
                        else {
                                MenuItem emptyTrash = new MenuItem("<span>" + AbstractImagePrototype.create(images.emptyTrash()).getHTML() + "&nbsp;Empty Trash</span>", true, new EmptyTrashCommand(app, this));
                                contextMenu.addItem(emptyTrash);
+                               empty = false;
                        }
                }
         }
@@ -211,6 +229,7 @@ public class ToolsMenu extends PopupPanel {
                        if (o instanceof User) {
                        MenuItem removeUser = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + "&nbsp;Remove User</span>", true, new RemoveUserCommand(app, this, (User) o));
                        contextMenu.addItem(removeUser);
+                               empty = false;
                        }
                        else if (o instanceof Group) {
                        MenuItem addUser = new MenuItem("<span>" + AbstractImagePrototype.create(images.user()).getHTML() + "&nbsp;Add User</span>", true, new AddUserCommand(app, this, (Group) o));
@@ -218,15 +237,13 @@ public class ToolsMenu extends PopupPanel {
                
                        MenuItem deleteGroup = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + "&nbsp;Delete Group</span>", true, new DeleteGroupCommand(app, this, (Group) o));
                        contextMenu.addItem(deleteGroup);
-                       }
-                       else {
-                       MenuItem createGroup = new MenuItem("<span>" + AbstractImagePrototype.create(images.group()).getHTML() + "&nbsp;Create Group</span>", true, new CreateGroupCommand(app, this));
-                       contextMenu.addItem(createGroup);
+                               empty = false;
                        }
                }
-               else
-                       empty = true;
         }
+        MenuItem createGroup = new MenuItem("<span>" + AbstractImagePrototype.create(images.group()).getHTML() + "&nbsp;Create Group</span>", true, new CreateGroupCommand(app, this));
+        contextMenu.addItem(createGroup);
+       empty = false;
                add(contextMenu);
        }