Search in sources :

Example 1 with Mode

use of org.pentaho.di.ui.repository.repositoryexplorer.model.UISecurity.Mode in project pentaho-kettle by pentaho.

the class EESecurityController method createBindings.

@Override
protected void createBindings() {
    super.createBindings();
    // User Role Binding
    // $NON-NLS-1$
    systemRoleRadioButton = (XulRadio) document.getElementById("system-role-radio-button");
    // $NON-NLS-1$
    roleRadioButton = (XulRadio) document.getElementById("role-radio-button");
    // $NON-NLS-1$
    userRadioButton = (XulRadio) document.getElementById("user-radio-button");
    // $NON-NLS-1$
    roleAddButton = (XulButton) document.getElementById("role-add");
    // $NON-NLS-1$
    roleEditButton = (XulButton) document.getElementById("role-edit");
    // $NON-NLS-1$
    roleRemoveButton = (XulButton) document.getElementById("role-remove");
    // $NON-NLS-1$
    addUserToRoleButton = (XulButton) document.getElementById("add-user-to-role");
    // $NON-NLS-1$
    removeUserFromRoleButton = (XulButton) document.getElementById("remove-user-from-role");
    // $NON-NLS-1$
    addRoleToUserButton = (XulButton) document.getElementById("add-role-to-user");
    // $NON-NLS-1$
    removeRoleFromUserButton = (XulButton) document.getElementById("remove-role-from-user");
    // $NON-NLS-1$
    roleDialog = (XulDialog) document.getElementById("add-role-dialog");
    // $NON-NLS-1$
    userRoleDeck = (XulDeck) document.getElementById("user-role-deck");
    // $NON-NLS-1$
    roleListBox = (XulListbox) document.getElementById("roles-list");
    // $NON-NLS-1$
    roleDetailTable = (XulTree) document.getElementById("role-detail-table");
    // Add User Binding
    // $NON-NLS-1$
    userListBox = (XulListbox) document.getElementById("users-list");
    // $NON-NLS-1$
    userDetailTable = (XulTree) document.getElementById("user-detail-table");
    // $NON-NLS-1$
    availableRoles = (XulListbox) document.getElementById("available-roles-list");
    // $NON-NLS-1$
    assignedRoles = (XulListbox) document.getElementById("selected-roles-list");
    // $NON-NLS-1$
    assignRoleToUserButton = (XulButton) document.getElementById("assign-role-to-user");
    // $NON-NLS-1$
    unassignRoleFromUserButton = (XulButton) document.getElementById("unassign-role-from-user");
    // $NON-NLS-1$
    systemRoleListBox = (XulListbox) document.getElementById("system-roles-list");
    // $NON-NLS-1$
    innerRoleVbox = (XulVbox) document.getElementById("inner-role-vbox");
    // $NON-NLS-1$
    roleVboxNonManaged = (XulVbox) document.getElementById("role-vbox-nonmanaged");
    // $NON-NLS-1$
    roleHbox = (XulHbox) document.getElementById("role-hbox");
    // $NON-NLS-1$
    instructionalTextLabel = (XulLabel) document.getElementById("instructional-text-label");
    bf.setBindingType(Binding.Type.BI_DIRECTIONAL);
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(eeSecurityUser, "assignedRoles", assignedRoles, "elements");
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(eeSecurityUser, "availableRoles", availableRoles, "elements");
    // Binding to convert role array to a role list object and vice versa
    BindingConvertor<List<IUIRole>, Object[]> arrayToListRoleConverter = new BindingConvertor<List<IUIRole>, Object[]>() {

        @Override
        public Object[] sourceToTarget(List<IUIRole> roles) {
            if (roles != null) {
                Object[] retVal = new Object[roles.size()];
                int i = 0;
                for (IUIRole role : roles) {
                    retVal[i++] = role;
                }
                return retVal;
            }
            return null;
        }

        @Override
        public List<IUIRole> targetToSource(Object[] roles) {
            if (roles != null) {
                List<IUIRole> retVal = new ArrayList<IUIRole>();
                for (int i = 0; i < roles.length; i++) {
                    retVal.add((IUIRole) roles[i]);
                }
                return retVal;
            }
            return null;
        }
    };
    // Binding to convert user array to a user list object and vice versa
    BindingConvertor<List<IUIUser>, Object[]> arrayToListUserConverter = new BindingConvertor<List<IUIUser>, Object[]>() {

        @Override
        public Object[] sourceToTarget(List<IUIUser> users) {
            if (users != null) {
                Object[] retVal = new Object[users.size()];
                int i = 0;
                for (IUIUser user : users) {
                    retVal[i++] = user;
                }
                return retVal;
            }
            return null;
        }

        @Override
        public List<IUIUser> targetToSource(Object[] users) {
            if (users != null) {
                List<IUIUser> retVal = new ArrayList<IUIUser>();
                for (int i = 0; i < users.length; i++) {
                    retVal.add((IUIUser) users[i]);
                }
                return retVal;
            }
            return null;
        }
    };
    bf.createBinding(eeSecurityUser, "availableSelectedRoles", availableRoles, "selectedItems", // $NON-NLS-1$ //$NON-NLS-2$
    arrayToListRoleConverter);
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(eeSecurityUser, "assignedSelectedRoles", assignedRoles, "selectedItems", arrayToListRoleConverter);
    BindingConvertor<Integer, Boolean> accumulatorButtonConverter = new BindingConvertor<Integer, Boolean>() {

        @Override
        public Boolean sourceToTarget(Integer value) {
            if (value != null && value >= 0) {
                return true;
            }
            return false;
        }

        @Override
        public Integer targetToSource(Boolean value) {
            return null;
        }
    };
    bf.setBindingType(Binding.Type.ONE_WAY);
    bf.createBinding(assignedRoles, "selectedIndex", eeSecurityUser, "roleUnassignmentPossible", // $NON-NLS-1$ //$NON-NLS-2$
    accumulatorButtonConverter);
    bf.createBinding(availableRoles, "selectedIndex", eeSecurityUser, "roleAssignmentPossible", // $NON-NLS-1$ //$NON-NLS-2$
    accumulatorButtonConverter);
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(eeSecurityUser, "roleUnassignmentPossible", unassignRoleFromUserButton, "!disabled");
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(eeSecurityUser, "roleAssignmentPossible", assignRoleToUserButton, "!disabled");
    // Add Role Binding
    // $NON-NLS-1$
    rolename = (XulTextbox) document.getElementById("role-name");
    // $NON-NLS-1$
    roleDescription = (XulTextbox) document.getElementById("role-description");
    // $NON-NLS-1$
    availableUsers = (XulListbox) document.getElementById("available-users-list");
    // $NON-NLS-1$
    assignedUsers = (XulListbox) document.getElementById("selected-users-list");
    // $NON-NLS-1$
    assignUserToRoleButton = (XulButton) document.getElementById("assign-user-to-role");
    // $NON-NLS-1$
    unassignUserFromRoleButton = (XulButton) document.getElementById("unassign-user-from-role");
    bf.setBindingType(Binding.Type.BI_DIRECTIONAL);
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(securityRole, "name", rolename, "value");
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(securityRole, "description", roleDescription, "value");
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(securityRole, "assignedUsers", assignedUsers, "elements");
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(securityRole, "availableUsers", availableUsers, "elements");
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(securityRole, "availableSelectedUsers", availableUsers, "selectedItems", arrayToListUserConverter);
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(securityRole, "assignedSelectedUsers", assignedUsers, "selectedItems", arrayToListUserConverter);
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(eeSecurity, "selectedRoleIndex", roleListBox, "selectedIndex");
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(eeSecurity, "selectedSystemRoleIndex", systemRoleListBox, "selectedIndex");
    bf.setBindingType(Binding.Type.ONE_WAY);
    bf.createBinding(assignedUsers, "selectedIndex", securityRole, "userUnassignmentPossible", // $NON-NLS-1$ //$NON-NLS-2$
    accumulatorButtonConverter);
    bf.createBinding(availableUsers, "selectedIndex", securityRole, "userAssignmentPossible", // $NON-NLS-1$ //$NON-NLS-2$
    accumulatorButtonConverter);
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(securityRole, "userUnassignmentPossible", unassignUserFromRoleButton, "!disabled");
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(securityRole, "userAssignmentPossible", assignUserToRoleButton, "!disabled");
    try {
        bf.setBindingType(Binding.Type.ONE_WAY);
        // $NON-NLS-1$ //$NON-NLS-2$
        bf.createBinding(roleListBox, "selectedIndex", this, "enableButtons");
        bf.setBindingType(Binding.Type.ONE_WAY);
        // Action based security permissions
        // $NON-NLS-1$ //$NON-NLS-2$
        bf.createBinding(roleListBox, "selectedItem", eeSecurity, "selectedRole");
        // $NON-NLS-1$ //$NON-NLS-2$
        bf.createBinding(eeSecurity, "roleList", roleListBox, "elements").fireSourceChanged();
        // $NON-NLS-1$ //$NON-NLS-2$
        bf.createBinding(roleListBox, "selectedItem", eeSecurity, "selectedRole");
        // $NON-NLS-1$ //$NON-NLS-2$
        bf.createBinding(systemRoleListBox, "selectedItem", eeSecurity, "selectedSystemRole");
        // $NON-NLS-1$ //$NON-NLS-2$
        bf.createBinding(eeSecurity, "systemRoleList", systemRoleListBox, "elements").fireSourceChanged();
        // $NON-NLS-1$ //$NON-NLS-2$
        bf.createBinding(systemRoleListBox, "selectedItem", eeSecurity, "selectedSystemRole");
        if (managed) {
            userDetailBinding = // $NON-NLS-1$ //$NON-NLS-2$
            bf.createBinding(// $NON-NLS-1$ //$NON-NLS-2$
            eeSecurity, // $NON-NLS-1$ //$NON-NLS-2$
            "selectedUser", // $NON-NLS-1$ //$NON-NLS-2$
            userDetailTable, // $NON-NLS-1$ //$NON-NLS-2$
            "elements", new BindingConvertor<IUIUser, List<IUIRole>>() {

                @Override
                public List<IUIRole> sourceToTarget(IUIUser ru) {
                    if (ru instanceof IUIEEUser) {
                        return new ArrayList<IUIRole>(((IUIEEUser) ru).getRoles());
                    } else {
                        return null;
                    }
                }

                @Override
                public IUIUser targetToSource(List<IUIRole> arg0) {
                    // TODO Auto-generated method stub
                    return null;
                }
            });
            roleDetailBinding = // $NON-NLS-1$ //$NON-NLS-2$
            bf.createBinding(// $NON-NLS-1$ //$NON-NLS-2$
            eeSecurity, // $NON-NLS-1$ //$NON-NLS-2$
            "selectedRole", // $NON-NLS-1$ //$NON-NLS-2$
            roleDetailTable, // $NON-NLS-1$ //$NON-NLS-2$
            "elements", new BindingConvertor<IUIRole, List<IUIUser>>() {

                @Override
                public List<IUIUser> sourceToTarget(IUIRole rr) {
                    return new ArrayList<IUIUser>(rr.getUsers());
                }

                @Override
                public IUIRole targetToSource(List<IUIUser> arg0) {
                    // TODO Auto-generated method stub
                    return null;
                }
            });
        }
        // $NON-NLS-1$ //$NON-NLS-2$
        bf.createBinding(// $NON-NLS-1$ //$NON-NLS-2$
        eeSecurity, // $NON-NLS-1$ //$NON-NLS-2$
        "selectedDeck", // $NON-NLS-1$ //$NON-NLS-2$
        userRoleDeck, // $NON-NLS-1$ //$NON-NLS-2$
        "selectedIndex", new BindingConvertor<ObjectRecipient.Type, Integer>() {

            @Override
            public Integer sourceToTarget(Type arg0) {
                if (arg0 == Type.ROLE) {
                    userRadioButton.setSelected(false);
                    roleRadioButton.setSelected(true);
                    systemRoleRadioButton.setSelected(false);
                    return 1;
                } else if (arg0 == Type.USER) {
                    userRadioButton.setSelected(true);
                    roleRadioButton.setSelected(false);
                    systemRoleRadioButton.setSelected(false);
                    return 0;
                } else if (arg0 == Type.SYSTEM_ROLE) {
                    userRadioButton.setSelected(false);
                    roleRadioButton.setSelected(false);
                    systemRoleRadioButton.setSelected(true);
                    return 2;
                } else {
                    return -1;
                }
            }

            @Override
            public Type targetToSource(Integer arg0) {
                return null;
            }
        });
        BindingConvertor<Mode, Boolean> modeBindingConverter = new BindingConvertor<Mode, Boolean>() {

            @Override
            public Boolean sourceToTarget(Mode arg0) {
                if (arg0.equals(Mode.ADD)) {
                    return false;
                }
                return true;
            }

            @Override
            public Mode targetToSource(Boolean arg0) {
                // TODO Auto-generated method stub
                return null;
            }
        };
        BindingConvertor<Mode, Boolean> anotherModeBindingConverter = new BindingConvertor<Mode, Boolean>() {

            @Override
            public Boolean sourceToTarget(Mode arg0) {
                if (arg0.equals(Mode.EDIT_MEMBER)) {
                    return true;
                } else {
                    return false;
                }
            }

            @Override
            public Mode targetToSource(Boolean arg0) {
                // TODO Auto-generated method stub
                return null;
            }
        };
        // $NON-NLS-1$ //$NON-NLS-2$
        bf.createBinding(securityRole, "mode", rolename, "disabled", modeBindingConverter);
        // $NON-NLS-1$ //$NON-NLS-2$
        bf.createBinding(securityRole, "mode", roleDescription, "disabled", anotherModeBindingConverter);
        // $NON-NLS-1$ //$NON-NLS-2$
        bf.createBinding(securityUser, "mode", userPassword, "disabled", anotherModeBindingConverter);
        // $NON-NLS-1$ //$NON-NLS-2$
        bf.createBinding(securityUser, "mode", userDescription, "disabled", anotherModeBindingConverter);
    } catch (Exception e) {
        // convert to runtime exception so it bubbles up through the UI
        throw new RuntimeException(e);
    }
}
Also used : Mode(org.pentaho.di.ui.repository.repositoryexplorer.model.UISecurity.Mode) ArrayList(java.util.ArrayList) IUIEEUser(org.pentaho.di.ui.repository.pur.repositoryexplorer.IUIEEUser) BindingConvertor(org.pentaho.ui.xul.binding.BindingConvertor) IUIRole(org.pentaho.di.ui.repository.pur.repositoryexplorer.IUIRole) KettleException(org.pentaho.di.core.exception.KettleException) UIObjectCreationException(org.pentaho.di.ui.repository.repositoryexplorer.model.UIObjectCreationException) Type(org.pentaho.di.repository.ObjectRecipient.Type) IUIUser(org.pentaho.di.ui.repository.repositoryexplorer.model.IUIUser) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 KettleException (org.pentaho.di.core.exception.KettleException)1 Type (org.pentaho.di.repository.ObjectRecipient.Type)1 IUIEEUser (org.pentaho.di.ui.repository.pur.repositoryexplorer.IUIEEUser)1 IUIRole (org.pentaho.di.ui.repository.pur.repositoryexplorer.IUIRole)1 IUIUser (org.pentaho.di.ui.repository.repositoryexplorer.model.IUIUser)1 UIObjectCreationException (org.pentaho.di.ui.repository.repositoryexplorer.model.UIObjectCreationException)1 Mode (org.pentaho.di.ui.repository.repositoryexplorer.model.UISecurity.Mode)1 BindingConvertor (org.pentaho.ui.xul.binding.BindingConvertor)1