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.ToTrashCommand;
42 import gr.grnet.pithos.web.client.foldertree.File;
43 import gr.grnet.pithos.web.client.foldertree.Folder;
44 import gr.grnet.pithos.web.client.rest.resource.FileResource;
46 import gr.grnet.pithos.web.client.rest.resource.GroupUserResource;
47 import gr.grnet.pithos.web.client.rest.resource.RestResourceWrapper;
49 import java.util.List;
51 import com.google.gwt.event.dom.client.ClickEvent;
52 import com.google.gwt.event.dom.client.ClickHandler;
53 import com.google.gwt.resources.client.ClientBundle;
54 import com.google.gwt.resources.client.ImageResource;
55 import com.google.gwt.user.client.Command;
56 import com.google.gwt.user.client.ui.AbstractImagePrototype;
57 import com.google.gwt.user.client.ui.MenuBar;
58 import com.google.gwt.user.client.ui.MenuItem;
59 import com.google.gwt.user.client.ui.PopupPanel;
62 * The 'Edit' menu implementation.
64 public class EditMenu extends MenuBar {
67 * The widget's images.
69 private final Images images;
72 * An image bundle for this widget's images.
74 public interface Images extends ClientBundle, FileMenu.Images, MessagePanel.Images {
77 * Will bundle the file 'editcut.png' residing in the package
78 * 'gr.grnet.pithos.web.resources'.
80 * @return the image prototype
82 @Source("gr/grnet/pithos/resources/editcut.png")
86 * Will bundle the file 'editcopy.png' residing in the package
87 * 'gr.grnet.pithos.web.resources'.
89 * @return the image prototype
91 @Source("gr/grnet/pithos/resources/editcopy.png")
95 * Will bundle the file 'editpaste.png' residing in the package
96 * 'gr.grnet.pithos.web.resources'.
98 * @return the image prototype
100 @Source("gr/grnet/pithos/resources/editpaste.png")
101 ImageResource paste();
104 * Will bundle the file 'editdelete.png' residing in the package
105 * 'gr.grnet.pithos.web.resources'.
107 * @return the image prototype
110 @Source("gr/grnet/pithos/resources/editdelete.png")
111 ImageResource delete();
114 * Will bundle the file 'translate.png' residing in the package
115 * 'gr.grnet.pithos.web.resources'.
117 * @return the image prototype
119 @Source("gr/grnet/pithos/resources/translate.png")
120 ImageResource selectAll();
123 * Will bundle the file 'border_remove.png' residing in the package
124 * 'gr.grnet.pithos.web.resources'.
126 * @return the image prototype
128 @Source("gr/grnet/pithos/resources/border_remove.png")
129 ImageResource unselectAll();
133 * The widget's constructor.
135 * @param newImages the image bundle passed on by the parent object
137 public EditMenu(final GSS _app, final Images newImages) {
139 setAnimationEnabled(true);
142 Folder selectedFolder = _app.getFolderTreeView().getSelection();
143 List<File> selectedFiles = _app.getFileList().getSelectedFiles();
145 String cutLabel = "Cut";
146 String copyLabel ="Copy";
147 String pasteLabel = "Paste";
148 if(selectedFiles.size() == 1) {
149 cutLabel = "Cut File";
150 copyLabel = "Copy File";
152 else if (selectedFiles.size() > 1) {
153 cutLabel = "Cut Files";
154 copyLabel = "Copy Files";
156 else if (selectedFolder != null) {
157 cutLabel = "Cut Folder";
158 copyLabel = "Copy Folder";
161 if (_app.getClipboard().hasFiles()) {
162 if (((List<File>) _app.getClipboard().getItem()).size() > 1)
163 pasteLabel = "Paste Files";
165 pasteLabel = "Paste File";
168 pasteLabel = "Paste Folder";
170 if (selectedFiles.size() > 0 || selectedFolder != null) {
171 Object cutObject = null;
172 if (selectedFiles.size() > 0)
173 cutObject = selectedFiles;
174 else if (selectedFolder != null)
175 cutObject = selectedFolder;
177 MenuItem cutItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.cut()).getHTML() + " " + cutLabel + "</span>", true, new CutCommand(_app, null, cutObject));
180 MenuItem copyItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.copy()).getHTML() + " "+copyLabel+"</span>", true, new CopyCommand(_app, null, cutObject));
183 MenuItem moveToTrashItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.emptyTrash()).getHTML() + " Move to Trash</span>", true, new ToTrashCommand(_app, null, cutObject));
184 addItem(moveToTrashItem);
186 MenuItem deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(null, cutObject, images));
190 if (selectedFolder != null && !_app.getClipboard().isEmpty()) {
191 MenuItem pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.paste()).getHTML() + " " + pasteLabel + "</span>", true, new PasteCommand(_app, null, selectedFolder));
196 MenuItem selectAllItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.selectAll()).getHTML() + " Select All</span>", true, new Command() {
199 public void execute() {
200 _app.getFileList().selectAllRows();
203 addItem(selectAllItem);
205 MenuItem unSelectAllItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.unselectAll()).getHTML() + " Unselect All</span>", true, new Command() {
208 public void execute() {
209 _app.getFileList().clearSelectedRows();
212 addItem(unSelectAllItem);