Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (9.2 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.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.ui.AbstractImagePrototype;
54
import com.google.gwt.user.client.ui.MenuBar;
55
import com.google.gwt.user.client.ui.MenuItem;
56
import com.google.gwt.user.client.ui.PopupPanel;
57

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

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

    
68
        private MenuItem cutItem;
69

    
70
        private MenuItem copyItem;
71

    
72
        private MenuItem pasteItem;
73

    
74
        private MenuItem updateItem;
75

    
76
        private MenuItem sharingItem;
77

    
78
        private MenuItem propItem;
79

    
80
        private MenuItem trashItem;
81

    
82
        private MenuItem deleteItem;
83

    
84
        private MenuItem downloadItem;
85

    
86
        private MenuItem saveAsItem;
87

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
177
        /**
178
         * The widget's constructor.
179
         *
180
         * @param newImages the image bundle passed on by the parent object
181
         */
182
        public FileContextMenu(final Pithos app, Images newImages, Folder selectedFolder, List<File> selectedFiles, boolean isTrash) {
183
                // The popup's constructor's argument is a boolean specifying that it
184
                // auto-close itself when the user clicks outside of it.
185
                super(true);
186
                setAnimationEnabled(true);
187
                images = newImages;
188
        MenuBar contextMenu = new MenuBar(true);
189

    
190
        if (!selectedFolder.isInTrash()) {
191
                if (app.getClipboard().hasFiles()) {
192
                    pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.paste()).getHTML() + "&nbsp;Paste</span>", true, new PasteCommand(app, this, selectedFolder));
193
                    contextMenu.addItem(pasteItem);
194
                }
195

    
196
                MenuItem upload = new MenuItem("<span>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(app, this, selectedFolder));
197
                contextMenu.addItem(upload);
198

    
199
                        cutItem = new MenuItem("<span id='fileContextMenu.cut'>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + "&nbsp;Cut</span>", true, new CutCommand(app, this, selectedFiles));
200
            contextMenu.addItem(cutItem);
201

    
202
                        copyItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + "&nbsp;Copy</span>", true, new CopyCommand(app, this, selectedFiles));
203
            contextMenu.addItem(copyItem);
204

    
205
                        trashItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(app, this, selectedFiles));
206
            contextMenu.addItem(trashItem);
207
        }
208
        else {
209
                        MenuItem restore = new MenuItem("<span>" + AbstractImagePrototype.create(images.versions()).getHTML() + "&nbsp;Restore</span>", true, new RestoreTrashCommand(app, this, selectedFiles));
210
                        contextMenu.addItem(restore);
211
        }
212

    
213
                deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(app, this, selectedFiles, MessagePanel.images));
214
        contextMenu.addItem(deleteItem);
215

    
216
//      MenuItem refresh = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
217
//      contextMenu.addItem(refresh);
218
//                        sharingItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + "&nbsp;Sharing</span>", true, new PropertiesCommand(this, images, 1));
219
//            contextMenu.addItem(sharingItem);
220
        if (!selectedFolder.isInTrash()) {
221
                contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(app, this, selectedFiles, images, 0)));
222

    
223
            if (!selectedFiles.isEmpty())
224
                            contextMenu.addItem(new MenuItem("<span><a class='hidden-link' href='" + app.getApiPath() + app.getUsername() + selectedFiles.get(0).getUri() + "?X-Auth-Token=" + app.getToken() + "' target='_blank'>" + AbstractImagePrototype.create(newImages.download()).getHTML() + " Download</a></span>", true, (Command) null));
225
        }
226
                MenuItem unSelect = new MenuItem("<span>" + AbstractImagePrototype.create(images.unselectAll()).getHTML() + "&nbsp;Unselect</span>", true, new Command() {
227
            @Override
228
            public void execute() {
229
                hide();
230
                app.getFileList().clearSelectedRows();
231
            }
232
        });
233
                contextMenu.addItem(unSelect);
234

    
235
//                }
236
                add(contextMenu);
237
        }
238
}