2 * Copyright 2011 GRNET S.A. All rights reserved.
4 * Redistribution and use in source and binary forms, with or
5 * without modification, are permitted provided that the following
8 * 1. Redistributions of source code must retain the above
9 * copyright notice, this list of conditions and the following
12 * 2. Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following
14 * disclaimer in the documentation and/or other materials
15 * provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
30 * The views and conclusions contained in the software and
31 * documentation are those of the authors and should not be
32 * interpreted as representing official policies, either expressed
33 * or implied, of GRNET S.A.
35 package gr.grnet.pithos.web.client;
37 import gr.grnet.pithos.web.client.commands.CopyCommand;
38 import gr.grnet.pithos.web.client.commands.CutCommand;
39 import gr.grnet.pithos.web.client.commands.DeleteCommand;
40 import gr.grnet.pithos.web.client.commands.PasteCommand;
41 import gr.grnet.pithos.web.client.commands.PropertiesCommand;
42 import gr.grnet.pithos.web.client.commands.ToTrashCommand;
43 import gr.grnet.pithos.web.client.commands.UploadFileCommand;
44 import gr.grnet.pithos.web.client.foldertree.File;
45 import gr.grnet.pithos.web.client.foldertree.Folder;
47 import java.util.List;
49 import com.google.gwt.resources.client.ClientBundle;
50 import com.google.gwt.resources.client.ImageResource;
51 import com.google.gwt.user.client.Command;
52 import com.google.gwt.user.client.ui.AbstractImagePrototype;
53 import com.google.gwt.user.client.ui.MenuBar;
54 import com.google.gwt.user.client.ui.MenuItem;
55 import com.google.gwt.user.client.ui.PopupPanel;
58 * The 'File Context' menu implementation.
60 public class FileContextMenu extends PopupPanel {
63 * The widget's images.
65 private final Images images;
67 private MenuItem cutItem;
69 private MenuItem copyItem;
71 private MenuItem pasteItem;
73 private MenuItem updateItem;
75 private MenuItem sharingItem;
77 private MenuItem propItem;
79 private MenuItem trashItem;
81 private MenuItem deleteItem;
83 private MenuItem downloadItem;
85 private MenuItem saveAsItem;
88 * The image bundle for this widget's images that reuses images defined in
91 public interface Images extends ClientBundle,FileMenu.Images, EditMenu.Images {
93 @Source("gr/grnet/pithos/resources/mimetypes/document.png")
94 ImageResource fileContextMenu();
96 @Source("gr/grnet/pithos/resources/doc_versions.png")
97 ImageResource versions();
100 @Source("gr/grnet/pithos/resources/group.png")
101 ImageResource sharing();
104 @Source("gr/grnet/pithos/resources/border_remove.png")
105 ImageResource unselectAll();
107 @Source("gr/grnet/pithos/resources/demo.png")
108 ImageResource viewImage();
111 public static native String getDate()/*-{
112 return (new Date()).toUTCString();
116 * The widget's constructor.
118 * @param newImages the image bundle passed on by the parent object
120 public FileContextMenu(Images newImages, Folder selectedFolder, List<File> selectedFiles, boolean isTrash) {
121 // The popup's constructor's argument is a boolean specifying that it
122 // auto-close itself when the user clicks outside of it.
124 Pithos gss = Pithos.get();
125 setAnimationEnabled(true);
127 MenuBar contextMenu = new MenuBar(true);
129 if (Pithos.get().getClipboard().hasFiles()) {
130 pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.paste()).getHTML() + " Paste</span>", true, new PasteCommand(Pithos.get(), this, selectedFolder));
131 contextMenu.addItem(pasteItem);
134 MenuItem upload = new MenuItem("<span>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this, selectedFolder));
135 contextMenu.addItem(upload);
137 // MenuItem refresh = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images));
138 // contextMenu.addItem(refresh);
141 // MenuItem restore = new MenuItem("<span>" + AbstractImagePrototype.create(images.versions()).getHTML() + " Restore</span>", true, new RestoreTrashCommand(this));
142 // contextMenu.addItem(restore);
144 // MenuItem delete = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, null, images));
145 // contextMenu.addItem(delete);
147 cutItem = new MenuItem("<span id='fileContextMenu.cut'>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + " Cut</span>", true, new CutCommand(Pithos.get(), this, selectedFiles));
148 contextMenu.addItem(cutItem);
150 copyItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + " Copy</span>", true, new CopyCommand(Pithos.get(), this, selectedFiles));
151 contextMenu.addItem(copyItem);
153 trashItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + " Move to Trash</span>", true, new ToTrashCommand(Pithos.get(), this, selectedFiles));
154 contextMenu.addItem(trashItem);
156 deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, selectedFiles, images));
157 contextMenu.addItem(deleteItem);
159 // sharingItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + " Sharing</span>", true, new PropertiesCommand(this, images, 1));
160 // contextMenu.addItem(sharingItem);
162 contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Properties</span>", true, new PropertiesCommand(Pithos.get(), this, selectedFiles, images, 0)));
164 if (!selectedFiles.isEmpty())
165 contextMenu.addItem(new MenuItem("<span><a class='hidden-link' href='" + Pithos.get().getApiPath() + Pithos.get().getUsername() + selectedFiles.get(0).getUri() + "?X-Auth-Token=" + Pithos.get().getToken() + "' target='_blank'>" + AbstractImagePrototype.create(newImages.download()).getHTML() + " Download</a></span>", true, (Command) null));
167 MenuItem unSelect = new MenuItem("<span>" + AbstractImagePrototype.create(images.unselectAll()).getHTML() + " Unselect</span>", true, new Command() {
169 public void execute() {
171 Pithos.get().getFileList().clearSelectedRows();
174 contextMenu.addItem(unSelect);