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(final Pithos app, 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 setAnimationEnabled(true);
126 MenuBar contextMenu = new MenuBar(true);
128 if (app.getClipboard().hasFiles()) {
129 pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.paste()).getHTML() + " Paste</span>", true, new PasteCommand(app, this, selectedFolder));
130 contextMenu.addItem(pasteItem);
133 MenuItem upload = new MenuItem("<span>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(app, this, selectedFolder));
134 contextMenu.addItem(upload);
136 // MenuItem refresh = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images));
137 // contextMenu.addItem(refresh);
140 // MenuItem restore = new MenuItem("<span>" + AbstractImagePrototype.create(images.versions()).getHTML() + " Restore</span>", true, new RestoreTrashCommand(this));
141 // contextMenu.addItem(restore);
143 // MenuItem delete = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, null, images));
144 // contextMenu.addItem(delete);
146 cutItem = new MenuItem("<span id='fileContextMenu.cut'>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + " Cut</span>", true, new CutCommand(app, this, selectedFiles));
147 contextMenu.addItem(cutItem);
149 copyItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + " Copy</span>", true, new CopyCommand(app, this, selectedFiles));
150 contextMenu.addItem(copyItem);
152 trashItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + " Move to Trash</span>", true, new ToTrashCommand(app, this, selectedFiles));
153 contextMenu.addItem(trashItem);
155 deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(app, this, selectedFiles, images));
156 contextMenu.addItem(deleteItem);
158 // sharingItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + " Sharing</span>", true, new PropertiesCommand(this, images, 1));
159 // contextMenu.addItem(sharingItem);
161 contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Properties</span>", true, new PropertiesCommand(app, this, selectedFiles, images, 0)));
163 if (!selectedFiles.isEmpty())
164 contextMenu.addItem(new MenuItem("<span><a class='hidden-link' href='" + app.getApiPath() + app.getUsername() + selectedFiles.get(0).getUri() + "?X-Auth-Token=" + app.getToken() + "' target='_blank'>" + AbstractImagePrototype.create(newImages.download()).getHTML() + " Download</a></span>", true, (Command) null));
166 MenuItem unSelect = new MenuItem("<span>" + AbstractImagePrototype.create(images.unselectAll()).getHTML() + " Unselect</span>", true, new Command() {
168 public void execute() {
170 app.getFileList().clearSelectedRows();
173 contextMenu.addItem(unSelect);