Add a temporary hard-coded notice for the extended token validity period. This should...
[pithos] / gss / src / gr / ebs / gss / client / EditMenu.java
1 /*\r
2  * Copyright 2007, 2008, 2009 Electronic Business Systems Ltd.\r
3  *\r
4  * This file is part of GSS.\r
5  *\r
6  * GSS is free software: you can redistribute it and/or modify\r
7  * it under the terms of the GNU General Public License as published by\r
8  * the Free Software Foundation, either version 3 of the License, or\r
9  * (at your option) any later version.\r
10  *\r
11  * GSS is distributed in the hope that it will be useful,\r
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14  * GNU General Public License for more details.\r
15  *\r
16  * You should have received a copy of the GNU General Public License\r
17  * along with GSS.  If not, see <http://www.gnu.org/licenses/>.\r
18  */\r
19 package gr.ebs.gss.client;\r
20 \r
21 import gr.ebs.gss.client.commands.CopyCommand;\r
22 import gr.ebs.gss.client.commands.CutCommand;\r
23 import gr.ebs.gss.client.commands.DeleteCommand;\r
24 import gr.ebs.gss.client.commands.PasteCommand;\r
25 import gr.ebs.gss.client.commands.ToTrashCommand;\r
26 import gr.ebs.gss.client.rest.resource.FileResource;\r
27 import gr.ebs.gss.client.rest.resource.FolderResource;\r
28 import gr.ebs.gss.client.rest.resource.GroupUserResource;\r
29 \r
30 import java.util.List;\r
31 \r
32 import com.google.gwt.user.client.Command;\r
33 import com.google.gwt.user.client.ui.AbstractImagePrototype;\r
34 import com.google.gwt.user.client.ui.ClickListener;\r
35 import com.google.gwt.user.client.ui.MenuBar;\r
36 import com.google.gwt.user.client.ui.PopupPanel;\r
37 import com.google.gwt.user.client.ui.Widget;\r
38 \r
39 /**\r
40  * The 'Edit' menu implementation.\r
41  */\r
42 public class EditMenu extends PopupPanel implements ClickListener {\r
43 \r
44         /**\r
45          * The widget's images.\r
46          */\r
47         private final Images images;\r
48 \r
49         private final MenuBar contextMenu  = new MenuBar(true);\r
50 \r
51         /**\r
52          * An image bundle for this widget's images.\r
53          */\r
54         public interface Images extends FileMenu.Images, MessagePanel.Images {\r
55 \r
56                 /**\r
57                  * Will bundle the file 'editcut.png' residing in the package\r
58                  * 'gr.ebs.gss.resources'.\r
59                  *\r
60                  * @return the image prototype\r
61                  */\r
62                 @Resource("gr/ebs/gss/resources/editcut.png")\r
63                 AbstractImagePrototype cut();\r
64 \r
65                 /**\r
66                  * Will bundle the file 'editcopy.png' residing in the package\r
67                  * 'gr.ebs.gss.resources'.\r
68                  *\r
69                  * @return the image prototype\r
70                  */\r
71                 @Resource("gr/ebs/gss/resources/editcopy.png")\r
72                 AbstractImagePrototype copy();\r
73 \r
74                 /**\r
75                  * Will bundle the file 'editpaste.png' residing in the package\r
76                  * 'gr.ebs.gss.resources'.\r
77                  *\r
78                  * @return the image prototype\r
79                  */\r
80                 @Resource("gr/ebs/gss/resources/editpaste.png")\r
81                 AbstractImagePrototype paste();\r
82 \r
83                 /**\r
84                  * Will bundle the file 'editdelete.png' residing in the package\r
85                  * 'gr.ebs.gss.resources'.\r
86                  *\r
87                  * @return the image prototype\r
88                  */\r
89                 @Resource("gr/ebs/gss/resources/editdelete.png")\r
90                 AbstractImagePrototype delete();\r
91 \r
92                 /**\r
93                  * Will bundle the file 'translate.png' residing in the package\r
94                  * 'gr.ebs.gss.resources'.\r
95                  *\r
96                  * @return the image prototype\r
97                  */\r
98                 @Resource("gr/ebs/gss/resources/translate.png")\r
99                 AbstractImagePrototype selectAll();\r
100 \r
101                 /**\r
102                  * Will bundle the file 'border_remove.png' residing in the package\r
103                  * 'gr.ebs.gss.resources'.\r
104                  *\r
105                  * @return the image prototype\r
106                  */\r
107                 @Resource("gr/ebs/gss/resources/border_remove.png")\r
108                 AbstractImagePrototype unselectAll();\r
109         }\r
110 \r
111         /**\r
112          * The widget's constructor.\r
113          *\r
114          * @param newImages the image bundle passed on by the parent object\r
115          */\r
116         public EditMenu(final Images newImages) {\r
117                 // The popup's constructor's argument is a boolean specifying that it\r
118                 // auto-close itself when the user clicks outside of it.\r
119                 super(true);\r
120                 setAnimationEnabled(true);\r
121                 images = newImages;\r
122                 createMenu();\r
123                 add(contextMenu);\r
124         }\r
125 \r
126         /*\r
127          * (non-Javadoc)\r
128          *\r
129          * @see com.google.gwt.user.client.ui.ClickListener#onClick(com.google.gwt.user.client.ui.Widget)\r
130          */\r
131         public void onClick(final Widget sender) {\r
132                 final EditMenu menu = new EditMenu(images);\r
133                 final int left = sender.getAbsoluteLeft();\r
134                 final int top = sender.getAbsoluteTop() + sender.getOffsetHeight();\r
135                 menu.setPopupPosition(left, top);\r
136 \r
137                 menu.show();\r
138         }\r
139 \r
140         public MenuBar createMenu() {\r
141                 contextMenu.clearItems();\r
142                 contextMenu.setAutoOpen(false);\r
143 \r
144                 final Command selectAllCommand = new Command() {\r
145 \r
146                         public void execute() {\r
147                                 hide();\r
148                                 if(GSS.get().isFileListShowing())\r
149                                         GSS.get().getFileList().selectAllRows();\r
150                                 else if(GSS.get().isSearchResultsShowing())\r
151                                         GSS.get().getSearchResults().selectAllRows();\r
152                         }\r
153                 };\r
154                 final Command unselectAllCommand = new Command() {\r
155 \r
156                         public void execute() {\r
157                                 hide();\r
158                                 if(GSS.get().isFileListShowing())\r
159                                         GSS.get().getFileList().clearSelectedRows();\r
160                                 else if(GSS.get().isSearchResultsShowing())\r
161                                         GSS.get().getSearchResults().clearSelectedRows();\r
162                         }\r
163                 };\r
164 \r
165                 boolean cutcopyVisible = GSS.get().getCurrentSelection() != null && (GSS.get().getCurrentSelection() instanceof FolderResource\r
166                                         || GSS.get().getCurrentSelection() instanceof FileResource || GSS       .get().getCurrentSelection() instanceof GroupUserResource || GSS        .get().getCurrentSelection() instanceof List);\r
167                 String cutLabel = "Cut";\r
168                 String copyLabel ="Copy";\r
169                 String pasteLabel = "Paste";\r
170                 if(GSS.get().getCurrentSelection() != null)\r
171                         if(GSS.get().getCurrentSelection() instanceof FolderResource){\r
172                                 cutLabel = "Cut Folder";\r
173                                 copyLabel = "Copy Folder";\r
174                         }\r
175                         else if(GSS.get().getCurrentSelection() instanceof FileResource){\r
176                                 cutLabel = "Cut File";\r
177                                 copyLabel = "Copy File";\r
178                         }\r
179                         else if(GSS.get().getCurrentSelection() instanceof List){\r
180                                 cutLabel = "Cut Files";\r
181                                 copyLabel = "Copy Files";\r
182                         }\r
183                 if(GSS.get().getClipboard().getItem() != null)\r
184                         if(GSS.get().getClipboard().getItem().getFile() != null)\r
185                                 pasteLabel = "Paste File";\r
186                         else if(GSS.get().getClipboard().getItem().getFiles() != null)\r
187                                 pasteLabel = "Paste Files";\r
188                         else if(GSS.get().getClipboard().getItem().getFolderResource() != null)\r
189                                 pasteLabel = "Paste Folder";\r
190                 contextMenu.addItem("<span>" + images.cut().getHTML() + "&nbsp;"+cutLabel+"</span>", true, new CutCommand(this)).setVisible(cutcopyVisible);\r
191                 contextMenu.addItem("<span>" + images.copy().getHTML() + "&nbsp;"+copyLabel+"</span>", true, new CopyCommand(this)).setVisible(cutcopyVisible);\r
192                 if (GSS.get().getClipboard().getItem() != null)\r
193                         if(GSS.get().isUserListVisible() && GSS.get().getClipboard().getItem().getUser() == null)\r
194                                 contextMenu.addItem("<span>" + images.paste().getHTML() + "&nbsp;"+pasteLabel+"</span>", true, new PasteCommand(this));\r
195                         else if(!GSS.get().isUserListVisible() && GSS.get().getClipboard().getItem().getUser() != null){\r
196                                 //do not show paste\r
197                         }\r
198                         else\r
199                                 contextMenu.addItem("<span>" + images.paste().getHTML() + "&nbsp;"+pasteLabel+"</span>", true, new PasteCommand(this));\r
200                 contextMenu     .addItem("<span>" + images.emptyTrash().getHTML() + "&nbsp;Move to Trash</span>", true, new ToTrashCommand(this))\r
201                                         .setVisible(cutcopyVisible);\r
202                 contextMenu     .addItem("<span>" + images.delete().getHTML() + "&nbsp;Delete</span>", true, new DeleteCommand(this, images))\r
203                                         .setVisible(cutcopyVisible);\r
204                 contextMenu.addItem("<span>" + images.selectAll().getHTML() + "&nbsp;Select All</span>", true, selectAllCommand);\r
205                 contextMenu.addItem("<span>" + images.unselectAll().getHTML() + "&nbsp;Unselect All</span>", true, unselectAllCommand);\r
206                 return contextMenu;\r
207         }\r
208 \r
209 }\r