Added two new classes. The first 'TestFolderSharing' handles the 'Sharing' option...
[pithos] / src / gr / ebs / gss / client / FolderContextMenu.java
1 /*
2  * Copyright 2007, 2008, 2009 Electronic Business Systems Ltd.
3  *
4  * This file is part of GSS.
5  *
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.
10  *
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.
15  *
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/>.
18  */
19 package gr.ebs.gss.client;
20
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;
41
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;
47
48 /**
49  * The 'Folder Context' menu implementation.
50  */
51 public class FolderContextMenu extends PopupPanel {
52
53         /**
54          * The widget's images.
55          */
56         private final Images images;
57
58         /**
59          * The image bundle for this widget's images that reuses images defined in
60          * other menus.
61          */
62         public interface Images extends ClientBundle,FileMenu.Images, EditMenu.Images {
63         }
64
65         private MenuItem pasteItem;
66
67         /**
68          * The widget's constructor.
69          *
70          * @param newImages the image bundle passed on by the parent object
71          */
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.
75                 super(true);
76                 setAnimationEnabled(true);
77                 images = newImages;
78
79                 pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.paste()).getHTML() + "&nbsp;Paste</span>", true, new PasteCommand(this));
80                 MenuBar contextMenu = new MenuBar(true);
81                 
82                 
83                 
84                 RestResource selectedItem = GSS.get().getTreeView().getSelection();
85
86
87                 if(selectedItem != null)
88                         if(selectedItem instanceof MyFolderResource){
89                                 MenuItem newFolder = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.folderNew()).getHTML() + "&nbsp;New Folder</span>", true, new NewFolderCommand(this, images));
90                                 newFolder.getElement().setId("folderContextMenu.newFolder");
91                                 contextMenu.addItem(newFolder);
92                                 
93                                 MenuItem upload = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this));
94                                 upload.getElement().setId("folderContextMenu.upload");
95                                 contextMenu.addItem(upload);
96                                                                 
97                                 boolean notRootFolder = !GSS.get().getTreeView().getMyFolders().equals(selectedItem);
98                                 if (notRootFolder) {
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() + "&nbsp;Cut</span>", true, new CutCommand(this));
101                                         cut.getElement().setId("folderContextMenu.cut");
102                                         contextMenu.addItem(cut);
103                                         
104                                         MenuItem copy = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + "&nbsp;Copy</span>", true, new CopyCommand(this));
105                                         copy.getElement().setId("folderContextMenu.copy");
106                                         contextMenu.addItem(copy);
107                                         
108                                 }
109                                 contextMenu.addItem(pasteItem);
110                                 if (notRootFolder) {
111                                         // do not show delete options for the user's root folder
112                                         MenuItem moveToTrash = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(this));
113                                         moveToTrash.getElement().setId("folderContextMenu.moveToTrash");
114                                         contextMenu.addItem(moveToTrash);
115                                         
116                                         MenuItem delete = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, newImages));
117                                         delete.getElement().setId("folderContextMenu.delete");
118                                         contextMenu.addItem(delete);                                    
119                                 }
120                                 
121                                 MenuItem refresh = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
122                                 refresh.getElement().setId("folderContextMenu.refresh");
123                                 contextMenu.addItem(refresh);
124                                 
125                                 MenuItem sharing = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + "&nbsp;Sharing</span>", true, new PropertiesCommand(this, newImages, 1));
126                                 sharing.getElement().setId("folderContextMenu.sharing");
127                                 contextMenu.addItem(sharing);
128                                 
129                                 MenuItem properties = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(this, newImages, 0));
130                                 properties.getElement().setId("folderContextMenu.properties");
131                                 contextMenu.addItem(properties);                
132                         }
133                 
134                         if(selectedItem instanceof SharedFolderResource){
135                                 MenuItem newFolder = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.folderNew()).getHTML() + "&nbsp;New Folder</span>", true, new NewFolderCommand(this, images));
136                                 newFolder.getElement().setId("folderContextMenu.newFolder");
137                                 contextMenu.addItem(newFolder);
138                                 
139                                 MenuItem upload = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this));
140                                 upload.getElement().setId("folderContextMenu.upload");
141                                 contextMenu.addItem(upload);
142                                 
143                                 MenuItem cut = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + "&nbsp;Cut</span>", true, new CutCommand(this));
144                                 cut.getElement().setId("folderContextMenu.cut");
145                                 contextMenu.addItem(cut);
146                                 
147                                 MenuItem copy = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + "&nbsp;Copy</span>", true, new CopyCommand(this));
148                                 copy.getElement().setId("folderContextMenu.copy");
149                                 contextMenu.addItem(copy);
150                                 
151                                 contextMenu.addItem(pasteItem);
152                                 
153                                 MenuItem moveToTrash = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(this));
154                                 moveToTrash.getElement().setId("folderContextMenu.moveToTrash");
155                                 contextMenu.addItem(moveToTrash);
156                                 
157                                 MenuItem delete = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, newImages));
158                                 delete.getElement().setId("folderContextMenu.delete");
159                                 contextMenu.addItem(delete);
160
161                                 MenuItem refresh = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
162                                 refresh.getElement().setId("folderContextMenu.refresh");
163                                 contextMenu.addItem(refresh);
164                                 
165                                 MenuItem sharing = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + "&nbsp;Sharing</span>", true, new PropertiesCommand(this, newImages, 1));
166                                 sharing.getElement().setId("folderContextMenu.sharing");
167                                 contextMenu.addItem(sharing);
168                                 
169                                 MenuItem properties = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(this, newImages, 0));
170                                 properties.getElement().setId("folderContextMenu.properties");
171                                 contextMenu.addItem(properties);
172                                 
173                         }
174                         if(selectedItem instanceof TrashFolderResource){
175                                 MenuItem restore = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Restore folder and contents</span>", true, new RestoreTrashCommand(this));
176                                 restore.getElement().setId("folderContextMenu.restore");
177                                 contextMenu.addItem(restore);
178                                 
179                                 MenuItem delete = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, newImages));
180                                 delete.getElement().setId("folderContextMenu.delete");
181                                 contextMenu.addItem(delete);
182                                 
183                                 MenuItem refresh = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
184                                 refresh.getElement().setId("folderContextMenu.refresh");
185                                 contextMenu.addItem(refresh);
186                                 
187                         }
188                         if(selectedItem instanceof OthersFolderResource){                               
189                                 MenuItem newFolder = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.folderNew()).getHTML() + "&nbsp;New Folder</span>", true, new NewFolderCommand(this, images));
190                                 newFolder.getElement().setId("folderContextMenu.newFolder");
191                                 contextMenu.addItem(newFolder);
192
193                                 MenuItem upload = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this));
194                                 upload.getElement().setId("folderContextMenu.upload");
195                                 contextMenu.addItem(upload);
196                                 
197                                 MenuItem cut = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + "&nbsp;Cut</span>", true, new CutCommand(this));
198                                 cut.getElement().setId("folderContextMenu.cut");
199                                 contextMenu.addItem(cut);
200                                 
201                                 MenuItem copy = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + "&nbsp;Copy</span>", true, new CopyCommand(this));
202                                 copy.getElement().setId("folderContextMenu.copy");
203                                 contextMenu.addItem(copy);
204                                 
205                                 contextMenu.addItem(pasteItem);
206                                 
207                                 MenuItem moveToTrash = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(this));
208                                 moveToTrash.getElement().setId("folderContextMenu.moveToTrash");
209                                 contextMenu.addItem(moveToTrash);
210                                 
211                                 MenuItem delete = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, newImages));
212                                 delete.getElement().setId("folderContextMenu.delete");
213                                 contextMenu.addItem(delete);
214
215                                 MenuItem refresh = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
216                                 refresh.getElement().setId("folderContextMenu.delete");
217                                 contextMenu.addItem(refresh);
218                                 
219                                 MenuItem sharing = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + "&nbsp;Sharing</span>", true, new PropertiesCommand(this, newImages, 1));
220                                 sharing.getElement().setId("folderContextMenu.sharing");
221                                 contextMenu.addItem(sharing);
222                                 
223                                 MenuItem properties = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(this, newImages, 0));
224                                 properties.getElement().setId("folderContextMenu.properties");
225                                 contextMenu.addItem(properties);
226                                 
227                         }
228                         if(selectedItem instanceof TrashResource){
229                                 MenuItem restore = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Restore Trash</span>", true, new RestoreTrashCommand(this));
230                                 restore.getElement().setId("folderContextMenu.restore");
231                                 contextMenu.addItem(restore);
232                                 
233                                 MenuItem emptyTrash = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Empty Trash</span>", true, new EmptyTrashCommand(this));
234                                 emptyTrash.getElement().setId("folderContextMenu.emptyTrash");
235                                 contextMenu.addItem(emptyTrash);
236                                 
237                                 MenuItem refresh = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
238                                 refresh.getElement().setId("folderContextMenu.refresh");
239                                 contextMenu.addItem(refresh);
240                                 
241                         }
242                         if(selectedItem instanceof SharedResource || selectedItem instanceof OthersResource || selectedItem instanceof OtherUserResource){
243                                 MenuItem refresh = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
244                                 refresh.getElement().setId("folderContextMenu.refresh");
245                                 contextMenu.addItem(refresh);
246                                 
247                         }
248                         
249                         /*
250                         if(folders.isTrashItem(selectedItem)){
251                                 if (folders.isTrash(selectedItem)){
252                                         contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Empty Trash</span>", true, new EmptyTrashCommand(this));
253                                         contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
254                                 }
255                                 else {
256                                         contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Restore folder and contents</span>", true, new RestoreTrashCommand(this));
257                                         contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, newImages));
258                                         contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
259                                 }
260                         }
261                         else if(folders.isFileItem(selectedItem)){
262                                 
263                         }
264                         else if(!folders.isMyShares(selectedItem) && folders.isMySharedItem(selectedItem)){
265                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.folderNew()).getHTML() + "&nbsp;New Folder</span>", true, new NewFolderCommand(this, images));
266                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this));
267                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + "&nbsp;Cut</span>", true, new CutCommand(this));
268                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + "&nbsp;Copy</span>", true, new CopyCommand(this));
269                                 contextMenu.addItem(pasteItem);
270                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(this));
271                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, newImages));
272                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
273                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + "&nbsp;Sharing</span>", true, new PropertiesCommand(this, newImages, 1));
274                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(this, newImages, 0));
275                         }
276                         else if(!folders.isOthersShared(selectedItem) && folders.isOthersSharedItem(selectedItem) && !(GSS.get().getCurrentSelection() instanceof OtherUserResource)){
277                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.folderNew()).getHTML() + "&nbsp;New Folder</span>", true, new NewFolderCommand(this, images));
278                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this));
279                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + "&nbsp;Cut</span>", true, new CutCommand(this));
280                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + "&nbsp;Copy</span>", true, new CopyCommand(this));
281                                 contextMenu.addItem(pasteItem);
282                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(this));
283                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, newImages));
284                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
285                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + "&nbsp;Sharing</span>", true, new PropertiesCommand(this, newImages, 1));
286                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(this, newImages, 0));
287                         } else if(!selectedItem.equals(folders.getSharesItem()))
288                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
289                         */
290                 
291                 add(contextMenu);
292                 if (GSS.get().getClipboard().hasFolderOrFileItem())
293                         pasteItem.setVisible(true);
294                 else
295                         pasteItem.setVisible(false);
296         }
297
298 }