Statistics
| Branch: | Tag: | Revision:

root / src / gr / grnet / pithos / web / client / FileContextMenu.java @ cae2a8db

History | View | Annotate | Download (9.9 kB)

1
/*
2
 * Copyright 2011-2012 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.PasteCommand;
41
import gr.grnet.pithos.web.client.commands.PropertiesCommand;
42
import gr.grnet.pithos.web.client.commands.RestoreTrashCommand;
43
import gr.grnet.pithos.web.client.commands.ToTrashCommand;
44
import gr.grnet.pithos.web.client.commands.UploadFileCommand;
45
import gr.grnet.pithos.web.client.foldertree.File;
46
import gr.grnet.pithos.web.client.foldertree.Folder;
47

    
48
import java.util.List;
49

    
50
import com.google.gwt.resources.client.ClientBundle;
51
import com.google.gwt.resources.client.ImageResource;
52
import com.google.gwt.user.client.Command;
53
import com.google.gwt.user.client.Window;
54
import com.google.gwt.user.client.ui.AbstractImagePrototype;
55
import com.google.gwt.user.client.ui.MenuBar;
56
import com.google.gwt.user.client.ui.MenuItem;
57
import com.google.gwt.user.client.ui.PopupPanel;
58

    
59
/**
60
 * The 'File Context' menu implementation.
61
 */
62
public class FileContextMenu extends PopupPanel {
63

    
64
        /**
65
         * The widget's images.
66
         */
67
        private final Images images;
68

    
69
        private MenuItem cutItem;
70

    
71
        private MenuItem copyItem;
72

    
73
        private MenuItem pasteItem;
74

    
75
        private MenuItem updateItem;
76

    
77
        private MenuItem sharingItem;
78

    
79
        private MenuItem propItem;
80

    
81
        private MenuItem trashItem;
82

    
83
        private MenuItem deleteItem;
84

    
85
        private MenuItem downloadItem;
86

    
87
        private MenuItem saveAsItem;
88

    
89
        /**
90
         * The image bundle for this widget's images that reuses images defined in
91
         * other menus.
92
         */
93
        public interface Images extends ClientBundle {
94

    
95
                @Source("gr/grnet/pithos/resources/mimetypes/document.png")
96
                ImageResource fileContextMenu();
97

    
98
                @Source("gr/grnet/pithos/resources/doc_versions.png")
99
                ImageResource versions();
100

    
101
                @Source("gr/grnet/pithos/resources/groups22.png")
102
                ImageResource sharing();
103

    
104
                @Source("gr/grnet/pithos/resources/border_remove.png")
105
                ImageResource unselectAll();
106

    
107
                @Source("gr/grnet/pithos/resources/demo.png")
108
                ImageResource viewImage();
109

    
110
        @Source("gr/grnet/pithos/resources/folder_new.png")
111
        ImageResource folderNew();
112

    
113
        @Source("gr/grnet/pithos/resources/folder_outbox.png")
114
        ImageResource fileUpdate();
115

    
116
        @Source("gr/grnet/pithos/resources/view_text.png")
117
        ImageResource viewText();
118

    
119
        @Source("gr/grnet/pithos/resources/folder_inbox.png")
120
        ImageResource download();
121

    
122
        @Source("gr/grnet/pithos/resources/trash.png")
123
        ImageResource emptyTrash();
124

    
125
        @Source("gr/grnet/pithos/resources/refresh.png")
126
        ImageResource refresh();
127

    
128
        /**
129
         * Will bundle the file 'editcut.png' residing in the package
130
         * 'gr.grnet.pithos.web.resources'.
131
         *
132
         * @return the image prototype
133
         */
134
        @Source("gr/grnet/pithos/resources/editcut.png")
135
        ImageResource cut();
136

    
137
        /**
138
         * Will bundle the file 'editcopy.png' residing in the package
139
         * 'gr.grnet.pithos.web.resources'.
140
         *
141
         * @return the image prototype
142
         */
143
        @Source("gr/grnet/pithos/resources/editcopy.png")
144
        ImageResource copy();
145

    
146
        /**
147
         * Will bundle the file 'editpaste.png' residing in the package
148
         * 'gr.grnet.pithos.web.resources'.
149
         *
150
         * @return the image prototype
151
         */
152
        @Source("gr/grnet/pithos/resources/editpaste.png")
153
        ImageResource paste();
154

    
155
        /**
156
         * Will bundle the file 'editdelete.png' residing in the package
157
         * 'gr.grnet.pithos.web.resources'.
158
         *
159
         * @return the image prototype
160
         */
161
        @Source("gr/grnet/pithos/resources/editdelete.png")
162
        ImageResource delete();
163

    
164
        /**
165
         * Will bundle the file 'translate.png' residing in the package
166
         * 'gr.grnet.pithos.web.resources'.
167
         *
168
         * @return the image prototype
169
         */
170
        @Source("gr/grnet/pithos/resources/translate.png")
171
        ImageResource selectAll();
172
    }
173

    
174
        public static native String getDate()/*-{
175
                return (new Date()).toUTCString();
176
        }-*/;
177

    
178
        /**
179
         * The widget's constructor.
180
         *
181
         * @param newImages the image bundle passed on by the parent object
182
         */
183
        public FileContextMenu(final Pithos app, Images newImages, TreeView selectedTree, Folder selectedFolder, final List<File> selectedFiles) {
184
                // The popup's constructor's argument is a boolean specifying that it
185
                // auto-close itself when the user clicks outside of it.
186
                super(true);
187
                setAnimationEnabled(true);
188
                images = newImages;
189
        MenuBar contextMenu = new MenuBar(true);
190
        Boolean[] permissions = null;
191
        boolean canWrite = true;
192
        if (selectedFolder != null) {
193
                permissions = selectedFolder.getPermissions().get(app.getUsername());
194
                canWrite = selectedFolder.getOwner().equals(app.getUsername()) || (permissions!= null && permissions[1] != null && permissions[1]);
195
                }
196
        else {
197
                for (File f : selectedFiles) {
198
                        permissions = f.getPermissions().get(app.getUsername());
199
                        canWrite &= (f.getOwner().equals(app.getUsername()) || (permissions!= null && permissions[1] != null && permissions[1]));
200
                }
201
        }
202
        boolean isFolderTreeSelected = selectedTree.equals(app.getFolderTreeView());
203
        if (selectedFolder != null) {
204
                    if (!selectedFolder.isInTrash()) {
205
                        if (canWrite && app.getClipboard().hasFiles()) {
206
                                pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.paste()).getHTML() + "&nbsp;Paste</span>", true, new PasteCommand(app, this, selectedFolder));
207
                                contextMenu.addItem(pasteItem);
208
                        }
209
                
210
                        if (canWrite) {
211
                                MenuItem upload = new MenuItem("<span>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(app, this, selectedFolder));
212
                                contextMenu.addItem(upload);
213
                        }
214
                        if (isFolderTreeSelected) {
215
                                        cutItem = new MenuItem("<span id='fileContextMenu.cut'>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + "&nbsp;Cut</span>", true, new CutCommand(app, this, selectedFiles));
216
                            contextMenu.addItem(cutItem);
217
                        }
218
                
219
                
220
                        if (isFolderTreeSelected) {
221
                                        trashItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(app, this, selectedFiles));
222
                            contextMenu.addItem(trashItem);
223
                        }
224
                    }
225
                    else {
226
                                MenuItem restore = new MenuItem("<span>" + AbstractImagePrototype.create(images.versions()).getHTML() + "&nbsp;Restore</span>", true, new RestoreTrashCommand(app, this, selectedFiles));
227
                                contextMenu.addItem(restore);
228
                    }
229
        }
230
                copyItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + "&nbsp;Copy</span>", true, new CopyCommand(app, this, selectedFiles));
231
        contextMenu.addItem(copyItem);
232

    
233
        if (isFolderTreeSelected) {
234
                        deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(app, this, selectedFiles, MessagePanel.images));
235
                contextMenu.addItem(deleteItem);
236
        }
237

    
238
        if (selectedFolder != null && !selectedFolder.isInTrash()) {
239
                if (isFolderTreeSelected && selectedFiles.size() == 1) {
240
                        contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(app, this, selectedFiles, PropertiesCommand.PROPERTIES)));
241
                        contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + "&nbsp;Sharing</span>", true, new PropertiesCommand(app, this, selectedFiles, PropertiesCommand.PERMISSIONS)));
242
                        contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.versions()).getHTML() + "&nbsp;Versions</span>", true, new PropertiesCommand(app, this, selectedFiles, PropertiesCommand.VERSIONS)));
243
                }
244

    
245
        }
246
            contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.download()).getHTML() + "&nbsp;Download</span>", true, new Command() {
247
                        
248
                        @Override
249
                        public void execute() {
250
                                for (File f : selectedFiles)
251
                                        Window.open(app.getApiPath() + f.getOwner() + f.getUri() + "?X-Auth-Token=" + app.getToken(), "_blank", "");
252
                        }
253
                }));
254

    
255
                add(contextMenu);
256
        }
257
}