Renamed various GSS references to Pithos
[pithos-web-client] / src / gr / grnet / pithos / web / client / FileContextMenu.java
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,FileMenu.Images, EditMenu.Images {
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                 @Override
100                 @Source("gr/grnet/pithos/resources/group.png")
101                 ImageResource sharing();
102
103                 @Override
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
111         public static native String getDate()/*-{
112                 return (new Date()).toUTCString();
113         }-*/;
114
115         /**
116          * The widget's constructor.
117          *
118          * @param newImages the image bundle passed on by the parent object
119          */
120         public FileContextMenu(Images newImages, Folder selectedFolder, List<File> selectedFiles, boolean isTrash) {
121                 // The popup's constructor's argument is a boolean specifying that it
122                 // auto-close itself when the user clicks outside of it.
123                 super(true);
124                 Pithos gss = Pithos.get();
125                 setAnimationEnabled(true);
126                 images = newImages;
127         MenuBar contextMenu = new MenuBar(true);
128
129         if (Pithos.get().getClipboard().hasFiles()) {
130             pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.paste()).getHTML() + "&nbsp;Paste</span>", true, new PasteCommand(Pithos.get(), this, selectedFolder));
131             contextMenu.addItem(pasteItem);
132         }
133
134         MenuItem upload = new MenuItem("<span>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this, selectedFolder));
135         contextMenu.addItem(upload);
136
137 //        MenuItem refresh = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
138 //        contextMenu.addItem(refresh);
139
140 //              if (isTrash) {
141 //                      MenuItem restore = new MenuItem("<span>" + AbstractImagePrototype.create(images.versions()).getHTML() + "&nbsp;Restore</span>", true, new RestoreTrashCommand(this));
142 //                      contextMenu.addItem(restore);
143 //
144 //                      MenuItem delete = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, null, images));
145 //                      contextMenu.addItem(delete);
146 //              } else {
147                         cutItem = new MenuItem("<span id='fileContextMenu.cut'>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + "&nbsp;Cut</span>", true, new CutCommand(Pithos.get(), this, selectedFiles));
148             contextMenu.addItem(cutItem);
149
150                         copyItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + "&nbsp;Copy</span>", true, new CopyCommand(Pithos.get(), this, selectedFiles));
151             contextMenu.addItem(copyItem);
152
153                         trashItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(Pithos.get(), this, selectedFiles));
154             contextMenu.addItem(trashItem);
155
156                         deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, selectedFiles, images));
157             contextMenu.addItem(deleteItem);
158
159 //                      sharingItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + "&nbsp;Sharing</span>", true, new PropertiesCommand(this, images, 1));
160 //            contextMenu.addItem(sharingItem);
161
162             contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(Pithos.get(), this, selectedFiles, images, 0)));
163
164             if (!selectedFiles.isEmpty())
165                             contextMenu.addItem(new MenuItem("<span><a class='hidden-link' href='" + Pithos.get().getApiPath() + Pithos.get().getUsername() + selectedFiles.get(0).getUri() + "?X-Auth-Token=" + Pithos.get().getToken() + "' target='_blank'>" + AbstractImagePrototype.create(newImages.download()).getHTML() + " Download</a></span>", true, (Command) null));
166
167                         MenuItem unSelect = new MenuItem("<span>" + AbstractImagePrototype.create(images.unselectAll()).getHTML() + "&nbsp;Unselect</span>", true, new Command() {
168                 @Override
169                 public void execute() {
170                     hide();
171                     Pithos.get().getFileList().clearSelectedRows();
172                 }
173             });
174                         contextMenu.addItem(unSelect);
175
176 //              }
177                 add(contextMenu);
178         }
179 }