}
});
// fields col headings =============================================
add(new ListView("fieldHeads", fields) {
protected void populateItem(ListItem listItem) {
Field f = (Field) listItem.getModelObject();
listItem.add(new Label("field", f.getLabel()));
}
});
// rows init =======================================================
List<Integer> stateKeys = new ArrayList(statesMap.keySet());
final List<Role> roles = new ArrayList(space.getMetadata().getRoleList());
final SimpleAttributeModifier rowspan = new SimpleAttributeModifier("rowspan", roles.size() + "");
final SimpleAttributeModifier yes = new SimpleAttributeModifier("src", "../resources/status-green.gif");
final SimpleAttributeModifier no = new SimpleAttributeModifier("src", "../resources/status-grey.gif");
final SimpleAttributeModifier readonly = new SimpleAttributeModifier("src", "../resources/field-readonly.gif");
final SimpleAttributeModifier mandatory = new SimpleAttributeModifier("src", "../resources/field-mandatory.gif");
final SimpleAttributeModifier optional = new SimpleAttributeModifier("src", "../resources/field-optional.gif");
final SimpleAttributeModifier hidden = new SimpleAttributeModifier("src", "../resources/field-hidden.gif");
final SimpleAttributeModifier altClass = new SimpleAttributeModifier("class", "alt");
//==================================================================
add(new ListView("states", stateKeys) {
protected void populateItem(ListItem listItem) {
final boolean firstState = listItem.getIndex() == 0;
final String stateClass = listItem.getIndex() % 2 == 1 ? "bdr-bottom alt" : "bdr-bottom";
final Integer stateKeyRow = (Integer) listItem.getModelObject();
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;
case State.MASK_HIDDEN : fieldButton.add(hidden); break;