private static final long serialVersionUID = 7137658050662575546L;
@Override
protected Component newContentComponent(final String id, final IModel<DefaultMutableTreeNode> node) {
final DefaultMutableTreeNode treeNode = node.getObject();
final RoleTO roleTO = (RoleTO) treeNode.getUserObject();
return new Folder<DefaultMutableTreeNode>(id, MembershipsPanel.this.tree, node) {
private static final long serialVersionUID = 9046323319920426493L;
@Override
protected boolean isClickable() {
return true;
}
@Override
protected IModel<?> newLabelModel(final IModel<DefaultMutableTreeNode> model) {
return new Model<String>(roleTO.getDisplayName());
}
@Override
protected void onClick(final AjaxRequestTarget target) {
membWin.setPageCreator(new ModalWindow.PageCreator() {
private static final long serialVersionUID = 7661763358801821185L;
@Override
public Page createPage() {
PageReference pageRef = getPage().getPageReference();
for (MembershipTO membTO : membView.getList()) {
if (membTO.getRoleId() == roleTO.getId()) {
return new MembershipModalPage(pageRef, membWin, membTO, templateMode);
}
}
MembershipTO membTO = new MembershipTO();
membTO.setRoleId(roleTO.getId());
membTO.setRoleName(roleTO.getName());
return new MembershipModalPage(pageRef, membWin, membTO, templateMode);
}
});
membWin.show(target);
}
};
}
};
tree.add(new WindowsTheme());
tree.setOutputMarkupId(true);
DefaultMutableTreeNodeExpansion.get().expandAll();
this.add(tree);
membView = new ListView<MembershipTO>("memberships",
new PropertyModel<List<? extends MembershipTO>>(userTO, "memberships")) {
private static final long serialVersionUID = 9101744072914090143L;
@Override
protected void populateItem(final ListItem<MembershipTO> item) {
final MembershipTO membershipTO = (MembershipTO) item.getDefaultModelObject();
item.add(new Label("roleId", new Model<Long>(membershipTO.getRoleId())));
item.add(new Label("roleName", new Model<String>(membershipTO.getRoleName())));
AjaxLink editLink = new ClearIndicatingAjaxLink("editLink", pageRef) {
private static final long serialVersionUID = -7978723352517770644L;
@Override
protected void onClickInternal(final AjaxRequestTarget target) {
membWin.setPageCreator(new ModalWindow.PageCreator() {
private static final long serialVersionUID = -7834632442532690940L;
@Override
public Page createPage() {
return new MembershipModalPage(getPage().getPageReference(), membWin,
membershipTO, templateMode);
}
});
membWin.show(target);
}
};
item.add(editLink);
AjaxLink deleteLink = new IndicatingDeleteOnConfirmAjaxLink("deleteLink", pageRef) {
private static final long serialVersionUID = -7978723352517770644L;
@Override
protected void onClickInternal(final AjaxRequestTarget target) {
userTO.removeMembership(membershipTO);
target.add(membershipsContainer);
RoleTO roleTO = RoleUtils.findRole(roleTreeBuilder, membershipTO.getRoleId());
Set<String> resourcesToRemove = roleTO == null
? Collections.<String>emptySet() : roleTO.getResources();
if (!resourcesToRemove.isEmpty()) {
Set<String> resourcesAssignedViaMembership = new HashSet<String>();
for (MembershipTO membTO : userTO.getMemberships()) {
roleTO = RoleUtils.findRole(roleTreeBuilder, membTO.getRoleId());
if (roleTO != null) {
resourcesAssignedViaMembership.addAll(roleTO.getResources());
}
}
resourcesToRemove.removeAll(resourcesAssignedViaMembership);
resourcesToRemove.removeAll(userTO.getResources());
}