use of org.apache.wicket.markup.html.link.ExternalLink in project midpoint by Evolveum.
the class UserMenuPanel method initLayout.
private void initLayout() {
WebMarkupContainer iconBox = new WebMarkupContainer(ID_ICON_BOX);
add(iconBox);
NonCachingImage img = new NonCachingImage(ID_PHOTO, new AbstractReadOnlyModel<AbstractResource>() {
@Override
public AbstractResource getObject() {
if (jpegPhoto == null) {
return null;
} else {
return new ByteArrayResource("image/jpeg", jpegPhoto);
}
}
});
img.add(new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
if (userModel != null && userModel.getObject() == null) {
loadModel(null);
}
return jpegPhoto != null;
}
});
iconBox.add(img);
ContextImage icon = new ContextImage(ID_ICON, "img/placeholder.png");
icon.add(new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
if (userModel != null && userModel.getObject() == null) {
loadModel(null);
}
return jpegPhoto == null;
}
});
iconBox.add(icon);
Label usernameLink = new Label(ID_USERNAME_LINK, new AbstractReadOnlyModel<String>() {
@Override
public String getObject() {
return getShortUserName();
}
});
add(usernameLink);
WebMarkupContainer panelIconBox = new WebMarkupContainer(ID_PANEL_ICON_BOX);
add(panelIconBox);
NonCachingImage panelImg = new NonCachingImage(ID_PANEL_PHOTO, new AbstractReadOnlyModel<AbstractResource>() {
@Override
public AbstractResource getObject() {
if (jpegPhoto == null) {
return null;
} else {
return new ByteArrayResource("image/jpeg", jpegPhoto);
}
}
});
panelImg.add(new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
if (userModel != null && userModel.getObject() == null) {
loadModel(null);
}
return jpegPhoto != null;
}
});
panelIconBox.add(panelImg);
ContextImage panelIcon = new ContextImage(ID_PANEL_ICON, "img/placeholder.png");
panelIcon.add(new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
if (userModel != null && userModel.getObject() == null) {
loadModel(null);
}
return jpegPhoto == null;
}
});
panelIconBox.add(panelIcon);
Label username = new Label(ID_USERNAME, new AbstractReadOnlyModel<String>() {
@Override
public String getObject() {
return getShortUserName();
}
});
username.setRenderBodyOnly(true);
add(username);
ExternalLink logoutLink = new ExternalLink(ID_LOGOUT_LINK, new Model<>(RequestCycle.get().getRequest().getContextPath() + "/j_spring_security_logout"), createStringResource("UserMenuPanel.logout"));
add(logoutLink);
AjaxButton editPasswordQ = new AjaxButton(ID_PASSWORD_QUESTIONS, createStringResource("UserMenuPanel.editPasswordQuestions")) {
@Override
public void onClick(AjaxRequestTarget target) {
PageMyPasswordQuestions myPasswordQuestions = new PageMyPasswordQuestions(passwordQuestionsDtoIModel);
setResponsePage(myPasswordQuestions);
}
};
add(editPasswordQ);
if (!isPasswordModelLoaded) {
passwordQuestionsDtoIModel = new LoadableModel<PasswordQuestionsDto>(false) {
private static final long serialVersionUID = 1L;
@Override
protected PasswordQuestionsDto load() {
return loadModel(null);
}
};
isPasswordModelLoaded = true;
}
securityPolicyQuestionsModel = new LoadableModel<List<SecurityQuestionDefinitionType>>(false) {
@Override
protected List<SecurityQuestionDefinitionType> load() {
return loadSecurityPloicyQuestionsModel();
}
};
editPasswordQ.add(new VisibleEnableBehaviour() {
@Override
public boolean isVisible() {
if (securityPolicyQuestionsModel == null || securityPolicyQuestionsModel.getObject() == null) {
loadSecurityPloicyQuestionsModel();
}
return hasQuestions() || (securityPolicyQuestionsModel.getObject() != null && securityPolicyQuestionsModel.getObject().size() > 0);
}
});
}
Aggregations