Statistics
| Branch: | Tag: | Revision:

root / web_client / src / gr / grnet / pithos / web / client / FileContextMenu.java @ 816de19f

History | View | Annotate | Download (8.6 kB)

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