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.user.client.Command;
\r
33 import com.google.gwt.user.client.ui.AbstractImagePrototype;
\r
34 import com.google.gwt.user.client.ui.ClickListener;
\r
35 import com.google.gwt.user.client.ui.MenuBar;
\r
36 import com.google.gwt.user.client.ui.PopupPanel;
\r
37 import com.google.gwt.user.client.ui.Widget;
\r
40 * The 'Edit' menu implementation.
\r
42 public class EditMenu extends PopupPanel implements ClickListener {
\r
45 * The widget's images.
\r
47 private final Images images;
\r
49 private final MenuBar contextMenu = new MenuBar(true);
\r
52 * An image bundle for this widget's images.
\r
54 public interface Images extends FileMenu.Images, MessagePanel.Images {
\r
57 * Will bundle the file 'editcut.png' residing in the package
\r
58 * 'gr.ebs.gss.resources'.
\r
60 * @return the image prototype
\r
62 @Resource("gr/ebs/gss/resources/editcut.png")
\r
63 AbstractImagePrototype cut();
\r
66 * Will bundle the file 'editcopy.png' residing in the package
\r
67 * 'gr.ebs.gss.resources'.
\r
69 * @return the image prototype
\r
71 @Resource("gr/ebs/gss/resources/editcopy.png")
\r
72 AbstractImagePrototype copy();
\r
75 * Will bundle the file 'editpaste.png' residing in the package
\r
76 * 'gr.ebs.gss.resources'.
\r
78 * @return the image prototype
\r
80 @Resource("gr/ebs/gss/resources/editpaste.png")
\r
81 AbstractImagePrototype paste();
\r
84 * Will bundle the file 'editdelete.png' residing in the package
\r
85 * 'gr.ebs.gss.resources'.
\r
87 * @return the image prototype
\r
89 @Resource("gr/ebs/gss/resources/editdelete.png")
\r
90 AbstractImagePrototype delete();
\r
93 * Will bundle the file 'translate.png' residing in the package
\r
94 * 'gr.ebs.gss.resources'.
\r
96 * @return the image prototype
\r
98 @Resource("gr/ebs/gss/resources/translate.png")
\r
99 AbstractImagePrototype selectAll();
\r
102 * Will bundle the file 'border_remove.png' residing in the package
\r
103 * 'gr.ebs.gss.resources'.
\r
105 * @return the image prototype
\r
107 @Resource("gr/ebs/gss/resources/border_remove.png")
\r
108 AbstractImagePrototype unselectAll();
\r
112 * The widget's constructor.
\r
114 * @param newImages the image bundle passed on by the parent object
\r
116 public EditMenu(final Images newImages) {
\r
117 // The popup's constructor's argument is a boolean specifying that it
\r
118 // auto-close itself when the user clicks outside of it.
\r
120 setAnimationEnabled(true);
\r
121 images = newImages;
\r
129 * @see com.google.gwt.user.client.ui.ClickListener#onClick(com.google.gwt.user.client.ui.Widget)
\r
131 public void onClick(final Widget sender) {
\r
132 final EditMenu menu = new EditMenu(images);
\r
133 final int left = sender.getAbsoluteLeft();
\r
134 final int top = sender.getAbsoluteTop() + sender.getOffsetHeight();
\r
135 menu.setPopupPosition(left, top);
\r
140 public MenuBar createMenu() {
\r
141 contextMenu.clearItems();
\r
142 contextMenu.setAutoOpen(false);
\r
144 final Command selectAllCommand = new Command() {
\r
146 public void execute() {
\r
148 if(GSS.get().isFileListShowing())
\r
149 GSS.get().getFileList().selectAllRows();
\r
150 else if(GSS.get().isSearchResultsShowing())
\r
151 GSS.get().getSearchResults().selectAllRows();
\r
154 final Command unselectAllCommand = new Command() {
\r
156 public void execute() {
\r
158 if(GSS.get().isFileListShowing())
\r
159 GSS.get().getFileList().clearSelectedRows();
\r
160 else if(GSS.get().isSearchResultsShowing())
\r
161 GSS.get().getSearchResults().clearSelectedRows();
\r
165 boolean cutcopyVisible = GSS.get().getCurrentSelection() != null && (GSS.get().getCurrentSelection() instanceof FolderResource
\r
166 || GSS.get().getCurrentSelection() instanceof FileResource || GSS .get().getCurrentSelection() instanceof GroupUserResource || GSS .get().getCurrentSelection() instanceof List);
\r
167 String cutLabel = "Cut";
\r
168 String copyLabel ="Copy";
\r
169 String pasteLabel = "Paste";
\r
170 if(GSS.get().getCurrentSelection() != null)
\r
171 if(GSS.get().getCurrentSelection() instanceof FolderResource){
\r
172 cutLabel = "Cut Folder";
\r
173 copyLabel = "Copy Folder";
\r
175 else if(GSS.get().getCurrentSelection() instanceof FileResource){
\r
176 cutLabel = "Cut File";
\r
177 copyLabel = "Copy File";
\r
179 else if(GSS.get().getCurrentSelection() instanceof List){
\r
180 cutLabel = "Cut Files";
\r
181 copyLabel = "Copy Files";
\r
183 if(GSS.get().getClipboard().getItem() != null)
\r
184 if(GSS.get().getClipboard().getItem().getFile() != null)
\r
185 pasteLabel = "Paste File";
\r
186 else if(GSS.get().getClipboard().getItem().getFiles() != null)
\r
187 pasteLabel = "Paste Files";
\r
188 else if(GSS.get().getClipboard().getItem().getFolderResource() != null)
\r
189 pasteLabel = "Paste Folder";
\r
190 contextMenu.addItem("<span>" + images.cut().getHTML() + " "+cutLabel+"</span>", true, new CutCommand(this)).setVisible(cutcopyVisible);
\r
191 contextMenu.addItem("<span>" + images.copy().getHTML() + " "+copyLabel+"</span>", true, new CopyCommand(this)).setVisible(cutcopyVisible);
\r
192 if (GSS.get().getClipboard().getItem() != null)
\r
193 if(GSS.get().isUserListVisible() && GSS.get().getClipboard().getItem().getUser() == null)
\r
194 contextMenu.addItem("<span>" + images.paste().getHTML() + " "+pasteLabel+"</span>", true, new PasteCommand(this));
\r
195 else if(!GSS.get().isUserListVisible() && GSS.get().getClipboard().getItem().getUser() != null){
\r
196 //do not show paste
\r
199 contextMenu.addItem("<span>" + images.paste().getHTML() + " "+pasteLabel+"</span>", true, new PasteCommand(this));
\r
200 contextMenu .addItem("<span>" + images.emptyTrash().getHTML() + " Move to Trash</span>", true, new ToTrashCommand(this))
\r
201 .setVisible(cutcopyVisible);
\r
202 contextMenu .addItem("<span>" + images.delete().getHTML() + " Delete</span>", true, new DeleteCommand(this, images))
\r
203 .setVisible(cutcopyVisible);
\r
204 contextMenu.addItem("<span>" + images.selectAll().getHTML() + " Select All</span>", true, selectAllCommand);
\r
205 contextMenu.addItem("<span>" + images.unselectAll().getHTML() + " Unselect All</span>", true, unselectAllCommand);
\r
206 return contextMenu;
\r