Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (8.3 kB)

1 a57faaf0 Christos Stathis
/*
2 63366925 Christos Stathis
 * Copyright 2011 GRNET S.A. All rights reserved.
3 63366925 Christos Stathis
 *
4 63366925 Christos Stathis
 * Redistribution and use in source and binary forms, with or
5 63366925 Christos Stathis
 * without modification, are permitted provided that the following
6 63366925 Christos Stathis
 * conditions are met:
7 63366925 Christos Stathis
 *
8 63366925 Christos Stathis
 *   1. Redistributions of source code must retain the above
9 63366925 Christos Stathis
 *      copyright notice, this list of conditions and the following
10 63366925 Christos Stathis
 *      disclaimer.
11 63366925 Christos Stathis
 *
12 63366925 Christos Stathis
 *   2. Redistributions in binary form must reproduce the above
13 63366925 Christos Stathis
 *      copyright notice, this list of conditions and the following
14 63366925 Christos Stathis
 *      disclaimer in the documentation and/or other materials
15 63366925 Christos Stathis
 *      provided with the distribution.
16 63366925 Christos Stathis
 *
17 63366925 Christos Stathis
 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18 63366925 Christos Stathis
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 63366925 Christos Stathis
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 63366925 Christos Stathis
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21 63366925 Christos Stathis
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 63366925 Christos Stathis
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 63366925 Christos Stathis
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24 63366925 Christos Stathis
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 63366925 Christos Stathis
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 63366925 Christos Stathis
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27 63366925 Christos Stathis
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 63366925 Christos Stathis
 * POSSIBILITY OF SUCH DAMAGE.
29 63366925 Christos Stathis
 *
30 63366925 Christos Stathis
 * The views and conclusions contained in the software and
31 63366925 Christos Stathis
 * documentation are those of the authors and should not be
32 63366925 Christos Stathis
 * interpreted as representing official policies, either expressed
33 63366925 Christos Stathis
 * or implied, of GRNET S.A.
34 a57faaf0 Christos Stathis
 */
35 a57faaf0 Christos Stathis
package gr.grnet.pithos.web.client;
36 a57faaf0 Christos Stathis
37 a57faaf0 Christos Stathis
import gr.grnet.pithos.web.client.commands.CopyCommand;
38 a57faaf0 Christos Stathis
import gr.grnet.pithos.web.client.commands.CutCommand;
39 a57faaf0 Christos Stathis
import gr.grnet.pithos.web.client.commands.DeleteCommand;
40 a57faaf0 Christos Stathis
import gr.grnet.pithos.web.client.commands.PasteCommand;
41 a57faaf0 Christos Stathis
import gr.grnet.pithos.web.client.commands.PropertiesCommand;
42 a57faaf0 Christos Stathis
import gr.grnet.pithos.web.client.commands.RefreshCommand;
43 a57faaf0 Christos Stathis
import gr.grnet.pithos.web.client.commands.RestoreTrashCommand;
44 a57faaf0 Christos Stathis
import gr.grnet.pithos.web.client.commands.ToTrashCommand;
45 a57faaf0 Christos Stathis
import gr.grnet.pithos.web.client.commands.UploadFileCommand;
46 d4374639 Christos Stathis
import gr.grnet.pithos.web.client.foldertree.File;
47 63366925 Christos Stathis
import gr.grnet.pithos.web.client.foldertree.Folder;
48 a57faaf0 Christos Stathis
import gr.grnet.pithos.web.client.rest.resource.FileResource;
49 a57faaf0 Christos Stathis
import gr.grnet.pithos.web.client.rest.resource.FolderResource;
50 a57faaf0 Christos Stathis
import gr.grnet.pithos.web.client.rest.resource.RestResource;
51 a57faaf0 Christos Stathis
import gr.grnet.pithos.web.client.rest.resource.RestResourceWrapper;
52 a57faaf0 Christos Stathis
import gr.grnet.pithos.web.client.rest.resource.TrashFolderResource;
53 a57faaf0 Christos Stathis
54 a57faaf0 Christos Stathis
import java.util.List;
55 a57faaf0 Christos Stathis
56 a57faaf0 Christos Stathis
import com.google.gwt.event.dom.client.ClickEvent;
57 a57faaf0 Christos Stathis
import com.google.gwt.event.dom.client.ClickHandler;
58 a57faaf0 Christos Stathis
import com.google.gwt.event.dom.client.ContextMenuEvent;
59 a57faaf0 Christos Stathis
import com.google.gwt.resources.client.ClientBundle;
60 a57faaf0 Christos Stathis
import com.google.gwt.resources.client.ImageResource;
61 a57faaf0 Christos Stathis
import com.google.gwt.user.client.Command;
62 a57faaf0 Christos Stathis
import com.google.gwt.user.client.Event;
63 a57faaf0 Christos Stathis
import com.google.gwt.user.client.ui.AbstractImagePrototype;
64 a57faaf0 Christos Stathis
import com.google.gwt.user.client.ui.MenuBar;
65 a57faaf0 Christos Stathis
import com.google.gwt.user.client.ui.MenuItem;
66 a57faaf0 Christos Stathis
import com.google.gwt.user.client.ui.PopupPanel;
67 a57faaf0 Christos Stathis
68 a57faaf0 Christos Stathis
/**
69 a57faaf0 Christos Stathis
 * The 'File Context' menu implementation.
70 a57faaf0 Christos Stathis
 */
71 63366925 Christos Stathis
public class FileContextMenu extends PopupPanel {
72 a57faaf0 Christos Stathis
73 a57faaf0 Christos Stathis
        /**
74 a57faaf0 Christos Stathis
         * The widget's images.
75 a57faaf0 Christos Stathis
         */
76 a57faaf0 Christos Stathis
        private final Images images;
77 a57faaf0 Christos Stathis
78 a57faaf0 Christos Stathis
        private MenuItem cutItem;
79 a57faaf0 Christos Stathis
80 a57faaf0 Christos Stathis
        private MenuItem copyItem;
81 a57faaf0 Christos Stathis
82 a57faaf0 Christos Stathis
        private MenuItem pasteItem;
83 a57faaf0 Christos Stathis
84 a57faaf0 Christos Stathis
        private MenuItem updateItem;
85 a57faaf0 Christos Stathis
86 a57faaf0 Christos Stathis
        private MenuItem sharingItem;
87 a57faaf0 Christos Stathis
88 a57faaf0 Christos Stathis
        private MenuItem propItem;
89 a57faaf0 Christos Stathis
90 a57faaf0 Christos Stathis
        private MenuItem trashItem;
91 a57faaf0 Christos Stathis
92 a57faaf0 Christos Stathis
        private MenuItem deleteItem;
93 a57faaf0 Christos Stathis
94 a57faaf0 Christos Stathis
        private MenuItem downloadItem;
95 a57faaf0 Christos Stathis
96 a57faaf0 Christos Stathis
        private MenuItem saveAsItem;
97 a57faaf0 Christos Stathis
98 a57faaf0 Christos Stathis
        /**
99 a57faaf0 Christos Stathis
         * The image bundle for this widget's images that reuses images defined in
100 a57faaf0 Christos Stathis
         * other menus.
101 a57faaf0 Christos Stathis
         */
102 a57faaf0 Christos Stathis
        public interface Images extends ClientBundle,FileMenu.Images, EditMenu.Images {
103 a57faaf0 Christos Stathis
104 a57faaf0 Christos Stathis
                @Source("gr/grnet/pithos/resources/mimetypes/document.png")
105 a57faaf0 Christos Stathis
                ImageResource fileContextMenu();
106 a57faaf0 Christos Stathis
107 a57faaf0 Christos Stathis
                @Source("gr/grnet/pithos/resources/doc_versions.png")
108 a57faaf0 Christos Stathis
                ImageResource versions();
109 a57faaf0 Christos Stathis
110 a57faaf0 Christos Stathis
                @Override
111 a57faaf0 Christos Stathis
                @Source("gr/grnet/pithos/resources/group.png")
112 a57faaf0 Christos Stathis
                ImageResource sharing();
113 a57faaf0 Christos Stathis
114 a57faaf0 Christos Stathis
                @Override
115 a57faaf0 Christos Stathis
                @Source("gr/grnet/pithos/resources/border_remove.png")
116 a57faaf0 Christos Stathis
                ImageResource unselectAll();
117 a57faaf0 Christos Stathis
118 a57faaf0 Christos Stathis
                @Source("gr/grnet/pithos/resources/demo.png")
119 a57faaf0 Christos Stathis
                ImageResource viewImage();
120 a57faaf0 Christos Stathis
}
121 a57faaf0 Christos Stathis
122 a57faaf0 Christos Stathis
        public static native String getDate()/*-{
123 a57faaf0 Christos Stathis
                return (new Date()).toUTCString();
124 a57faaf0 Christos Stathis
        }-*/;
125 a57faaf0 Christos Stathis
126 a57faaf0 Christos Stathis
        /**
127 a57faaf0 Christos Stathis
         * The widget's constructor.
128 a57faaf0 Christos Stathis
         *
129 a57faaf0 Christos Stathis
         * @param newImages the image bundle passed on by the parent object
130 a57faaf0 Christos Stathis
         */
131 d4374639 Christos Stathis
        public FileContextMenu(Images newImages, Folder selectedFolder, List<File> selectedFiles, boolean isTrash) {
132 a57faaf0 Christos Stathis
                // The popup's constructor's argument is a boolean specifying that it
133 a57faaf0 Christos Stathis
                // auto-close itself when the user clicks outside of it.
134 a57faaf0 Christos Stathis
                super(true);
135 a57faaf0 Christos Stathis
                GSS gss = GSS.get();
136 a57faaf0 Christos Stathis
                setAnimationEnabled(true);
137 a57faaf0 Christos Stathis
                images = newImages;
138 63366925 Christos Stathis
        MenuBar contextMenu = new MenuBar(true);
139 a57faaf0 Christos Stathis
140 390f5c04 Christos Stathis
        if (GSS.get().getClipboard().hasFiles()) {
141 390f5c04 Christos Stathis
            pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(images.paste()).getHTML() + "&nbsp;Paste</span>", true, new PasteCommand(GSS.get(), this, selectedFolder));
142 390f5c04 Christos Stathis
            contextMenu.addItem(pasteItem);
143 390f5c04 Christos Stathis
        }
144 390f5c04 Christos Stathis
145 390f5c04 Christos Stathis
//        MenuItem upload = new MenuItem("<span>" + AbstractImagePrototype.create(images.fileUpdate()).getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this, selectedFolder));
146 390f5c04 Christos Stathis
//        contextMenu.addItem(upload);
147 390f5c04 Christos Stathis
148 390f5c04 Christos Stathis
//        MenuItem refresh = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
149 390f5c04 Christos Stathis
//        contextMenu.addItem(refresh);
150 390f5c04 Christos Stathis
151 390f5c04 Christos Stathis
//                if (isTrash) {
152 390f5c04 Christos Stathis
//                        MenuItem restore = new MenuItem("<span>" + AbstractImagePrototype.create(images.versions()).getHTML() + "&nbsp;Restore</span>", true, new RestoreTrashCommand(this));
153 390f5c04 Christos Stathis
//                        contextMenu.addItem(restore);
154 390f5c04 Christos Stathis
//
155 390f5c04 Christos Stathis
//                        MenuItem delete = new MenuItem("<span>" + AbstractImagePrototype.create(images.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, null, images));
156 390f5c04 Christos Stathis
//                        contextMenu.addItem(delete);
157 390f5c04 Christos Stathis
//                } else {
158 1e413f9b Christos Stathis
                        cutItem = new MenuItem("<span id='fileContextMenu.cut'>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + "&nbsp;Cut</span>", true, new CutCommand(GSS.get(), this, selectedFiles));
159 63366925 Christos Stathis
            contextMenu.addItem(cutItem);
160 63366925 Christos Stathis
161 1e413f9b Christos Stathis
                        copyItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + "&nbsp;Copy</span>", true, new CopyCommand(GSS.get(), this, selectedFiles));
162 63366925 Christos Stathis
            contextMenu.addItem(copyItem);
163 63366925 Christos Stathis
164 81918908 Christos Stathis
                        trashItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(GSS.get(), this, selectedFiles));
165 63366925 Christos Stathis
            contextMenu.addItem(trashItem);
166 63366925 Christos Stathis
167 d4374639 Christos Stathis
                        deleteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, selectedFiles, images));
168 63366925 Christos Stathis
            contextMenu.addItem(deleteItem);
169 a57faaf0 Christos Stathis
170 390f5c04 Christos Stathis
//                        sharingItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + "&nbsp;Sharing</span>", true, new PropertiesCommand(this, images, 1));
171 390f5c04 Christos Stathis
//            contextMenu.addItem(sharingItem);
172 63366925 Christos Stathis
173 390f5c04 Christos Stathis
//                        propItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(this, images, 0));
174 390f5c04 Christos Stathis
//            contextMenu.addItem(propItem);
175 63366925 Christos Stathis
176 390f5c04 Christos Stathis
//                        downloadItem = 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(newImages.download()).getHTML() + " Download</a></span>", true, new Command() {
177 390f5c04 Christos Stathis
//                @Override
178 390f5c04 Christos Stathis
//                public void execute() {
179 390f5c04 Christos Stathis
//                }
180 390f5c04 Christos Stathis
//            });
181 390f5c04 Christos Stathis
//                        contextMenu.addItem(downloadItem);
182 a57faaf0 Christos Stathis
                        
183 390f5c04 Christos Stathis
//            final Command unselectAllCommand = new Command() {
184 390f5c04 Christos Stathis
//
185 390f5c04 Christos Stathis
//                @Override
186 390f5c04 Christos Stathis
//                public void execute() {
187 390f5c04 Christos Stathis
//                    hide();
188 390f5c04 Christos Stathis
//                    if(GSS.get().isFileListShowing())
189 390f5c04 Christos Stathis
//                        GSS.get().getFileList().clearSelectedRows();
190 390f5c04 Christos Stathis
//                }
191 390f5c04 Christos Stathis
//            };
192 390f5c04 Christos Stathis
//                        MenuItem unSelect = new MenuItem("<span>" + AbstractImagePrototype.create(images.unselectAll()).getHTML() + "&nbsp;Unselect</span>", true, unselectAllCommand);
193 390f5c04 Christos Stathis
//                        contextMenu.addItem(unSelect);
194 390f5c04 Christos Stathis
195 390f5c04 Christos Stathis
//                }
196 a57faaf0 Christos Stathis
                add(contextMenu);
197 a57faaf0 Christos Stathis
        }
198 a57faaf0 Christos Stathis
}