Statistics
| Branch: | Tag: | Revision:

root / src / gr / ebs / gss / client / GroupMenu.java @ 0f8b2929

History | View | Annotate | Download (2.6 kB)

1 023f6f1e Panagiotis Astithas
/*
2 023f6f1e Panagiotis Astithas
 * Copyright 2007, 2008, 2009 Electronic Business Systems Ltd.
3 023f6f1e Panagiotis Astithas
 *
4 023f6f1e Panagiotis Astithas
 * This file is part of GSS.
5 023f6f1e Panagiotis Astithas
 *
6 023f6f1e Panagiotis Astithas
 * GSS is free software: you can redistribute it and/or modify
7 023f6f1e Panagiotis Astithas
 * it under the terms of the GNU General Public License as published by
8 023f6f1e Panagiotis Astithas
 * the Free Software Foundation, either version 3 of the License, or
9 023f6f1e Panagiotis Astithas
 * (at your option) any later version.
10 023f6f1e Panagiotis Astithas
 *
11 023f6f1e Panagiotis Astithas
 * GSS is distributed in the hope that it will be useful,
12 023f6f1e Panagiotis Astithas
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 023f6f1e Panagiotis Astithas
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 023f6f1e Panagiotis Astithas
 * GNU General Public License for more details.
15 023f6f1e Panagiotis Astithas
 *
16 023f6f1e Panagiotis Astithas
 * You should have received a copy of the GNU General Public License
17 023f6f1e Panagiotis Astithas
 * along with GSS.  If not, see <http://www.gnu.org/licenses/>.
18 023f6f1e Panagiotis Astithas
 */
19 023f6f1e Panagiotis Astithas
package gr.ebs.gss.client;
20 023f6f1e Panagiotis Astithas
21 023f6f1e Panagiotis Astithas
import gr.ebs.gss.client.commands.NewGroupCommand;
22 023f6f1e Panagiotis Astithas
23 023f6f1e Panagiotis Astithas
import com.google.gwt.event.dom.client.ClickEvent;
24 023f6f1e Panagiotis Astithas
import com.google.gwt.event.dom.client.ClickHandler;
25 023f6f1e Panagiotis Astithas
import com.google.gwt.resources.client.ClientBundle;
26 023f6f1e Panagiotis Astithas
import com.google.gwt.resources.client.ImageResource;
27 023f6f1e Panagiotis Astithas
import com.google.gwt.user.client.ui.AbstractImagePrototype;
28 023f6f1e Panagiotis Astithas
import com.google.gwt.user.client.ui.MenuBar;
29 023f6f1e Panagiotis Astithas
import com.google.gwt.user.client.ui.PopupPanel;
30 023f6f1e Panagiotis Astithas
31 023f6f1e Panagiotis Astithas
/**
32 023f6f1e Panagiotis Astithas
 * The 'Group' menu implementation.
33 023f6f1e Panagiotis Astithas
 */
34 023f6f1e Panagiotis Astithas
public class GroupMenu extends PopupPanel implements ClickHandler {
35 023f6f1e Panagiotis Astithas
        /**
36 023f6f1e Panagiotis Astithas
         * The widget's images.
37 023f6f1e Panagiotis Astithas
         */
38 023f6f1e Panagiotis Astithas
        private Images images;
39 023f6f1e Panagiotis Astithas
        private final MenuBar contextMenu;
40 023f6f1e Panagiotis Astithas
41 023f6f1e Panagiotis Astithas
        /**
42 023f6f1e Panagiotis Astithas
         * An image bundle for this widgets images.
43 023f6f1e Panagiotis Astithas
         */
44 023f6f1e Panagiotis Astithas
        public interface Images extends ClientBundle {
45 023f6f1e Panagiotis Astithas
                @Source("gr/ebs/gss/resources/groupevent.png")
46 023f6f1e Panagiotis Astithas
                ImageResource groupNew();
47 023f6f1e Panagiotis Astithas
48 023f6f1e Panagiotis Astithas
                @Source("gr/ebs/gss/resources/view_text.png")
49 023f6f1e Panagiotis Astithas
                ImageResource viewText();
50 023f6f1e Panagiotis Astithas
51 023f6f1e Panagiotis Astithas
        }
52 023f6f1e Panagiotis Astithas
53 023f6f1e Panagiotis Astithas
        /**
54 023f6f1e Panagiotis Astithas
         * The widget's constructor.
55 023f6f1e Panagiotis Astithas
         *
56 023f6f1e Panagiotis Astithas
         * @param newImages the image bundle passed on by the parent object
57 023f6f1e Panagiotis Astithas
         */
58 023f6f1e Panagiotis Astithas
        public GroupMenu(final Images newImages) {
59 023f6f1e Panagiotis Astithas
                // The popup's constructor's argument is a boolean specifying that it
60 023f6f1e Panagiotis Astithas
                // auto-close itself when the user clicks outside of it.
61 023f6f1e Panagiotis Astithas
                super(true);
62 023f6f1e Panagiotis Astithas
                setAnimationEnabled(true);
63 023f6f1e Panagiotis Astithas
                images = newImages;
64 023f6f1e Panagiotis Astithas
65 023f6f1e Panagiotis Astithas
                contextMenu = new MenuBar(true);
66 023f6f1e Panagiotis Astithas
                contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.groupNew()).getHTML() + "&nbsp;New Group</span>", true, new NewGroupCommand(this));
67 023f6f1e Panagiotis Astithas
68 023f6f1e Panagiotis Astithas
                add(contextMenu);
69 023f6f1e Panagiotis Astithas
        }
70 023f6f1e Panagiotis Astithas
71 023f6f1e Panagiotis Astithas
        @Override
72 023f6f1e Panagiotis Astithas
        public void onClick(ClickEvent event) {
73 023f6f1e Panagiotis Astithas
                GroupMenu menu = new GroupMenu(images);
74 023f6f1e Panagiotis Astithas
                int left = event.getRelativeElement().getAbsoluteLeft();
75 023f6f1e Panagiotis Astithas
                int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight();
76 023f6f1e Panagiotis Astithas
                menu.setPopupPosition(left, top);
77 023f6f1e Panagiotis Astithas
78 023f6f1e Panagiotis Astithas
                menu.show();
79 023f6f1e Panagiotis Astithas
        }
80 023f6f1e Panagiotis Astithas
81 023f6f1e Panagiotis Astithas
        /**
82 023f6f1e Panagiotis Astithas
         * Retrieve the contextMenu.
83 023f6f1e Panagiotis Astithas
         *
84 023f6f1e Panagiotis Astithas
         * @return the contextMenu
85 023f6f1e Panagiotis Astithas
         */
86 023f6f1e Panagiotis Astithas
        public MenuBar getContextMenu() {
87 023f6f1e Panagiotis Astithas
                contextMenu.setAutoOpen(false);
88 023f6f1e Panagiotis Astithas
                return contextMenu;
89 023f6f1e Panagiotis Astithas
        }
90 023f6f1e Panagiotis Astithas
91 023f6f1e Panagiotis Astithas
}