Statistics
| Branch: | Tag: | Revision:

root / src / gr / ebs / gss / client / SettingsMenu.java @ 023f6f1e

History | View | Annotate | Download (3.3 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 com.google.gwt.event.dom.client.ClickEvent;
22
import com.google.gwt.event.dom.client.ClickHandler;
23
import com.google.gwt.resources.client.ClientBundle;
24
import com.google.gwt.resources.client.ImageResource;
25
import com.google.gwt.user.client.Command;
26
import com.google.gwt.user.client.ui.AbstractImagePrototype;
27
import com.google.gwt.user.client.ui.MenuBar;
28
import com.google.gwt.user.client.ui.PopupPanel;
29

    
30
/**
31
 * The 'settings' menu implementation.
32
 */
33
public class SettingsMenu extends PopupPanel implements ClickHandler {
34

    
35
        /**
36
         * The widget's images.
37
         */
38
        private Images images;
39
        private final MenuBar contextMenu;
40
        /**
41
         * An image bundle for this widgets images.
42
         */
43
        public interface Images extends ClientBundle,MessagePanel.Images {
44

    
45
                /**
46
                 * Will bundle the file 'advancedsettings.png' residing in the package
47
                 * 'gr.ebs.gss.resources'.
48
                 *
49
                 * @return the image prototype
50
                 */
51
                @Source("gr/ebs/gss/resources/advancedsettings.png")
52
                ImageResource preferences();
53

    
54
                @Source("gr/ebs/gss/resources/lock.png")
55
                ImageResource credentials();
56

    
57
        }
58

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

    
71
                Command userCredentialsCommand = new Command(){
72
                        @Override
73
                        public void execute() {
74
                                CredentialsDialog dlg = new CredentialsDialog(newImages);
75
                                dlg.center();
76
                        }
77
                };
78
                contextMenu = new MenuBar(true);
79
//                contextMenu.addItem("<span>" + newImages.preferences().getHTML() + "&nbsp;Preferences</span>", true, cmd);
80
                contextMenu.addItem("<span>" + AbstractImagePrototype.create(newImages.credentials()).getHTML() + "&nbsp;Show Credentials</span>", true, userCredentialsCommand);
81

    
82
                add(contextMenu);
83
                // setStyleName("toolbarPopup");
84
        }
85

    
86
        @Override
87
        public void onClick(final ClickEvent event) {
88
                final SettingsMenu menu = new SettingsMenu(images);
89
                final int left = event.getRelativeElement().getAbsoluteLeft();
90
                final int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight();
91
                menu.setPopupPosition(left, top);
92

    
93
                menu.show();
94
        }
95

    
96

    
97
        /**
98
         * Retrieve the contextMenu.
99
         *
100
         * @return the contextMenu
101
         */
102
        public MenuBar getContextMenu() {
103
                contextMenu.setAutoOpen(false);
104
                return contextMenu;
105
        }
106

    
107

    
108
}