2 * Copyright 2007, 2008, 2009 Electronic Business Systems Ltd.
4 * This file is part of GSS.
6 * GSS is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GSS is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GSS. If not, see <http://www.gnu.org/licenses/>.
19 package gr.ebs.gss.client;
21 import gr.ebs.gss.client.commands.CopyCommand;
22 import gr.ebs.gss.client.commands.CutCommand;
23 import gr.ebs.gss.client.commands.DeleteCommand;
24 import gr.ebs.gss.client.commands.PasteCommand;
25 import gr.ebs.gss.client.commands.ToTrashCommand;
26 import gr.ebs.gss.client.rest.resource.FileResource;
27 import gr.ebs.gss.client.rest.resource.FolderResource;
28 import gr.ebs.gss.client.rest.resource.GroupUserResource;
30 import java.util.List;
32 import com.google.gwt.event.dom.client.ClickEvent;
33 import com.google.gwt.event.dom.client.ClickHandler;
34 import com.google.gwt.resources.client.ClientBundle;
35 import com.google.gwt.resources.client.ImageResource;
36 import com.google.gwt.user.client.Command;
37 import com.google.gwt.user.client.ui.AbstractImagePrototype;
38 import com.google.gwt.user.client.ui.MenuBar;
39 import com.google.gwt.user.client.ui.MenuItem;
40 import com.google.gwt.user.client.ui.PopupPanel;
43 * The 'Edit' menu implementation.
45 public class EditMenu extends PopupPanel implements ClickHandler {
48 * The widget's images.
50 private final Images images;
52 private final MenuBar contextMenu = new MenuBar(true);
55 * An image bundle for this widget's images.
57 public interface Images extends ClientBundle, FileMenu.Images, MessagePanel.Images {
60 * Will bundle the file 'editcut.png' residing in the package
61 * 'gr.ebs.gss.resources'.
63 * @return the image prototype
65 @Source("gr/ebs/gss/resources/editcut.png")
69 * Will bundle the file 'editcopy.png' residing in the package
70 * 'gr.ebs.gss.resources'.
72 * @return the image prototype
74 @Source("gr/ebs/gss/resources/editcopy.png")
78 * Will bundle the file 'editpaste.png' residing in the package
79 * 'gr.ebs.gss.resources'.
81 * @return the image prototype
83 @Source("gr/ebs/gss/resources/editpaste.png")
84 ImageResource paste();
87 * Will bundle the file 'editdelete.png' residing in the package
88 * 'gr.ebs.gss.resources'.
90 * @return the image prototype
93 @Source("gr/ebs/gss/resources/editdelete.png")
94 ImageResource delete();
97 * Will bundle the file 'translate.png' residing in the package
98 * 'gr.ebs.gss.resources'.
100 * @return the image prototype
102 @Source("gr/ebs/gss/resources/translate.png")
103 ImageResource selectAll();
106 * Will bundle the file 'border_remove.png' residing in the package
107 * 'gr.ebs.gss.resources'.
109 * @return the image prototype
111 @Source("gr/ebs/gss/resources/border_remove.png")
112 ImageResource unselectAll();
116 * The widget's constructor.
118 * @param newImages the image bundle passed on by the parent object
120 public EditMenu(final Images newImages) {
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);
131 public void onClick(ClickEvent event) {
132 final EditMenu menu = new EditMenu(images);
133 final int left = event.getRelativeElement().getAbsoluteLeft();
134 final int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight();
135 menu.setPopupPosition(left, top);
139 public MenuBar createMenu() {
140 contextMenu.clearItems();
141 contextMenu.setAutoOpen(false);
143 final Command selectAllCommand = new Command() {
146 public void execute() {
148 if(GSS.get().isFileListShowing())
149 GSS.get().getFileList().selectAllRows();
150 else if(GSS.get().isSearchResultsShowing())
151 GSS.get().getSearchResults().selectAllRows();
154 final Command unselectAllCommand = new Command() {
157 public void execute() {
159 if(GSS.get().isFileListShowing())
160 GSS.get().getFileList().clearSelectedRows();
161 else if(GSS.get().isSearchResultsShowing())
162 GSS.get().getSearchResults().clearSelectedRows();
166 boolean cutcopyVisible = GSS.get().getCurrentSelection() != null && (GSS.get().getCurrentSelection() instanceof FolderResource
167 || GSS.get().getCurrentSelection() instanceof FileResource || GSS .get().getCurrentSelection() instanceof GroupUserResource || GSS .get().getCurrentSelection() instanceof List);
168 String cutLabel = "Cut";
169 String copyLabel ="Copy";
170 String pasteLabel = "Paste";
171 if(GSS.get().getCurrentSelection() != null)
172 if(GSS.get().getCurrentSelection() instanceof FolderResource){
173 cutLabel = "Cut Folder";
174 copyLabel = "Copy Folder";
176 else if(GSS.get().getCurrentSelection() instanceof FileResource){
177 cutLabel = "Cut File";
178 copyLabel = "Copy File";
180 else if(GSS.get().getCurrentSelection() instanceof List){
181 cutLabel = "Cut Files";
182 copyLabel = "Copy Files";
184 if(GSS.get().getClipboard().getItem() != null)
185 if(GSS.get().getClipboard().getItem().getFile() != null)
186 pasteLabel = "Paste File";
187 else if(GSS.get().getClipboard().getItem().getFiles() != null)
188 pasteLabel = "Paste Files";
189 else if(GSS.get().getClipboard().getItem().getRestResourceWrapper() != null)
190 pasteLabel = "Paste Folder";
191 MenuItem cutItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.cut()).getHTML() + " "+cutLabel+"</span>", true, new CutCommand(this));
192 cutItem.getElement().setId("topMenu.edit.cut");
193 contextMenu.addItem(cutItem).setVisible(cutcopyVisible);
195 MenuItem copyItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.copy()).getHTML() + " "+copyLabel+"</span>", true, new CopyCommand(this));
196 copyItem.getElement().setId("topMenu.edit.copy");
197 contextMenu.addItem(copyItem).setVisible(cutcopyVisible);
199 MenuItem pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.paste()).getHTML() + " "+pasteLabel+"</span>", true, new PasteCommand(this));
200 pasteItem.getElement().setId("topMenu.edit.paste");
201 if (GSS.get().getClipboard().getItem() != null)
202 if(GSS.get().isUserListVisible() && GSS.get().getClipboard().getItem().getUser() == null){
203 contextMenu.addItem(pasteItem);
205 else if(!GSS.get().isUserListVisible() && GSS.get().getClipboard().getItem().getUser() != null){
208 else if (GSS.get().getTreeView().getSelection() instanceof FolderResource){
209 contextMenu.addItem(pasteItem);
211 MenuItem moveToTrashItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.emptyTrash()).getHTML() + " Move to Trash</span>", true, new ToTrashCommand(this));
212 moveToTrashItem.getElement().setId("topMenu.edit.moveToTrash");
213 contextMenu .addItem(moveToTrashItem)
214 .setVisible(cutcopyVisible);
216 MenuItem deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, images));
217 deleteItem.getElement().setId("topMenu.edit.delete");
218 contextMenu .addItem(deleteItem)
219 .setVisible(cutcopyVisible);
221 MenuItem selectAllItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.selectAll()).getHTML() + " Select All</span>", true, selectAllCommand);
222 selectAllItem.getElement().setId("topMenu.edit.selectAll");
223 contextMenu.addItem(selectAllItem);
225 MenuItem unSelectAllItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.unselectAll()).getHTML() + " Unselect All</span>", true, unselectAllCommand);
226 unSelectAllItem.getElement().setId("topMenu.edit.unSelectAll");
227 contextMenu.addItem(unSelectAllItem);