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 MenuBar contextMenu = new MenuBar(true);
84 RestResource selectedItem = GSS.get().getTreeView().getSelection();
87 if(selectedItem != null)
88 if(selectedItem instanceof MyFolderResource){
89 MenuItem newFolder = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.folderNew()).getHTML() + " New Folder</span>", true, new NewFolderCommand(this, images));
90 newFolder.getElement().setId("folderContextMenu.newFolder");
91 contextMenu.addItem(newFolder);
93 MenuItem upload = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this));
94 upload.getElement().setId("folderContextMenu.upload");
95 contextMenu.addItem(upload);
97 boolean notRootFolder = !GSS.get().getTreeView().getMyFolders().equals(selectedItem);
99 // do not show the copy & cut option for the user's root folder
100 MenuItem cut = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + " Cut</span>", true, new CutCommand(this));
101 cut.getElement().setId("folderContextMenu.cut");
102 contextMenu.addItem(cut);
104 MenuItem copy = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + " Copy</span>", true, new CopyCommand(this));
105 copy.getElement().setId("folderContextMenu.copy");
106 contextMenu.addItem(copy);
109 contextMenu.addItem(pasteItem);
111 // do not show delete options for the user's root folder
112 MenuItem moveToTrash = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + " Move to Trash</span>", true, new ToTrashCommand(this));
113 moveToTrash.getElement().setId("folderContextMenu.moveToTrash");
114 contextMenu.addItem(moveToTrash);
116 MenuItem delete = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, newImages));
117 delete.getElement().setId("folderContextMenu.delete");
118 contextMenu.addItem(delete);
121 MenuItem refresh = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images));
122 refresh.getElement().setId("folderContextMenu.refresh");
123 contextMenu.addItem(refresh);
125 MenuItem sharing = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + " Sharing</span>", true, new PropertiesCommand(this, newImages, 1));
126 sharing.getElement().setId("folderContextMenu.sharing");
127 contextMenu.addItem(sharing);
129 MenuItem properties = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Properties</span>", true, new PropertiesCommand(this, newImages, 0));
130 properties.getElement().setId("folderContextMenu.properties");
131 contextMenu.addItem(properties);
134 if(selectedItem instanceof SharedFolderResource){
135 MenuItem newFolder = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.folderNew()).getHTML() + " New Folder</span>", true, new NewFolderCommand(this, images));
136 newFolder.getElement().setId("folderContextMenu.newFolder");
137 contextMenu.addItem(newFolder);
139 MenuItem upload = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this));
140 upload.getElement().setId("folderContextMenu.upload");
141 contextMenu.addItem(upload);
143 MenuItem cut = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + " Cut</span>", true, new CutCommand(this));
144 cut.getElement().setId("folderContextMenu.cut");
145 contextMenu.addItem(cut);
147 MenuItem copy = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + " Copy</span>", true, new CopyCommand(this));
148 copy.getElement().setId("folderContextMenu.copy");
149 contextMenu.addItem(copy);
151 contextMenu.addItem(pasteItem);
153 MenuItem moveToTrash = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + " Move to Trash</span>", true, new ToTrashCommand(this));
154 moveToTrash.getElement().setId("folderContextMenu.moveToTrash");
155 contextMenu.addItem(moveToTrash);
157 MenuItem delete = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, newImages));
158 delete.getElement().setId("folderContextMenu.delete");
159 contextMenu.addItem(delete);
161 MenuItem refresh = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images));
162 refresh.getElement().setId("folderContextMenu.refresh");
163 contextMenu.addItem(refresh);
165 MenuItem sharing = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + " Sharing</span>", true, new PropertiesCommand(this, newImages, 1));
166 sharing.getElement().setId("folderContextMenu.sharing");
167 contextMenu.addItem(sharing);
169 MenuItem properties = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Properties</span>", true, new PropertiesCommand(this, newImages, 0));
170 properties.getElement().setId("folderContextMenu.properties");
171 contextMenu.addItem(properties);
174 if(selectedItem instanceof TrashFolderResource){
175 MenuItem restore = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Restore folder and contents</span>", true, new RestoreTrashCommand(this));
176 restore.getElement().setId("folderContextMenu.restore");
177 contextMenu.addItem(restore);
179 MenuItem delete = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, newImages));
180 delete.getElement().setId("folderContextMenu.delete");
181 contextMenu.addItem(delete);
183 MenuItem refresh = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images));
184 refresh.getElement().setId("folderContextMenu.refresh");
185 contextMenu.addItem(refresh);
188 if(selectedItem instanceof OthersFolderResource){
189 MenuItem newFolder = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.folderNew()).getHTML() + " New Folder</span>", true, new NewFolderCommand(this, images));
190 newFolder.getElement().setId("folderContextMenu.newFolder");
191 contextMenu.addItem(newFolder);
193 MenuItem upload = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this));
194 upload.getElement().setId("folderContextMenu.upload");
195 contextMenu.addItem(upload);
197 MenuItem cut = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + " Cut</span>", true, new CutCommand(this));
198 cut.getElement().setId("folderContextMenu.cut");
199 contextMenu.addItem(cut);
201 MenuItem copy = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + " Copy</span>", true, new CopyCommand(this));
202 copy.getElement().setId("folderContextMenu.copy");
203 contextMenu.addItem(copy);
205 contextMenu.addItem(pasteItem);
207 MenuItem moveToTrash = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + " Move to Trash</span>", true, new ToTrashCommand(this));
208 moveToTrash.getElement().setId("folderContextMenu.moveToTrash");
209 contextMenu.addItem(moveToTrash);
211 MenuItem delete = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, newImages));
212 delete.getElement().setId("folderContextMenu.delete");
213 contextMenu.addItem(delete);
215 MenuItem refresh = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images));
216 refresh.getElement().setId("folderContextMenu.delete");
217 contextMenu.addItem(refresh);
219 MenuItem sharing = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + " Sharing</span>", true, new PropertiesCommand(this, newImages, 1));
220 sharing.getElement().setId("folderContextMenu.sharing");
221 contextMenu.addItem(sharing);
223 MenuItem properties = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Properties</span>", true, new PropertiesCommand(this, newImages, 0));
224 properties.getElement().setId("folderContextMenu.properties");
225 contextMenu.addItem(properties);
228 if(selectedItem instanceof TrashResource){
229 MenuItem restore = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Restore Trash</span>", true, new RestoreTrashCommand(this));
230 restore.getElement().setId("folderContextMenu.restore");
231 contextMenu.addItem(restore);
233 MenuItem emptyTrash = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Empty Trash</span>", true, new EmptyTrashCommand(this));
234 emptyTrash.getElement().setId("folderContextMenu.emptyTrash");
235 contextMenu.addItem(emptyTrash);
237 MenuItem refresh = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images));
238 refresh.getElement().setId("folderContextMenu.refresh");
239 contextMenu.addItem(refresh);
242 if(selectedItem instanceof SharedResource || selectedItem instanceof OthersResource || selectedItem instanceof OtherUserResource){
243 MenuItem refresh = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images));
244 refresh.getElement().setId("folderContextMenu.refresh");
245 contextMenu.addItem(refresh);
250 if(folders.isTrashItem(selectedItem)){
251 if (folders.isTrash(selectedItem)){
252 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Empty Trash</span>", true, new EmptyTrashCommand(this));
253 contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images));
256 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Restore folder and contents</span>", true, new RestoreTrashCommand(this));
257 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, newImages));
258 contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images));
261 else if(folders.isFileItem(selectedItem)){
264 else if(!folders.isMyShares(selectedItem) && folders.isMySharedItem(selectedItem)){
265 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.folderNew()).getHTML() + " New Folder</span>", true, new NewFolderCommand(this, images));
266 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this));
267 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + " Cut</span>", true, new CutCommand(this));
268 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + " Copy</span>", true, new CopyCommand(this));
269 contextMenu.addItem(pasteItem);
270 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + " Move to Trash</span>", true, new ToTrashCommand(this));
271 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, newImages));
272 contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images));
273 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + " Sharing</span>", true, new PropertiesCommand(this, newImages, 1));
274 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Properties</span>", true, new PropertiesCommand(this, newImages, 0));
276 else if(!folders.isOthersShared(selectedItem) && folders.isOthersSharedItem(selectedItem) && !(GSS.get().getCurrentSelection() instanceof OtherUserResource)){
277 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.folderNew()).getHTML() + " New Folder</span>", true, new NewFolderCommand(this, images));
278 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + " Upload</span>", true, new UploadFileCommand(this));
279 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + " Cut</span>", true, new CutCommand(this));
280 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + " Copy</span>", true, new CopyCommand(this));
281 contextMenu.addItem(pasteItem);
282 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + " Move to Trash</span>", true, new ToTrashCommand(this));
283 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete</span>", true, new DeleteCommand(this, newImages));
284 contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images));
285 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + " Sharing</span>", true, new PropertiesCommand(this, newImages, 1));
286 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Properties</span>", true, new PropertiesCommand(this, newImages, 0));
287 } else if(!selectedItem.equals(folders.getSharesItem()))
288 contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh</span>", true, new RefreshCommand(this, images));
292 if (GSS.get().getClipboard().hasFolderOrFileItem())
293 pasteItem.setVisible(true);
295 pasteItem.setVisible(false);