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