Statistics
| Branch: | Tag: | Revision:

root / web_client / src / gr / grnet / pithos / web / client / EditMenu.java @ 9e8e14e4

History | View | Annotate | Download (7.5 kB)

1 ab1eb3f8 Christos Stathis
/*
2 6dd67d1c Christos Stathis
 *  Copyright (c) 2011 Greek Research and Technology Network
3 ab1eb3f8 Christos Stathis
 */
4 ab1eb3f8 Christos Stathis
package gr.grnet.pithos.web.client;
5 ab1eb3f8 Christos Stathis
6 ab1eb3f8 Christos Stathis
import gr.grnet.pithos.web.client.commands.CopyCommand;
7 ab1eb3f8 Christos Stathis
import gr.grnet.pithos.web.client.commands.CutCommand;
8 ab1eb3f8 Christos Stathis
import gr.grnet.pithos.web.client.commands.DeleteCommand;
9 ab1eb3f8 Christos Stathis
import gr.grnet.pithos.web.client.commands.PasteCommand;
10 ab1eb3f8 Christos Stathis
import gr.grnet.pithos.web.client.commands.ToTrashCommand;
11 ab1eb3f8 Christos Stathis
import gr.grnet.pithos.web.client.rest.resource.FileResource;
12 ab1eb3f8 Christos Stathis
13 ab1eb3f8 Christos Stathis
import gr.grnet.pithos.web.client.rest.resource.GroupUserResource;
14 ab1eb3f8 Christos Stathis
import gr.grnet.pithos.web.client.rest.resource.RestResourceWrapper;
15 ab1eb3f8 Christos Stathis
16 ab1eb3f8 Christos Stathis
import java.util.List;
17 ab1eb3f8 Christos Stathis
18 ab1eb3f8 Christos Stathis
import com.google.gwt.event.dom.client.ClickEvent;
19 ab1eb3f8 Christos Stathis
import com.google.gwt.event.dom.client.ClickHandler;
20 ab1eb3f8 Christos Stathis
import com.google.gwt.resources.client.ClientBundle;
21 ab1eb3f8 Christos Stathis
import com.google.gwt.resources.client.ImageResource;
22 ab1eb3f8 Christos Stathis
import com.google.gwt.user.client.Command;
23 ab1eb3f8 Christos Stathis
import com.google.gwt.user.client.ui.AbstractImagePrototype;
24 ab1eb3f8 Christos Stathis
import com.google.gwt.user.client.ui.MenuBar;
25 ab1eb3f8 Christos Stathis
import com.google.gwt.user.client.ui.MenuItem;
26 ab1eb3f8 Christos Stathis
import com.google.gwt.user.client.ui.PopupPanel;
27 ab1eb3f8 Christos Stathis
28 ab1eb3f8 Christos Stathis
/**
29 ab1eb3f8 Christos Stathis
 * The 'Edit' menu implementation.
30 ab1eb3f8 Christos Stathis
 */
31 ab1eb3f8 Christos Stathis
public class EditMenu extends PopupPanel implements ClickHandler {
32 ab1eb3f8 Christos Stathis
33 ab1eb3f8 Christos Stathis
        /**
34 ab1eb3f8 Christos Stathis
         * The widget's images.
35 ab1eb3f8 Christos Stathis
         */
36 ab1eb3f8 Christos Stathis
        private final Images images;
37 ab1eb3f8 Christos Stathis
38 ab1eb3f8 Christos Stathis
        private final MenuBar contextMenu  = new MenuBar(true);
39 ab1eb3f8 Christos Stathis
40 ab1eb3f8 Christos Stathis
        /**
41 ab1eb3f8 Christos Stathis
         * An image bundle for this widget's images.
42 ab1eb3f8 Christos Stathis
         */
43 ab1eb3f8 Christos Stathis
        public interface Images extends ClientBundle, FileMenu.Images, MessagePanel.Images {
44 ab1eb3f8 Christos Stathis
45 ab1eb3f8 Christos Stathis
                /**
46 ab1eb3f8 Christos Stathis
                 * Will bundle the file 'editcut.png' residing in the package
47 ab1eb3f8 Christos Stathis
                 * 'gr.grnet.pithos.web.resources'.
48 ab1eb3f8 Christos Stathis
                 *
49 ab1eb3f8 Christos Stathis
                 * @return the image prototype
50 ab1eb3f8 Christos Stathis
                 */
51 ab1eb3f8 Christos Stathis
                @Source("gr/grnet/pithos/resources/editcut.png")
52 ab1eb3f8 Christos Stathis
                ImageResource cut();
53 ab1eb3f8 Christos Stathis
54 ab1eb3f8 Christos Stathis
                /**
55 ab1eb3f8 Christos Stathis
                 * Will bundle the file 'editcopy.png' residing in the package
56 ab1eb3f8 Christos Stathis
                 * 'gr.grnet.pithos.web.resources'.
57 ab1eb3f8 Christos Stathis
                 *
58 ab1eb3f8 Christos Stathis
                 * @return the image prototype
59 ab1eb3f8 Christos Stathis
                 */
60 ab1eb3f8 Christos Stathis
                @Source("gr/grnet/pithos/resources/editcopy.png")
61 ab1eb3f8 Christos Stathis
                ImageResource copy();
62 ab1eb3f8 Christos Stathis
63 ab1eb3f8 Christos Stathis
                /**
64 ab1eb3f8 Christos Stathis
                 * Will bundle the file 'editpaste.png' residing in the package
65 ab1eb3f8 Christos Stathis
                 * 'gr.grnet.pithos.web.resources'.
66 ab1eb3f8 Christos Stathis
                 *
67 ab1eb3f8 Christos Stathis
                 * @return the image prototype
68 ab1eb3f8 Christos Stathis
                 */
69 ab1eb3f8 Christos Stathis
                @Source("gr/grnet/pithos/resources/editpaste.png")
70 ab1eb3f8 Christos Stathis
                ImageResource paste();
71 ab1eb3f8 Christos Stathis
72 ab1eb3f8 Christos Stathis
                /**
73 ab1eb3f8 Christos Stathis
                 * Will bundle the file 'editdelete.png' residing in the package
74 ab1eb3f8 Christos Stathis
                 * 'gr.grnet.pithos.web.resources'.
75 ab1eb3f8 Christos Stathis
                 *
76 ab1eb3f8 Christos Stathis
                 * @return the image prototype
77 ab1eb3f8 Christos Stathis
                 */
78 ab1eb3f8 Christos Stathis
                @Override
79 ab1eb3f8 Christos Stathis
                @Source("gr/grnet/pithos/resources/editdelete.png")
80 ab1eb3f8 Christos Stathis
                ImageResource delete();
81 ab1eb3f8 Christos Stathis
82 ab1eb3f8 Christos Stathis
                /**
83 ab1eb3f8 Christos Stathis
                 * Will bundle the file 'translate.png' residing in the package
84 ab1eb3f8 Christos Stathis
                 * 'gr.grnet.pithos.web.resources'.
85 ab1eb3f8 Christos Stathis
                 *
86 ab1eb3f8 Christos Stathis
                 * @return the image prototype
87 ab1eb3f8 Christos Stathis
                 */
88 ab1eb3f8 Christos Stathis
                @Source("gr/grnet/pithos/resources/translate.png")
89 ab1eb3f8 Christos Stathis
                ImageResource selectAll();
90 ab1eb3f8 Christos Stathis
91 ab1eb3f8 Christos Stathis
                /**
92 ab1eb3f8 Christos Stathis
                 * Will bundle the file 'border_remove.png' residing in the package
93 ab1eb3f8 Christos Stathis
                 * 'gr.grnet.pithos.web.resources'.
94 ab1eb3f8 Christos Stathis
                 *
95 ab1eb3f8 Christos Stathis
                 * @return the image prototype
96 ab1eb3f8 Christos Stathis
                 */
97 ab1eb3f8 Christos Stathis
                @Source("gr/grnet/pithos/resources/border_remove.png")
98 ab1eb3f8 Christos Stathis
                ImageResource unselectAll();
99 ab1eb3f8 Christos Stathis
        }
100 ab1eb3f8 Christos Stathis
101 ab1eb3f8 Christos Stathis
        /**
102 ab1eb3f8 Christos Stathis
         * The widget's constructor.
103 ab1eb3f8 Christos Stathis
         *
104 ab1eb3f8 Christos Stathis
         * @param newImages the image bundle passed on by the parent object
105 ab1eb3f8 Christos Stathis
         */
106 ab1eb3f8 Christos Stathis
        public EditMenu(final Images newImages) {
107 ab1eb3f8 Christos Stathis
                // The popup's constructor's argument is a boolean specifying that it
108 ab1eb3f8 Christos Stathis
                // auto-close itself when the user clicks outside of it.
109 ab1eb3f8 Christos Stathis
                super(true);
110 ab1eb3f8 Christos Stathis
                setAnimationEnabled(true);
111 ab1eb3f8 Christos Stathis
                images = newImages;
112 ab1eb3f8 Christos Stathis
                createMenu();
113 ab1eb3f8 Christos Stathis
                add(contextMenu);
114 ab1eb3f8 Christos Stathis
        }
115 ab1eb3f8 Christos Stathis
116 ab1eb3f8 Christos Stathis
        @Override
117 ab1eb3f8 Christos Stathis
        public void onClick(ClickEvent event) {
118 ab1eb3f8 Christos Stathis
                final EditMenu menu = new EditMenu(images);
119 ab1eb3f8 Christos Stathis
                final int left = event.getRelativeElement().getAbsoluteLeft();
120 ab1eb3f8 Christos Stathis
                final int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight();
121 ab1eb3f8 Christos Stathis
                menu.setPopupPosition(left, top);
122 ab1eb3f8 Christos Stathis
                menu.show();
123 ab1eb3f8 Christos Stathis
        }
124 ab1eb3f8 Christos Stathis
125 ab1eb3f8 Christos Stathis
        public MenuBar createMenu() {
126 ab1eb3f8 Christos Stathis
                contextMenu.clearItems();
127 ab1eb3f8 Christos Stathis
                contextMenu.setAutoOpen(false);
128 ab1eb3f8 Christos Stathis
129 ab1eb3f8 Christos Stathis
                final Command selectAllCommand = new Command() {
130 ab1eb3f8 Christos Stathis
131 ab1eb3f8 Christos Stathis
                        @Override
132 ab1eb3f8 Christos Stathis
                        public void execute() {
133 ab1eb3f8 Christos Stathis
                                hide();
134 ab1eb3f8 Christos Stathis
                                if(GSS.get().isFileListShowing())
135 ab1eb3f8 Christos Stathis
                                        GSS.get().getFileList().selectAllRows();
136 ab1eb3f8 Christos Stathis
                        }
137 ab1eb3f8 Christos Stathis
                };
138 ab1eb3f8 Christos Stathis
                final Command unselectAllCommand = new Command() {
139 ab1eb3f8 Christos Stathis
140 ab1eb3f8 Christos Stathis
                        @Override
141 ab1eb3f8 Christos Stathis
                        public void execute() {
142 ab1eb3f8 Christos Stathis
                                hide();
143 ab1eb3f8 Christos Stathis
                                if(GSS.get().isFileListShowing())
144 ab1eb3f8 Christos Stathis
                                        GSS.get().getFileList().clearSelectedRows();
145 ab1eb3f8 Christos Stathis
                        }
146 ab1eb3f8 Christos Stathis
                };
147 ab1eb3f8 Christos Stathis
148 ab1eb3f8 Christos Stathis
                boolean cutcopyVisible = GSS.get().getCurrentSelection() != null && (GSS.get().getCurrentSelection() instanceof RestResourceWrapper
149 ab1eb3f8 Christos Stathis
                                        || GSS.get().getCurrentSelection() instanceof FileResource || GSS        .get().getCurrentSelection() instanceof GroupUserResource || GSS        .get().getCurrentSelection() instanceof List);
150 ab1eb3f8 Christos Stathis
                String cutLabel = "Cut";
151 ab1eb3f8 Christos Stathis
                String copyLabel ="Copy";
152 ab1eb3f8 Christos Stathis
                String pasteLabel = "Paste";
153 ab1eb3f8 Christos Stathis
                if(GSS.get().getCurrentSelection() != null)
154 ab1eb3f8 Christos Stathis
                        if(GSS.get().getCurrentSelection() instanceof RestResourceWrapper){
155 ab1eb3f8 Christos Stathis
                                cutLabel = "Cut Folder";
156 ab1eb3f8 Christos Stathis
                                copyLabel = "Copy Folder";
157 ab1eb3f8 Christos Stathis
                        }
158 ab1eb3f8 Christos Stathis
                        else if(GSS.get().getCurrentSelection() instanceof FileResource){
159 ab1eb3f8 Christos Stathis
                                cutLabel = "Cut File";
160 ab1eb3f8 Christos Stathis
                                copyLabel = "Copy File";
161 ab1eb3f8 Christos Stathis
                        }
162 ab1eb3f8 Christos Stathis
                        else if(GSS.get().getCurrentSelection() instanceof List){
163 ab1eb3f8 Christos Stathis
                                cutLabel = "Cut Files";
164 ab1eb3f8 Christos Stathis
                                copyLabel = "Copy Files";
165 ab1eb3f8 Christos Stathis
                        }
166 ab1eb3f8 Christos Stathis
                if(GSS.get().getClipboard().getItem() != null)
167 ab1eb3f8 Christos Stathis
                        if(GSS.get().getClipboard().getItem().getFile() != null)
168 ab1eb3f8 Christos Stathis
                                pasteLabel = "Paste File";
169 ab1eb3f8 Christos Stathis
                        else if(GSS.get().getClipboard().getItem().getFiles() != null)
170 ab1eb3f8 Christos Stathis
                                pasteLabel = "Paste Files";
171 ab1eb3f8 Christos Stathis
                        else if(GSS.get().getClipboard().getItem().getRestResourceWrapper() != null)
172 ab1eb3f8 Christos Stathis
                                pasteLabel = "Paste Folder";
173 ab1eb3f8 Christos Stathis
                MenuItem cutItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.cut()).getHTML() + "&nbsp;"+cutLabel+"</span>", true, new CutCommand(this));
174 ab1eb3f8 Christos Stathis
                cutItem.getElement().setId("topMenu.edit.cut");
175 ab1eb3f8 Christos Stathis
                contextMenu.addItem(cutItem).setVisible(cutcopyVisible);
176 ab1eb3f8 Christos Stathis
                
177 ab1eb3f8 Christos Stathis
                MenuItem copyItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.copy()).getHTML() + "&nbsp;"+copyLabel+"</span>", true, new CopyCommand(this));
178 ab1eb3f8 Christos Stathis
                copyItem.getElement().setId("topMenu.edit.copy");
179 ab1eb3f8 Christos Stathis
                contextMenu.addItem(copyItem).setVisible(cutcopyVisible);
180 ab1eb3f8 Christos Stathis
181 ab1eb3f8 Christos Stathis
                MenuItem pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.paste()).getHTML() + "&nbsp;"+pasteLabel+"</span>", true, new PasteCommand(this));                                
182 ab1eb3f8 Christos Stathis
                pasteItem.getElement().setId("topMenu.edit.paste");
183 ab1eb3f8 Christos Stathis
                if (GSS.get().getClipboard().getItem() != null)
184 ab1eb3f8 Christos Stathis
                        if(GSS.get().isUserListVisible() && GSS.get().getClipboard().getItem().getUser() == null){
185 ab1eb3f8 Christos Stathis
                                contextMenu.addItem(pasteItem);
186 ab1eb3f8 Christos Stathis
                        }
187 ab1eb3f8 Christos Stathis
                        else if(!GSS.get().isUserListVisible() && GSS.get().getClipboard().getItem().getUser() != null){
188 ab1eb3f8 Christos Stathis
                                //do not show paste
189 ab1eb3f8 Christos Stathis
                        }
190 ab1eb3f8 Christos Stathis
                        else if (GSS.get().getTreeView().getSelection() instanceof RestResourceWrapper){
191 ab1eb3f8 Christos Stathis
                                contextMenu.addItem(pasteItem);
192 ab1eb3f8 Christos Stathis
                        }
193 ab1eb3f8 Christos Stathis
                MenuItem moveToTrashItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(this));
194 ab1eb3f8 Christos Stathis
                moveToTrashItem.getElement().setId("topMenu.edit.moveToTrash");
195 ab1eb3f8 Christos Stathis
                contextMenu        .addItem(moveToTrashItem)
196 ab1eb3f8 Christos Stathis
                                        .setVisible(cutcopyVisible);
197 ab1eb3f8 Christos Stathis
                
198 ab1eb3f8 Christos Stathis
                MenuItem deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, images));
199 ab1eb3f8 Christos Stathis
                deleteItem.getElement().setId("topMenu.edit.delete");
200 ab1eb3f8 Christos Stathis
                contextMenu        .addItem(deleteItem)
201 ab1eb3f8 Christos Stathis
                                        .setVisible(cutcopyVisible);
202 ab1eb3f8 Christos Stathis
                
203 ab1eb3f8 Christos Stathis
                MenuItem selectAllItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.selectAll()).getHTML() + "&nbsp;Select All</span>", true, selectAllCommand);
204 ab1eb3f8 Christos Stathis
                selectAllItem.getElement().setId("topMenu.edit.selectAll");
205 ab1eb3f8 Christos Stathis
                contextMenu.addItem(selectAllItem);
206 ab1eb3f8 Christos Stathis
                
207 ab1eb3f8 Christos Stathis
                MenuItem unSelectAllItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.unselectAll()).getHTML() + "&nbsp;Unselect All</span>", true, unselectAllCommand);
208 ab1eb3f8 Christos Stathis
                unSelectAllItem.getElement().setId("topMenu.edit.unSelectAll");
209 ab1eb3f8 Christos Stathis
                contextMenu.addItem(unSelectAllItem);
210 ab1eb3f8 Christos Stathis
                return contextMenu;
211 ab1eb3f8 Christos Stathis
        }
212 ab1eb3f8 Christos Stathis
213 ab1eb3f8 Christos Stathis
214 ab1eb3f8 Christos Stathis
215 ab1eb3f8 Christos Stathis
}