Added ids to folder context menu for trash folder after a wrong merge.
[pithos] / src / gr / ebs / gss / client / SettingsMenu.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 com.google.gwt.event.dom.client.ClickEvent;\r
22 import com.google.gwt.event.dom.client.ClickHandler;\r
23 import com.google.gwt.resources.client.ClientBundle;\r
24 import com.google.gwt.resources.client.ImageResource;\r
25 import com.google.gwt.user.client.Command;\r
26 import com.google.gwt.user.client.ui.AbstractImagePrototype;\r
27 import com.google.gwt.user.client.ui.MenuBar;\r
28 import com.google.gwt.user.client.ui.MenuItem;\r
29 import com.google.gwt.user.client.ui.PopupPanel;\r
30 \r
31 /**\r
32  * The 'settings' menu implementation.\r
33  */\r
34 public class SettingsMenu extends PopupPanel implements ClickHandler {\r
35 \r
36         /**\r
37          * The widget's images.\r
38          */\r
39         private Images images;\r
40         private final MenuBar contextMenu;\r
41         /**\r
42          * An image bundle for this widgets images.\r
43          */\r
44         public interface Images extends ClientBundle,MessagePanel.Images {\r
45 \r
46                 /**\r
47                  * Will bundle the file 'advancedsettings.png' residing in the package\r
48                  * 'gr.ebs.gss.resources'.\r
49                  *\r
50                  * @return the image prototype\r
51                  */\r
52                 @Source("gr/ebs/gss/resources/advancedsettings.png")\r
53                 ImageResource preferences();\r
54 \r
55                 @Source("gr/ebs/gss/resources/lock.png")\r
56                 ImageResource credentials();\r
57 \r
58         }\r
59 \r
60         /**\r
61          * The widget's constructor.\r
62          *\r
63          * @param newImages the image bundle passed on by the parent object\r
64          */\r
65         public SettingsMenu(final Images newImages) {\r
66                 // The popup's constructor's argument is a boolean specifying that it\r
67                 // auto-close itself when the user clicks outside of it.\r
68                 super(true);\r
69                 setAnimationEnabled(true);\r
70                 images = newImages;\r
71 \r
72                 Command userCredentialsCommand = new Command(){\r
73                         @Override\r
74                         public void execute() {\r
75                                 CredentialsDialog dlg = new CredentialsDialog(newImages);\r
76                                 dlg.center();\r
77                         }\r
78                 };\r
79                 contextMenu = new MenuBar(true);\r
80 //              contextMenu.addItem("<span>" + newImages.preferences().getHTML() + "&nbsp;Preferences</span>", true, cmd);\r
81                 MenuItem showCredentialsItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.credentials()).getHTML() + "&nbsp;Show Credentials</span>", true, userCredentialsCommand);\r
82                 showCredentialsItem.getElement().setId("topMenu.settingsMenu.showCredentials");\r
83                 contextMenu.addItem(showCredentialsItem);\r
84                 \r
85                 add(contextMenu);\r
86                 // setStyleName("toolbarPopup");\r
87         }\r
88 \r
89         @Override\r
90         public void onClick(final ClickEvent event) {\r
91                 final SettingsMenu menu = new SettingsMenu(images);\r
92                 final int left = event.getRelativeElement().getAbsoluteLeft();\r
93                 final int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight();\r
94                 menu.setPopupPosition(left, top);\r
95 \r
96                 menu.show();\r
97         }\r
98 \r
99 \r
100         /**\r
101          * Retrieve the contextMenu.\r
102          *\r
103          * @return the contextMenu\r
104          */\r
105         public MenuBar getContextMenu() {\r
106                 contextMenu.setAutoOpen(false);\r
107                 return contextMenu;\r
108         }\r
109 \r
110 \r
111 }\r