Don't allow Cut, Move to Trash, Delete options for the home folder. This solves issue 76.
[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.FolderResource;
33 import gr.ebs.gss.client.rest.resource.MyFolderResource;
34 import gr.ebs.gss.client.rest.resource.OtherUserResource;
35 import gr.ebs.gss.client.rest.resource.OthersFolderResource;
36 import gr.ebs.gss.client.rest.resource.OthersResource;
37 import gr.ebs.gss.client.rest.resource.RestResource;
38 import gr.ebs.gss.client.rest.resource.SharedFolderResource;
39 import gr.ebs.gss.client.rest.resource.SharedResource;
40 import gr.ebs.gss.client.rest.resource.TrashFolderResource;
41 import gr.ebs.gss.client.rest.resource.TrashResource;
42
43 import com.google.gwt.resources.client.ClientBundle;
44 import com.google.gwt.user.client.ui.AbstractImagePrototype;
45 import com.google.gwt.user.client.ui.MenuBar;
46 import com.google.gwt.user.client.ui.MenuItem;
47 import com.google.gwt.user.client.ui.PopupPanel;
48
49 /**
50  * The 'Folder Context' menu implementation.
51  */
52 public class FolderContextMenu extends PopupPanel {
53
54         /**
55          * The widget's images.
56          */
57         private final Images images;
58
59         /**
60          * The image bundle for this widget's images that reuses images defined in
61          * other menus.
62          */
63         public interface Images extends ClientBundle,FileMenu.Images, EditMenu.Images {
64         }
65
66         private MenuItem pasteItem;
67
68         /**
69          * The widget's constructor.
70          *
71          * @param newImages the image bundle passed on by the parent object
72          */
73         public FolderContextMenu(final Images newImages) {
74                 // The popup's constructor's argument is a boolean specifying that it
75                 // auto-close itself when the user clicks outside of it.
76                 super(true);
77                 setAnimationEnabled(true);
78                 images = newImages;
79
80                 pasteItem = new MenuItem("<span id = 'folderContextMenu.paste'>" + AbstractImagePrototype.create(newImages.paste()).getHTML() + "&nbsp;Paste</span>", true, new PasteCommand(this));
81                 MenuBar contextMenu = new MenuBar(true);
82                 
83                 RestResource selectedItem = GSS.get().getTreeView().getSelection();
84
85                 if(selectedItem != null)
86                         if(selectedItem instanceof MyFolderResource){           
87                                 MenuItem newFolder = new MenuItem("<span id = 'folderContextMenu.newFolder'>" + AbstractImagePrototype.create(newImages.folderNew()).getHTML() + "&nbsp;New Folder</span>", true, new NewFolderCommand(this, images));
88                                 contextMenu.addItem(newFolder);
89                                 
90                                 MenuItem upload = new MenuItem("<span id = 'folderContextMenu.upload'>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this));
91                                 contextMenu.addItem(upload);
92                                                                                         
93                                 boolean notRootFolder =(((MyFolderResource) selectedItem).getResource()).getParentURI() != null ? true : false; 
94                                 if (notRootFolder) {
95                                         // do not show the copy & cut option for the user's root folder                                 
96                                         MenuItem cut = new MenuItem("<span id = 'folderContextMenu.cut'>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + "&nbsp;Cut</span>", true, new CutCommand(this));
97                                         contextMenu.addItem(cut);
98                                         
99                                 }
100                                 MenuItem copy = new MenuItem("<span id = 'folderContextMenu.copy'>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + "&nbsp;Copy</span>", true, new CopyCommand(this));                                    
101                                 contextMenu.addItem(copy);
102                                 contextMenu.addItem(pasteItem);
103                                 if (notRootFolder) {
104                                         // do not show delete options for the user's root folder
105                                         MenuItem moveToTrash = new MenuItem("<span id = 'folderContextMenu.moveToTrash'>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(this));                                    
106                                         contextMenu.addItem(moveToTrash);
107                                         
108                                         MenuItem delete = new MenuItem("<span id = 'folderContextMenu.delete'>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, newImages));
109                                         contextMenu.addItem(delete);                                    
110                                 }
111                                 
112                                 MenuItem refresh = new MenuItem("<span id = 'folderContextMenu.refresh'>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
113                                 contextMenu.addItem(refresh);
114                                 
115                                 MenuItem sharing = new MenuItem("<span id = 'folderContextMenu.sharing'>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + "&nbsp;Sharing</span>", true, new PropertiesCommand(this, newImages, 1));
116                                 contextMenu.addItem(sharing);
117                                 
118                                 MenuItem properties = new MenuItem("<span id = 'folderContextMenu.properties'>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(this, newImages, 0));
119                                 contextMenu.addItem(properties);                
120                         }
121                 
122                         if(selectedItem instanceof SharedFolderResource){
123                                 MenuItem newFolder = new MenuItem("<span id = 'folderContextMenu.newFolder'>" + AbstractImagePrototype.create(newImages.folderNew()).getHTML() + "&nbsp;New Folder</span>", true, new NewFolderCommand(this, images));
124                                 contextMenu.addItem(newFolder);
125                                 
126                                 MenuItem upload = new MenuItem("<span id = 'folderContextMenu.upload'>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this));
127                                 contextMenu.addItem(upload);
128                                 
129                                 MenuItem cut = new MenuItem("<span id = 'folderContextMenu.cut'>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + "&nbsp;Cut</span>", true, new CutCommand(this));
130                                 contextMenu.addItem(cut);
131                                 
132                                 MenuItem copy = new MenuItem("<span id = 'folderContextMenu.copy'>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + "&nbsp;Copy</span>", true, new CopyCommand(this));
133                                 contextMenu.addItem(copy);
134                                 
135                                 contextMenu.addItem(pasteItem);
136                                 
137                                 MenuItem moveToTrash = new MenuItem("<span id = 'folderContextMenu.moveToTrash'>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(this));
138                                 contextMenu.addItem(moveToTrash);
139                                 
140                                 MenuItem delete = new MenuItem("<span id = 'folderContextMenu.delete'>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, newImages));
141                                 contextMenu.addItem(delete);
142
143                                 MenuItem refresh = new MenuItem("<span id = 'folderContextMenu.refresh'>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
144                                 contextMenu.addItem(refresh);
145                                 
146                                 MenuItem sharing = new MenuItem("<span id = 'folderContextMenu.sharing'>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + "&nbsp;Sharing</span>", true, new PropertiesCommand(this, newImages, 1));
147                                 contextMenu.addItem(sharing);
148                                 
149                                 MenuItem properties = new MenuItem("<span id = 'folderContextMenu.properties'>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(this, newImages, 0));
150                                 contextMenu.addItem(properties);
151                                 
152                         }
153                         if(selectedItem instanceof TrashFolderResource){
154                                 MenuItem restore = new MenuItem("<span id = 'folderContextMenu.restore'>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Restore folder and contents</span>", true, new RestoreTrashCommand(this));
155                                 contextMenu.addItem(restore);
156                                 
157                                 MenuItem delete = new MenuItem("<span id = 'folderContextMenu.delete'>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, newImages));
158                                 contextMenu.addItem(delete);
159                                 
160                                 MenuItem refresh = new MenuItem("<span id = 'folderContextMenu.refresh'>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
161                                 contextMenu.addItem(refresh);
162                                 
163                         }
164                         if(selectedItem instanceof OthersFolderResource){                               
165                                 MenuItem newFolder = new MenuItem("<span id = 'folderContextMenu.newFolder'>" + AbstractImagePrototype.create(newImages.folderNew()).getHTML() + "&nbsp;New Folder</span>", true, new NewFolderCommand(this, images));
166                                 contextMenu.addItem(newFolder);
167
168                                 MenuItem upload = new MenuItem("<span id ='folderContextMenu.upload'>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this));
169                                 contextMenu.addItem(upload);
170                                 
171                                 MenuItem cut = new MenuItem("<span id = 'folderContextMenu.cut'>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + "&nbsp;Cut</span>", true, new CutCommand(this));
172                                 contextMenu.addItem(cut);
173                                 
174                                 MenuItem copy = new MenuItem("<span id = 'folderContextMenu.copy'>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + "&nbsp;Copy</span>", true, new CopyCommand(this));
175                                 contextMenu.addItem(copy);
176                                 
177                                 contextMenu.addItem(pasteItem);
178                                 
179                                 MenuItem moveToTrash = new MenuItem("<span id = 'folderContextMenu.moveToTrash'>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(this));
180                                 contextMenu.addItem(moveToTrash);
181                                 
182                                 MenuItem delete = new MenuItem("<span id = 'folderContextMenu.delete'>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, newImages));
183                                 contextMenu.addItem(delete);
184
185                                 MenuItem refresh = new MenuItem("<span id = 'folderContextMenu.delete'>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
186                                 contextMenu.addItem(refresh);
187                                 
188                                 MenuItem sharing = new MenuItem("<span id = 'folderContextMenu.sharing'>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + "&nbsp;Sharing</span>", true, new PropertiesCommand(this, newImages, 1));
189                                 contextMenu.addItem(sharing);
190                                 
191                                 MenuItem properties = new MenuItem("<span id = 'folderContextMenu.properties'>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(this, newImages, 0));
192                                 contextMenu.addItem(properties);
193                                 
194                         }
195                         if(selectedItem instanceof TrashResource){
196                                 MenuItem restore = new MenuItem("<span id ='folderContextMenu.restore'>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Restore Trash</span>", true, new RestoreTrashCommand(this));
197                                 contextMenu.addItem(restore);
198                                 
199                                 MenuItem emptyTrash = new MenuItem("<span id = 'folderContextMenu.emptyTrash'>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Empty Trash</span>", true, new EmptyTrashCommand(this));
200                                 contextMenu.addItem(emptyTrash);
201                                 
202                                 MenuItem refresh = new MenuItem("<span id = 'folderContextMenu.refresh'>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
203                                 contextMenu.addItem(refresh);
204                                 
205                         }
206                         if(selectedItem instanceof SharedResource || selectedItem instanceof OthersResource || selectedItem instanceof OtherUserResource){
207                                 MenuItem refresh = new MenuItem("<span id = 'folderContextMenu.refresh'>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
208                                 contextMenu.addItem(refresh);
209                                 
210                         }
211                         
212                         /*
213                         if(folders.isTrashItem(selectedItem)){
214                                 if (folders.isTrash(selectedItem)){
215                                         contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Empty Trash</span>", true, new EmptyTrashCommand(this));
216                                         contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
217                                 }
218                                 else {
219                                         contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Restore folder and contents</span>", true, new RestoreTrashCommand(this));
220                                         contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, newImages));
221                                         contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
222                                 }
223                         }
224                         else if(folders.isFileItem(selectedItem)){
225                                 
226                         }
227                         else if(!folders.isMyShares(selectedItem) && folders.isMySharedItem(selectedItem)){
228                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.folderNew()).getHTML() + "&nbsp;New Folder</span>", true, new NewFolderCommand(this, images));
229                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this));
230                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + "&nbsp;Cut</span>", true, new CutCommand(this));
231                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + "&nbsp;Copy</span>", true, new CopyCommand(this));
232                                 contextMenu.addItem(pasteItem);
233                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(this));
234                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, newImages));
235                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
236                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + "&nbsp;Sharing</span>", true, new PropertiesCommand(this, newImages, 1));
237                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(this, newImages, 0));
238                         }
239                         else if(!folders.isOthersShared(selectedItem) && folders.isOthersSharedItem(selectedItem) && !(GSS.get().getCurrentSelection() instanceof OtherUserResource)){
240                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.folderNew()).getHTML() + "&nbsp;New Folder</span>", true, new NewFolderCommand(this, images));
241                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this));
242                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + "&nbsp;Cut</span>", true, new CutCommand(this));
243                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + "&nbsp;Copy</span>", true, new CopyCommand(this));
244                                 contextMenu.addItem(pasteItem);
245                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(this));
246                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, newImages));
247                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
248                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + "&nbsp;Sharing</span>", true, new PropertiesCommand(this, newImages, 1));
249                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(this, newImages, 0));
250                         } else if(!selectedItem.equals(folders.getSharesItem()))
251                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
252                         */
253                 
254                 add(contextMenu);
255                 if (GSS.get().getClipboard().hasFolderOrFileItem())
256                         pasteItem.setVisible(true);
257                 else
258                         pasteItem.setVisible(false);
259         }
260
261 }