final ModalWindow membershipWin = new ModalWindow("membershipWin");
membershipWin.setCssClassName(ModalWindow.CSS_CLASS_GRAY);
membershipWin.setCookieName("create-membership-modal");
add(membershipWin);
BaseTree tree = new LinkTree("treeTable", roleTreeBuilder.build()) {
private static final long serialVersionUID = -5514696922119256101L;
@Override
protected IModel getNodeTextModel(final IModel model) {
return new PropertyModel(model, "userObject.displayName");
}
@Override
protected void onNodeLinkClicked(final Object node, final BaseTree tree, final AjaxRequestTarget target) {
final RoleTO roleTO = (RoleTO) ((DefaultMutableTreeNode) node).getUserObject();
membershipWin.setPageCreator(new ModalWindow.PageCreator() {
private static final long serialVersionUID = 7661763358801821185L;
private MembershipTO membershipTO;
@Override
public Page createPage() {
for (MembershipTO memberTO : membershipsView.getList()) {
if (memberTO.getRoleId() == roleTO.getId()) {
return new MembershipModalPage(getPage().getPageReference(), membershipWin, memberTO,
templateMode);
}
}
membershipTO = new MembershipTO();
membershipTO.setRoleId(roleTO.getId());
membershipTO.setRoleName(roleTO.getName());
return new MembershipModalPage(getPage().getPageReference(), membershipWin, membershipTO,
templateMode);
}
});
membershipWin.show(target);
}
};
tree.setOutputMarkupId(true);
tree.getTreeState().expandAll();
add(tree);
membershipsView = new ListView<MembershipTO>("memberships", new PropertyModel<List<? extends MembershipTO>>(
userTO, "memberships")) {