/*
- * 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
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.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.foldertree.File;
import gr.grnet.pithos.web.client.foldertree.Folder;
-import gr.grnet.pithos.web.client.rest.resource.FileResource;
-import gr.grnet.pithos.web.client.rest.resource.FolderResource;
-import gr.grnet.pithos.web.client.rest.resource.RestResource;
-import gr.grnet.pithos.web.client.rest.resource.RestResourceWrapper;
-import gr.grnet.pithos.web.client.rest.resource.TrashFolderResource;
import java.util.List;
-import com.google.gwt.event.dom.client.ClickEvent;
-import com.google.gwt.event.dom.client.ClickHandler;
-import com.google.gwt.event.dom.client.ContextMenuEvent;
+import com.google.gwt.http.client.URL;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.user.client.Command;
-import com.google.gwt.user.client.Event;
+import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.AbstractImagePrototype;
import com.google.gwt.user.client.ui.MenuBar;
import com.google.gwt.user.client.ui.MenuItem;
* 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 ClientBundle {
@Source("gr/grnet/pithos/resources/mimetypes/document.png")
ImageResource fileContextMenu();
@Source("gr/grnet/pithos/resources/doc_versions.png")
ImageResource versions();
- @Override
- @Source("gr/grnet/pithos/resources/group.png")
+ @Source("gr/grnet/pithos/resources/groups22.png")
ImageResource sharing();
- @Override
@Source("gr/grnet/pithos/resources/border_remove.png")
ImageResource unselectAll();
@Source("gr/grnet/pithos/resources/demo.png")
ImageResource viewImage();
-}
+
+ @Source("gr/grnet/pithos/resources/folder_new.png")
+ ImageResource folderNew();
+
+ @Source("gr/grnet/pithos/resources/folder_outbox.png")
+ ImageResource fileUpdate();
+
+ @Source("gr/grnet/pithos/resources/view_text.png")
+ ImageResource viewText();
+
+ @Source("gr/grnet/pithos/resources/folder_inbox.png")
+ ImageResource download();
+
+ @Source("gr/grnet/pithos/resources/trash.png")
+ ImageResource emptyTrash();
+
+ @Source("gr/grnet/pithos/resources/refresh.png")
+ ImageResource refresh();
+
+ /**
+ * Will bundle the file 'editcut.png' residing in the package
+ * 'gr.grnet.pithos.web.resources'.
+ *
+ * @return the image prototype
+ */
+ @Source("gr/grnet/pithos/resources/editcut.png")
+ ImageResource cut();
+
+ /**
+ * Will bundle the file 'editcopy.png' residing in the package
+ * 'gr.grnet.pithos.web.resources'.
+ *
+ * @return the image prototype
+ */
+ @Source("gr/grnet/pithos/resources/editcopy.png")
+ ImageResource copy();
+
+ /**
+ * Will bundle the file 'editpaste.png' residing in the package
+ * 'gr.grnet.pithos.web.resources'.
+ *
+ * @return the image prototype
+ */
+ @Source("gr/grnet/pithos/resources/editpaste.png")
+ ImageResource paste();
+
+ /**
+ * Will bundle the file 'editdelete.png' residing in the package
+ * 'gr.grnet.pithos.web.resources'.
+ *
+ * @return the image prototype
+ */
+ @Source("gr/grnet/pithos/resources/editdelete.png")
+ ImageResource delete();
+
+ /**
+ * Will bundle the file 'translate.png' residing in the package
+ * 'gr.grnet.pithos.web.resources'.
+ *
+ * @return the image prototype
+ */
+ @Source("gr/grnet/pithos/resources/translate.png")
+ ImageResource selectAll();
+
+ @Source("gr/grnet/pithos/resources/internet.png")
+ ImageResource internet();
+ }
public static native String getDate()/*-{
return (new Date()).toUTCString();
*
* @param newImages the image bundle passed on by the parent object
*/
- public FileContextMenu(Images newImages, Folder selectedFolder, List<File> selectedFiles, boolean isTrash) {
+ public FileContextMenu(final Pithos app, Images newImages, TreeView selectedTree, Folder selectedFolder, final List<File> selectedFiles) {
// The popup's constructor's argument is a boolean specifying that it
// auto-close itself when the user clicks outside of it.
super(true);
- GSS gss = GSS.get();
setAnimationEnabled(true);
images = newImages;
MenuBar contextMenu = new MenuBar(true);
-
- pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.paste()).getHTML() + " Paste</span>", true, new PasteCommand(GSS.get(), this, selectedFolder));
- contextMenu.addItem(pasteItem);
-
- MenuItem upload = new MenuItem("<span>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this, selectedFolder));
- contextMenu.addItem(upload);
-
- MenuItem refresh = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images));
- contextMenu.addItem(refresh);
-
- if (isTrash) {
- MenuItem restore = new MenuItem("<span>" + AbstractImagePrototype.create(images.versions()).getHTML() + " Restore</span>", true, new RestoreTrashCommand(this));
- contextMenu.addItem(restore);
-
- MenuItem delete = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, null, images));
- contextMenu.addItem(delete);
- } else {
- cutItem = new MenuItem("<span id='fileContextMenu.cut'>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + " Cut</span>", true, new CutCommand(GSS.get(), this, selectedFiles));
- contextMenu.addItem(cutItem);
-
- copyItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + " Copy</span>", true, new CopyCommand(GSS.get(), this, selectedFiles));
- contextMenu.addItem(copyItem);
-
- trashItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + " Move to Trash</span>", true, new ToTrashCommand(GSS.get(), this, selectedFiles));
- contextMenu.addItem(trashItem);
-
- deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, selectedFiles, images));
- contextMenu.addItem(deleteItem);
-
- sharingItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + " Sharing</span>", true, new PropertiesCommand(this, images, 1));
- contextMenu.addItem(sharingItem);
-
- propItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Properties</span>", true, new PropertiesCommand(this, images, 0));
- contextMenu.addItem(propItem);
-
- downloadItem = new MenuItem("<span><a class='hidden-link' href='" + GSS.get().getApiPath() + GSS.get().getUsername() + selectedFiles.get(0).getUri() + "?X-Auth-Token=" + GSS.get().getToken() + "' target='_blank'>" + AbstractImagePrototype.create(newImages.download()).getHTML() + " Download</a></span>", true, new Command() {
- @Override
- public void execute() {
- }
- });
- contextMenu.addItem(downloadItem);
+ 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]);
+ }
+ else {
+ for (File f : selectedFiles) {
+ permissions = f.getPermissions().get(app.getUsername());
+ canWrite &= (f.getOwner().equals(app.getUsername()) || (permissions!= null && permissions[1] != null && permissions[1]));
+ }
+ }
+ boolean isFolderTreeSelected = selectedTree.equals(app.getFolderTreeView());
+ boolean isMysharedSelected = selectedTree.equals(app.getMySharedTreeView());
+ if (selectedFolder != null) {
+ if (!selectedFolder.isInTrash()) {
+ if (canWrite && app.getClipboard().hasFiles() && !isMysharedSelected) {
+ pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.paste()).getHTML() + " Paste</span>", true, new PasteCommand(app, this, selectedFolder));
+ contextMenu.addItem(pasteItem);
+ }
+
+ if (canWrite && !isMysharedSelected) {
+ MenuItem upload = new MenuItem("<span>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(app, this, selectedFolder));
+ contextMenu.addItem(upload);
+ }
+ if (isFolderTreeSelected || isMysharedSelected) {
+ cutItem = new MenuItem("<span id='fileContextMenu.cut'>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + " Cut</span>", true, new CutCommand(app, this, selectedFiles));
+ contextMenu.addItem(cutItem);
+ }
+
+ copyItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + " Copy</span>", true, new CopyCommand(app, this, selectedFiles));
+ contextMenu.addItem(copyItem);
+
+ if (isFolderTreeSelected || isMysharedSelected) {
+ trashItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + " Move to Trash</span>", true, new ToTrashCommand(app, this, selectedFiles));
+ contextMenu.addItem(trashItem);
+ }
+ }
+ else {
+ MenuItem restore = new MenuItem("<span>" + AbstractImagePrototype.create(images.versions()).getHTML() + " Restore</span>", true, new RestoreTrashCommand(app, this, selectedFiles));
+ contextMenu.addItem(restore);
+ }
+ }
+
+ if (isFolderTreeSelected || isMysharedSelected) {
+ deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(app, this, selectedFiles, MessagePanel.images));
+ contextMenu.addItem(deleteItem);
+ }
+
+ if (selectedFolder != null && !selectedFolder.isInTrash()) {
+ if ((isFolderTreeSelected || isMysharedSelected) && selectedFiles.size() == 1) {
+ contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Properties</span>", true, new PropertiesCommand(app, this, selectedFiles, PropertiesCommand.PROPERTIES)));
+ contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + " Sharing</span>", true, new PropertiesCommand(app, this, selectedFiles, PropertiesCommand.PERMISSIONS)));
+ contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.internet()).getHTML() + " Publish</span>", true, new PropertiesCommand(app, this, selectedFiles, PropertiesCommand.PUBLISH)));
+ contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.versions()).getHTML() + " Versions</span>", true, new PropertiesCommand(app, this, selectedFiles, PropertiesCommand.VERSIONS)));
+ }
+
+ }
+ contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.download()).getHTML() + " Download</span>", true, new Command() {
- final Command unselectAllCommand = new Command() {
-
- @Override
- public void execute() {
- hide();
- if(GSS.get().isFileListShowing())
- GSS.get().getFileList().clearSelectedRows();
- }
- };
- MenuItem unSelect = new MenuItem("<span>" + AbstractImagePrototype.create(images.unselectAll()).getHTML() + " Unselect</span>", true, unselectAllCommand);
- contextMenu.addItem(unSelect);
+ @Override
+ public void execute() {
+ for (File f : selectedFiles)
+ Window.open(app.getApiPath() + f.getOwner() + f.getUri(), "_blank", "");
+ }
+ }));
- }
add(contextMenu);
-
-// if (gss.getClipboard().hasFileItem())
-// pasteItem.setVisible(true);
-// else
-// pasteItem.setVisible(false);
}
}