Statistics
| Branch: | Tag: | Revision:

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

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.ToTrashCommand;
43
import gr.grnet.pithos.web.client.commands.UploadFileCommand;
44
import gr.grnet.pithos.web.client.foldertree.File;
45
import gr.grnet.pithos.web.client.foldertree.Folder;
46

    
47
import java.util.List;
48

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

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

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

    
67
        private MenuItem cutItem;
68

    
69
        private MenuItem copyItem;
70

    
71
        private MenuItem pasteItem;
72

    
73
        private MenuItem updateItem;
74

    
75
        private MenuItem sharingItem;
76

    
77
        private MenuItem propItem;
78

    
79
        private MenuItem trashItem;
80

    
81
        private MenuItem deleteItem;
82

    
83
        private MenuItem downloadItem;
84

    
85
        private MenuItem saveAsItem;
86

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
197
//        MenuItem refresh = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
198
//        contextMenu.addItem(refresh);
199

    
200
//                if (isTrash) {
201
//                        MenuItem restore = new MenuItem("<span>" + AbstractImagePrototype.create(images.versions()).getHTML() + "&nbsp;Restore</span>", true, new RestoreTrashCommand(this));
202
//                        contextMenu.addItem(restore);
203
//
204
//                        MenuItem delete = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, null, images));
205
//                        contextMenu.addItem(delete);
206
//                } else {
207
                        cutItem = new MenuItem("<span id='fileContextMenu.cut'>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + "&nbsp;Cut</span>", true, new CutCommand(app, this, selectedFiles));
208
            contextMenu.addItem(cutItem);
209

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

    
213
                        trashItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(app, this, selectedFiles));
214
            contextMenu.addItem(trashItem);
215

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

    
219
//                        sharingItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + "&nbsp;Sharing</span>", true, new PropertiesCommand(this, images, 1));
220
//            contextMenu.addItem(sharingItem);
221

    
222
            contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(app, this, selectedFiles, images, 0)));
223

    
224
            if (!selectedFiles.isEmpty())
225
                            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));
226

    
227
                        MenuItem unSelect = new MenuItem("<span>" + AbstractImagePrototype.create(images.unselectAll()).getHTML() + "&nbsp;Unselect</span>", true, new Command() {
228
                @Override
229
                public void execute() {
230
                    hide();
231
                    app.getFileList().clearSelectedRows();
232
                }
233
            });
234
                        contextMenu.addItem(unSelect);
235

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