Statistics
| Branch: | Tag: | Revision:

root / src / gr / ebs / gss / client / GroupMenu.java @ fc0fa492

History | View | Annotate | Download (2.6 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 gr.ebs.gss.client;
20

    
21
import gr.ebs.gss.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.PopupPanel;
30

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

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

    
48
                @Source("gr/ebs/gss/resources/view_text.png")
49
                ImageResource viewText();
50

    
51
        }
52

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

    
65
                contextMenu = new MenuBar(true);
66
                contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.groupNew()).getHTML() + "&nbsp;New Group</span>", true, new NewGroupCommand(this));
67

    
68
                add(contextMenu);
69
        }
70

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

    
78
                menu.show();
79
        }
80

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

    
91
}