Bump version to 0.16
[pithos-web-client] / src / gr / grnet / pithos / web / client / FolderContextMenu.java
index c030730..e846655 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2011 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.EmptyTrashCommand;
-import gr.grnet.pithos.web.client.commands.NewFolderCommand;
-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.foldertree.File;
+import gr.grnet.pithos.web.client.commands.*;
+import gr.grnet.pithos.web.client.commands.PurgeContainerCommand;
 import gr.grnet.pithos.web.client.foldertree.Folder;
 
-import java.util.List;
-
 import com.google.gwt.user.client.ui.AbstractImagePrototype;
 import com.google.gwt.user.client.ui.MenuBar;
 import com.google.gwt.user.client.ui.MenuItem;
@@ -82,24 +71,24 @@ public class FolderContextMenu 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 = folder.getPermissions().get(app.getUsername());
-       boolean canWrite = folder.getOwner().equals(app.getUsername()) || (permissions!= null && permissions[1] != null && permissions[1]);
+        Boolean[] permissions = folder.getPermissions().get(app.getUserID());
+       boolean canWrite = folder.getOwnerID().equals(app.getUserID()) || (permissions!= null && permissions[1] != null && permissions[1]);
        boolean isFolderTreeSelected = selectedTree.equals(app.getFolderTreeView());
        boolean otherSharedTreeSelected = selectedTree.equals(app.getOtherSharedTreeView());
+       boolean mysharedTreeSelected = selectedTree.equals(app.getMySharedTreeView());
        
-       if (isFolderTreeSelected || otherSharedTreeSelected) {
-               MenuItem refresh = new MenuItem("<span id = 'folderContextMenu.refresh'>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(app, this, folder));
-               contextMenu.addItem(refresh);
-       }
+       MenuItem refresh = new MenuItem("<span id = 'folderContextMenu.refresh'>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(app, this, folder));
+        contextMenu.addItem(refresh);
 
         if (!folder.isInTrash()) {
                if (canWrite) {
-                       MenuItem newFolder = new MenuItem("<span id = 'folderContextMenu.newFolder'>" + AbstractImagePrototype.create(newImages.folderNew()).getHTML() + "&nbsp;New Folder</span>", true, new NewFolderCommand(app, this, folder, images));
-                       contextMenu.addItem(newFolder);
+                       if (!mysharedTreeSelected) {
+                               MenuItem newFolder = new MenuItem("<span id = 'folderContextMenu.newFolder'>" + AbstractImagePrototype.create(newImages.folderNew()).getHTML() + "&nbsp;New Folder</span>", true, new NewFolderCommand(app, this, folder));
+                               contextMenu.addItem(newFolder);
+                       }
 
                        if (isFolderTreeSelected && !folder.isContainer()) {
                            MenuItem cut = new MenuItem("<span id = 'folderContextMenu.cut'>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + "&nbsp;Cut</span>", true, new CutCommand(app, this, folder));
@@ -107,22 +96,19 @@ public class FolderContextMenu extends PopupPanel {
                        }
                }
 
-               MenuItem copy = new MenuItem("<span id = 'folderContextMenu.copy'>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + "&nbsp;Copy</span>", true, new CopyCommand(app, this, folder));
-               contextMenu.addItem(copy);
+               if (!folder.isContainer()) {
+                       MenuItem copy = new MenuItem("<span id = 'folderContextMenu.copy'>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + "&nbsp;Copy</span>", true, new CopyCommand(app, this, folder));
+                       contextMenu.addItem(copy);
+               }
        
                if (canWrite) {
-                       if (!app.getClipboard().isEmpty()) {
+                       if (!app.getClipboard().isEmpty() && !mysharedTreeSelected) {
                                Object item = app.getClipboard().getItem();
-                               boolean showPaste = false;
-                               if (item instanceof List) {
-                                       List<File> files = (List<File>) item;
-                                       if (files.get(0).getOwner().equals(folder.getOwner()))
-                                               showPaste = true;
-                               }
-                               else {
+                               boolean showPaste = true;
+                               if (item instanceof Folder) {
                                        Folder f = (Folder) item;
-                                       if (f.getOwner().equals(folder.getOwner()) && !f.contains(folder))
-                                               showPaste = true;
+                                       if (f.contains(folder))
+                                               showPaste = false;
                                }
                                if (showPaste) {
                                    pasteItem = new MenuItem("<span id = 'folderContextMenu.paste'>" + AbstractImagePrototype.create(newImages.paste()).getHTML() + "&nbsp;Paste</span>", true, new PasteCommand(app, this, folder));
@@ -133,27 +119,31 @@ public class FolderContextMenu extends PopupPanel {
                            if (isFolderTreeSelected && !folder.isContainer()) {
                                MenuItem moveToTrash = new MenuItem("<span id = 'folderContextMenu.moveToTrash'>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(app, this, folder));
                                contextMenu.addItem(moveToTrash);
-                       
-                               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);
-                       
-                               MenuItem properties = new MenuItem("<span id = 'folderContextMenu.properties'>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(app, this, folder, newImages, 0));
-                               contextMenu.addItem(properties);
+
+                               contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(app, this, folder, PropertiesCommand.PROPERTIES)));
+                               contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + "&nbsp;Share</span>", true, new PropertiesCommand(app, this, folder, PropertiesCommand.PERMISSIONS)));
+                           }
+                           
+                           if (folder.isContainer()) {
+                               MenuItem purgeContainer = new MenuItem(
+                        "<span>" + Const.PurgeContainer(folder.getName()) + "</span>",
+                        true,
+                        new PurgeContainerCommand(app, this, folder)
+                    );
+                               contextMenu.addItem(purgeContainer);
                            }
                }
         }
-        else {
-               if (!folder.isTrash()) {
-                       MenuItem restore = new MenuItem("<span>" + AbstractImagePrototype.create(images.versions()).getHTML() + "&nbsp;Restore</span>", true, new RestoreTrashCommand(app, this, folder));
-                       contextMenu.addItem(restore);
+        else if(!folder.isTrash()) {
+            MenuItem 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);
-               }
-               else {
-                       MenuItem emptyTrash = new MenuItem("<span>" + AbstractImagePrototype.create(images.emptyTrash()).getHTML() + "&nbsp;Empty Trash</span>", true, new EmptyTrashCommand(app, this));
-                       contextMenu.addItem(emptyTrash);
-               }
+            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);
+        }
+        else {
+            MenuItem emptyTrash = new MenuItem("<span>" + AbstractImagePrototype.create(images.emptyTrash()).getHTML() + "&nbsp;Empty Trash</span>", true, new PurgeContainerCommand(app, this, folder));
+            contextMenu.addItem(emptyTrash);
         }
                add(contextMenu);
        }