X-Git-Url: https://code.grnet.gr/git/pithos-web-client/blobdiff_plain/390f5c04552c4a83b0f24d219e413bf1109504d8..HEAD:/src/gr/grnet/pithos/web/client/FolderContextMenu.java
diff --git a/src/gr/grnet/pithos/web/client/FolderContextMenu.java b/src/gr/grnet/pithos/web/client/FolderContextMenu.java
index 4d39001..e846655 100644
--- a/src/gr/grnet/pithos/web/client/FolderContextMenu.java
+++ b/src/gr/grnet/pithos/web/client/FolderContextMenu.java
@@ -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
@@ -34,30 +34,10 @@
*/
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.commands.UploadFileCommand;
+import gr.grnet.pithos.web.client.commands.*;
+import gr.grnet.pithos.web.client.commands.PurgeContainerCommand;
import gr.grnet.pithos.web.client.foldertree.Folder;
-import gr.grnet.pithos.web.client.foldertree.FolderTreeView;
-import gr.grnet.pithos.web.client.rest.resource.MyFolderResource;
-import gr.grnet.pithos.web.client.rest.resource.OtherUserResource;
-import gr.grnet.pithos.web.client.rest.resource.OthersFolderResource;
-import gr.grnet.pithos.web.client.rest.resource.OthersResource;
-import gr.grnet.pithos.web.client.rest.resource.RestResource;
-import gr.grnet.pithos.web.client.rest.resource.SharedFolderResource;
-import gr.grnet.pithos.web.client.rest.resource.SharedResource;
-import gr.grnet.pithos.web.client.rest.resource.TrashFolderResource;
-import gr.grnet.pithos.web.client.rest.resource.TrashResource;
-import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.user.client.ui.AbstractImagePrototype;
import com.google.gwt.user.client.ui.MenuBar;
import com.google.gwt.user.client.ui.MenuItem;
@@ -77,7 +57,7 @@ public class FolderContextMenu extends PopupPanel {
* The image bundle for this widget's images that reuses images defined in
* other menus.
*/
- public interface Images extends ClientBundle,FileMenu.Images, EditMenu.Images {
+ public interface Images extends FileContextMenu.Images {
}
private MenuItem pasteItem;
@@ -87,47 +67,84 @@ public class FolderContextMenu extends PopupPanel {
*
* @param newImages the image bundle passed on by the parent object
*/
- public FolderContextMenu(final Images newImages, Folder folder) {
+ public FolderContextMenu(Pithos app, final Images newImages, TreeView selectedTree, Folder folder) {
// 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);
- MenuItem newFolder = new MenuItem("", true, new NewFolderCommand(this, folder, images));
- contextMenu.addItem(newFolder);
-
- if (!folder.isContainer()) {
- MenuItem cut = new MenuItem("", true, new CutCommand(GSS.get(), this, folder));
- contextMenu.addItem(cut);
+ 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());
+
+ MenuItem refresh = new MenuItem("", true, new RefreshCommand(app, this, folder));
+ contextMenu.addItem(refresh);
+
+ if (!folder.isInTrash()) {
+ if (canWrite) {
+ if (!mysharedTreeSelected) {
+ MenuItem newFolder = new MenuItem("", true, new NewFolderCommand(app, this, folder));
+ contextMenu.addItem(newFolder);
+ }
+
+ if (isFolderTreeSelected && !folder.isContainer()) {
+ MenuItem cut = new MenuItem("", true, new CutCommand(app, this, folder));
+ contextMenu.addItem(cut);
+ }
+ }
+
+ if (!folder.isContainer()) {
+ MenuItem copy = new MenuItem("", true, new CopyCommand(app, this, folder));
+ contextMenu.addItem(copy);
+ }
+
+ if (canWrite) {
+ if (!app.getClipboard().isEmpty() && !mysharedTreeSelected) {
+ Object item = app.getClipboard().getItem();
+ boolean showPaste = true;
+ if (item instanceof Folder) {
+ Folder f = (Folder) item;
+ if (f.contains(folder))
+ showPaste = false;
+ }
+ if (showPaste) {
+ pasteItem = new MenuItem("", true, new PasteCommand(app, this, folder));
+ contextMenu.addItem(pasteItem);
+ }
+ }
+
+ if (isFolderTreeSelected && !folder.isContainer()) {
+ MenuItem moveToTrash = new MenuItem("", true, new ToTrashCommand(app, this, folder));
+ contextMenu.addItem(moveToTrash);
+
+ contextMenu.addItem(new MenuItem("" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Properties", true, new PropertiesCommand(app, this, folder, PropertiesCommand.PROPERTIES)));
+ contextMenu.addItem(new MenuItem("" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + " Share", true, new PropertiesCommand(app, this, folder, PropertiesCommand.PERMISSIONS)));
+ }
+
+ if (folder.isContainer()) {
+ MenuItem purgeContainer = new MenuItem(
+ "" + Const.PurgeContainer(folder.getName()) + "",
+ true,
+ new PurgeContainerCommand(app, this, folder)
+ );
+ contextMenu.addItem(purgeContainer);
+ }
+ }
}
+ else if(!folder.isTrash()) {
+ MenuItem restore = new MenuItem("" + AbstractImagePrototype.create(images.versions()).getHTML() + " Restore", true, new RestoreTrashCommand(app, this, folder));
+ contextMenu.addItem(restore);
- MenuItem copy = new MenuItem("", true, new CopyCommand(GSS.get(), this, folder));
- contextMenu.addItem(copy);
-
- if (!GSS.get().getClipboard().isEmpty()) {
- pasteItem = new MenuItem("", true, new PasteCommand(GSS.get(), this, folder));
- contextMenu.addItem(pasteItem);
- }
-
- if (!folder.isContainer()) {
- MenuItem moveToTrash = new MenuItem("", true, new ToTrashCommand(GSS.get(), this, folder));
- contextMenu.addItem(moveToTrash);
-
- MenuItem delete = new MenuItem("", true, new DeleteCommand(this, folder, newImages));
+ MenuItem delete = new MenuItem("", true, new DeleteCommand(app, this, folder, MessagePanel.images));
contextMenu.addItem(delete);
}
-
-// MenuItem refresh = new MenuItem("", true, new RefreshCommand(this, images));
-// contextMenu.addItem(refresh);
-
-// MenuItem sharing = new MenuItem("", true, new PropertiesCommand(this, newImages, 1));
-// contextMenu.addItem(sharing);
-
-// MenuItem properties = new MenuItem("", true, new PropertiesCommand(this, newImages, 0));
-// contextMenu.addItem(properties);
-
+ else {
+ MenuItem emptyTrash = new MenuItem("" + AbstractImagePrototype.create(images.emptyTrash()).getHTML() + " Empty Trash", true, new PurgeContainerCommand(app, this, folder));
+ contextMenu.addItem(emptyTrash);
+ }
add(contextMenu);
}
}