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();
placeManager.revealPlace(
new PlaceRequest(NameTokens.ToolsPresenter).with("name", "run-as-role")
);
}
});
usermenu.add(runAsBtn);
}
usermenu.add(new HTML("<hr/>"));
usermenu.add(logoutHtml);
menuPopup.setWidget(usermenu);
top.add(tools);
top.setWidgetRightWidth(tools, 15, Style.Unit.PX, 700, Style.Unit.PX);
top.setWidgetTopHeight(tools, 2, Style.Unit.PX, 32, Style.Unit.PX);
top.setWidgetHorizontalPosition(tools, Layout.Alignment.END);