a515180fc873560c96f2473e9bcd654688320a50
[pithos] / web_client / src / gr / grnet / pithos / web / client / FileMenu.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.EmptyTrashCommand;
38 import gr.grnet.pithos.web.client.commands.NewFolderCommand;
39 import gr.grnet.pithos.web.client.commands.PropertiesCommand;
40 import gr.grnet.pithos.web.client.commands.RefreshCommand;
41 import gr.grnet.pithos.web.client.commands.UploadFileCommand;
42 import gr.grnet.pithos.web.client.foldertree.File;
43 import gr.grnet.pithos.web.client.foldertree.Folder;
44 import gr.grnet.pithos.web.client.rest.resource.FileResource;
45
46 import java.util.List;
47
48 import com.google.gwt.event.dom.client.ClickEvent;
49 import com.google.gwt.event.dom.client.ClickHandler;
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
57 /**
58  * The 'File' menu implementation.
59  */
60 public class FileMenu extends MenuBar {
61
62         /**
63          * The widget's images.
64          */
65         private final Images images;
66
67         /**
68          * An image bundle for this widgets images.
69          */
70         public interface Images extends ClientBundle,FilePropertiesDialog.Images {
71
72                 @Source("gr/grnet/pithos/resources/folder_new.png")
73                 ImageResource folderNew();
74
75                 @Source("gr/grnet/pithos/resources/folder_outbox.png")
76                 ImageResource fileUpdate();
77
78                 @Source("gr/grnet/pithos/resources/view_text.png")
79                 ImageResource viewText();
80
81                 @Override
82                 @Source("gr/grnet/pithos/resources/folder_inbox.png")
83                 ImageResource download();
84
85                 @Source("gr/grnet/pithos/resources/trashcan_empty.png")
86                 ImageResource emptyTrash();
87
88                 @Source("gr/grnet/pithos/resources/internet.png")
89                 ImageResource sharing();
90
91                 @Source("gr/grnet/pithos/resources/refresh.png")
92                 ImageResource refresh();
93
94         @Source("gr/grnet/pithos/resources/")
95         ImageResource unselectAll();
96     }
97
98         /**
99          * The widget's constructor.
100          *
101          * @param _images the image bundle passed on by the parent object
102          */
103         public FileMenu(GSS _app, final Images _images) {
104         super(true);
105                 setAnimationEnabled(true);
106                 images = _images;
107
108         Folder selectedFolder = _app.getFolderTreeView().getSelection();
109         List<File> selectedFiles = _app.getFileList().getSelectedFiles();
110         if (selectedFolder != null) {
111                     MenuItem newFolderItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.folderNew()).getHTML() + "&nbsp;New Folder</span>", true, new NewFolderCommand(null, selectedFolder, images));
112                     addItem(newFolderItem);
113
114             MenuItem uploadItem = new MenuItem("<span id='topMenu.file.upload'>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(null, selectedFolder));
115             addItem(uploadItem);
116         }
117         if (selectedFiles.size() == 1) {
118             addItem(new MenuItem("<span><a class='hidden-link' href='" + GSS.get().getApiPath() + GSS.get().getUsername() + selectedFiles.get(0).getUri() + "?X-Auth-Token=" + GSS.get().getToken() + "' target='_blank'>" + AbstractImagePrototype.create(images.download()).getHTML() + " Download</a></span>", true, (Command) null));
119         }
120
121 //        MenuItem emptyTrashItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.emptyTrash()).getHTML() + "&nbsp;Empty Trash</span>", true, new EmptyTrashCommand(this));
122 //        emptyTrashItem.getElement().setId("topMenu.file.emptyTrash");
123 //        contextMenu.addItem(emptyTrashItem);
124
125 //        MenuItem refreshItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
126 //        refreshItem.getElement().setId("topMenu.file.refresh");
127 //        contextMenu.addItem(refreshItem);
128
129 //        MenuItem sharingItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.sharing()).getHTML() + "&nbsp;Sharing</span>", true, new PropertiesCommand(this, images, 1));
130 //        sharingItem.getElement().setId("topMenu.file.sharing");
131 //        contextMenu.addItem(sharingItem)
132 //                       .setVisible(propertiesVisible);
133 //
134 //        MenuItem propertiesItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(this, images, 0));
135 //        propertiesItem.getElement().setId("topMenu.file.properties");
136 //        contextMenu.addItem(propertiesItem)
137 //                       .setVisible(propertiesVisible);
138         }
139 }