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.PopupPanel;
42 * The 'Edit' menu implementation.
44 public class EditMenu extends PopupPanel implements ClickHandler {
47 * The widget's images.
49 private final Images images;
51 private final MenuBar contextMenu = new MenuBar(true);
54 * An image bundle for this widget's images.
56 public interface Images extends ClientBundle, FileMenu.Images, MessagePanel.Images {
59 * Will bundle the file 'editcut.png' residing in the package
60 * 'gr.ebs.gss.resources'.
62 * @return the image prototype
64 @Source("gr/ebs/gss/resources/editcut.png")
68 * Will bundle the file 'editcopy.png' residing in the package
69 * 'gr.ebs.gss.resources'.
71 * @return the image prototype
73 @Source("gr/ebs/gss/resources/editcopy.png")
77 * Will bundle the file 'editpaste.png' residing in the package
78 * 'gr.ebs.gss.resources'.
80 * @return the image prototype
82 @Source("gr/ebs/gss/resources/editpaste.png")
83 ImageResource paste();
86 * Will bundle the file 'editdelete.png' residing in the package
87 * 'gr.ebs.gss.resources'.
89 * @return the image prototype
92 @Source("gr/ebs/gss/resources/editdelete.png")
93 ImageResource delete();
96 * Will bundle the file 'translate.png' residing in the package
97 * 'gr.ebs.gss.resources'.
99 * @return the image prototype
101 @Source("gr/ebs/gss/resources/translate.png")
102 ImageResource selectAll();
105 * Will bundle the file 'border_remove.png' residing in the package
106 * 'gr.ebs.gss.resources'.
108 * @return the image prototype
110 @Source("gr/ebs/gss/resources/border_remove.png")
111 ImageResource unselectAll();
115 * The widget's constructor.
117 * @param newImages the image bundle passed on by the parent object
119 public EditMenu(final Images newImages) {
120 // The popup's constructor's argument is a boolean specifying that it
121 // auto-close itself when the user clicks outside of it.
123 setAnimationEnabled(true);
130 public void onClick(ClickEvent event) {
131 final EditMenu menu = new EditMenu(images);
132 final int left = event.getRelativeElement().getAbsoluteLeft();
133 final int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight();
134 menu.setPopupPosition(left, top);
138 public MenuBar createMenu() {
139 contextMenu.clearItems();
140 contextMenu.setAutoOpen(false);
142 final Command selectAllCommand = new Command() {
145 public void execute() {
147 if(GSS.get().isFileListShowing())
148 GSS.get().getFileList().selectAllRows();
149 else if(GSS.get().isSearchResultsShowing())
150 GSS.get().getSearchResults().selectAllRows();
153 final Command unselectAllCommand = new Command() {
156 public void execute() {
158 if(GSS.get().isFileListShowing())
159 GSS.get().getFileList().clearSelectedRows();
160 else if(GSS.get().isSearchResultsShowing())
161 GSS.get().getSearchResults().clearSelectedRows();
165 boolean cutcopyVisible = GSS.get().getCurrentSelection() != null && (GSS.get().getCurrentSelection() instanceof FolderResource
166 || GSS.get().getCurrentSelection() instanceof FileResource || GSS .get().getCurrentSelection() instanceof GroupUserResource || GSS .get().getCurrentSelection() instanceof List);
167 String cutLabel = "Cut";
168 String copyLabel ="Copy";
169 String pasteLabel = "Paste";
170 if(GSS.get().getCurrentSelection() != null)
171 if(GSS.get().getCurrentSelection() instanceof FolderResource){
172 cutLabel = "Cut Folder";
173 copyLabel = "Copy Folder";
175 else if(GSS.get().getCurrentSelection() instanceof FileResource){
176 cutLabel = "Cut File";
177 copyLabel = "Copy File";
179 else if(GSS.get().getCurrentSelection() instanceof List){
180 cutLabel = "Cut Files";
181 copyLabel = "Copy Files";
183 if(GSS.get().getClipboard().getItem() != null)
184 if(GSS.get().getClipboard().getItem().getFile() != null)
185 pasteLabel = "Paste File";
186 else if(GSS.get().getClipboard().getItem().getFiles() != null)
187 pasteLabel = "Paste Files";
188 else if(GSS.get().getClipboard().getItem().getFolderResource() != null)
189 pasteLabel = "Paste Folder";
190 contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.cut()).getHTML() + " "+cutLabel+"</span>", true, new CutCommand(this)).setVisible(cutcopyVisible);
191 contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.copy()).getHTML() + " "+copyLabel+"</span>", true, new CopyCommand(this)).setVisible(cutcopyVisible);
192 if (GSS.get().getClipboard().getItem() != null)
193 if(GSS.get().isUserListVisible() && GSS.get().getClipboard().getItem().getUser() == null)
194 contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.paste()).getHTML() + " "+pasteLabel+"</span>", true, new PasteCommand(this));
195 else if(!GSS.get().isUserListVisible() && GSS.get().getClipboard().getItem().getUser() != null){
198 else if (GSS.get().getTreeView().getSelection() instanceof FolderResource)
199 contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.paste()).getHTML() + " "+pasteLabel+"</span>", true, new PasteCommand(this));
200 contextMenu .addItem("<span>" + AbstractImagePrototype.create(images.emptyTrash()).getHTML() + " Move to Trash</span>", true, new ToTrashCommand(this))
201 .setVisible(cutcopyVisible);
202 contextMenu .addItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, images))
203 .setVisible(cutcopyVisible);
204 contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.selectAll()).getHTML() + " Select All</span>", true, selectAllCommand);
205 contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.unselectAll()).getHTML() + " Unselect All</span>", true, unselectAllCommand);