Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (7.7 kB)

1
/*
2
 *  Copyright (c) 2011 Greek Research and Technology Network
3
 */
4
package gr.grnet.pithos.web.client;
5

    
6
import gr.grnet.pithos.web.client.commands.CopyCommand;
7
import gr.grnet.pithos.web.client.commands.CutCommand;
8
import gr.grnet.pithos.web.client.commands.DeleteCommand;
9
import gr.grnet.pithos.web.client.commands.PasteCommand;
10
import gr.grnet.pithos.web.client.commands.ToTrashCommand;
11
import gr.grnet.pithos.web.client.rest.resource.FileResource;
12

    
13
import gr.grnet.pithos.web.client.rest.resource.GroupUserResource;
14
import gr.grnet.pithos.web.client.rest.resource.RestResourceWrapper;
15

    
16
import java.util.List;
17

    
18
import com.google.gwt.event.dom.client.ClickEvent;
19
import com.google.gwt.event.dom.client.ClickHandler;
20
import com.google.gwt.resources.client.ClientBundle;
21
import com.google.gwt.resources.client.ImageResource;
22
import com.google.gwt.user.client.Command;
23
import com.google.gwt.user.client.ui.AbstractImagePrototype;
24
import com.google.gwt.user.client.ui.MenuBar;
25
import com.google.gwt.user.client.ui.MenuItem;
26
import com.google.gwt.user.client.ui.PopupPanel;
27

    
28
/**
29
 * The 'Edit' menu implementation.
30
 */
31
public class EditMenu extends PopupPanel implements ClickHandler {
32

    
33
        /**
34
         * The widget's images.
35
         */
36
        private final Images images;
37

    
38
        private final MenuBar contextMenu  = new MenuBar(true);
39

    
40
        /**
41
         * An image bundle for this widget's images.
42
         */
43
        public interface Images extends ClientBundle, FileMenu.Images, MessagePanel.Images {
44

    
45
                /**
46
                 * Will bundle the file 'editcut.png' residing in the package
47
                 * 'gr.grnet.pithos.web.resources'.
48
                 *
49
                 * @return the image prototype
50
                 */
51
                @Source("gr/grnet/pithos/resources/editcut.png")
52
                ImageResource cut();
53

    
54
                /**
55
                 * Will bundle the file 'editcopy.png' residing in the package
56
                 * 'gr.grnet.pithos.web.resources'.
57
                 *
58
                 * @return the image prototype
59
                 */
60
                @Source("gr/grnet/pithos/resources/editcopy.png")
61
                ImageResource copy();
62

    
63
                /**
64
                 * Will bundle the file 'editpaste.png' residing in the package
65
                 * 'gr.grnet.pithos.web.resources'.
66
                 *
67
                 * @return the image prototype
68
                 */
69
                @Source("gr/grnet/pithos/resources/editpaste.png")
70
                ImageResource paste();
71

    
72
                /**
73
                 * Will bundle the file 'editdelete.png' residing in the package
74
                 * 'gr.grnet.pithos.web.resources'.
75
                 *
76
                 * @return the image prototype
77
                 */
78
                @Override
79
                @Source("gr/grnet/pithos/resources/editdelete.png")
80
                ImageResource delete();
81

    
82
                /**
83
                 * Will bundle the file 'translate.png' residing in the package
84
                 * 'gr.grnet.pithos.web.resources'.
85
                 *
86
                 * @return the image prototype
87
                 */
88
                @Source("gr/grnet/pithos/resources/translate.png")
89
                ImageResource selectAll();
90

    
91
                /**
92
                 * Will bundle the file 'border_remove.png' residing in the package
93
                 * 'gr.grnet.pithos.web.resources'.
94
                 *
95
                 * @return the image prototype
96
                 */
97
                @Source("gr/grnet/pithos/resources/border_remove.png")
98
                ImageResource unselectAll();
99
        }
100

    
101
        /**
102
         * The widget's constructor.
103
         *
104
         * @param newImages the image bundle passed on by the parent object
105
         */
106
        public EditMenu(final Images newImages) {
107
                // The popup's constructor's argument is a boolean specifying that it
108
                // auto-close itself when the user clicks outside of it.
109
                super(true);
110
                setAnimationEnabled(true);
111
                images = newImages;
112
                createMenu();
113
                add(contextMenu);
114
        }
115

    
116
        @Override
117
        public void onClick(ClickEvent event) {
118
                final EditMenu menu = new EditMenu(images);
119
                final int left = event.getRelativeElement().getAbsoluteLeft();
120
                final int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight();
121
                menu.setPopupPosition(left, top);
122
                menu.show();
123
        }
124

    
125
        public MenuBar createMenu() {
126
                contextMenu.clearItems();
127
                contextMenu.setAutoOpen(false);
128

    
129
                final Command selectAllCommand = new Command() {
130

    
131
                        @Override
132
                        public void execute() {
133
                                hide();
134
                                if(GSS.get().isFileListShowing())
135
                                        GSS.get().getFileList().selectAllRows();
136
                                else if(GSS.get().isSearchResultsShowing())
137
                                        GSS.get().getSearchResults().selectAllRows();
138
                        }
139
                };
140
                final Command unselectAllCommand = new Command() {
141

    
142
                        @Override
143
                        public void execute() {
144
                                hide();
145
                                if(GSS.get().isFileListShowing())
146
                                        GSS.get().getFileList().clearSelectedRows();
147
                                else if(GSS.get().isSearchResultsShowing())
148
                                        GSS.get().getSearchResults().clearSelectedRows();
149
                        }
150
                };
151

    
152
                boolean cutcopyVisible = GSS.get().getCurrentSelection() != null && (GSS.get().getCurrentSelection() instanceof RestResourceWrapper
153
                                        || GSS.get().getCurrentSelection() instanceof FileResource || GSS        .get().getCurrentSelection() instanceof GroupUserResource || GSS        .get().getCurrentSelection() instanceof List);
154
                String cutLabel = "Cut";
155
                String copyLabel ="Copy";
156
                String pasteLabel = "Paste";
157
                if(GSS.get().getCurrentSelection() != null)
158
                        if(GSS.get().getCurrentSelection() instanceof RestResourceWrapper){
159
                                cutLabel = "Cut Folder";
160
                                copyLabel = "Copy Folder";
161
                        }
162
                        else if(GSS.get().getCurrentSelection() instanceof FileResource){
163
                                cutLabel = "Cut File";
164
                                copyLabel = "Copy File";
165
                        }
166
                        else if(GSS.get().getCurrentSelection() instanceof List){
167
                                cutLabel = "Cut Files";
168
                                copyLabel = "Copy Files";
169
                        }
170
                if(GSS.get().getClipboard().getItem() != null)
171
                        if(GSS.get().getClipboard().getItem().getFile() != null)
172
                                pasteLabel = "Paste File";
173
                        else if(GSS.get().getClipboard().getItem().getFiles() != null)
174
                                pasteLabel = "Paste Files";
175
                        else if(GSS.get().getClipboard().getItem().getRestResourceWrapper() != null)
176
                                pasteLabel = "Paste Folder";
177
                MenuItem cutItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.cut()).getHTML() + "&nbsp;"+cutLabel+"</span>", true, new CutCommand(this));
178
                cutItem.getElement().setId("topMenu.edit.cut");
179
                contextMenu.addItem(cutItem).setVisible(cutcopyVisible);
180
                
181
                MenuItem copyItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.copy()).getHTML() + "&nbsp;"+copyLabel+"</span>", true, new CopyCommand(this));
182
                copyItem.getElement().setId("topMenu.edit.copy");
183
                contextMenu.addItem(copyItem).setVisible(cutcopyVisible);
184

    
185
                MenuItem pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.paste()).getHTML() + "&nbsp;"+pasteLabel+"</span>", true, new PasteCommand(this));                                
186
                pasteItem.getElement().setId("topMenu.edit.paste");
187
                if (GSS.get().getClipboard().getItem() != null)
188
                        if(GSS.get().isUserListVisible() && GSS.get().getClipboard().getItem().getUser() == null){
189
                                contextMenu.addItem(pasteItem);
190
                        }
191
                        else if(!GSS.get().isUserListVisible() && GSS.get().getClipboard().getItem().getUser() != null){
192
                                //do not show paste
193
                        }
194
                        else if (GSS.get().getTreeView().getSelection() instanceof RestResourceWrapper){
195
                                contextMenu.addItem(pasteItem);
196
                        }
197
                MenuItem moveToTrashItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(this));
198
                moveToTrashItem.getElement().setId("topMenu.edit.moveToTrash");
199
                contextMenu        .addItem(moveToTrashItem)
200
                                        .setVisible(cutcopyVisible);
201
                
202
                MenuItem deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, images));
203
                deleteItem.getElement().setId("topMenu.edit.delete");
204
                contextMenu        .addItem(deleteItem)
205
                                        .setVisible(cutcopyVisible);
206
                
207
                MenuItem selectAllItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.selectAll()).getHTML() + "&nbsp;Select All</span>", true, selectAllCommand);
208
                selectAllItem.getElement().setId("topMenu.edit.selectAll");
209
                contextMenu.addItem(selectAllItem);
210
                
211
                MenuItem unSelectAllItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.unselectAll()).getHTML() + "&nbsp;Unselect All</span>", true, unselectAllCommand);
212
                unSelectAllItem.getElement().setId("topMenu.edit.unSelectAll");
213
                contextMenu.addItem(unSelectAllItem);
214
                return contextMenu;
215
        }
216

    
217

    
218

    
219
}