Fixed tools and folder context menus
[pithos-web-client] / src / gr / grnet / pithos / web / client / FolderContextMenu.java
index a915c95..15e9859 100644 (file)
@@ -34,8 +34,6 @@
  */
 package gr.grnet.pithos.web.client;
 
-import java.util.List;
-
 import gr.grnet.pithos.web.client.commands.CopyCommand;
 import gr.grnet.pithos.web.client.commands.CutCommand;
 import gr.grnet.pithos.web.client.commands.DeleteCommand;
@@ -43,11 +41,14 @@ 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.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;
@@ -88,10 +89,16 @@ public class FolderContextMenu 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 otherSharedTreeSelected = selectedTree.equals(app.getOtherSharedTreeView());
        
+       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);
+       }
+
         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));
+                       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()) {
@@ -100,22 +107,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()) {
                                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()))
-                                               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));
@@ -148,14 +152,6 @@ public class FolderContextMenu extends PopupPanel {
                        contextMenu.addItem(emptyTrash);
                }
         }
-
-//        MenuItem refresh = new MenuItem("<span id = 'folderContextMenu.refresh'>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
-//        contextMenu.addItem(refresh);
-
-//        MenuItem sharing = new MenuItem("<span id = 'folderContextMenu.sharing'>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + "&nbsp;Sharing</span>", true, new PropertiesCommand(this, newImages, 1));
-//        contextMenu.addItem(sharing);
-
-
                add(contextMenu);
        }
 }