Statistics
| Branch: | Tag: | Revision:

root / web_client / src / gr / grnet / pithos / web / client / FolderContextMenu.java @ 58777026

History | View | Annotate | Download (17.6 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.EmptyTrashCommand;
41
import gr.grnet.pithos.web.client.commands.NewFolderCommand;
42
import gr.grnet.pithos.web.client.commands.PasteCommand;
43
import gr.grnet.pithos.web.client.commands.PropertiesCommand;
44
import gr.grnet.pithos.web.client.commands.RefreshCommand;
45
import gr.grnet.pithos.web.client.commands.RestoreTrashCommand;
46
import gr.grnet.pithos.web.client.commands.ToTrashCommand;
47
import gr.grnet.pithos.web.client.commands.UploadFileCommand;
48
import gr.grnet.pithos.web.client.rest.resource.MyFolderResource;
49
import gr.grnet.pithos.web.client.rest.resource.OtherUserResource;
50
import gr.grnet.pithos.web.client.rest.resource.OthersFolderResource;
51
import gr.grnet.pithos.web.client.rest.resource.OthersResource;
52
import gr.grnet.pithos.web.client.rest.resource.RestResource;
53
import gr.grnet.pithos.web.client.rest.resource.SharedFolderResource;
54
import gr.grnet.pithos.web.client.rest.resource.SharedResource;
55
import gr.grnet.pithos.web.client.rest.resource.TrashFolderResource;
56
import gr.grnet.pithos.web.client.rest.resource.TrashResource;
57

    
58
import com.google.gwt.resources.client.ClientBundle;
59
import com.google.gwt.user.client.ui.AbstractImagePrototype;
60
import com.google.gwt.user.client.ui.MenuBar;
61
import com.google.gwt.user.client.ui.MenuItem;
62
import com.google.gwt.user.client.ui.PopupPanel;
63

    
64
/**
65
 * The 'Folder Context' menu implementation.
66
 */
67
public class FolderContextMenu extends PopupPanel {
68

    
69
        /**
70
         * The widget's images.
71
         */
72
        private final Images images;
73

    
74
        /**
75
         * The image bundle for this widget's images that reuses images defined in
76
         * other menus.
77
         */
78
        public interface Images extends ClientBundle,FileMenu.Images, EditMenu.Images {
79
        }
80

    
81
        private MenuItem pasteItem;
82

    
83
        /**
84
         * The widget's constructor.
85
         *
86
         * @param newImages the image bundle passed on by the parent object
87
         */
88
        public FolderContextMenu(final Images newImages) {
89
                // The popup's constructor's argument is a boolean specifying that it
90
                // auto-close itself when the user clicks outside of it.
91
                super(true);
92
                setAnimationEnabled(true);
93
                images = newImages;
94

    
95
                pasteItem = new MenuItem("<span id = 'folderContextMenu.paste'>" + AbstractImagePrototype.create(newImages.paste()).getHTML() + "&nbsp;Paste</span>", true, new PasteCommand(this));
96
                MenuBar contextMenu = new MenuBar(true);
97
                
98
                RestResource selectedItem = GSS.get().getTreeView().getSelection();
99

    
100
                if(selectedItem != null)
101
                        if(selectedItem instanceof MyFolderResource){                
102
                                MenuItem newFolder = new MenuItem("<span id = 'folderContextMenu.newFolder'>" + AbstractImagePrototype.create(newImages.folderNew()).getHTML() + "&nbsp;New Folder</span>", true, new NewFolderCommand(this, images));
103
                                contextMenu.addItem(newFolder);
104
                                
105
                                MenuItem upload = new MenuItem("<span id = 'folderContextMenu.upload'>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this));
106
                                contextMenu.addItem(upload);
107
                                                                                        
108
                                boolean notRootFolder =(((MyFolderResource) selectedItem).getResource()).getParentURI() != null ? true : false;        
109
                                if (notRootFolder) {
110
                                        // do not show the copy & cut option for the user's root folder                                        
111
                                        MenuItem cut = new MenuItem("<span id = 'folderContextMenu.cut'>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + "&nbsp;Cut</span>", true, new CutCommand(this));
112
                                        contextMenu.addItem(cut);
113
                                        
114
                                }
115
                                MenuItem copy = new MenuItem("<span id = 'folderContextMenu.copy'>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + "&nbsp;Copy</span>", true, new CopyCommand(this));                                        
116
                                contextMenu.addItem(copy);
117
                                contextMenu.addItem(pasteItem);
118
                                if (notRootFolder) {
119
                                        // do not show delete options for the user's root folder
120
                                        MenuItem moveToTrash = new MenuItem("<span id = 'folderContextMenu.moveToTrash'>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(this));                                        
121
                                        contextMenu.addItem(moveToTrash);
122
                                        
123
                                        MenuItem delete = new MenuItem("<span id = 'folderContextMenu.delete'>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, newImages));
124
                                        contextMenu.addItem(delete);                                        
125
                                }
126
                                
127
                                MenuItem refresh = new MenuItem("<span id = 'folderContextMenu.refresh'>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
128
                                contextMenu.addItem(refresh);
129
                                
130
                                MenuItem sharing = new MenuItem("<span id = 'folderContextMenu.sharing'>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + "&nbsp;Sharing</span>", true, new PropertiesCommand(this, newImages, 1));
131
                                contextMenu.addItem(sharing);
132
                                
133
                                MenuItem properties = new MenuItem("<span id = 'folderContextMenu.properties'>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(this, newImages, 0));
134
                                contextMenu.addItem(properties);                
135
                        }
136
                
137
                        if(selectedItem instanceof SharedFolderResource){
138
                                MenuItem newFolder = new MenuItem("<span id = 'folderContextMenu.newFolder'>" + AbstractImagePrototype.create(newImages.folderNew()).getHTML() + "&nbsp;New Folder</span>", true, new NewFolderCommand(this, images));
139
                                contextMenu.addItem(newFolder);
140
                                
141
                                MenuItem upload = new MenuItem("<span id = 'folderContextMenu.upload'>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this));
142
                                contextMenu.addItem(upload);
143
                                
144
                                MenuItem cut = new MenuItem("<span id = 'folderContextMenu.cut'>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + "&nbsp;Cut</span>", true, new CutCommand(this));
145
                                contextMenu.addItem(cut);
146
                                
147
                                MenuItem copy = new MenuItem("<span id = 'folderContextMenu.copy'>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + "&nbsp;Copy</span>", true, new CopyCommand(this));
148
                                contextMenu.addItem(copy);
149
                                
150
                                contextMenu.addItem(pasteItem);
151
                                
152
                                MenuItem moveToTrash = new MenuItem("<span id = 'folderContextMenu.moveToTrash'>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(this));
153
                                contextMenu.addItem(moveToTrash);
154
                                
155
                                MenuItem delete = new MenuItem("<span id = 'folderContextMenu.delete'>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, newImages));
156
                                contextMenu.addItem(delete);
157

    
158
                                MenuItem refresh = new MenuItem("<span id = 'folderContextMenu.refresh'>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
159
                                contextMenu.addItem(refresh);
160
                                
161
                                MenuItem sharing = new MenuItem("<span id = 'folderContextMenu.sharing'>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + "&nbsp;Sharing</span>", true, new PropertiesCommand(this, newImages, 1));
162
                                contextMenu.addItem(sharing);
163
                                
164
                                MenuItem properties = new MenuItem("<span id = 'folderContextMenu.properties'>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(this, newImages, 0));
165
                                contextMenu.addItem(properties);
166
                                
167
                        }
168
                        if(selectedItem instanceof TrashFolderResource){
169
                                MenuItem restore = new MenuItem("<span id = 'folderContextMenu.restore'>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Restore folder and contents</span>", true, new RestoreTrashCommand(this));
170
                                contextMenu.addItem(restore);
171
                                
172
                                MenuItem delete = new MenuItem("<span id = 'folderContextMenu.delete'>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, newImages));
173
                                contextMenu.addItem(delete);
174
                                
175
                                MenuItem refresh = new MenuItem("<span id = 'folderContextMenu.refresh'>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
176
                                contextMenu.addItem(refresh);
177
                                
178
                        }
179
                        if(selectedItem instanceof OthersFolderResource){                                
180
                                MenuItem newFolder = new MenuItem("<span id = 'folderContextMenu.newFolder'>" + AbstractImagePrototype.create(newImages.folderNew()).getHTML() + "&nbsp;New Folder</span>", true, new NewFolderCommand(this, images));
181
                                contextMenu.addItem(newFolder);
182

    
183
                                MenuItem upload = new MenuItem("<span id ='folderContextMenu.upload'>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this));
184
                                contextMenu.addItem(upload);
185
                                
186
                                MenuItem cut = new MenuItem("<span id = 'folderContextMenu.cut'>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + "&nbsp;Cut</span>", true, new CutCommand(this));
187
                                contextMenu.addItem(cut);
188
                                
189
                                MenuItem copy = new MenuItem("<span id = 'folderContextMenu.copy'>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + "&nbsp;Copy</span>", true, new CopyCommand(this));
190
                                contextMenu.addItem(copy);
191
                                
192
                                contextMenu.addItem(pasteItem);
193
                                
194
                                MenuItem moveToTrash = new MenuItem("<span id = 'folderContextMenu.moveToTrash'>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(this));
195
                                contextMenu.addItem(moveToTrash);
196
                                
197
                                MenuItem delete = new MenuItem("<span id = 'folderContextMenu.delete'>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, newImages));
198
                                contextMenu.addItem(delete);
199

    
200
                                MenuItem refresh = new MenuItem("<span id = 'folderContextMenu.delete'>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
201
                                contextMenu.addItem(refresh);
202
                                
203
                                MenuItem sharing = new MenuItem("<span id = 'folderContextMenu.sharing'>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + "&nbsp;Sharing</span>", true, new PropertiesCommand(this, newImages, 1));
204
                                contextMenu.addItem(sharing);
205
                                
206
                                MenuItem properties = new MenuItem("<span id = 'folderContextMenu.properties'>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(this, newImages, 0));
207
                                contextMenu.addItem(properties);
208
                                
209
                        }
210
                        if(selectedItem instanceof TrashResource){
211
                                MenuItem restore = new MenuItem("<span id ='folderContextMenu.restore'>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Restore Trash</span>", true, new RestoreTrashCommand(this));
212
                                contextMenu.addItem(restore);
213
                                
214
                                MenuItem emptyTrash = new MenuItem("<span id = 'folderContextMenu.emptyTrash'>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Empty Trash</span>", true, new EmptyTrashCommand(this));
215
                                contextMenu.addItem(emptyTrash);
216
                                
217
                                MenuItem refresh = new MenuItem("<span id = 'folderContextMenu.refresh'>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
218
                                contextMenu.addItem(refresh);
219
                                
220
                        }
221
                        if(selectedItem instanceof SharedResource || selectedItem instanceof OthersResource || selectedItem instanceof OtherUserResource){
222
                                MenuItem refresh = new MenuItem("<span id = 'folderContextMenu.refresh'>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
223
                                contextMenu.addItem(refresh);
224
                                
225
                        }
226
                        
227
                        /*
228
                        if(folders.isTrashItem(selectedItem)){
229
                                if (folders.isTrash(selectedItem)){
230
                                        contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Empty Trash</span>", true, new EmptyTrashCommand(this));
231
                                        contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
232
                                }
233
                                else {
234
                                        contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Restore folder and contents</span>", true, new RestoreTrashCommand(this));
235
                                        contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, newImages));
236
                                        contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
237
                                }
238
                        }
239
                        else if(folders.isFileItem(selectedItem)){
240
                                
241
                        }
242
                        else if(!folders.isMyShares(selectedItem) && folders.isMySharedItem(selectedItem)){
243
                                contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.folderNew()).getHTML() + "&nbsp;New Folder</span>", true, new NewFolderCommand(this, images));
244
                                contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this));
245
                                contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + "&nbsp;Cut</span>", true, new CutCommand(this));
246
                                contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + "&nbsp;Copy</span>", true, new CopyCommand(this));
247
                                contextMenu.addItem(pasteItem);
248
                                contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(this));
249
                                contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, newImages));
250
                                contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
251
                                contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + "&nbsp;Sharing</span>", true, new PropertiesCommand(this, newImages, 1));
252
                                contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(this, newImages, 0));
253
                        }
254
                        else if(!folders.isOthersShared(selectedItem) && folders.isOthersSharedItem(selectedItem) && !(GSS.get().getCurrentSelection() instanceof OtherUserResource)){
255
                                contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.folderNew()).getHTML() + "&nbsp;New Folder</span>", true, new NewFolderCommand(this, images));
256
                                contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this));
257
                                contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + "&nbsp;Cut</span>", true, new CutCommand(this));
258
                                contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + "&nbsp;Copy</span>", true, new CopyCommand(this));
259
                                contextMenu.addItem(pasteItem);
260
                                contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(this));
261
                                contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, newImages));
262
                                contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
263
                                contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + "&nbsp;Sharing</span>", true, new PropertiesCommand(this, newImages, 1));
264
                                contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(this, newImages, 0));
265
                        } else if(!selectedItem.equals(folders.getSharesItem()))
266
                                contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
267
                        */
268
                
269
                add(contextMenu);
270
                if (GSS.get().getClipboard().hasFolderOrFileItem())
271
                        pasteItem.setVisible(true);
272
                else
273
                        pasteItem.setVisible(false);
274
        }
275

    
276
}