2 * Copyright (c) 2011 Greek Research and Technology Network
\r
4 package gr.grnet.pithos.web.client;
\r
6 import com.google.gwt.event.dom.client.ClickEvent;
\r
7 import com.google.gwt.event.dom.client.ClickHandler;
\r
8 import com.google.gwt.resources.client.ClientBundle;
\r
9 import com.google.gwt.resources.client.ImageResource;
\r
10 import com.google.gwt.user.client.Command;
\r
11 import com.google.gwt.user.client.ui.AbstractImagePrototype;
\r
12 import com.google.gwt.user.client.ui.MenuBar;
\r
13 import com.google.gwt.user.client.ui.MenuItem;
\r
14 import com.google.gwt.user.client.ui.PopupPanel;
\r
17 * The 'settings' menu implementation.
\r
19 public class SettingsMenu extends PopupPanel implements ClickHandler {
\r
22 * The widget's images.
\r
24 private Images images;
\r
25 private final MenuBar contextMenu;
\r
27 * An image bundle for this widgets images.
\r
29 public interface Images extends ClientBundle,MessagePanel.Images {
\r
32 * Will bundle the file 'advancedsettings.png' residing in the package
\r
33 * 'gr.grnet.pithos.web.resources'.
\r
35 * @return the image prototype
\r
37 @Source("gr/grnet/pithos/resources/advancedsettings.png")
\r
38 ImageResource preferences();
\r
40 @Source("gr/grnet/pithos/resources/lock.png")
\r
41 ImageResource credentials();
\r
46 * The widget's constructor.
\r
48 * @param newImages the image bundle passed on by the parent object
\r
50 public SettingsMenu(final Images newImages) {
\r
51 // The popup's constructor's argument is a boolean specifying that it
\r
52 // auto-close itself when the user clicks outside of it.
\r
54 setAnimationEnabled(true);
\r
57 Command userCredentialsCommand = new Command(){
\r
59 public void execute() {
\r
60 CredentialsDialog dlg = new CredentialsDialog(newImages);
\r
64 contextMenu = new MenuBar(true);
\r
65 // contextMenu.addItem("<span>" + newImages.preferences().getHTML() + " Preferences</span>", true, cmd);
\r
66 MenuItem showCredentialsItem = new MenuItem("<span>" + AbstractImagePrototype.create(newImages.credentials()).getHTML() + " Show Credentials</span>", true, userCredentialsCommand);
\r
67 showCredentialsItem.getElement().setId("topMenu.settingsMenu.showCredentials");
\r
68 contextMenu.addItem(showCredentialsItem);
\r
71 // setStyleName("toolbarPopup");
\r
75 public void onClick(final ClickEvent event) {
\r
76 final SettingsMenu menu = new SettingsMenu(images);
\r
77 final int left = event.getRelativeElement().getAbsoluteLeft();
\r
78 final int top = event.getRelativeElement().getAbsoluteTop() + event.getRelativeElement().getOffsetHeight();
\r
79 menu.setPopupPosition(left, top);
\r
86 * Retrieve the contextMenu.
\r
88 * @return the contextMenu
\r
90 public MenuBar getContextMenu() {
\r
91 contextMenu.setAutoOpen(false);
\r