// user menu
// roles
Set<String> roles = bootstrap.getRoles();
SafeHtmlBuilder sb = new SafeHtmlBuilder();
sb.appendHtmlConstant("<div class='roles-menu'>");
for(String role : roles)
{
sb.appendEscaped(role).appendHtmlConstant("<br/>");
}
sb.appendHtmlConstant("<div>");
// current user
String userHtml = "<i style='color:#cecece' class='icon-user'></i> "+bootstrap.getPrincipal();
SafeHtml principal = new SafeHtmlBuilder().appendHtmlConstant("<div class='header-textlink'>"+userHtml+"</div>").toSafeHtml();
final HTML userButton = new HTML(principal);
userButton.getElement().setAttribute("style", "cursor:pointer");
tools.add(userButton);
final DefaultPopup menuPopup = new DefaultPopup(DefaultPopup.Arrow.TOP);
ClickHandler clickHandler = new ClickHandler() {
public void onClick(ClickEvent event) {
int width = 120;
int height = 50;
menuPopup.setPopupPosition(
userButton.getAbsoluteLeft() - (width+2- userButton.getOffsetWidth()) ,
userButton.getAbsoluteTop() + 25
);
menuPopup.show();
menuPopup.setWidth(width+"px");
menuPopup.setHeight(height+"px");
}
};
userButton.addClickHandler(clickHandler);
HTML logoutHtml = new HTML("<i class='icon-signout'></i> " + Console.CONSTANTS.common_label_logout());
logoutHtml.getElement().setAttribute("style", "cursor:pointer;padding-top:3px");
logoutHtml.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
menuPopup.hide();
Feedback.confirm(
Console.CONSTANTS.common_label_logout(),
Console.CONSTANTS.logout_confirm(),
new Feedback.ConfirmationHandler() {
@Override
public void onConfirmation(boolean isConfirmed) {
if (isConfirmed) {
new LogoutCmd().execute();
}
}
}
);
}
});
logoutHtml.addStyleName("html-link");
VerticalPanel usermenu = new VerticalPanel();
usermenu.setStyleName("fill-layout-width");
usermenu.addStyleName("user-menu");
usermenu.add(new HTML("Roles:"));
usermenu.add(new HTML(sb.toSafeHtml()));
if(bootstrap.isSuperUser())
{
usermenu.add(new HTML("<hr/>"));
HTML runAsBtn = new HTML();
runAsBtn.addStyleName("html-link");
SafeHtmlBuilder runAsRole = new SafeHtmlBuilder();
runAsRole.appendHtmlConstant("<i class='icon-flag'></i> ").appendEscaped("Run as");
if (bootstrap.getRunAs()!=null) {
runAsRole.appendHtmlConstant(" ").appendEscaped(bootstrap.getRunAs());
} else {
runAsRole.appendEscaped("...");
}
runAsBtn.setHTML(runAsRole.toSafeHtml());
runAsBtn.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
menuPopup.hide();