root / web_client / src / gr / grnet / pithos / web / client / SettingsMenu.java @ 58777026
History | View | Annotate | Download (4.3 kB)
1 |
/*
|
---|---|
2 |
* Copyright 2011 GRNET S.A. All rights reserved.
|
3 |
*
|
4 |
* Redistribution and use in source and binary forms, with or
|
5 |
* without modification, are permitted provided that the following
|
6 |
* conditions are met:
|
7 |
*
|
8 |
* 1. Redistributions of source code must retain the above
|
9 |
* copyright notice, this list of conditions and the following
|
10 |
* disclaimer.
|
11 |
*
|
12 |
* 2. Redistributions in binary form must reproduce the above
|
13 |
* copyright notice, this list of conditions and the following
|
14 |
* disclaimer in the documentation and/or other materials
|
15 |
* provided with the distribution.
|
16 |
*
|
17 |
* THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
18 |
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
20 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
21 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
22 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
23 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
24 |
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
25 |
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
26 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
27 |
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28 |
* POSSIBILITY OF SUCH DAMAGE.
|
29 |
*
|
30 |
* The views and conclusions contained in the software and
|
31 |
* documentation are those of the authors and should not be
|
32 |
* interpreted as representing official policies, either expressed
|
33 |
* or implied, of GRNET S.A.
|
34 |
*/
|
35 |
package gr.grnet.pithos.web.client; |
36 |
|
37 |
import com.google.gwt.event.dom.client.ClickEvent; |
38 |
import com.google.gwt.event.dom.client.ClickHandler; |
39 |
import com.google.gwt.resources.client.ClientBundle; |
40 |
import com.google.gwt.resources.client.ImageResource; |
41 |
import com.google.gwt.user.client.Command; |
42 |
import com.google.gwt.user.client.ui.AbstractImagePrototype; |
43 |
import com.google.gwt.user.client.ui.MenuBar; |
44 |
import com.google.gwt.user.client.ui.MenuItem; |
45 |
import com.google.gwt.user.client.ui.PopupPanel; |
46 |
|
47 |
/**
|
48 |
* The 'settings' menu implementation.
|
49 |
*/
|
50 |
public class SettingsMenu extends PopupPanel implements ClickHandler { |
51 |
|
52 |
/**
|
53 |
* The widget's images.
|
54 |
*/
|
55 |
private Images images;
|
56 |
private final MenuBar contextMenu; |
57 |
/**
|
58 |
* An image bundle for this widgets images.
|
59 |
*/
|
60 |
public interface Images extends ClientBundle,MessagePanel.Images { |
61 |
|
62 |
/**
|
63 |
* Will bundle the file 'advancedsettings.png' residing in the package
|
64 |
* 'gr.grnet.pithos.web.resources'.
|
65 |
*
|
66 |
* @return the image prototype
|
67 |
*/
|
68 |
@Source("gr/grnet/pithos/resources/advancedsettings.png") |
69 |
ImageResource preferences(); |
70 |
|
71 |
@Source("gr/grnet/pithos/resources/lock.png") |
72 |
ImageResource credentials(); |
73 |
|
74 |
} |
75 |
|
76 |
/**
|
77 |
* The widget's constructor.
|
78 |
*
|
79 |
* @param newImages the image bundle passed on by the parent object
|
80 |
*/
|
81 |
public SettingsMenu(final Images newImages) { |
82 |
// The popup's constructor's argument is a boolean specifying that it
|
83 |
// auto-close itself when the user clicks outside of it.
|
84 |
super(true); |
85 |
setAnimationEnabled(true);
|
86 |
images = newImages; |
87 |
|
88 |
Command userCredentialsCommand = new Command(){
|
89 |
@Override
|
90 |
public void execute() { |
91 |
CredentialsDialog dlg = new CredentialsDialog(newImages);
|
92 |
dlg.center(); |
93 |
} |
94 |
}; |
95 |
contextMenu = new MenuBar(true); |
96 |
// contextMenu.addItem("<span>" + newImages.preferences().getHTML() + " Preferences</span>", true, cmd);
|
97 |
MenuItem showCredentialsItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.credentials()).getHTML() + " Show Credentials</span>", true, userCredentialsCommand); |
98 |
showCredentialsItem.getElement().setId("topMenu.settingsMenu.showCredentials");
|
99 |
contextMenu.addItem(showCredentialsItem); |
100 |
|
101 |
add(contextMenu); |
102 |
// setStyleName("toolbarPopup");
|
103 |
} |
104 |
|
105 |
@Override
|
106 |
public void onClick(final ClickEvent event) { |
107 |
final SettingsMenu menu = new SettingsMenu(images); |
108 |
final int left = event.getRelativeElement().getAbsoluteLeft(); |
109 |
final int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight(); |
110 |
menu.setPopupPosition(left, top); |
111 |
|
112 |
menu.show(); |
113 |
} |
114 |
|
115 |
|
116 |
/**
|
117 |
* Retrieve the contextMenu.
|
118 |
*
|
119 |
* @return the contextMenu
|
120 |
*/
|
121 |
public MenuBar getContextMenu() { |
122 |
contextMenu.setAutoOpen(false);
|
123 |
return contextMenu;
|
124 |
} |
125 |
|
126 |
|
127 |
} |