Removed all static references to the Pithos class
[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(final Pithos app, 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                 setAnimationEnabled(true);
125                 images = newImages;
126         MenuBar contextMenu = new MenuBar(true);
127
128         if (app.getClipboard().hasFiles()) {
129             pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.paste()).getHTML() + "&nbsp;Paste</span>", true, new PasteCommand(app, this, selectedFolder));
130             contextMenu.addItem(pasteItem);
131         }
132
133         MenuItem upload = new MenuItem("<span>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(app, this, selectedFolder));
134         contextMenu.addItem(upload);
135
136 //        MenuItem refresh = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
137 //        contextMenu.addItem(refresh);
138
139 //              if (isTrash) {
140 //                      MenuItem restore = new MenuItem("<span>" + AbstractImagePrototype.create(images.versions()).getHTML() + "&nbsp;Restore</span>", true, new RestoreTrashCommand(this));
141 //                      contextMenu.addItem(restore);
142 //
143 //                      MenuItem delete = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, null, images));
144 //                      contextMenu.addItem(delete);
145 //              } else {
146                         cutItem = new MenuItem("<span id='fileContextMenu.cut'>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + "&nbsp;Cut</span>", true, new CutCommand(app, this, selectedFiles));
147             contextMenu.addItem(cutItem);
148
149                         copyItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + "&nbsp;Copy</span>", true, new CopyCommand(app, this, selectedFiles));
150             contextMenu.addItem(copyItem);
151
152                         trashItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(app, this, selectedFiles));
153             contextMenu.addItem(trashItem);
154
155                         deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(app, this, selectedFiles, images));
156             contextMenu.addItem(deleteItem);
157
158 //                      sharingItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + "&nbsp;Sharing</span>", true, new PropertiesCommand(this, images, 1));
159 //            contextMenu.addItem(sharingItem);
160
161             contextMenu.addItem(new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(app, this, selectedFiles, images, 0)));
162
163             if (!selectedFiles.isEmpty())
164                             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));
165
166                         MenuItem unSelect = new MenuItem("<span>" + AbstractImagePrototype.create(images.unselectAll()).getHTML() + "&nbsp;Unselect</span>", true, new Command() {
167                 @Override
168                 public void execute() {
169                     hide();
170                     app.getFileList().clearSelectedRows();
171                 }
172             });
173                         contextMenu.addItem(unSelect);
174
175 //              }
176                 add(contextMenu);
177         }
178 }