Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (10.2 kB)

1 a57faaf0 Christos Stathis
/*
2 e6e9f6e6 Christos KK Loverdos
 * Copyright 2011-2013 GRNET S.A. All rights reserved.
3 63366925 Christos Stathis
 *
4 63366925 Christos Stathis
 * Redistribution and use in source and binary forms, with or
5 63366925 Christos Stathis
 * without modification, are permitted provided that the following
6 63366925 Christos Stathis
 * conditions are met:
7 63366925 Christos Stathis
 *
8 63366925 Christos Stathis
 *   1. Redistributions of source code must retain the above
9 63366925 Christos Stathis
 *      copyright notice, this list of conditions and the following
10 63366925 Christos Stathis
 *      disclaimer.
11 63366925 Christos Stathis
 *
12 63366925 Christos Stathis
 *   2. Redistributions in binary form must reproduce the above
13 63366925 Christos Stathis
 *      copyright notice, this list of conditions and the following
14 63366925 Christos Stathis
 *      disclaimer in the documentation and/or other materials
15 63366925 Christos Stathis
 *      provided with the distribution.
16 63366925 Christos Stathis
 *
17 63366925 Christos Stathis
 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18 63366925 Christos Stathis
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 63366925 Christos Stathis
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 63366925 Christos Stathis
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21 63366925 Christos Stathis
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 63366925 Christos Stathis
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 63366925 Christos Stathis
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24 63366925 Christos Stathis
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 63366925 Christos Stathis
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 63366925 Christos Stathis
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27 63366925 Christos Stathis
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 63366925 Christos Stathis
 * POSSIBILITY OF SUCH DAMAGE.
29 63366925 Christos Stathis
 *
30 63366925 Christos Stathis
 * The views and conclusions contained in the software and
31 63366925 Christos Stathis
 * documentation are those of the authors and should not be
32 63366925 Christos Stathis
 * interpreted as representing official policies, either expressed
33 63366925 Christos Stathis
 * or implied, of GRNET S.A.
34 a57faaf0 Christos Stathis
 */
35 a57faaf0 Christos Stathis
package gr.grnet.pithos.web.client;
36 a57faaf0 Christos Stathis
37 a57faaf0 Christos Stathis
import gr.grnet.pithos.web.client.commands.CopyCommand;
38 a57faaf0 Christos Stathis
import gr.grnet.pithos.web.client.commands.CutCommand;
39 a57faaf0 Christos Stathis
import gr.grnet.pithos.web.client.commands.DeleteCommand;
40 a57faaf0 Christos Stathis
import gr.grnet.pithos.web.client.commands.PasteCommand;
41 a57faaf0 Christos Stathis
import gr.grnet.pithos.web.client.commands.PropertiesCommand;
42 31477486 Christos Stathis
import gr.grnet.pithos.web.client.commands.RestoreTrashCommand;
43 a57faaf0 Christos Stathis
import gr.grnet.pithos.web.client.commands.ToTrashCommand;
44 a57faaf0 Christos Stathis
import gr.grnet.pithos.web.client.commands.UploadFileCommand;
45 d4374639 Christos Stathis
import gr.grnet.pithos.web.client.foldertree.File;
46 63366925 Christos Stathis
import gr.grnet.pithos.web.client.foldertree.Folder;
47 a57faaf0 Christos Stathis
48 a57faaf0 Christos Stathis
import java.util.List;
49 a57faaf0 Christos Stathis
50 a57faaf0 Christos Stathis
import com.google.gwt.resources.client.ClientBundle;
51 a57faaf0 Christos Stathis
import com.google.gwt.resources.client.ImageResource;
52 a57faaf0 Christos Stathis
import com.google.gwt.user.client.Command;
53 05bb97f8 Christos Stathis
import com.google.gwt.user.client.Window;
54 a57faaf0 Christos Stathis
import com.google.gwt.user.client.ui.AbstractImagePrototype;
55 a57faaf0 Christos Stathis
import com.google.gwt.user.client.ui.MenuBar;
56 a57faaf0 Christos Stathis
import com.google.gwt.user.client.ui.MenuItem;
57 a57faaf0 Christos Stathis
import com.google.gwt.user.client.ui.PopupPanel;
58 a57faaf0 Christos Stathis
59 a57faaf0 Christos Stathis
/**
60 a57faaf0 Christos Stathis
 * The 'File Context' menu implementation.
61 a57faaf0 Christos Stathis
 */
62 63366925 Christos Stathis
public class FileContextMenu extends PopupPanel {
63 a57faaf0 Christos Stathis
64 a57faaf0 Christos Stathis
        /**
65 a57faaf0 Christos Stathis
         * The widget's images.
66 a57faaf0 Christos Stathis
         */
67 a57faaf0 Christos Stathis
        private final Images images;
68 a57faaf0 Christos Stathis
69 a57faaf0 Christos Stathis
        private MenuItem cutItem;
70 a57faaf0 Christos Stathis
71 a57faaf0 Christos Stathis
        private MenuItem copyItem;
72 a57faaf0 Christos Stathis
73 a57faaf0 Christos Stathis
        private MenuItem pasteItem;
74 a57faaf0 Christos Stathis
75 a57faaf0 Christos Stathis
        private MenuItem updateItem;
76 a57faaf0 Christos Stathis
77 a57faaf0 Christos Stathis
        private MenuItem sharingItem;
78 a57faaf0 Christos Stathis
79 a57faaf0 Christos Stathis
        private MenuItem propItem;
80 a57faaf0 Christos Stathis
81 a57faaf0 Christos Stathis
        private MenuItem trashItem;
82 a57faaf0 Christos Stathis
83 a57faaf0 Christos Stathis
        private MenuItem deleteItem;
84 a57faaf0 Christos Stathis
85 a57faaf0 Christos Stathis
        private MenuItem downloadItem;
86 a57faaf0 Christos Stathis
87 a57faaf0 Christos Stathis
        private MenuItem saveAsItem;
88 a57faaf0 Christos Stathis
89 a57faaf0 Christos Stathis
        /**
90 a57faaf0 Christos Stathis
         * The image bundle for this widget's images that reuses images defined in
91 a57faaf0 Christos Stathis
         * other menus.
92 a57faaf0 Christos Stathis
         */
93 f6445935 Christos Stathis
        public interface Images extends ClientBundle {
94 a57faaf0 Christos Stathis
95 a57faaf0 Christos Stathis
                @Source("gr/grnet/pithos/resources/mimetypes/document.png")
96 a57faaf0 Christos Stathis
                ImageResource fileContextMenu();
97 a57faaf0 Christos Stathis
98 a57faaf0 Christos Stathis
                @Source("gr/grnet/pithos/resources/doc_versions.png")
99 a57faaf0 Christos Stathis
                ImageResource versions();
100 a57faaf0 Christos Stathis
101 9d8521d7 Christos Stathis
                @Source("gr/grnet/pithos/resources/groups22.png")
102 a57faaf0 Christos Stathis
                ImageResource sharing();
103 a57faaf0 Christos Stathis
104 a57faaf0 Christos Stathis
                @Source("gr/grnet/pithos/resources/border_remove.png")
105 a57faaf0 Christos Stathis
                ImageResource unselectAll();
106 a57faaf0 Christos Stathis
107 a57faaf0 Christos Stathis
                @Source("gr/grnet/pithos/resources/demo.png")
108 a57faaf0 Christos Stathis
                ImageResource viewImage();
109 f6445935 Christos Stathis
110 f6445935 Christos Stathis
        @Source("gr/grnet/pithos/resources/folder_new.png")
111 f6445935 Christos Stathis
        ImageResource folderNew();
112 f6445935 Christos Stathis
113 f6445935 Christos Stathis
        @Source("gr/grnet/pithos/resources/folder_outbox.png")
114 f6445935 Christos Stathis
        ImageResource fileUpdate();
115 f6445935 Christos Stathis
116 f6445935 Christos Stathis
        @Source("gr/grnet/pithos/resources/view_text.png")
117 f6445935 Christos Stathis
        ImageResource viewText();
118 f6445935 Christos Stathis
119 f6445935 Christos Stathis
        @Source("gr/grnet/pithos/resources/folder_inbox.png")
120 f6445935 Christos Stathis
        ImageResource download();
121 f6445935 Christos Stathis
122 9d8521d7 Christos Stathis
        @Source("gr/grnet/pithos/resources/trash.png")
123 f6445935 Christos Stathis
        ImageResource emptyTrash();
124 f6445935 Christos Stathis
125 f6445935 Christos Stathis
        @Source("gr/grnet/pithos/resources/refresh.png")
126 f6445935 Christos Stathis
        ImageResource refresh();
127 f6445935 Christos Stathis
128 f6445935 Christos Stathis
        /**
129 f6445935 Christos Stathis
         * Will bundle the file 'editcut.png' residing in the package
130 f6445935 Christos Stathis
         * 'gr.grnet.pithos.web.resources'.
131 f6445935 Christos Stathis
         *
132 f6445935 Christos Stathis
         * @return the image prototype
133 f6445935 Christos Stathis
         */
134 f6445935 Christos Stathis
        @Source("gr/grnet/pithos/resources/editcut.png")
135 f6445935 Christos Stathis
        ImageResource cut();
136 f6445935 Christos Stathis
137 f6445935 Christos Stathis
        /**
138 f6445935 Christos Stathis
         * Will bundle the file 'editcopy.png' residing in the package
139 f6445935 Christos Stathis
         * 'gr.grnet.pithos.web.resources'.
140 f6445935 Christos Stathis
         *
141 f6445935 Christos Stathis
         * @return the image prototype
142 f6445935 Christos Stathis
         */
143 f6445935 Christos Stathis
        @Source("gr/grnet/pithos/resources/editcopy.png")
144 f6445935 Christos Stathis
        ImageResource copy();
145 f6445935 Christos Stathis
146 f6445935 Christos Stathis
        /**
147 f6445935 Christos Stathis
         * Will bundle the file 'editpaste.png' residing in the package
148 f6445935 Christos Stathis
         * 'gr.grnet.pithos.web.resources'.
149 f6445935 Christos Stathis
         *
150 f6445935 Christos Stathis
         * @return the image prototype
151 f6445935 Christos Stathis
         */
152 f6445935 Christos Stathis
        @Source("gr/grnet/pithos/resources/editpaste.png")
153 f6445935 Christos Stathis
        ImageResource paste();
154 f6445935 Christos Stathis
155 f6445935 Christos Stathis
        /**
156 f6445935 Christos Stathis
         * Will bundle the file 'editdelete.png' residing in the package
157 f6445935 Christos Stathis
         * 'gr.grnet.pithos.web.resources'.
158 f6445935 Christos Stathis
         *
159 f6445935 Christos Stathis
         * @return the image prototype
160 f6445935 Christos Stathis
         */
161 f6445935 Christos Stathis
        @Source("gr/grnet/pithos/resources/editdelete.png")
162 f6445935 Christos Stathis
        ImageResource delete();
163 f6445935 Christos Stathis
164 f6445935 Christos Stathis
        /**
165 f6445935 Christos Stathis
         * Will bundle the file 'translate.png' residing in the package
166 f6445935 Christos Stathis
         * 'gr.grnet.pithos.web.resources'.
167 f6445935 Christos Stathis
         *
168 f6445935 Christos Stathis
         * @return the image prototype
169 f6445935 Christos Stathis
         */
170 f6445935 Christos Stathis
        @Source("gr/grnet/pithos/resources/translate.png")
171 f6445935 Christos Stathis
        ImageResource selectAll();
172 71875b42 Christos Stathis
        
173 71875b42 Christos Stathis
        @Source("gr/grnet/pithos/resources/internet.png")
174 71875b42 Christos Stathis
        ImageResource internet();
175 f6445935 Christos Stathis
    }
176 a57faaf0 Christos Stathis
177 a57faaf0 Christos Stathis
        public static native String getDate()/*-{
178 a57faaf0 Christos Stathis
                return (new Date()).toUTCString();
179 a57faaf0 Christos Stathis
        }-*/;
180 a57faaf0 Christos Stathis
181 a57faaf0 Christos Stathis
        /**
182 a57faaf0 Christos Stathis
         * The widget's constructor.
183 a57faaf0 Christos Stathis
         *
184 a57faaf0 Christos Stathis
         * @param newImages the image bundle passed on by the parent object
185 a57faaf0 Christos Stathis
         */
186 05bb97f8 Christos Stathis
        public FileContextMenu(final Pithos app, Images newImages, TreeView selectedTree, Folder selectedFolder, final List<File> selectedFiles) {
187 a57faaf0 Christos Stathis
                // The popup's constructor's argument is a boolean specifying that it
188 a57faaf0 Christos Stathis
                // auto-close itself when the user clicks outside of it.
189 a57faaf0 Christos Stathis
                super(true);
190 a57faaf0 Christos Stathis
                images = newImages;
191 63366925 Christos Stathis
        MenuBar contextMenu = new MenuBar(true);
192 63ee965c Christos Stathis
        Boolean[] permissions = null;
193 63ee965c Christos Stathis
        boolean canWrite = true;
194 63ee965c Christos Stathis
        if (selectedFolder != null) {
195 cc0120ab Christos KK Loverdos
                permissions = selectedFolder.getPermissions().get(app.getUserID());
196 4eaecbac Christos KK Loverdos
                canWrite = selectedFolder.getOwnerID().equals(app.getUserID()) || (permissions!= null && permissions[1] != null && permissions[1]);
197 63ee965c Christos Stathis
                }
198 63ee965c Christos Stathis
        else {
199 63ee965c Christos Stathis
                for (File f : selectedFiles) {
200 cc0120ab Christos KK Loverdos
                        permissions = f.getPermissions().get(app.getUserID());
201 cde22209 Christos KK Loverdos
                        canWrite &= (f.getOwnerID().equals(app.getUserID()) || (permissions!= null && permissions[1] != null && permissions[1]));
202 63ee965c Christos Stathis
                }
203 63ee965c Christos Stathis
        }
204 02d3a335 Christos Stathis
        boolean isFolderTreeSelected = selectedTree.equals(app.getFolderTreeView());
205 5d18aa82 Christos Stathis
        boolean isMysharedSelected = selectedTree.equals(app.getMySharedTreeView());
206 02d3a335 Christos Stathis
        if (selectedFolder != null) {
207 02d3a335 Christos Stathis
                    if (!selectedFolder.isInTrash()) {
208 5d18aa82 Christos Stathis
                        if (canWrite && app.getClipboard().hasFiles() && !isMysharedSelected) {
209 43c372e8 Christos Stathis
                                pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.paste()).getHTML() + "&nbsp;Paste</span>", true, new PasteCommand(app, this, selectedFolder));
210 43c372e8 Christos Stathis
                                contextMenu.addItem(pasteItem);
211 02d3a335 Christos Stathis
                        }
212 02d3a335 Christos Stathis
                
213 5d18aa82 Christos Stathis
                        if (canWrite && !isMysharedSelected) {
214 02d3a335 Christos Stathis
                                MenuItem upload = new MenuItem("<span>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(app, this, selectedFolder));
215 02d3a335 Christos Stathis
                                contextMenu.addItem(upload);
216 02d3a335 Christos Stathis
                        }
217 3586ad5e Christos Stathis
                        if (isFolderTreeSelected || isMysharedSelected) {
218 02d3a335 Christos Stathis
                                        cutItem = new MenuItem("<span id='fileContextMenu.cut'>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + "&nbsp;Cut</span>", true, new CutCommand(app, this, selectedFiles));
219 02d3a335 Christos Stathis
                            contextMenu.addItem(cutItem);
220 02d3a335 Christos Stathis
                        }
221 02d3a335 Christos Stathis
                
222 3586ad5e Christos Stathis
                                copyItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + "&nbsp;Copy</span>", true, new CopyCommand(app, this, selectedFiles));
223 3586ad5e Christos Stathis
                        contextMenu.addItem(copyItem);
224 02d3a335 Christos Stathis
                
225 3586ad5e Christos Stathis
                        if (isFolderTreeSelected || isMysharedSelected) {
226 02d3a335 Christos Stathis
                                        trashItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(app, this, selectedFiles));
227 02d3a335 Christos Stathis
                            contextMenu.addItem(trashItem);
228 02d3a335 Christos Stathis
                        }
229 02d3a335 Christos Stathis
                    }
230 02d3a335 Christos Stathis
                    else {
231 02d3a335 Christos Stathis
                                MenuItem restore = new MenuItem("<span>" + AbstractImagePrototype.create(images.versions()).getHTML() + "&nbsp;Restore</span>", true, new RestoreTrashCommand(app, this, selectedFiles));
232 02d3a335 Christos Stathis
                                contextMenu.addItem(restore);
233 02d3a335 Christos Stathis
                    }
234 31477486 Christos Stathis
        }
235 63366925 Christos Stathis
236 3586ad5e Christos Stathis
        if (isFolderTreeSelected || isMysharedSelected) {
237 3ebb88f4 Christos Stathis
                        deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(app, this, selectedFiles, MessagePanel.images));
238 3ebb88f4 Christos Stathis
                contextMenu.addItem(deleteItem);
239 3ebb88f4 Christos Stathis
        }
240 a57faaf0 Christos Stathis
241 02d3a335 Christos Stathis
        if (selectedFolder != null && !selectedFolder.isInTrash()) {
242 5d18aa82 Christos Stathis
                if ((isFolderTreeSelected || isMysharedSelected) && selectedFiles.size() == 1) {
243 9326b841 Christos Stathis
                        contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(app, this, selectedFiles, PropertiesCommand.PROPERTIES)));
244 64d3b76b Christos KK Loverdos
                        contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + "&nbsp;Share</span>", true, new PropertiesCommand(app, this, selectedFiles, PropertiesCommand.PERMISSIONS)));
245 3586ad5e Christos Stathis
                               contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.versions()).getHTML() + "&nbsp;Versions</span>", true, new PropertiesCommand(app, this, selectedFiles, PropertiesCommand.VERSIONS)));
246 9326b841 Christos Stathis
                }
247 63366925 Christos Stathis
248 31477486 Christos Stathis
        }
249 05bb97f8 Christos Stathis
            contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.download()).getHTML() + "&nbsp;Download</span>", true, new Command() {
250 05bb97f8 Christos Stathis
                        
251 05bb97f8 Christos Stathis
                        @Override
252 05bb97f8 Christos Stathis
                        public void execute() {
253 05bb97f8 Christos Stathis
                                for (File f : selectedFiles)
254 cde22209 Christos KK Loverdos
                                        Window.open(app.getApiPath() + f.getOwnerID() + f.getUri(), "_blank", "");
255 05bb97f8 Christos Stathis
                        }
256 05bb97f8 Christos Stathis
                }));
257 390f5c04 Christos Stathis
258 a57faaf0 Christos Stathis
                add(contextMenu);
259 a57faaf0 Christos Stathis
        }
260 a57faaf0 Christos Stathis
}