2 * Copyright (c) 2011 Greek Research and Technology Network
4 package gr.grnet.pithos.web.client;
6 import gr.grnet.pithos.web.client.commands.CopyCommand;
7 import gr.grnet.pithos.web.client.commands.CutCommand;
8 import gr.grnet.pithos.web.client.commands.DeleteCommand;
9 import gr.grnet.pithos.web.client.commands.PasteCommand;
10 import gr.grnet.pithos.web.client.commands.ToTrashCommand;
11 import gr.grnet.pithos.web.client.rest.resource.FileResource;
13 import gr.grnet.pithos.web.client.rest.resource.GroupUserResource;
14 import gr.grnet.pithos.web.client.rest.resource.RestResourceWrapper;
16 import java.util.List;
18 import com.google.gwt.event.dom.client.ClickEvent;
19 import com.google.gwt.event.dom.client.ClickHandler;
20 import com.google.gwt.resources.client.ClientBundle;
21 import com.google.gwt.resources.client.ImageResource;
22 import com.google.gwt.user.client.Command;
23 import com.google.gwt.user.client.ui.AbstractImagePrototype;
24 import com.google.gwt.user.client.ui.MenuBar;
25 import com.google.gwt.user.client.ui.MenuItem;
26 import com.google.gwt.user.client.ui.PopupPanel;
29 * The 'Edit' menu implementation.
31 public class EditMenu extends PopupPanel implements ClickHandler {
34 * The widget's images.
36 private final Images images;
38 private final MenuBar contextMenu = new MenuBar(true);
41 * An image bundle for this widget's images.
43 public interface Images extends ClientBundle, FileMenu.Images, MessagePanel.Images {
46 * Will bundle the file 'editcut.png' residing in the package
47 * 'gr.grnet.pithos.web.resources'.
49 * @return the image prototype
51 @Source("gr/grnet/pithos/resources/editcut.png")
55 * Will bundle the file 'editcopy.png' residing in the package
56 * 'gr.grnet.pithos.web.resources'.
58 * @return the image prototype
60 @Source("gr/grnet/pithos/resources/editcopy.png")
64 * Will bundle the file 'editpaste.png' residing in the package
65 * 'gr.grnet.pithos.web.resources'.
67 * @return the image prototype
69 @Source("gr/grnet/pithos/resources/editpaste.png")
70 ImageResource paste();
73 * Will bundle the file 'editdelete.png' residing in the package
74 * 'gr.grnet.pithos.web.resources'.
76 * @return the image prototype
79 @Source("gr/grnet/pithos/resources/editdelete.png")
80 ImageResource delete();
83 * Will bundle the file 'translate.png' residing in the package
84 * 'gr.grnet.pithos.web.resources'.
86 * @return the image prototype
88 @Source("gr/grnet/pithos/resources/translate.png")
89 ImageResource selectAll();
92 * Will bundle the file 'border_remove.png' residing in the package
93 * 'gr.grnet.pithos.web.resources'.
95 * @return the image prototype
97 @Source("gr/grnet/pithos/resources/border_remove.png")
98 ImageResource unselectAll();
102 * The widget's constructor.
104 * @param newImages the image bundle passed on by the parent object
106 public EditMenu(final Images newImages) {
107 // The popup's constructor's argument is a boolean specifying that it
108 // auto-close itself when the user clicks outside of it.
110 setAnimationEnabled(true);
117 public void onClick(ClickEvent event) {
118 final EditMenu menu = new EditMenu(images);
119 final int left = event.getRelativeElement().getAbsoluteLeft();
120 final int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight();
121 menu.setPopupPosition(left, top);
125 public MenuBar createMenu() {
126 contextMenu.clearItems();
127 contextMenu.setAutoOpen(false);
129 final Command selectAllCommand = new Command() {
132 public void execute() {
134 if(GSS.get().isFileListShowing())
135 GSS.get().getFileList().selectAllRows();
138 final Command unselectAllCommand = new Command() {
141 public void execute() {
143 if(GSS.get().isFileListShowing())
144 GSS.get().getFileList().clearSelectedRows();
148 boolean cutcopyVisible = GSS.get().getCurrentSelection() != null && (GSS.get().getCurrentSelection() instanceof RestResourceWrapper
149 || GSS.get().getCurrentSelection() instanceof FileResource || GSS .get().getCurrentSelection() instanceof GroupUserResource || GSS .get().getCurrentSelection() instanceof List);
150 String cutLabel = "Cut";
151 String copyLabel ="Copy";
152 String pasteLabel = "Paste";
153 if(GSS.get().getCurrentSelection() != null)
154 if(GSS.get().getCurrentSelection() instanceof RestResourceWrapper){
155 cutLabel = "Cut Folder";
156 copyLabel = "Copy Folder";
158 else if(GSS.get().getCurrentSelection() instanceof FileResource){
159 cutLabel = "Cut File";
160 copyLabel = "Copy File";
162 else if(GSS.get().getCurrentSelection() instanceof List){
163 cutLabel = "Cut Files";
164 copyLabel = "Copy Files";
166 if(GSS.get().getClipboard().getItem() != null)
167 if(GSS.get().getClipboard().getItem().getFile() != null)
168 pasteLabel = "Paste File";
169 else if(GSS.get().getClipboard().getItem().getFiles() != null)
170 pasteLabel = "Paste Files";
171 else if(GSS.get().getClipboard().getItem().getRestResourceWrapper() != null)
172 pasteLabel = "Paste Folder";
173 MenuItem cutItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.cut()).getHTML() + " "+cutLabel+"</span>", true, new CutCommand(this));
174 cutItem.getElement().setId("topMenu.edit.cut");
175 contextMenu.addItem(cutItem).setVisible(cutcopyVisible);
177 MenuItem copyItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.copy()).getHTML() + " "+copyLabel+"</span>", true, new CopyCommand(this));
178 copyItem.getElement().setId("topMenu.edit.copy");
179 contextMenu.addItem(copyItem).setVisible(cutcopyVisible);
181 MenuItem pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.paste()).getHTML() + " "+pasteLabel+"</span>", true, new PasteCommand(this));
182 pasteItem.getElement().setId("topMenu.edit.paste");
183 if (GSS.get().getClipboard().getItem() != null)
184 if(GSS.get().isUserListVisible() && GSS.get().getClipboard().getItem().getUser() == null){
185 contextMenu.addItem(pasteItem);
187 else if(!GSS.get().isUserListVisible() && GSS.get().getClipboard().getItem().getUser() != null){
190 else if (GSS.get().getTreeView().getSelection() instanceof RestResourceWrapper){
191 contextMenu.addItem(pasteItem);
193 MenuItem moveToTrashItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.emptyTrash()).getHTML() + " Move to Trash</span>", true, new ToTrashCommand(this));
194 moveToTrashItem.getElement().setId("topMenu.edit.moveToTrash");
195 contextMenu .addItem(moveToTrashItem)
196 .setVisible(cutcopyVisible);
198 MenuItem deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, images));
199 deleteItem.getElement().setId("topMenu.edit.delete");
200 contextMenu .addItem(deleteItem)
201 .setVisible(cutcopyVisible);
203 MenuItem selectAllItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.selectAll()).getHTML() + " Select All</span>", true, selectAllCommand);
204 selectAllItem.getElement().setId("topMenu.edit.selectAll");
205 contextMenu.addItem(selectAllItem);
207 MenuItem unSelectAllItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.unselectAll()).getHTML() + " Unselect All</span>", true, unselectAllCommand);
208 unSelectAllItem.getElement().setId("topMenu.edit.unSelectAll");
209 contextMenu.addItem(unSelectAllItem);