Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (7.5 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
                        }
137
                };
138
                final Command unselectAllCommand = new Command() {
139

    
140
                        @Override
141
                        public void execute() {
142
                                hide();
143
                                if(GSS.get().isFileListShowing())
144
                                        GSS.get().getFileList().clearSelectedRows();
145
                        }
146
                };
147

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

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

    
213

    
214

    
215
}