moved towards gwt version 2.0 - updated dnd to version 3 -removed all deprecations
[pithos] / src / gr / ebs / gss / client / GroupMenu.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.NewGroupCommand;\r
22 \r
23 import com.google.gwt.event.dom.client.ClickEvent;\r
24 import com.google.gwt.event.dom.client.ClickHandler;\r
25 import com.google.gwt.resources.client.ClientBundle;\r
26 import com.google.gwt.resources.client.ImageResource;\r
27 import com.google.gwt.user.client.ui.AbstractImagePrototype;\r
28 import com.google.gwt.user.client.ui.MenuBar;\r
29 import com.google.gwt.user.client.ui.PopupPanel;\r
30 \r
31 /**\r
32  * The 'Group' menu implementation.\r
33  */\r
34 public class GroupMenu extends PopupPanel implements ClickHandler {\r
35         /**\r
36          * The widget's images.\r
37          */\r
38         private Images images;\r
39         private final MenuBar contextMenu;\r
40 \r
41         /**\r
42          * An image bundle for this widgets images.\r
43          */\r
44         public interface Images extends ClientBundle {\r
45                 @Source("gr/ebs/gss/resources/groupevent.png")\r
46                 ImageResource groupNew();\r
47 \r
48                 @Source("gr/ebs/gss/resources/view_text.png")\r
49                 ImageResource viewText();\r
50 \r
51         }\r
52 \r
53         /**\r
54          * The widget's constructor.\r
55          *\r
56          * @param newImages the image bundle passed on by the parent object\r
57          */\r
58         public GroupMenu(final Images newImages) {\r
59                 // The popup's constructor's argument is a boolean specifying that it\r
60                 // auto-close itself when the user clicks outside of it.\r
61                 super(true);\r
62                 setAnimationEnabled(true);\r
63                 images = newImages;\r
64 \r
65                 contextMenu = new MenuBar(true);\r
66                 contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.groupNew()).getHTML() + "&nbsp;New Group</span>", true, new NewGroupCommand(this));\r
67 \r
68                 add(contextMenu);\r
69         }\r
70 \r
71         public void onClick(ClickEvent event) {\r
72                 GroupMenu menu = new GroupMenu(images);\r
73                 int left = event.getRelativeElement().getAbsoluteLeft();\r
74                 int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight();\r
75                 menu.setPopupPosition(left, top);\r
76 \r
77                 menu.show();\r
78         }\r
79 \r
80         /**\r
81          * Retrieve the contextMenu.\r
82          *\r
83          * @return the contextMenu\r
84          */\r
85         public MenuBar getContextMenu() {\r
86                 contextMenu.setAutoOpen(false);\r
87                 return contextMenu;\r
88         }\r
89 \r
90 }\r