Statistics
| Branch: | Tag: | Revision:

root / src / gr / grnet / pithos / web / client / EditMenu.java @ 1e413f9b

History | View | Annotate | Download (8.8 kB)

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.Folder;
43
import gr.grnet.pithos.web.client.rest.resource.FileResource;
44

    
45
import gr.grnet.pithos.web.client.rest.resource.GroupUserResource;
46
import gr.grnet.pithos.web.client.rest.resource.RestResourceWrapper;
47

    
48
import java.util.List;
49

    
50
import com.google.gwt.event.dom.client.ClickEvent;
51
import com.google.gwt.event.dom.client.ClickHandler;
52
import com.google.gwt.resources.client.ClientBundle;
53
import com.google.gwt.resources.client.ImageResource;
54
import com.google.gwt.user.client.Command;
55
import com.google.gwt.user.client.ui.AbstractImagePrototype;
56
import com.google.gwt.user.client.ui.MenuBar;
57
import com.google.gwt.user.client.ui.MenuItem;
58
import com.google.gwt.user.client.ui.PopupPanel;
59

    
60
/**
61
 * The 'Edit' menu implementation.
62
 */
63
public class EditMenu extends PopupPanel implements ClickHandler {
64

    
65
        /**
66
         * The widget's images.
67
         */
68
        private final Images images;
69

    
70
        private final MenuBar contextMenu  = new MenuBar(true);
71

    
72
        /**
73
         * An image bundle for this widget's images.
74
         */
75
        public interface Images extends ClientBundle, FileMenu.Images, MessagePanel.Images {
76

    
77
                /**
78
                 * Will bundle the file 'editcut.png' residing in the package
79
                 * 'gr.grnet.pithos.web.resources'.
80
                 *
81
                 * @return the image prototype
82
                 */
83
                @Source("gr/grnet/pithos/resources/editcut.png")
84
                ImageResource cut();
85

    
86
                /**
87
                 * Will bundle the file 'editcopy.png' residing in the package
88
                 * 'gr.grnet.pithos.web.resources'.
89
                 *
90
                 * @return the image prototype
91
                 */
92
                @Source("gr/grnet/pithos/resources/editcopy.png")
93
                ImageResource copy();
94

    
95
                /**
96
                 * Will bundle the file 'editpaste.png' residing in the package
97
                 * 'gr.grnet.pithos.web.resources'.
98
                 *
99
                 * @return the image prototype
100
                 */
101
                @Source("gr/grnet/pithos/resources/editpaste.png")
102
                ImageResource paste();
103

    
104
                /**
105
                 * Will bundle the file 'editdelete.png' residing in the package
106
                 * 'gr.grnet.pithos.web.resources'.
107
                 *
108
                 * @return the image prototype
109
                 */
110
                @Override
111
                @Source("gr/grnet/pithos/resources/editdelete.png")
112
                ImageResource delete();
113

    
114
                /**
115
                 * Will bundle the file 'translate.png' residing in the package
116
                 * 'gr.grnet.pithos.web.resources'.
117
                 *
118
                 * @return the image prototype
119
                 */
120
                @Source("gr/grnet/pithos/resources/translate.png")
121
                ImageResource selectAll();
122

    
123
                /**
124
                 * Will bundle the file 'border_remove.png' residing in the package
125
                 * 'gr.grnet.pithos.web.resources'.
126
                 *
127
                 * @return the image prototype
128
                 */
129
                @Source("gr/grnet/pithos/resources/border_remove.png")
130
                ImageResource unselectAll();
131
        }
132

    
133
        /**
134
         * The widget's constructor.
135
         *
136
         * @param newImages the image bundle passed on by the parent object
137
         */
138
        public EditMenu(final Images newImages) {
139
                // The popup's constructor's argument is a boolean specifying that it
140
                // auto-close itself when the user clicks outside of it.
141
                super(true);
142
                setAnimationEnabled(true);
143
                images = newImages;
144
                createMenu();
145
                add(contextMenu);
146
        }
147

    
148
        @Override
149
        public void onClick(ClickEvent event) {
150
                final EditMenu menu = new EditMenu(images);
151
                final int left = event.getRelativeElement().getAbsoluteLeft();
152
                final int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight();
153
                menu.setPopupPosition(left, top);
154
                menu.show();
155
        }
156

    
157
        public MenuBar createMenu() {
158
                contextMenu.clearItems();
159
                contextMenu.setAutoOpen(false);
160

    
161
                final Command selectAllCommand = new Command() {
162

    
163
                        @Override
164
                        public void execute() {
165
                                hide();
166
                                if(GSS.get().isFileListShowing())
167
                                        GSS.get().getFileList().selectAllRows();
168
                        }
169
                };
170
                final Command unselectAllCommand = new Command() {
171

    
172
                        @Override
173
                        public void execute() {
174
                                hide();
175
                                if(GSS.get().isFileListShowing())
176
                                        GSS.get().getFileList().clearSelectedRows();
177
                        }
178
                };
179

    
180
                boolean cutcopyVisible = GSS.get().getCurrentSelection() != null && (GSS.get().getCurrentSelection() instanceof RestResourceWrapper
181
                                        || GSS.get().getCurrentSelection() instanceof FileResource || GSS        .get().getCurrentSelection() instanceof GroupUserResource || GSS        .get().getCurrentSelection() instanceof List);
182
                String cutLabel = "Cut";
183
                String copyLabel ="Copy";
184
                String pasteLabel = "Paste";
185
                if(GSS.get().getCurrentSelection() != null)
186
                        if(GSS.get().getCurrentSelection() instanceof RestResourceWrapper){
187
                                cutLabel = "Cut Folder";
188
                                copyLabel = "Copy Folder";
189
                        }
190
                        else if(GSS.get().getCurrentSelection() instanceof FileResource){
191
                                cutLabel = "Cut File";
192
                                copyLabel = "Copy File";
193
                        }
194
                        else if(GSS.get().getCurrentSelection() instanceof List){
195
                                cutLabel = "Cut Files";
196
                                copyLabel = "Copy Files";
197
                        }
198
                if(GSS.get().getClipboard().getItem() != null)
199
                        if(GSS.get().getClipboard().getItem() instanceof List) {
200
                if (((List) GSS.get().getClipboard().getItem()).size() > 1)
201
                                    pasteLabel = "Paste Files";
202
                else
203
                    pasteLabel = "Paste File";
204
            }
205
                        else if(GSS.get().getClipboard().getItem() instanceof Folder)
206
                                pasteLabel = "Paste Folder";
207
                MenuItem cutItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.cut()).getHTML() + "&nbsp;"+cutLabel+"</span>", true, new CutCommand(GSS.get(), this, null));
208
                cutItem.getElement().setId("topMenu.edit.cut");
209
                contextMenu.addItem(cutItem).setVisible(cutcopyVisible);
210
                
211
                MenuItem copyItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.copy()).getHTML() + "&nbsp;"+copyLabel+"</span>", true, new CopyCommand(GSS.get(), this, null));
212
                copyItem.getElement().setId("topMenu.edit.copy");
213
                contextMenu.addItem(copyItem).setVisible(cutcopyVisible);
214

    
215
                MenuItem pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.paste()).getHTML() + "&nbsp;"+pasteLabel+"</span>", true, new PasteCommand(GSS.get(), this, null));
216
                pasteItem.getElement().setId("topMenu.edit.paste");
217
                if (GSS.get().getClipboard().getItem() != null)
218
                    contextMenu.addItem(pasteItem);
219
                MenuItem moveToTrashItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(this));
220
                moveToTrashItem.getElement().setId("topMenu.edit.moveToTrash");
221
                contextMenu        .addItem(moveToTrashItem)
222
                                        .setVisible(cutcopyVisible);
223
                
224
                MenuItem deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, null, images));
225
                deleteItem.getElement().setId("topMenu.edit.delete");
226
                contextMenu        .addItem(deleteItem)
227
                                        .setVisible(cutcopyVisible);
228
                
229
                MenuItem selectAllItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.selectAll()).getHTML() + "&nbsp;Select All</span>", true, selectAllCommand);
230
                selectAllItem.getElement().setId("topMenu.edit.selectAll");
231
                contextMenu.addItem(selectAllItem);
232
                
233
                MenuItem unSelectAllItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.unselectAll()).getHTML() + "&nbsp;Unselect All</span>", true, unselectAllCommand);
234
                unSelectAllItem.getElement().setId("topMenu.edit.unSelectAll");
235
                contextMenu.addItem(unSelectAllItem);
236
                return contextMenu;
237
        }
238

    
239

    
240

    
241
}