Statistics
| Branch: | Tag: | Revision:

root / web_client / src / gr / grnet / pithos / web / client / EditMenu.java @ 7529fcd7

History | View | Annotate | Download (8.8 kB)

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