Statistics
| Branch: | Tag: | Revision:

root / src / org / gss_project / gss / web / client / GroupMenu.java @ 1206:292dec4eae08

History | View | Annotate | Download (2.8 kB)

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 org.gss_project.gss.web.client;
20

    
21
import org.gss_project.gss.web.client.commands.NewGroupCommand;
22

    
23
import com.google.gwt.event.dom.client.ClickEvent;
24
import com.google.gwt.event.dom.client.ClickHandler;
25
import com.google.gwt.resources.client.ClientBundle;
26
import com.google.gwt.resources.client.ImageResource;
27
import com.google.gwt.user.client.ui.AbstractImagePrototype;
28
import com.google.gwt.user.client.ui.MenuBar;
29
import com.google.gwt.user.client.ui.MenuItem;
30
import com.google.gwt.user.client.ui.PopupPanel;
31

    
32
/**
33
 * The 'Group' menu implementation.
34
 */
35
public class GroupMenu extends PopupPanel implements ClickHandler {
36
        /**
37
         * The widget's images.
38
         */
39
        private Images images;
40
        private final MenuBar contextMenu;
41

    
42
        /**
43
         * An image bundle for this widgets images.
44
         */
45
        public interface Images extends ClientBundle {
46
                @Source("org/gss_project/gss/resources/groupevent.png")
47
                ImageResource groupNew();
48

    
49
                @Source("org/gss_project/gss/resources/view_text.png")
50
                ImageResource viewText();
51

    
52
        }
53

    
54
        /**
55
         * The widget's constructor.
56
         *
57
         * @param newImages the image bundle passed on by the parent object
58
         */
59
        public GroupMenu(final Images newImages) {
60
                // The popup's constructor's argument is a boolean specifying that it
61
                // auto-close itself when the user clicks outside of it.
62
                super(true);
63
                setAnimationEnabled(true);
64
                images = newImages;
65

    
66
                contextMenu = new MenuBar(true);
67
                MenuItem newGroupItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.groupNew()).getHTML() + "&nbsp;New Group</span>", true, new NewGroupCommand(this));
68
                newGroupItem.getElement().setId("topMenu.group.newGroup");
69
                contextMenu.addItem(newGroupItem);
70
                
71
                add(contextMenu);
72
        }
73

    
74
        @Override
75
        public void onClick(ClickEvent event) {
76
                GroupMenu menu = new GroupMenu(images);
77
                int left = event.getRelativeElement().getAbsoluteLeft();
78
                int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight();
79
                menu.setPopupPosition(left, top);
80

    
81
                menu.show();
82
        }
83

    
84
        /**
85
         * Retrieve the contextMenu.
86
         *
87
         * @return the contextMenu
88
         */
89
        public MenuBar getContextMenu() {
90
                contextMenu.setAutoOpen(false);
91
                return contextMenu;
92
        }
93

    
94
}