2 * Copyright 2007, 2008, 2009 Electronic Business Systems Ltd.
\r
4 * This file is part of GSS.
\r
6 * GSS is free software: you can redistribute it and/or modify
\r
7 * it under the terms of the GNU General Public License as published by
\r
8 * the Free Software Foundation, either version 3 of the License, or
\r
9 * (at your option) any later version.
\r
11 * GSS is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with GSS. If not, see <http://www.gnu.org/licenses/>.
\r
19 package gr.ebs.gss.client;
\r
21 import gr.ebs.gss.client.commands.CopyCommand;
\r
22 import gr.ebs.gss.client.commands.CutCommand;
\r
23 import gr.ebs.gss.client.commands.DeleteCommand;
\r
24 import gr.ebs.gss.client.commands.PasteCommand;
\r
25 import gr.ebs.gss.client.commands.ToTrashCommand;
\r
26 import gr.ebs.gss.client.rest.resource.FileResource;
\r
27 import gr.ebs.gss.client.rest.resource.FolderResource;
\r
28 import gr.ebs.gss.client.rest.resource.GroupUserResource;
\r
30 import java.util.List;
\r
32 import com.google.gwt.event.dom.client.ClickEvent;
\r
33 import com.google.gwt.event.dom.client.ClickHandler;
\r
34 import com.google.gwt.resources.client.ClientBundle;
\r
35 import com.google.gwt.resources.client.ImageResource;
\r
36 import com.google.gwt.user.client.Command;
\r
37 import com.google.gwt.user.client.ui.AbstractImagePrototype;
\r
38 import com.google.gwt.user.client.ui.MenuBar;
\r
39 import com.google.gwt.user.client.ui.PopupPanel;
\r
42 * The 'Edit' menu implementation.
\r
44 public class EditMenu extends PopupPanel implements ClickHandler {
\r
47 * The widget's images.
\r
49 private final Images images;
\r
51 private final MenuBar contextMenu = new MenuBar(true);
\r
54 * An image bundle for this widget's images.
\r
56 public interface Images extends ClientBundle, FileMenu.Images, MessagePanel.Images {
\r
59 * Will bundle the file 'editcut.png' residing in the package
\r
60 * 'gr.ebs.gss.resources'.
\r
62 * @return the image prototype
\r
64 @Source("gr/ebs/gss/resources/editcut.png")
\r
65 ImageResource cut();
\r
68 * Will bundle the file 'editcopy.png' residing in the package
\r
69 * 'gr.ebs.gss.resources'.
\r
71 * @return the image prototype
\r
73 @Source("gr/ebs/gss/resources/editcopy.png")
\r
74 ImageResource copy();
\r
77 * Will bundle the file 'editpaste.png' residing in the package
\r
78 * 'gr.ebs.gss.resources'.
\r
80 * @return the image prototype
\r
82 @Source("gr/ebs/gss/resources/editpaste.png")
\r
83 ImageResource paste();
\r
86 * Will bundle the file 'editdelete.png' residing in the package
\r
87 * 'gr.ebs.gss.resources'.
\r
89 * @return the image prototype
\r
91 @Source("gr/ebs/gss/resources/editdelete.png")
\r
92 ImageResource delete();
\r
95 * Will bundle the file 'translate.png' residing in the package
\r
96 * 'gr.ebs.gss.resources'.
\r
98 * @return the image prototype
\r
100 @Source("gr/ebs/gss/resources/translate.png")
\r
101 ImageResource selectAll();
\r
104 * Will bundle the file 'border_remove.png' residing in the package
\r
105 * 'gr.ebs.gss.resources'.
\r
107 * @return the image prototype
\r
109 @Source("gr/ebs/gss/resources/border_remove.png")
\r
110 ImageResource unselectAll();
\r
114 * The widget's constructor.
\r
116 * @param newImages the image bundle passed on by the parent object
\r
118 public EditMenu(final Images newImages) {
\r
119 // The popup's constructor's argument is a boolean specifying that it
\r
120 // auto-close itself when the user clicks outside of it.
\r
122 setAnimationEnabled(true);
\r
123 images = newImages;
\r
129 public void onClick(ClickEvent event) {
\r
130 final EditMenu menu = new EditMenu(images);
\r
131 final int left = event.getRelativeElement().getAbsoluteLeft();
\r
132 final int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight();
\r
133 menu.setPopupPosition(left, top);
\r
137 public MenuBar createMenu() {
\r
138 contextMenu.clearItems();
\r
139 contextMenu.setAutoOpen(false);
\r
141 final Command selectAllCommand = new Command() {
\r
143 public void execute() {
\r
145 if(GSS.get().isFileListShowing())
\r
146 GSS.get().getFileList().selectAllRows();
\r
147 else if(GSS.get().isSearchResultsShowing())
\r
148 GSS.get().getSearchResults().selectAllRows();
\r
151 final Command unselectAllCommand = new Command() {
\r
153 public void execute() {
\r
155 if(GSS.get().isFileListShowing())
\r
156 GSS.get().getFileList().clearSelectedRows();
\r
157 else if(GSS.get().isSearchResultsShowing())
\r
158 GSS.get().getSearchResults().clearSelectedRows();
\r
162 boolean cutcopyVisible = GSS.get().getCurrentSelection() != null && (GSS.get().getCurrentSelection() instanceof FolderResource
\r
163 || GSS.get().getCurrentSelection() instanceof FileResource || GSS .get().getCurrentSelection() instanceof GroupUserResource || GSS .get().getCurrentSelection() instanceof List);
\r
164 String cutLabel = "Cut";
\r
165 String copyLabel ="Copy";
\r
166 String pasteLabel = "Paste";
\r
167 if(GSS.get().getCurrentSelection() != null)
\r
168 if(GSS.get().getCurrentSelection() instanceof FolderResource){
\r
169 cutLabel = "Cut Folder";
\r
170 copyLabel = "Copy Folder";
\r
172 else if(GSS.get().getCurrentSelection() instanceof FileResource){
\r
173 cutLabel = "Cut File";
\r
174 copyLabel = "Copy File";
\r
176 else if(GSS.get().getCurrentSelection() instanceof List){
\r
177 cutLabel = "Cut Files";
\r
178 copyLabel = "Copy Files";
\r
180 if(GSS.get().getClipboard().getItem() != null)
\r
181 if(GSS.get().getClipboard().getItem().getFile() != null)
\r
182 pasteLabel = "Paste File";
\r
183 else if(GSS.get().getClipboard().getItem().getFiles() != null)
\r
184 pasteLabel = "Paste Files";
\r
185 else if(GSS.get().getClipboard().getItem().getFolderResource() != null)
\r
186 pasteLabel = "Paste Folder";
\r
187 contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.cut()).getHTML() + " "+cutLabel+"</span>", true, new CutCommand(this)).setVisible(cutcopyVisible);
\r
188 contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.copy()).getHTML() + " "+copyLabel+"</span>", true, new CopyCommand(this)).setVisible(cutcopyVisible);
\r
189 if (GSS.get().getClipboard().getItem() != null)
\r
190 if(GSS.get().isUserListVisible() && GSS.get().getClipboard().getItem().getUser() == null)
\r
191 contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.paste()).getHTML() + " "+pasteLabel+"</span>", true, new PasteCommand(this));
\r
192 else if(!GSS.get().isUserListVisible() && GSS.get().getClipboard().getItem().getUser() != null){
\r
193 //do not show paste
\r
195 else if (GSS.get().getFolders().getCurrent().getUserObject() instanceof FolderResource)
\r
196 contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.paste()).getHTML() + " "+pasteLabel+"</span>", true, new PasteCommand(this));
\r
197 contextMenu .addItem("<span>" + AbstractImagePrototype.create(images.emptyTrash()).getHTML() + " Move to Trash</span>", true, new ToTrashCommand(this))
\r
198 .setVisible(cutcopyVisible);
\r
199 contextMenu .addItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, images))
\r
200 .setVisible(cutcopyVisible);
\r
201 contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.selectAll()).getHTML() + " Select All</span>", true, selectAllCommand);
\r
202 contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.unselectAll()).getHTML() + " Unselect All</span>", true, unselectAllCommand);
\r
203 return contextMenu;
\r