Made a new arrangement of tests on folder utilities and added some new methods regard...
[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                 pasteItem.getElement().setId("folderContextMenu.paste");
81                 MenuBar contextMenu = new MenuBar(true);
82                 
83                 
84                 
85                 RestResource selectedItem = GSS.get().getTreeView().getSelection();
86
87
88                 if(selectedItem != null)
89                         if(selectedItem instanceof MyFolderResource){
90                                 MenuItem newFolder = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.folderNew()).getHTML() + "&nbsp;New Folder</span>", true, new NewFolderCommand(this, images));
91                                 newFolder.getElement().setId("folderContextMenu.newFolder");
92                                 contextMenu.addItem(newFolder);
93                                 
94                                 MenuItem upload = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this));
95                                 upload.getElement().setId("folderContextMenu.upload");
96                                 contextMenu.addItem(upload);
97                                                                 
98                                 boolean notRootFolder = !GSS.get().getTreeView().getMyFolders().equals(selectedItem);
99                                 if (notRootFolder) {
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() + "&nbsp;Cut</span>", true, new CutCommand(this));
102                                         cut.getElement().setId("folderContextMenu.cut");
103                                         contextMenu.addItem(cut);
104                                         
105                                         MenuItem copy = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + "&nbsp;Copy</span>", true, new CopyCommand(this));
106                                         copy.getElement().setId("folderContextMenu.copy");
107                                         contextMenu.addItem(copy);
108                                         
109                                 }
110                                 contextMenu.addItem(pasteItem);
111                                 if (notRootFolder) {
112                                         // do not show delete options for the user's root folder
113                                         MenuItem moveToTrash = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(this));
114                                         moveToTrash.getElement().setId("folderContextMenu.moveToTrash");
115                                         contextMenu.addItem(moveToTrash);
116                                         
117                                         MenuItem delete = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, newImages));
118                                         delete.getElement().setId("folderContextMenu.delete");
119                                         contextMenu.addItem(delete);                                    
120                                 }
121                                 
122                                 MenuItem refresh = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
123                                 refresh.getElement().setId("folderContextMenu.refresh");
124                                 contextMenu.addItem(refresh);
125                                 
126                                 MenuItem sharing = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + "&nbsp;Sharing</span>", true, new PropertiesCommand(this, newImages, 1));
127                                 sharing.getElement().setId("folderContextMenu.sharing");
128                                 contextMenu.addItem(sharing);
129                                 
130                                 MenuItem properties = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(this, newImages, 0));
131                                 properties.getElement().setId("folderContextMenu.properties");
132                                 contextMenu.addItem(properties);                
133                         }
134                 
135                         if(selectedItem instanceof SharedFolderResource){
136                                 MenuItem newFolder = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.folderNew()).getHTML() + "&nbsp;New Folder</span>", true, new NewFolderCommand(this, images));
137                                 newFolder.getElement().setId("folderContextMenu.newFolder");
138                                 contextMenu.addItem(newFolder);
139                                 
140                                 MenuItem upload = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this));
141                                 upload.getElement().setId("folderContextMenu.upload");
142                                 contextMenu.addItem(upload);
143                                 
144                                 MenuItem cut = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + "&nbsp;Cut</span>", true, new CutCommand(this));
145                                 cut.getElement().setId("folderContextMenu.cut");
146                                 contextMenu.addItem(cut);
147                                 
148                                 MenuItem copy = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + "&nbsp;Copy</span>", true, new CopyCommand(this));
149                                 copy.getElement().setId("folderContextMenu.copy");
150                                 contextMenu.addItem(copy);
151                                 
152                                 contextMenu.addItem(pasteItem);
153                                 
154                                 MenuItem moveToTrash = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(this));
155                                 moveToTrash.getElement().setId("folderContextMenu.moveToTrash");
156                                 contextMenu.addItem(moveToTrash);
157                                 
158                                 MenuItem delete = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, newImages));
159                                 delete.getElement().setId("folderContextMenu.delete");
160                                 contextMenu.addItem(delete);
161
162                                 MenuItem refresh = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
163                                 refresh.getElement().setId("folderContextMenu.refresh");
164                                 contextMenu.addItem(refresh);
165                                 
166                                 MenuItem sharing = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + "&nbsp;Sharing</span>", true, new PropertiesCommand(this, newImages, 1));
167                                 sharing.getElement().setId("folderContextMenu.sharing");
168                                 contextMenu.addItem(sharing);
169                                 
170                                 MenuItem properties = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(this, newImages, 0));
171                                 properties.getElement().setId("folderContextMenu.properties");
172                                 contextMenu.addItem(properties);
173                                 
174                         }
175                         if(selectedItem instanceof TrashFolderResource){
176                                 MenuItem restore = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Restore folder and contents</span>", true, new RestoreTrashCommand(this));
177                                 restore.getElement().setId("folderContextMenu.restore");
178                                 contextMenu.addItem(restore);
179                                 
180                                 MenuItem delete = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, newImages));
181                                 delete.getElement().setId("folderContextMenu.delete");
182                                 contextMenu.addItem(delete);
183                                 
184                                 MenuItem refresh = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
185                                 refresh.getElement().setId("folderContextMenu.refresh");
186                                 contextMenu.addItem(refresh);
187                                 
188                         }
189                         if(selectedItem instanceof OthersFolderResource){                               
190                                 MenuItem newFolder = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.folderNew()).getHTML() + "&nbsp;New Folder</span>", true, new NewFolderCommand(this, images));
191                                 newFolder.getElement().setId("folderContextMenu.newFolder");
192                                 contextMenu.addItem(newFolder);
193
194                                 MenuItem upload = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this));
195                                 upload.getElement().setId("folderContextMenu.upload");
196                                 contextMenu.addItem(upload);
197                                 
198                                 MenuItem cut = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + "&nbsp;Cut</span>", true, new CutCommand(this));
199                                 cut.getElement().setId("folderContextMenu.cut");
200                                 contextMenu.addItem(cut);
201                                 
202                                 MenuItem copy = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + "&nbsp;Copy</span>", true, new CopyCommand(this));
203                                 copy.getElement().setId("folderContextMenu.copy");
204                                 contextMenu.addItem(copy);
205                                 
206                                 contextMenu.addItem(pasteItem);
207                                 
208                                 MenuItem moveToTrash = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(this));
209                                 moveToTrash.getElement().setId("folderContextMenu.moveToTrash");
210                                 contextMenu.addItem(moveToTrash);
211                                 
212                                 MenuItem delete = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, newImages));
213                                 delete.getElement().setId("folderContextMenu.delete");
214                                 contextMenu.addItem(delete);
215
216                                 MenuItem refresh = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
217                                 refresh.getElement().setId("folderContextMenu.delete");
218                                 contextMenu.addItem(refresh);
219                                 
220                                 MenuItem sharing = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + "&nbsp;Sharing</span>", true, new PropertiesCommand(this, newImages, 1));
221                                 sharing.getElement().setId("folderContextMenu.sharing");
222                                 contextMenu.addItem(sharing);
223                                 
224                                 MenuItem properties = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(this, newImages, 0));
225                                 properties.getElement().setId("folderContextMenu.properties");
226                                 contextMenu.addItem(properties);
227                                 
228                         }
229                         if(selectedItem instanceof TrashResource){
230                                 MenuItem restore = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Restore Trash</span>", true, new RestoreTrashCommand(this));
231                                 restore.getElement().setId("folderContextMenu.restore");
232                                 contextMenu.addItem(restore);
233                                 
234                                 MenuItem emptyTrash = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Empty Trash</span>", true, new EmptyTrashCommand(this));
235                                 emptyTrash.getElement().setId("folderContextMenu.emptyTrash");
236                                 contextMenu.addItem(emptyTrash);
237                                 
238                                 MenuItem refresh = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
239                                 refresh.getElement().setId("folderContextMenu.refresh");
240                                 contextMenu.addItem(refresh);
241                                 
242                         }
243                         if(selectedItem instanceof SharedResource || selectedItem instanceof OthersResource || selectedItem instanceof OtherUserResource){
244                                 MenuItem refresh = new MenuItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
245                                 refresh.getElement().setId("folderContextMenu.refresh");
246                                 contextMenu.addItem(refresh);
247                                 
248                         }
249                         
250                         /*
251                         if(folders.isTrashItem(selectedItem)){
252                                 if (folders.isTrash(selectedItem)){
253                                         contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Empty Trash</span>", true, new EmptyTrashCommand(this));
254                                         contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
255                                 }
256                                 else {
257                                         contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Restore folder and contents</span>", true, new RestoreTrashCommand(this));
258                                         contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, newImages));
259                                         contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
260                                 }
261                         }
262                         else if(folders.isFileItem(selectedItem)){
263                                 
264                         }
265                         else if(!folders.isMyShares(selectedItem) && folders.isMySharedItem(selectedItem)){
266                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.folderNew()).getHTML() + "&nbsp;New Folder</span>", true, new NewFolderCommand(this, images));
267                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this));
268                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + "&nbsp;Cut</span>", true, new CutCommand(this));
269                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + "&nbsp;Copy</span>", true, new CopyCommand(this));
270                                 contextMenu.addItem(pasteItem);
271                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(this));
272                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, newImages));
273                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
274                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + "&nbsp;Sharing</span>", true, new PropertiesCommand(this, newImages, 1));
275                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(this, newImages, 0));
276                         }
277                         else if(!folders.isOthersShared(selectedItem) && folders.isOthersSharedItem(selectedItem) && !(GSS.get().getCurrentSelection() instanceof OtherUserResource)){
278                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.folderNew()).getHTML() + "&nbsp;New Folder</span>", true, new NewFolderCommand(this, images));
279                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this));
280                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + "&nbsp;Cut</span>", true, new CutCommand(this));
281                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + "&nbsp;Copy</span>", true, new CopyCommand(this));
282                                 contextMenu.addItem(pasteItem);
283                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(this));
284                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, newImages));
285                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
286                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + "&nbsp;Sharing</span>", true, new PropertiesCommand(this, newImages, 1));
287                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(this, newImages, 0));
288                         } else if(!selectedItem.equals(folders.getSharesItem()))
289                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
290                         */
291                 
292                 add(contextMenu);
293                 if (GSS.get().getClipboard().hasFolderOrFileItem())
294                         pasteItem.setVisible(true);
295                 else
296                         pasteItem.setVisible(false);
297         }
298
299 }