Statistics
| Branch: | Tag: | Revision:

root / web_client / src / gr / grnet / pithos / web / client / SettingsMenu.java @ ab1eb3f8

History | View | Annotate | Download (3.5 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.grnet.pithos.web.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.MenuItem;
29
import com.google.gwt.user.client.ui.PopupPanel;
30

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

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

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

    
55
                @Source("gr/grnet/pithos/resources/lock.png")
56
                ImageResource credentials();
57

    
58
        }
59

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

    
72
                Command userCredentialsCommand = new Command(){
73
                        @Override
74
                        public void execute() {
75
                                CredentialsDialog dlg = new CredentialsDialog(newImages);
76
                                dlg.center();
77
                        }
78
                };
79
                contextMenu = new MenuBar(true);
80
//                contextMenu.addItem("<span>" + newImages.preferences().getHTML() + "&nbsp;Preferences</span>", true, cmd);
81
                MenuItem showCredentialsItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.credentials()).getHTML() + "&nbsp;Show Credentials</span>", true, userCredentialsCommand);
82
                showCredentialsItem.getElement().setId("topMenu.settingsMenu.showCredentials");
83
                contextMenu.addItem(showCredentialsItem);
84
                
85
                add(contextMenu);
86
                // setStyleName("toolbarPopup");
87
        }
88

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

    
96
                menu.show();
97
        }
98

    
99

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

    
110

    
111
}