9769a7e00ea84c4bda35251138c3f161be8d6703
[pithos] / web_client / src / gr / grnet / pithos / web / client / EditMenu.java
1 /*
2  * Copyright 2011 GRNET S.A. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or
5  * without modification, are permitted provided that the following
6  * conditions are met:
7  *
8  *   1. Redistributions of source code must retain the above
9  *      copyright notice, this list of conditions and the following
10  *      disclaimer.
11  *
12  *   2. Redistributions in binary form must reproduce the above
13  *      copyright notice, this list of conditions and the following
14  *      disclaimer in the documentation and/or other materials
15  *      provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  *
30  * The views and conclusions contained in the software and
31  * documentation are those of the authors and should not be
32  * interpreted as representing official policies, either expressed
33  * or implied, of GRNET S.A.
34  */
35 package gr.grnet.pithos.web.client;
36
37 import gr.grnet.pithos.web.client.commands.CopyCommand;
38 import gr.grnet.pithos.web.client.commands.CutCommand;
39 import gr.grnet.pithos.web.client.commands.DeleteCommand;
40 import gr.grnet.pithos.web.client.commands.PasteCommand;
41 import gr.grnet.pithos.web.client.commands.ToTrashCommand;
42 import gr.grnet.pithos.web.client.foldertree.File;
43 import gr.grnet.pithos.web.client.foldertree.Folder;
44 import gr.grnet.pithos.web.client.rest.resource.FileResource;
45
46 import gr.grnet.pithos.web.client.rest.resource.GroupUserResource;
47 import gr.grnet.pithos.web.client.rest.resource.RestResourceWrapper;
48
49 import java.util.List;
50
51 import com.google.gwt.event.dom.client.ClickEvent;
52 import com.google.gwt.event.dom.client.ClickHandler;
53 import com.google.gwt.resources.client.ClientBundle;
54 import com.google.gwt.resources.client.ImageResource;
55 import com.google.gwt.user.client.Command;
56 import com.google.gwt.user.client.ui.AbstractImagePrototype;
57 import com.google.gwt.user.client.ui.MenuBar;
58 import com.google.gwt.user.client.ui.MenuItem;
59 import com.google.gwt.user.client.ui.PopupPanel;
60
61 /**
62  * The 'Edit' menu implementation.
63  */
64 public class EditMenu extends MenuBar {
65
66         /**
67          * The widget's images.
68          */
69         private final Images images;
70
71         /**
72          * An image bundle for this widget's images.
73          */
74         public interface Images extends ClientBundle, FileMenu.Images, MessagePanel.Images {
75
76                 /**
77                  * Will bundle the file 'editcut.png' residing in the package
78                  * 'gr.grnet.pithos.web.resources'.
79                  *
80                  * @return the image prototype
81                  */
82                 @Source("gr/grnet/pithos/resources/editcut.png")
83                 ImageResource cut();
84
85                 /**
86                  * Will bundle the file 'editcopy.png' residing in the package
87                  * 'gr.grnet.pithos.web.resources'.
88                  *
89                  * @return the image prototype
90                  */
91                 @Source("gr/grnet/pithos/resources/editcopy.png")
92                 ImageResource copy();
93
94                 /**
95                  * Will bundle the file 'editpaste.png' residing in the package
96                  * 'gr.grnet.pithos.web.resources'.
97                  *
98                  * @return the image prototype
99                  */
100                 @Source("gr/grnet/pithos/resources/editpaste.png")
101                 ImageResource paste();
102
103                 /**
104                  * Will bundle the file 'editdelete.png' residing in the package
105                  * 'gr.grnet.pithos.web.resources'.
106                  *
107                  * @return the image prototype
108                  */
109                 @Override
110                 @Source("gr/grnet/pithos/resources/editdelete.png")
111                 ImageResource delete();
112
113                 /**
114                  * Will bundle the file 'translate.png' residing in the package
115                  * 'gr.grnet.pithos.web.resources'.
116                  *
117                  * @return the image prototype
118                  */
119                 @Source("gr/grnet/pithos/resources/translate.png")
120                 ImageResource selectAll();
121
122                 /**
123                  * Will bundle the file 'border_remove.png' residing in the package
124                  * 'gr.grnet.pithos.web.resources'.
125                  *
126                  * @return the image prototype
127                  */
128                 @Source("gr/grnet/pithos/resources/border_remove.png")
129                 ImageResource unselectAll();
130         }
131
132         /**
133          * The widget's constructor.
134          *
135          * @param newImages the image bundle passed on by the parent object
136          */
137         public EditMenu(final GSS _app, final Images newImages) {
138                 super(true);
139                 setAnimationEnabled(true);
140                 images = newImages;
141
142         Folder selectedFolder = _app.getFolderTreeView().getSelection();
143         List<File> selectedFiles = _app.getFileList().getSelectedFiles();
144
145         String cutLabel = "Cut";
146         String copyLabel ="Copy";
147         String pasteLabel = "Paste";
148         if(selectedFiles.size() == 1) {
149             cutLabel = "Cut File";
150             copyLabel = "Copy File";
151         }
152         else if (selectedFiles.size() > 1) {
153             cutLabel = "Cut Files";
154             copyLabel = "Copy Files";
155         }
156         else if (selectedFolder != null) {
157             cutLabel = "Cut Folder";
158             copyLabel = "Copy Folder";
159         }
160
161         if (_app.getClipboard().hasFiles()) {
162             if (((List<File>) _app.getClipboard().getItem()).size() > 1)
163                 pasteLabel = "Paste Files";
164             else
165                 pasteLabel = "Paste File";
166         }
167         else
168             pasteLabel = "Paste Folder";
169
170         if (selectedFiles.size() > 0 || selectedFolder != null) {
171             Object cutObject = null;
172             if (selectedFiles.size() > 0)
173                 cutObject = selectedFiles;
174             else if (selectedFolder != null)
175                 cutObject = selectedFolder;
176
177             MenuItem cutItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.cut()).getHTML() + "&nbsp;" + cutLabel + "</span>", true, new CutCommand(_app, null, cutObject));
178             addItem(cutItem);
179
180             MenuItem copyItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.copy()).getHTML() + "&nbsp;"+copyLabel+"</span>", true, new CopyCommand(_app, null, cutObject));
181             addItem(copyItem);
182
183             MenuItem moveToTrashItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(_app, null, cutObject));
184             addItem(moveToTrashItem);
185
186             MenuItem deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(null, cutObject, images));
187             addItem(deleteItem);
188         }
189
190         if (selectedFolder != null && !_app.getClipboard().isEmpty()) {
191             MenuItem pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.paste()).getHTML() + "&nbsp;" + pasteLabel + "</span>", true, new PasteCommand(_app, null, selectedFolder));
192             addItem(pasteItem);
193         }
194
195
196         MenuItem selectAllItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.selectAll()).getHTML() + "&nbsp;Select All</span>", true, new Command() {
197
198             @Override
199             public void execute() {
200                 _app.getFileList().selectAllRows();
201             }
202         });
203         addItem(selectAllItem);
204
205         MenuItem unSelectAllItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.unselectAll()).getHTML() + "&nbsp;Unselect All</span>", true, new Command() {
206
207             @Override
208             public void execute() {
209                     _app.getFileList().clearSelectedRows();
210             }
211         });
212         addItem(unSelectAllItem);
213         }
214 }