Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (8.5 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.RefreshCommand;
43
import gr.grnet.pithos.web.client.commands.RestoreTrashCommand;
44
import gr.grnet.pithos.web.client.commands.ToTrashCommand;
45
import gr.grnet.pithos.web.client.commands.UploadFileCommand;
46
import gr.grnet.pithos.web.client.foldertree.Folder;
47
import gr.grnet.pithos.web.client.rest.resource.FileResource;
48
import gr.grnet.pithos.web.client.rest.resource.FolderResource;
49
import gr.grnet.pithos.web.client.rest.resource.RestResource;
50
import gr.grnet.pithos.web.client.rest.resource.RestResourceWrapper;
51
import gr.grnet.pithos.web.client.rest.resource.TrashFolderResource;
52

    
53
import java.util.List;
54

    
55
import com.google.gwt.event.dom.client.ClickEvent;
56
import com.google.gwt.event.dom.client.ClickHandler;
57
import com.google.gwt.event.dom.client.ContextMenuEvent;
58
import com.google.gwt.resources.client.ClientBundle;
59
import com.google.gwt.resources.client.ImageResource;
60
import com.google.gwt.user.client.Command;
61
import com.google.gwt.user.client.Event;
62
import com.google.gwt.user.client.ui.AbstractImagePrototype;
63
import com.google.gwt.user.client.ui.MenuBar;
64
import com.google.gwt.user.client.ui.MenuItem;
65
import com.google.gwt.user.client.ui.PopupPanel;
66

    
67
/**
68
 * The 'File Context' menu implementation.
69
 */
70
public class FileContextMenu extends PopupPanel {
71

    
72
        /**
73
         * The widget's images.
74
         */
75
        private final Images images;
76

    
77
        private MenuItem cutItem;
78

    
79
        private MenuItem copyItem;
80

    
81
        private MenuItem pasteItem;
82

    
83
        private MenuItem updateItem;
84

    
85
        private MenuItem sharingItem;
86

    
87
        private MenuItem propItem;
88

    
89
        private MenuItem trashItem;
90

    
91
        private MenuItem deleteItem;
92

    
93
        private MenuItem downloadItem;
94

    
95
        private MenuItem saveAsItem;
96

    
97
        /**
98
         * The image bundle for this widget's images that reuses images defined in
99
         * other menus.
100
         */
101
        public interface Images extends ClientBundle,FileMenu.Images, EditMenu.Images {
102

    
103
                @Source("gr/grnet/pithos/resources/mimetypes/document.png")
104
                ImageResource fileContextMenu();
105

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

    
109
                @Override
110
                @Source("gr/grnet/pithos/resources/group.png")
111
                ImageResource sharing();
112

    
113
                @Override
114
                @Source("gr/grnet/pithos/resources/border_remove.png")
115
                ImageResource unselectAll();
116

    
117
                @Source("gr/grnet/pithos/resources/demo.png")
118
                ImageResource viewImage();
119
}
120

    
121
        public static native String getDate()/*-{
122
                return (new Date()).toUTCString();
123
        }-*/;
124

    
125
        /**
126
         * The widget's constructor.
127
         *
128
         * @param newImages the image bundle passed on by the parent object
129
         */
130
        public FileContextMenu(Images newImages, Folder selectedFolder, boolean isTrash) {
131
                // The popup's constructor's argument is a boolean specifying that it
132
                // auto-close itself when the user clicks outside of it.
133
                super(true);
134
                GSS gss = GSS.get();
135
                setAnimationEnabled(true);
136
                images = newImages;
137
        MenuBar contextMenu = new MenuBar(true);
138

    
139
                pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.paste()).getHTML() + "&nbsp;Paste</span>", true, new PasteCommand(this));
140
        contextMenu.addItem(pasteItem);
141

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

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

    
148
                if (isTrash) {
149
                        MenuItem restore = new MenuItem("<span>" + AbstractImagePrototype.create(images.versions()).getHTML() + "&nbsp;Restore</span>", true, new RestoreTrashCommand(this));
150
                        contextMenu.addItem(restore);
151

    
152
                        MenuItem delete = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, null, images));
153
                        contextMenu.addItem(delete);
154
                } else {
155
                        cutItem = new MenuItem("<span id='fileContextMenu.cut'>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + "&nbsp;Cut</span>", true, new CutCommand(this));
156
            contextMenu.addItem(cutItem);
157

    
158
                        copyItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + "&nbsp;Copy</span>", true, new CopyCommand(this));
159
            contextMenu.addItem(copyItem);
160

    
161
                        trashItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(this));
162
            contextMenu.addItem(trashItem);
163

    
164
                        deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, null, images));
165
            contextMenu.addItem(deleteItem);
166

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

    
170
                        propItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(this, images, 0));
171
            contextMenu.addItem(propItem);
172

    
173

    
174
                        String[] link = {"", ""};
175
                        gss.getTopPanel().getFileMenu().createDownloadLink(link, false);
176
                // The command that does some validation before downloading a file.
177
            Command downloadCmd = new Command() {
178

    
179
                @Override
180
                public void execute() {
181
                    hide();
182
                    GSS.get().getTopPanel().getFileMenu().preDownloadCheck();
183
                }
184
            };
185
                        downloadItem = new MenuItem("<span>" + link[0] + AbstractImagePrototype.create(newImages.download()).getHTML() + " Download" + link[1] + "</span>", true, downloadCmd);
186
                        contextMenu.addItem(downloadItem);
187
                        
188
                        gss.getTopPanel().getFileMenu().createDownloadLink(link, true);
189
                        saveAsItem = new MenuItem("<span>" + link[0] + AbstractImagePrototype.create(newImages.download()).getHTML() + " Save As" + link[1] + "</span>", true, downloadCmd);
190
                        contextMenu.addItem(saveAsItem);
191

    
192
            final Command unselectAllCommand = new Command() {
193

    
194
                @Override
195
                public void execute() {
196
                    hide();
197
                    if(GSS.get().isFileListShowing())
198
                        GSS.get().getFileList().clearSelectedRows();
199
                }
200
            };
201
                        MenuItem unSelect = new MenuItem("<span>" + AbstractImagePrototype.create(images.unselectAll()).getHTML() + "&nbsp;Unselect</span>", true, unselectAllCommand);
202
                        contextMenu.addItem(unSelect);
203

    
204
                }
205
                add(contextMenu);
206

    
207
//                if (gss.getClipboard().hasFileItem())
208
//                        pasteItem.setVisible(true);
209
//                else
210
//                        pasteItem.setVisible(false);
211
        }
212
}