use of com.vaadin.data.StatusChangeListener in project catma by forTEXT.
the class ResourcePermissionView method createRoleEditor.
private Binding<Resource, RBACRole> createRoleEditor(Member member) {
final ComboBox<RBACRole> roleBox = new ComboBox<>();
roleBox.setEmptySelectionAllowed(false);
Binder<Resource> binder = permissionGrid.getEditor().getBinder();
binder.addStatusChangeListener(new StatusChangeListener() {
@Override
public void statusChange(StatusChangeEvent event) {
Resource resource = (Resource) event.getBinder().getBean();
Collection<RBACRole> availableRoles = new HashSet<RBACRole>();
if (resource != null) {
RBACRole role = permissionMatrix.get(resource, member);
availableRoles.add(role);
RBACRole projectRole = member.getRole();
availableRoles.add(projectRole);
if (projectRole.getAccessLevel() == RBACRole.REPORTER.getAccessLevel()) {
if (resource.isCollection()) {
availableRoles.add(RBACRole.ASSISTANT);
}
} else if (projectRole.getAccessLevel() == RBACRole.GUEST.getAccessLevel()) {
availableRoles.add(RBACRole.REPORTER);
if (resource.isCollection()) {
availableRoles.add(RBACRole.ASSISTANT);
}
}
}
roleBox.setItems(availableRoles);
roleBox.setEnabled(availableRoles.size() > 1);
}
});
return binder.bind(roleBox, resource -> permissionMatrix.get(resource, member), (resource, role) -> handleRoleChange(resource, member, role));
}
Aggregations