Search in sources :

Example 1 with StatusChangeEvent

use of com.vaadin.data.StatusChangeEvent 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));
}
Also used : StatusChangeListener(com.vaadin.data.StatusChangeListener) StatusChangeEvent(com.vaadin.data.StatusChangeEvent) RBACRole(de.catma.rbac.RBACRole) ComboBox(com.vaadin.ui.ComboBox) Collection(java.util.Collection)

Aggregations

StatusChangeEvent (com.vaadin.data.StatusChangeEvent)1 StatusChangeListener (com.vaadin.data.StatusChangeListener)1 ComboBox (com.vaadin.ui.ComboBox)1 RBACRole (de.catma.rbac.RBACRole)1 Collection (java.util.Collection)1