listItem.add(new ListView("roles", roles) {
protected void populateItem(ListItem listItem) {
String roleClass = listItem.getIndex() % 2 == 1 ? " alt" : "";
String lastRole = listItem.getIndex() == roles.size() - 1 ? " bdr-bottom" : "";
listItem.add(new SimpleAttributeModifier("class", "center" + roleClass + lastRole));
final Role role = (Role) listItem.getModelObject();
if(listItem.getIndex() == 0) {
SimpleAttributeModifier rowClass = new SimpleAttributeModifier("class", stateClass);
listItem.add(new Label("state", statesMap.get(stateKeyRow)).add(rowspan).add(rowClass));
WebMarkupContainer editState = new WebMarkupContainer("editState");
editState.add(rowspan).add(rowClass);
Button editStateButton = new Button("editState") {
@Override
public void onSubmit() {
setResponsePage(new SpaceStatePage(space, stateKeyRow, previous));
}
};
editState.add(editStateButton);
if(stateKeyRow == State.NEW) { // user can customize state names, even for Closed
editStateButton.setVisible(false);
}
listItem.add(editState);
} else {
listItem.add(new WebMarkupContainer("state").setVisible(false));
listItem.add(new WebMarkupContainer("editState").setVisible(false));
}
listItem.add(new Label("role", role.getName()));
Button editRoleButton = new Button("editRole") {
@Override
public void onSubmit() {
setResponsePage(new SpaceRolePage(space, role.getName(), previous));
}
};
listItem.add(editRoleButton);
if(!firstState) {
editRoleButton.setVisible(false);
}
listItem.add(new ListView("stateHeads", stateKeysNoNew) {
protected void populateItem(ListItem listItem) {
final Integer stateKeyCol = (Integer) listItem.getModelObject();
Button stateButton = new Button("state") {
@Override
public void onSubmit() {
space.getMetadata().toggleTransition(role.getName(), stateKeyRow, stateKeyCol);
setResponsePage(new SpacePermissionsPage(space, previous));
}
};
if(stateKeyRow == State.NEW && stateKeyCol != State.OPEN) {
stateButton.setVisible(false);
}
State state = role.getStates().get(stateKeyRow);
if(state != null && state.getTransitions().contains(stateKeyCol)) {
stateButton.add(yes);
} else {
stateButton.add(no);
}
listItem.add(stateButton);
}
});
listItem.add(new ListView("fieldHeads", fields) {
protected void populateItem(ListItem listItem) {
if(roles.size() == 1 && listItem.getIndex() % 2 == 0) {
listItem.add(altClass);
}
final Field field = (Field) listItem.getModelObject();
Button fieldButton = new Button("field") {
@Override
public void onSubmit() {
space.getMetadata().switchMask(stateKeyRow, role.getName(), field.getName().getText());
setResponsePage(new SpacePermissionsPage(space, previous));
}
};
State state = role.getStates().get(stateKeyRow);
int mask = state.getFields().get(field.getName());
switch(mask) {
case State.MASK_MANDATORY : fieldButton.add(mandatory); break;
case State.MASK_OPTIONAL : fieldButton.add(optional); break;
case State.MASK_READONLY : fieldButton.add(readonly); break;