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.Folder;
43 import gr.grnet.pithos.web.client.rest.resource.FileResource;
45 import gr.grnet.pithos.web.client.rest.resource.GroupUserResource;
46 import gr.grnet.pithos.web.client.rest.resource.RestResourceWrapper;
48 import java.util.List;
50 import com.google.gwt.event.dom.client.ClickEvent;
51 import com.google.gwt.event.dom.client.ClickHandler;
52 import com.google.gwt.resources.client.ClientBundle;
53 import com.google.gwt.resources.client.ImageResource;
54 import com.google.gwt.user.client.Command;
55 import com.google.gwt.user.client.ui.AbstractImagePrototype;
56 import com.google.gwt.user.client.ui.MenuBar;
57 import com.google.gwt.user.client.ui.MenuItem;
58 import com.google.gwt.user.client.ui.PopupPanel;
61 * The 'Edit' menu implementation.
63 public class EditMenu extends PopupPanel implements ClickHandler {
66 * The widget's images.
68 private final Images images;
70 private final MenuBar contextMenu = new MenuBar(true);
73 * An image bundle for this widget's images.
75 public interface Images extends ClientBundle, FileMenu.Images, MessagePanel.Images {
78 * Will bundle the file 'editcut.png' residing in the package
79 * 'gr.grnet.pithos.web.resources'.
81 * @return the image prototype
83 @Source("gr/grnet/pithos/resources/editcut.png")
87 * Will bundle the file 'editcopy.png' residing in the package
88 * 'gr.grnet.pithos.web.resources'.
90 * @return the image prototype
92 @Source("gr/grnet/pithos/resources/editcopy.png")
96 * Will bundle the file 'editpaste.png' residing in the package
97 * 'gr.grnet.pithos.web.resources'.
99 * @return the image prototype
101 @Source("gr/grnet/pithos/resources/editpaste.png")
102 ImageResource paste();
105 * Will bundle the file 'editdelete.png' residing in the package
106 * 'gr.grnet.pithos.web.resources'.
108 * @return the image prototype
111 @Source("gr/grnet/pithos/resources/editdelete.png")
112 ImageResource delete();
115 * Will bundle the file 'translate.png' residing in the package
116 * 'gr.grnet.pithos.web.resources'.
118 * @return the image prototype
120 @Source("gr/grnet/pithos/resources/translate.png")
121 ImageResource selectAll();
124 * Will bundle the file 'border_remove.png' residing in the package
125 * 'gr.grnet.pithos.web.resources'.
127 * @return the image prototype
129 @Source("gr/grnet/pithos/resources/border_remove.png")
130 ImageResource unselectAll();
134 * The widget's constructor.
136 * @param newImages the image bundle passed on by the parent object
138 public EditMenu(final Images newImages) {
139 // The popup's constructor's argument is a boolean specifying that it
140 // auto-close itself when the user clicks outside of it.
142 setAnimationEnabled(true);
149 public void onClick(ClickEvent event) {
150 final EditMenu menu = new EditMenu(images);
151 final int left = event.getRelativeElement().getAbsoluteLeft();
152 final int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight();
153 menu.setPopupPosition(left, top);
157 public MenuBar createMenu() {
158 contextMenu.clearItems();
159 contextMenu.setAutoOpen(false);
161 final Command selectAllCommand = new Command() {
164 public void execute() {
166 if(GSS.get().isFileListShowing())
167 GSS.get().getFileList().selectAllRows();
170 final Command unselectAllCommand = new Command() {
173 public void execute() {
175 if(GSS.get().isFileListShowing())
176 GSS.get().getFileList().clearSelectedRows();
180 boolean cutcopyVisible = GSS.get().getCurrentSelection() != null && (GSS.get().getCurrentSelection() instanceof RestResourceWrapper
181 || GSS.get().getCurrentSelection() instanceof FileResource || GSS .get().getCurrentSelection() instanceof GroupUserResource || GSS .get().getCurrentSelection() instanceof List);
182 String cutLabel = "Cut";
183 String copyLabel ="Copy";
184 String pasteLabel = "Paste";
185 if(GSS.get().getCurrentSelection() != null)
186 if(GSS.get().getCurrentSelection() instanceof RestResourceWrapper){
187 cutLabel = "Cut Folder";
188 copyLabel = "Copy Folder";
190 else if(GSS.get().getCurrentSelection() instanceof FileResource){
191 cutLabel = "Cut File";
192 copyLabel = "Copy File";
194 else if(GSS.get().getCurrentSelection() instanceof List){
195 cutLabel = "Cut Files";
196 copyLabel = "Copy Files";
198 if(GSS.get().getClipboard().getItem() != null)
199 if(GSS.get().getClipboard().getItem() instanceof List) {
200 if (((List) GSS.get().getClipboard().getItem()).size() > 1)
201 pasteLabel = "Paste Files";
203 pasteLabel = "Paste File";
205 else if(GSS.get().getClipboard().getItem() instanceof Folder)
206 pasteLabel = "Paste Folder";
207 MenuItem cutItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.cut()).getHTML() + " "+cutLabel+"</span>", true, new CutCommand(GSS.get(), this, null));
208 cutItem.getElement().setId("topMenu.edit.cut");
209 contextMenu.addItem(cutItem).setVisible(cutcopyVisible);
211 MenuItem copyItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.copy()).getHTML() + " "+copyLabel+"</span>", true, new CopyCommand(GSS.get(), this, null));
212 copyItem.getElement().setId("topMenu.edit.copy");
213 contextMenu.addItem(copyItem).setVisible(cutcopyVisible);
215 MenuItem pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.paste()).getHTML() + " "+pasteLabel+"</span>", true, new PasteCommand(GSS.get(), this, null));
216 pasteItem.getElement().setId("topMenu.edit.paste");
217 if (GSS.get().getClipboard().getItem() != null)
218 contextMenu.addItem(pasteItem);
219 MenuItem moveToTrashItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.emptyTrash()).getHTML() + " Move to Trash</span>", true, new ToTrashCommand(this));
220 moveToTrashItem.getElement().setId("topMenu.edit.moveToTrash");
221 contextMenu .addItem(moveToTrashItem)
222 .setVisible(cutcopyVisible);
224 MenuItem deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, null, images));
225 deleteItem.getElement().setId("topMenu.edit.delete");
226 contextMenu .addItem(deleteItem)
227 .setVisible(cutcopyVisible);
229 MenuItem selectAllItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.selectAll()).getHTML() + " Select All</span>", true, selectAllCommand);
230 selectAllItem.getElement().setId("topMenu.edit.selectAll");
231 contextMenu.addItem(selectAllItem);
233 MenuItem unSelectAllItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.unselectAll()).getHTML() + " Unselect All</span>", true, unselectAllCommand);
234 unSelectAllItem.getElement().setId("topMenu.edit.unSelectAll");
235 contextMenu.addItem(unSelectAllItem);