2 * Copyright 2007, 2008, 2009 Electronic Business Systems Ltd.
4 * This file is part of GSS.
6 * GSS is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GSS is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GSS. If not, see <http://www.gnu.org/licenses/>.
19 package gr.ebs.gss.client;
21 import gr.ebs.gss.client.commands.CopyCommand;
22 import gr.ebs.gss.client.commands.CutCommand;
23 import gr.ebs.gss.client.commands.DeleteCommand;
24 import gr.ebs.gss.client.commands.EmptyTrashCommand;
25 import gr.ebs.gss.client.commands.NewFolderCommand;
26 import gr.ebs.gss.client.commands.PasteCommand;
27 import gr.ebs.gss.client.commands.PropertiesCommand;
28 import gr.ebs.gss.client.commands.RefreshCommand;
29 import gr.ebs.gss.client.commands.RestoreTrashCommand;
30 import gr.ebs.gss.client.commands.ToTrashCommand;
31 import gr.ebs.gss.client.commands.UploadFileCommand;
32 import gr.ebs.gss.client.rest.resource.MyFolderResource;
33 import gr.ebs.gss.client.rest.resource.OtherUserResource;
34 import gr.ebs.gss.client.rest.resource.OthersFolderResource;
35 import gr.ebs.gss.client.rest.resource.OthersResource;
36 import gr.ebs.gss.client.rest.resource.RestResource;
37 import gr.ebs.gss.client.rest.resource.SharedFolderResource;
38 import gr.ebs.gss.client.rest.resource.SharedResource;
39 import gr.ebs.gss.client.rest.resource.TrashFolderResource;
40 import gr.ebs.gss.client.rest.resource.TrashResource;
42 import com.google.gwt.resources.client.ClientBundle;
43 import com.google.gwt.user.client.ui.AbstractImagePrototype;
44 import com.google.gwt.user.client.ui.MenuBar;
45 import com.google.gwt.user.client.ui.MenuItem;
46 import com.google.gwt.user.client.ui.PopupPanel;
49 * The 'Folder Context' menu implementation.
51 public class FolderContextMenu extends PopupPanel {
54 * The widget's images.
56 private final Images images;
59 * The image bundle for this widget's images that reuses images defined in
62 public interface Images extends ClientBundle,FileMenu.Images, EditMenu.Images {
65 private MenuItem pasteItem;
68 * The widget's constructor.
70 * @param newImages the image bundle passed on by the parent object
72 public FolderContextMenu(final Images newImages) {
73 // The popup's constructor's argument is a boolean specifying that it
74 // auto-close itself when the user clicks outside of it.
76 setAnimationEnabled(true);
79 pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.paste()).getHTML() + " Paste</span>", true, new PasteCommand(this));
80 pasteItem.getElement().setId("folderContextMenu.paste");
81 MenuBar contextMenu = new MenuBar(true);
85 RestResource selectedItem = GSS.get().getTreeView().getSelection();
88 if(selectedItem != null)
89 if(selectedItem instanceof MyFolderResource){
90 MenuItem newFolder = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.folderNew()).getHTML() + " New Folder</span>", true, new NewFolderCommand(this, images));
91 newFolder.getElement().setId("folderContextMenu.newFolder");
92 contextMenu.addItem(newFolder);
94 MenuItem upload = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this));
95 upload.getElement().setId("folderContextMenu.upload");
96 contextMenu.addItem(upload);
98 boolean notRootFolder = !GSS.get().getTreeView().getMyFolders().equals(selectedItem);
100 // do not show the copy & cut option for the user's root folder
101 MenuItem cut = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + " Cut</span>", true, new CutCommand(this));
102 cut.getElement().setId("folderContextMenu.cut");
103 contextMenu.addItem(cut);
105 MenuItem copy = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + " Copy</span>", true, new CopyCommand(this));
106 copy.getElement().setId("folderContextMenu.copy");
107 contextMenu.addItem(copy);
110 contextMenu.addItem(pasteItem);
112 // do not show delete options for the user's root folder
113 MenuItem moveToTrash = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + " Move to Trash</span>", true, new ToTrashCommand(this));
114 moveToTrash.getElement().setId("folderContextMenu.moveToTrash");
115 contextMenu.addItem(moveToTrash);
117 MenuItem delete = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, newImages));
118 delete.getElement().setId("folderContextMenu.delete");
119 contextMenu.addItem(delete);
122 MenuItem refresh = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images));
123 refresh.getElement().setId("folderContextMenu.refresh");
124 contextMenu.addItem(refresh);
126 MenuItem sharing = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + " Sharing</span>", true, new PropertiesCommand(this, newImages, 1));
127 sharing.getElement().setId("folderContextMenu.sharing");
128 contextMenu.addItem(sharing);
130 MenuItem properties = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Properties</span>", true, new PropertiesCommand(this, newImages, 0));
131 properties.getElement().setId("folderContextMenu.properties");
132 contextMenu.addItem(properties);
135 if(selectedItem instanceof SharedFolderResource){
136 MenuItem newFolder = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.folderNew()).getHTML() + " New Folder</span>", true, new NewFolderCommand(this, images));
137 newFolder.getElement().setId("folderContextMenu.newFolder");
138 contextMenu.addItem(newFolder);
140 MenuItem upload = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this));
141 upload.getElement().setId("folderContextMenu.upload");
142 contextMenu.addItem(upload);
144 MenuItem cut = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + " Cut</span>", true, new CutCommand(this));
145 cut.getElement().setId("folderContextMenu.cut");
146 contextMenu.addItem(cut);
148 MenuItem copy = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + " Copy</span>", true, new CopyCommand(this));
149 copy.getElement().setId("folderContextMenu.copy");
150 contextMenu.addItem(copy);
152 contextMenu.addItem(pasteItem);
154 MenuItem moveToTrash = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + " Move to Trash</span>", true, new ToTrashCommand(this));
155 moveToTrash.getElement().setId("folderContextMenu.moveToTrash");
156 contextMenu.addItem(moveToTrash);
158 MenuItem delete = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, newImages));
159 delete.getElement().setId("folderContextMenu.delete");
160 contextMenu.addItem(delete);
162 MenuItem refresh = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images));
163 refresh.getElement().setId("folderContextMenu.refresh");
164 contextMenu.addItem(refresh);
166 MenuItem sharing = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + " Sharing</span>", true, new PropertiesCommand(this, newImages, 1));
167 sharing.getElement().setId("folderContextMenu.sharing");
168 contextMenu.addItem(sharing);
170 MenuItem properties = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Properties</span>", true, new PropertiesCommand(this, newImages, 0));
171 properties.getElement().setId("folderContextMenu.properties");
172 contextMenu.addItem(properties);
175 if(selectedItem instanceof TrashFolderResource){
176 MenuItem restore = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Restore folder and contents</span>", true, new RestoreTrashCommand(this));
177 restore.getElement().setId("folderContextMenu.restore");
178 contextMenu.addItem(restore);
180 MenuItem delete = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, newImages));
181 delete.getElement().setId("folderContextMenu.delete");
182 contextMenu.addItem(delete);
184 MenuItem refresh = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images));
185 refresh.getElement().setId("folderContextMenu.refresh");
186 contextMenu.addItem(refresh);
189 if(selectedItem instanceof OthersFolderResource){
190 MenuItem newFolder = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.folderNew()).getHTML() + " New Folder</span>", true, new NewFolderCommand(this, images));
191 newFolder.getElement().setId("folderContextMenu.newFolder");
192 contextMenu.addItem(newFolder);
194 MenuItem upload = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this));
195 upload.getElement().setId("folderContextMenu.upload");
196 contextMenu.addItem(upload);
198 MenuItem cut = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + " Cut</span>", true, new CutCommand(this));
199 cut.getElement().setId("folderContextMenu.cut");
200 contextMenu.addItem(cut);
202 MenuItem copy = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + " Copy</span>", true, new CopyCommand(this));
203 copy.getElement().setId("folderContextMenu.copy");
204 contextMenu.addItem(copy);
206 contextMenu.addItem(pasteItem);
208 MenuItem moveToTrash = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + " Move to Trash</span>", true, new ToTrashCommand(this));
209 moveToTrash.getElement().setId("folderContextMenu.moveToTrash");
210 contextMenu.addItem(moveToTrash);
212 MenuItem delete = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, newImages));
213 delete.getElement().setId("folderContextMenu.delete");
214 contextMenu.addItem(delete);
216 MenuItem refresh = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images));
217 refresh.getElement().setId("folderContextMenu.delete");
218 contextMenu.addItem(refresh);
220 MenuItem sharing = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + " Sharing</span>", true, new PropertiesCommand(this, newImages, 1));
221 sharing.getElement().setId("folderContextMenu.sharing");
222 contextMenu.addItem(sharing);
224 MenuItem properties = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Properties</span>", true, new PropertiesCommand(this, newImages, 0));
225 properties.getElement().setId("folderContextMenu.properties");
226 contextMenu.addItem(properties);
229 if(selectedItem instanceof TrashResource){
230 MenuItem restore = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Restore Trash</span>", true, new RestoreTrashCommand(this));
231 restore.getElement().setId("folderContextMenu.restore");
232 contextMenu.addItem(restore);
234 MenuItem emptyTrash = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Empty Trash</span>", true, new EmptyTrashCommand(this));
235 emptyTrash.getElement().setId("folderContextMenu.emptyTrash");
236 contextMenu.addItem(emptyTrash);
238 MenuItem refresh = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images));
239 refresh.getElement().setId("folderContextMenu.refresh");
240 contextMenu.addItem(refresh);
243 if(selectedItem instanceof SharedResource || selectedItem instanceof OthersResource || selectedItem instanceof OtherUserResource){
244 MenuItem refresh = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images));
245 refresh.getElement().setId("folderContextMenu.refresh");
246 contextMenu.addItem(refresh);
251 if(folders.isTrashItem(selectedItem)){
252 if (folders.isTrash(selectedItem)){
253 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Empty Trash</span>", true, new EmptyTrashCommand(this));
254 contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images));
257 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Restore folder and contents</span>", true, new RestoreTrashCommand(this));
258 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, newImages));
259 contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images));
262 else if(folders.isFileItem(selectedItem)){
265 else if(!folders.isMyShares(selectedItem) && folders.isMySharedItem(selectedItem)){
266 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.folderNew()).getHTML() + " New Folder</span>", true, new NewFolderCommand(this, images));
267 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this));
268 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + " Cut</span>", true, new CutCommand(this));
269 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + " Copy</span>", true, new CopyCommand(this));
270 contextMenu.addItem(pasteItem);
271 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + " Move to Trash</span>", true, new ToTrashCommand(this));
272 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, newImages));
273 contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images));
274 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + " Sharing</span>", true, new PropertiesCommand(this, newImages, 1));
275 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Properties</span>", true, new PropertiesCommand(this, newImages, 0));
277 else if(!folders.isOthersShared(selectedItem) && folders.isOthersSharedItem(selectedItem) && !(GSS.get().getCurrentSelection() instanceof OtherUserResource)){
278 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.folderNew()).getHTML() + " New Folder</span>", true, new NewFolderCommand(this, images));
279 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this));
280 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + " Cut</span>", true, new CutCommand(this));
281 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + " Copy</span>", true, new CopyCommand(this));
282 contextMenu.addItem(pasteItem);
283 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + " Move to Trash</span>", true, new ToTrashCommand(this));
284 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, newImages));
285 contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images));
286 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + " Sharing</span>", true, new PropertiesCommand(this, newImages, 1));
287 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Properties</span>", true, new PropertiesCommand(this, newImages, 0));
288 } else if(!selectedItem.equals(folders.getSharesItem()))
289 contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images));
293 if (GSS.get().getClipboard().hasFolderOrFileItem())
294 pasteItem.setVisible(true);
296 pasteItem.setVisible(false);