replace tree with celltree ( still work in progress)
[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.OtherUserResource;
33
34 import com.google.gwt.resources.client.ClientBundle;
35 import com.google.gwt.user.client.ui.AbstractImagePrototype;
36 import com.google.gwt.user.client.ui.MenuBar;
37 import com.google.gwt.user.client.ui.MenuItem;
38 import com.google.gwt.user.client.ui.PopupPanel;
39 import com.google.gwt.user.client.ui.TreeItem;
40
41 /**
42  * The 'Folder Context' menu implementation.
43  */
44 public class FolderContextMenu extends PopupPanel {
45
46         /**
47          * The widget's images.
48          */
49         private final Images images;
50
51         /**
52          * The image bundle for this widget's images that reuses images defined in
53          * other menus.
54          */
55         public interface Images extends ClientBundle,FileMenu.Images, EditMenu.Images {
56         }
57
58         private MenuItem pasteItem;
59
60         /**
61          * The widget's constructor.
62          *
63          * @param newImages the image bundle passed on by the parent object
64          */
65         public FolderContextMenu(final Images newImages) {
66                 // The popup's constructor's argument is a boolean specifying that it
67                 // auto-close itself when the user clicks outside of it.
68                 super(true);
69                 setAnimationEnabled(true);
70                 images = newImages;
71
72                 pasteItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.paste()).getHTML() + "&nbsp;Paste</span>", true, new PasteCommand(this));
73                 MenuBar contextMenu = new MenuBar(true);
74                 //TODO:CELLTREE
75                 /*
76                 Folders  folders = GSS.get().getFolders();
77                 TreeItem selectedItem = folders.getCurrent();
78
79
80                 if(selectedItem != null)
81                         if(folders.isTrashItem(selectedItem)){
82                                 if (folders.isTrash(selectedItem)){
83                                         contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Empty Trash</span>", true, new EmptyTrashCommand(this));
84                                         contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
85                                 }
86                                 else {
87                                         contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Restore folder and contents</span>", true, new RestoreTrashCommand(this));
88                                         contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, newImages));
89                                         contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
90                                 }
91                         }
92                         else if(folders.isFileItem(selectedItem)){
93                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.folderNew()).getHTML() + "&nbsp;New Folder</span>", true, new NewFolderCommand(this, images));
94                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this));
95                                 boolean notRootFolder = !folders.getRootItem().equals(selectedItem);
96                                 if (notRootFolder) {
97                                         // do not show the copy & cut option for the user's root folder
98                                         contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + "&nbsp;Cut</span>", true, new CutCommand(this));
99                                         contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + "&nbsp;Copy</span>", true, new CopyCommand(this));
100                                 }
101                                 contextMenu.addItem(pasteItem);
102                                 if (notRootFolder) {
103                                         // do not show delete options for the user's root folder
104                                         contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(this));
105                                         contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, newImages));
106                                 }
107                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
108                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + "&nbsp;Sharing</span>", true, new PropertiesCommand(this, newImages, 1));
109                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(this, newImages, 0));
110                         }
111                         else if(!folders.isMyShares(selectedItem) && folders.isMySharedItem(selectedItem)){
112                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.folderNew()).getHTML() + "&nbsp;New Folder</span>", true, new NewFolderCommand(this, images));
113                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this));
114                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + "&nbsp;Cut</span>", true, new CutCommand(this));
115                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + "&nbsp;Copy</span>", true, new CopyCommand(this));
116                                 contextMenu.addItem(pasteItem);
117                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(this));
118                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, newImages));
119                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
120                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + "&nbsp;Sharing</span>", true, new PropertiesCommand(this, newImages, 1));
121                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(this, newImages, 0));
122                         }
123                         else if(!folders.isOthersShared(selectedItem) && folders.isOthersSharedItem(selectedItem) && !(GSS.get().getCurrentSelection() instanceof OtherUserResource)){
124                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.folderNew()).getHTML() + "&nbsp;New Folder</span>", true, new NewFolderCommand(this, images));
125                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.fileUpdate()).getHTML() + "&nbsp;Upload</span>", true, new UploadFileCommand(this));
126                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.cut()).getHTML() + "&nbsp;Cut</span>", true, new CutCommand(this));
127                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.copy()).getHTML() + "&nbsp;Copy</span>", true, new CopyCommand(this));
128                                 contextMenu.addItem(pasteItem);
129                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.emptyTrash()).getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(this));
130                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.delete()).getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, newImages));
131                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
132                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + "&nbsp;Sharing</span>", true, new PropertiesCommand(this, newImages, 1));
133                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + "&nbsp;Properties</span>", true, new PropertiesCommand(this, newImages, 0));
134                         } else if(!selectedItem.equals(folders.getSharesItem()))
135                                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(images.refresh()).getHTML() + "&nbsp;Refresh</span>", true, new RefreshCommand(this, images));
136                 */
137                 add(contextMenu);
138                 if (GSS.get().getClipboard().hasFolderOrFileItem())
139                         pasteItem.setVisible(true);
140                 else
141                         pasteItem.setVisible(false);
142         }
143
144 }