Search in sources :

Example 6 with BindingConvertor

use of org.pentaho.ui.xul.binding.BindingConvertor in project pentaho-kettle by pentaho.

the class AbstractPermissionsController method createBindings.

protected void createBindings() {
    // $NON-NLS-1$
    userRoleList = (XulListbox) document.getElementById(getXulPrefix() + "user-role-list");
    // $NON-NLS-1$
    writeCheckbox = (XulCheckbox) document.getElementById(getXulPrefix() + "write-checkbox");
    // $NON-NLS-1$
    readCheckbox = (XulCheckbox) document.getElementById(getXulPrefix() + "read-checkbox");
    // $NON-NLS-1$
    manageAclCheckbox = (XulCheckbox) document.getElementById(getXulPrefix() + "manage-checkbox");
    // $NON-NLS-1$
    deleteCheckbox = (XulCheckbox) document.getElementById(getXulPrefix() + "delete-checkbox");
    // $NON-NLS-1$
    addAclButton = (XulButton) document.getElementById(getXulPrefix() + "add-acl-button");
    // $NON-NLS-1$
    removeAclButton = (XulButton) document.getElementById(getXulPrefix() + "remove-acl-button");
    // $NON-NLS-1$
    manageAclsDialog = (XulDialog) document.getElementById(getXulPrefix() + "manage-acls-dialog");
    permissionsCheckboxHandler = new PermissionsCheckboxHandler(readCheckbox, writeCheckbox, deleteCheckbox, manageAclCheckbox);
    // Add/Remove Acl Binding
    // $NON-NLS-1$
    availableUserList = (XulListbox) document.getElementById(getXulPrefix() + "available-user-list");
    // $NON-NLS-1$
    selectedUserList = (XulListbox) document.getElementById(getXulPrefix() + "selected-user-list");
    // $NON-NLS-1$
    availableRoleList = (XulListbox) document.getElementById(getXulPrefix() + "available-role-list");
    // $NON-NLS-1$
    selectedRoleList = (XulListbox) document.getElementById(getXulPrefix() + "selected-role-list");
    // $NON-NLS-1$
    assignRoleButton = (XulButton) document.getElementById(getXulPrefix() + "assign-role");
    // $NON-NLS-1$
    unassignRoleButton = (XulButton) document.getElementById(getXulPrefix() + "unassign-role");
    // $NON-NLS-1$
    assignUserButton = (XulButton) document.getElementById(getXulPrefix() + "assign-user");
    // $NON-NLS-1$
    unassignUserButton = (XulButton) document.getElementById(getXulPrefix() + "unassign-user");
    // $NON-NLS-1$
    applyAclButton = (XulButton) document.getElementById(getXulPrefix() + "apply-acl");
    // Binding the model user or role list to the ui user or role list
    bf.setBindingType(Binding.Type.ONE_WAY);
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(manageAclsModel, "availableUserList", availableUserList, "elements");
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(manageAclsModel, "selectedUserList", selectedUserList, "elements");
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(manageAclsModel, "availableRoleList", availableRoleList, "elements");
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(manageAclsModel, "selectedRoleList", selectedRoleList, "elements");
    // indicesToObjectsConverter convert the selected indices to the list of objects and vice versa
    BindingConvertor<int[], List<UIRepositoryObjectAcl>> indicesToObjectsConverter = new BindingConvertor<int[], List<UIRepositoryObjectAcl>>() {

        @Override
        public int[] targetToSource(List<UIRepositoryObjectAcl> acls) {
            if (acls != null) {
                int i = 0;
                int[] retVal = new int[acls.size()];
                for (UIRepositoryObjectAcl acl : acls) {
                    retVal[i++] = viewAclsModel.getAceIndex(acl.getAce());
                }
                return retVal;
            }
            return null;
        }

        @Override
        public List<UIRepositoryObjectAcl> sourceToTarget(int[] indices) {
            if (indices != null && indices.length > 0) {
                List<UIRepositoryObjectAcl> retVal = new ArrayList<UIRepositoryObjectAcl>();
                for (int i = 0; i < indices.length; i++) {
                    retVal.add(new UIRepositoryObjectAcl(viewAclsModel.getAceAtIndex(indices[i])));
                }
                return retVal;
            }
            return null;
        }
    };
    // indexToAvalableUserConverter convert the selected indices to the list of objects and vice versa
    BindingConvertor<int[], List<String>> indexToAvailableUserConverter = new BindingConvertor<int[], List<String>>() {

        @Override
        public List<String> sourceToTarget(int[] indices) {
            List<String> userList = new ArrayList<String>();
            for (int i = 0; i < indices.length; i++) {
                userList.add(manageAclsModel.getAvailableUser(indices[i]));
            }
            return userList;
        }

        @Override
        public int[] targetToSource(List<String> userList) {
            int[] indices = new int[userList.size()];
            int i = 0;
            for (String user : userList) {
                indices[i++] = manageAclsModel.getAvailableUserIndex(user);
            }
            return indices;
        }
    };
    BindingConvertor<int[], List<String>> indexToAvailableRoleConverter = new BindingConvertor<int[], List<String>>() {

        @Override
        public List<String> sourceToTarget(int[] indices) {
            List<String> roleList = new ArrayList<String>();
            for (int i = 0; i < indices.length; i++) {
                roleList.add(manageAclsModel.getAvailableRole(indices[i]));
            }
            return roleList;
        }

        @Override
        public int[] targetToSource(List<String> roleList) {
            int[] indices = new int[roleList.size()];
            int i = 0;
            for (String role : roleList) {
                indices[i++] = manageAclsModel.getAvailableRoleIndex(role);
            }
            return indices;
        }
    };
    BindingConvertor<int[], List<UIRepositoryObjectAcl>> indexToSelectedUserConverter = new BindingConvertor<int[], List<UIRepositoryObjectAcl>>() {

        @Override
        public List<UIRepositoryObjectAcl> sourceToTarget(int[] indices) {
            List<UIRepositoryObjectAcl> userList = new ArrayList<UIRepositoryObjectAcl>();
            for (int i = 0; i < indices.length; i++) {
                userList.add(manageAclsModel.getSelectedUser(indices[i]));
            }
            return userList;
        }

        @Override
        public int[] targetToSource(List<UIRepositoryObjectAcl> userList) {
            int[] indices = new int[userList.size()];
            int i = 0;
            for (UIRepositoryObjectAcl user : userList) {
                indices[i++] = manageAclsModel.getSelectedUserIndex(user);
            }
            return indices;
        }
    };
    BindingConvertor<int[], List<UIRepositoryObjectAcl>> indexToSelectedRoleConverter = new BindingConvertor<int[], List<UIRepositoryObjectAcl>>() {

        @Override
        public List<UIRepositoryObjectAcl> sourceToTarget(int[] indices) {
            List<UIRepositoryObjectAcl> roleList = new ArrayList<UIRepositoryObjectAcl>();
            for (int i = 0; i < indices.length; i++) {
                roleList.add(manageAclsModel.getSelectedRole(indices[i]));
            }
            return roleList;
        }

        @Override
        public int[] targetToSource(List<UIRepositoryObjectAcl> roleList) {
            int[] indices = new int[roleList.size()];
            int i = 0;
            for (UIRepositoryObjectAcl role : roleList) {
                indices[i++] = manageAclsModel.getSelectedRoleIndex(role);
            }
            return indices;
        }
    };
    // Binding between the selected incides of the lists to the mode list objects
    bf.setBindingType(Binding.Type.BI_DIRECTIONAL);
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(// $NON-NLS-1$ //$NON-NLS-2$
    availableUserList, // $NON-NLS-1$ //$NON-NLS-2$
    "selectedIndices", // $NON-NLS-1$ //$NON-NLS-2$
    manageAclsModel, // $NON-NLS-1$ //$NON-NLS-2$
    "selectedAvailableUsers", indexToAvailableUserConverter);
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(// $NON-NLS-1$ //$NON-NLS-2$
    selectedUserList, // $NON-NLS-1$ //$NON-NLS-2$
    "selectedIndices", // $NON-NLS-1$ //$NON-NLS-2$
    manageAclsModel, // $NON-NLS-1$ //$NON-NLS-2$
    "selectedAssignedUsers", indexToSelectedUserConverter);
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(// $NON-NLS-1$ //$NON-NLS-2$
    availableRoleList, // $NON-NLS-1$ //$NON-NLS-2$
    "selectedIndices", // $NON-NLS-1$ //$NON-NLS-2$
    manageAclsModel, // $NON-NLS-1$ //$NON-NLS-2$
    "selectedAvailableRoles", indexToAvailableRoleConverter);
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(// $NON-NLS-1$ //$NON-NLS-2$
    selectedRoleList, // $NON-NLS-1$ //$NON-NLS-2$
    "selectedIndices", // $NON-NLS-1$ //$NON-NLS-2$
    manageAclsModel, // $NON-NLS-1$ //$NON-NLS-2$
    "selectedAssignedRoles", indexToSelectedRoleConverter);
    // Binding the selected indices of acl list to the list of acl objects in the mode
    // $NON-NLS-1$  //$NON-NLS-2$
    bf.createBinding(userRoleList, "selectedIndices", viewAclsModel, "selectedAclList", indicesToObjectsConverter);
    // accumulatorButtonConverter determine whether to enable of disable the accumulator buttons
    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) {
            // One way binding, nothing to do here
            return null;
        }
    };
    bf.setBindingType(Binding.Type.ONE_WAY);
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(// $NON-NLS-1$ //$NON-NLS-2$
    selectedUserList, // $NON-NLS-1$ //$NON-NLS-2$
    "selectedIndex", // $NON-NLS-1$ //$NON-NLS-2$
    manageAclsModel, // $NON-NLS-1$ //$NON-NLS-2$
    "userUnassignmentPossible", accumulatorButtonConverter);
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(// $NON-NLS-1$ //$NON-NLS-2$
    availableUserList, // $NON-NLS-1$ //$NON-NLS-2$
    "selectedIndex", // $NON-NLS-1$ //$NON-NLS-2$
    manageAclsModel, // $NON-NLS-1$ //$NON-NLS-2$
    "userAssignmentPossible", accumulatorButtonConverter);
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(manageAclsModel, "userUnassignmentPossible", unassignUserButton, "!disabled");
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(manageAclsModel, "userAssignmentPossible", assignUserButton, "!disabled");
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(// $NON-NLS-1$ //$NON-NLS-2$
    selectedRoleList, // $NON-NLS-1$ //$NON-NLS-2$
    "selectedIndex", // $NON-NLS-1$ //$NON-NLS-2$
    manageAclsModel, // $NON-NLS-1$ //$NON-NLS-2$
    "roleUnassignmentPossible", accumulatorButtonConverter);
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(// $NON-NLS-1$ //$NON-NLS-2$
    availableRoleList, // $NON-NLS-1$ //$NON-NLS-2$
    "selectedIndex", // $NON-NLS-1$ //$NON-NLS-2$
    manageAclsModel, // $NON-NLS-1$ //$NON-NLS-2$
    "roleAssignmentPossible", accumulatorButtonConverter);
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(manageAclsModel, "roleUnassignmentPossible", unassignRoleButton, "!disabled");
    // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(manageAclsModel, "roleAssignmentPossible", assignRoleButton, "!disabled");
    // Only enable remove Acl button if the entries checkbox is unchecked and acl is selected from the list
    // $NON-NLS-1$  //$NON-NLS-2$
    bf.createBinding(viewAclsModel, "removeEnabled", removeAclButton, "!disabled");
    // Binding when the user select from the list
    // $NON-NLS-1$  //$NON-NLS-2$
    bf.createBinding(// $NON-NLS-1$  //$NON-NLS-2$
    viewAclsModel, // $NON-NLS-1$  //$NON-NLS-2$
    "selectedAclList", // $NON-NLS-1$  //$NON-NLS-2$
    this, // $NON-NLS-1$  //$NON-NLS-2$
    "aclState", new BindingConvertor<List<UIRepositoryObjectAcl>, UIRepositoryObjectAcl>() {

        @Override
        public UIRepositoryObjectAcl sourceToTarget(List<UIRepositoryObjectAcl> value) {
            if (value != null && value.size() > 0) {
                return value.get(0);
            }
            return null;
        }

        @Override
        public List<UIRepositoryObjectAcl> targetToSource(UIRepositoryObjectAcl value) {
            return null;
        }
    });
    // $NON-NLS-1$  //$NON-NLS-2$
    bf.createBinding(userRoleList, "selectedItem", this, "recipientChanged");
}
Also used : UIRepositoryObjectAcl(org.pentaho.di.ui.repository.pur.repositoryexplorer.model.UIRepositoryObjectAcl) ArrayList(java.util.ArrayList) BindingConvertor(org.pentaho.ui.xul.binding.BindingConvertor) ArrayList(java.util.ArrayList) List(java.util.List)

Example 7 with BindingConvertor

use of org.pentaho.ui.xul.binding.BindingConvertor in project pentaho-kettle by pentaho.

the class ConnectionPermissionsController method createBindings.

protected void createBindings() {
    super.createBindings();
    // $NON-NLS-1$
    connNameLabel = (XulLabel) document.getElementById("conn-name");
    bf.setBindingType(Binding.Type.ONE_WAY);
    BindingConvertor<List<UIDatabaseConnection>, List<UIRepositoryObjectAcl>> securityBindingConverter = new BindingConvertor<List<UIDatabaseConnection>, List<UIRepositoryObjectAcl>>() {

        @Override
        public List<UIRepositoryObjectAcl> sourceToTarget(List<UIDatabaseConnection> ro) {
            if (ro == null) {
                return null;
            }
            if (ro.size() <= 0) {
                return null;
            }
            setSelectedDatabaseConnections(ro);
            if (!hasManageAclAccess()) {
                applyAclButton.setDisabled(true);
                addAclButton.setDisabled(true);
                removeAclButton.setDisabled(true);
                manageAclCheckbox.setDisabled(true);
                deleteCheckbox.setDisabled(true);
                writeCheckbox.setDisabled(true);
                readCheckbox.setDisabled(true);
                viewAclsModel.setHasManageAclAccess(false);
            } else {
                applyAclButton.setDisabled(false);
                addAclButton.setDisabled(false);
                viewAclsModel.setHasManageAclAccess(true);
            }
            viewAclsModel.setRemoveEnabled(false);
            List<UIRepositoryObjectAcl> selectedAclList = Collections.emptyList();
            // we've moved to a connection; need to clear out what the model thinks is selected
            viewAclsModel.setSelectedAclList(selectedAclList);
            permissionsCheckboxHandler.setAllChecked(false);
            UIDatabaseConnection dbconnObject = ro.get(0);
            try {
                if (dbconnObject instanceof IAclObject) {
                    IAclObject aclObj = (IAclObject) dbconnObject;
                    // This is a special case for DB Connections, wipe out the isEnherting flag.
                    // This will cause the model to become "dirty", and prompt the user for changes the first time
                    // let's make sure the default creation behavior of connections is to be that inheritance is
                    // set to false, so this case never presents itself in the wild.
                    aclObj.getAcls(viewAclsModel);
                    if (viewAclsModel.isEntriesInheriting()) {
                        viewAclsModel.setEntriesInheriting(false);
                        aclObj.setAcls(viewAclsModel);
                        viewAclsModel.setModelDirty(false);
                    }
                } else {
                    // $NON-NLS-1$
                    throw new IllegalStateException(BaseMessages.getString(PKG, "PermissionsController.NoAclSupport"));
                }
                connNameLabel.setValue(BaseMessages.getString(PKG, "AclTab.ConnectionPermission", // $NON-NLS-1$
                dbconnObject.getDisplayName()));
                bf.setBindingType(Binding.Type.ONE_WAY);
                // $NON-NLS-1$ //$NON-NLS-2$
                bf.createBinding(viewAclsModel, "acls", userRoleList, "elements");
            } catch (AccessDeniedException ade) {
                // $NON-NLS-1$
                messageBox.setTitle(BaseMessages.getString(PKG, "Dialog.Error"));
                // $NON-NLS-1$
                messageBox.setAcceptLabel(BaseMessages.getString(PKG, "Dialog.Ok"));
                messageBox.setMessage(BaseMessages.getString(PKG, "PermissionsController.UnableToGetAcls", dbconnObject.getName(), // $NON-NLS-1$
                ade.getLocalizedMessage()));
                messageBox.open();
            } catch (Exception e) {
                if (mainController == null || !mainController.handleLostRepository(e)) {
                    // $NON-NLS-1$
                    messageBox.setTitle(BaseMessages.getString(PKG, "Dialog.Error"));
                    // $NON-NLS-1$
                    messageBox.setAcceptLabel(BaseMessages.getString(PKG, "Dialog.Ok"));
                    messageBox.setMessage(BaseMessages.getString(PKG, "PermissionsController.UnableToGetAcls", dbconnObject.getName(), // $NON-NLS-1$
                    e.getLocalizedMessage()));
                    messageBox.open();
                }
            }
            return viewAclsModel.getAcls();
        }

        @Override
        public List<UIDatabaseConnection> targetToSource(List<UIRepositoryObjectAcl> elements) {
            // One way binding, nothing to do here
            return null;
        }
    };
    // Binding between the selected repository objects and the user role list for acls
    securityBinding = bf.createBinding(connectionsController, "repositoryConnections", userRoleList, "elements", // $NON-NLS-1$ //$NON-NLS-2$
    securityBindingConverter);
    try {
        if (securityBinding != null) {
            securityBinding.fireSourceChanged();
        }
    } catch (Exception e) {
        if (mainController == null || !mainController.handleLostRepository(e)) {
            // convert to runtime exception so it bubbles up through the UI
            throw new RuntimeException(e);
        }
    }
}
Also used : AccessDeniedException(org.pentaho.di.ui.repository.repositoryexplorer.AccessDeniedException) UIDatabaseConnection(org.pentaho.di.ui.repository.repositoryexplorer.model.UIDatabaseConnection) UIRepositoryObjectAcl(org.pentaho.di.ui.repository.pur.repositoryexplorer.model.UIRepositoryObjectAcl) ArrayList(java.util.ArrayList) List(java.util.List) IAclObject(org.pentaho.di.ui.repository.pur.repositoryexplorer.IAclObject) BindingConvertor(org.pentaho.ui.xul.binding.BindingConvertor) AccessDeniedException(org.pentaho.di.ui.repository.repositoryexplorer.AccessDeniedException) ControllerInitializationException(org.pentaho.di.ui.repository.repositoryexplorer.ControllerInitializationException)

Example 8 with BindingConvertor

use of org.pentaho.ui.xul.binding.BindingConvertor 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)

Example 9 with BindingConvertor

use of org.pentaho.ui.xul.binding.BindingConvertor in project pentaho-kettle by pentaho.

the class RevisionController method createBindings.

private void createBindings() {
    // $NON-NLS-1$
    filePropertiesTabbox = (XulTabbox) document.getElementById("file-properties-tabs");
    // $NON-NLS-1$
    historyTab = (XulTab) document.getElementById("history");
    // $NON-NLS-1$
    revisionTable = (XulTree) document.getElementById("revision-table");
    // $NON-NLS-1$
    folderTree = (XulTree) document.getElementById("folder-tree");
    // $NON-NLS-1$
    fileTable = (XulTree) document.getElementById("file-table");
    // Hide the history tab if versioning is off
    historyTab.setVisible(false);
    bf.setBindingType(Binding.Type.ONE_WAY);
    BindingConvertor<int[], Boolean> forButtons = new BindingConvertor<int[], Boolean>() {

        @Override
        public Boolean sourceToTarget(int[] value) {
            return value != null && !(value.length <= 0);
        }

        @Override
        public int[] targetToSource(Boolean value) {
            return null;
        }
    };
    Binding openButtonBinding = // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    bf.createBinding(revisionTable, "selectedRows", OPEN_REVISION_BUTTON, "!disabled", forButtons);
    Binding restoreButtonBinding = // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    bf.createBinding(revisionTable, "selectedRows", RESTORE_REVISION_BUTTON, "!disabled", forButtons);
    bf.setBindingType(Binding.Type.ONE_WAY);
    // $NON-NLS-1$  //$NON-NLS-2$
    bf.createBinding(folderTree, "selectedItems", this, "historyTabVisibility");
    // $NON-NLS-1$ //$NON-NLS-2$
    revisionBinding = bf.createBinding(this, "revisionObjects", revisionTable, "elements");
    revisionBinding = // $NON-NLS-1$ //$NON-NLS-2$
    bf.createBinding(// $NON-NLS-1$ //$NON-NLS-2$
    browseController, // $NON-NLS-1$ //$NON-NLS-2$
    "repositoryItems", // $NON-NLS-1$ //$NON-NLS-2$
    this, // $NON-NLS-1$ //$NON-NLS-2$
    "revisionObjects", new BindingConvertor<List<UIRepositoryObject>, UIRepositoryObjectRevisions>() {

        private void disableButtons() {
            document.getElementById(OPEN_REVISION_BUTTON).setDisabled(true);
            document.getElementById(RESTORE_REVISION_BUTTON).setDisabled(true);
        }

        @Override
        public UIRepositoryObjectRevisions sourceToTarget(List<UIRepositoryObject> ro) {
            if (ro == null || ro.isEmpty() || !masterVersioningEnabled) {
                return new UIRepositoryObjectRevisions();
            }
            if (ro.get(0) instanceof UIRepositoryDirectory) {
                historyTab.setVisible(false);
                filePropertiesTabbox.setSelectedIndex(0);
                disableButtons();
                return null;
            }
            UIRepositoryObjectRevisions revisions = null;
            try {
                UIRepositoryContent rc = (UIRepositoryContent) ro.get(0);
                if (rc instanceof IRevisionObject) {
                    Boolean versioningEnabled = ((IRevisionObject) rc).getVersioningEnabled();
                    // Show/hide the Verison History tab
                    historyTab.setVisible(versioningEnabled);
                    if (!versioningEnabled) {
                        return new UIRepositoryObjectRevisions();
                    }
                    Boolean versionCommentEnabled = ((IRevisionObject) rc).getVersionCommentEnabled();
                    // Show/Hide the version comment column
                    setRevisionTableColumns(versionCommentEnabled);
                    revisions = ((IRevisionObject) rc).getRevisions();
                } else {
                    throw new IllegalStateException(BaseMessages.getString(PKG, // $NON-NLS-1$
                    "RevisionsController.RevisionsNotSupported"));
                }
            } catch (KettleException e) {
                if (mainController == null || !mainController.handleLostRepository(e)) {
                    // convert to runtime exception so it bubbles up through the UI
                    throw new RuntimeException(e);
                }
            }
            return revisions;
        }

        @Override
        public List<UIRepositoryObject> targetToSource(UIRepositoryObjectRevisions elements) {
            return null;
        }
    });
    try {
        openButtonBinding.fireSourceChanged();
        restoreButtonBinding.fireSourceChanged();
        revisionBinding.fireSourceChanged();
    } catch (Exception e) {
        if (mainController == null || !mainController.handleLostRepository(e)) {
            // convert to runtime exception so it bubbles up through the UI
            throw new RuntimeException(e);
        }
    }
}
Also used : Binding(org.pentaho.ui.xul.binding.Binding) UIRepositoryDirectory(org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryDirectory) KettleException(org.pentaho.di.core.exception.KettleException) IRevisionObject(org.pentaho.di.ui.repository.pur.repositoryexplorer.IRevisionObject) UIRepositoryContent(org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryContent) BindingConvertor(org.pentaho.ui.xul.binding.BindingConvertor) XulException(org.pentaho.ui.xul.XulException) KettleException(org.pentaho.di.core.exception.KettleException) ControllerInitializationException(org.pentaho.di.ui.repository.repositoryexplorer.ControllerInitializationException) UIRepositoryObject(org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryObject) UIRepositoryObjectRevisions(org.pentaho.di.ui.repository.pur.repositoryexplorer.model.UIRepositoryObjectRevisions) ArrayList(java.util.ArrayList) List(java.util.List)

Example 10 with BindingConvertor

use of org.pentaho.ui.xul.binding.BindingConvertor in project pentaho-kettle by pentaho.

the class BrowseController method createBindings.

protected void createBindings() {
    shell = ((SwtDialog) document.getElementById("repository-explorer-dialog")).getShell();
    folderTree = (XulTree) document.getElementById("folder-tree");
    fileTable = (XulTree) document.getElementById("file-table");
    if (!repositoryDirectory.isVisible()) {
        folderTree.setHiddenrootnode(true);
    } else {
        folderTree.setHiddenrootnode(false);
    }
    BindingConvertor<List<?>, Boolean> checkIfMultipleItemsAreSelected = new BindingConvertor<List<?>, Boolean>() {

        @Override
        public Boolean sourceToTarget(List<?> value) {
            return value != null && value.size() == 1 && value.get(0) != null;
        }

        @Override
        public List<?> targetToSource(Boolean value) {
            return null;
        }
    };
    bf.setBindingType(Binding.Type.ONE_WAY);
    bf.createBinding(fileTable, "selectedItems", "file-context-rename", "!disabled", checkIfMultipleItemsAreSelected);
    bf.createBinding(fileTable, "selectedItems", this, "selectedFileItems");
    // begin PDI-3326 hack
    PropertyChangeListener childrenListener = new PropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent evt) {
            fireRepositoryDirectoryChange();
        }
    };
    repositoryDirectory.addPropertyChangeListener("children", childrenListener);
    // end PDI-3326 hack
    directoryBinding = createDirectoryBinding();
    // Bind the selected index from the folder tree to the list of repository objects in the file table.
    bf.setBindingType(Binding.Type.ONE_WAY);
    bf.createBinding(folderTree, "selectedItems", this, "selectedFolderItems");
    bf.setBindingType(Binding.Type.ONE_WAY);
    selectedItemsBinding = bf.createBinding(this, "selectedRepoDirChildren", fileTable, "elements");
    // bindings can be added here in subclasses
    doCreateBindings();
    try {
        // Fires the population of the repository tree of folders.
        directoryBinding.fireSourceChanged();
    } catch (Exception e) {
        // convert to runtime exception so it bubbles up through the UI
        throw new RuntimeException(e);
    }
    try {
        // Set the initial selected directory as the users home directory
        RepositoryDirectoryInterface homeDir = repository.getUserHomeDirectory();
        int currentDir = 0;
        String[] homePath = homeDir == null ? null : homeDir.getPathArray();
        if (homePath != null) {
            UIRepositoryDirectory tempRoot = repositoryDirectory;
            // Check to see if the first item in homePath is the root directory
            if (homePath.length > 0 && tempRoot.getName().equalsIgnoreCase(homePath[currentDir])) {
                if (homePath.length == 1) {
                    // The home directory is home root
                    setSelectedFolderItems(Arrays.asList(tempRoot));
                }
                // We have used the first element. Increment to the next
                currentDir++;
            }
            // Traverse the tree until we find our destination
            for (; currentDir < homePath.length; currentDir++) {
                for (UIRepositoryObject uiObj : tempRoot) {
                    if (uiObj instanceof UIRepositoryDirectory) {
                        if (uiObj.getName().equalsIgnoreCase(homePath[currentDir])) {
                            // We have a match. Let's move on to the next
                            tempRoot = (UIRepositoryDirectory) uiObj;
                            break;
                        }
                    }
                }
            }
            // If we have traversed as many directories as there are in the path, we have found the directory
            if (homePath.length == currentDir) {
                setSelectedFolderItems(Arrays.asList(tempRoot));
                folderTree.setSelectedItems(this.selectedFolderItems);
            }
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : UIRepositoryDirectory(org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryDirectory) RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) BindingConvertor(org.pentaho.ui.xul.binding.BindingConvertor) XulException(org.pentaho.ui.xul.XulException) ControllerInitializationException(org.pentaho.di.ui.repository.repositoryexplorer.ControllerInitializationException) UIObjectCreationException(org.pentaho.di.ui.repository.repositoryexplorer.model.UIObjectCreationException) KettleException(org.pentaho.di.core.exception.KettleException) Point(org.eclipse.swt.graphics.Point) UIRepositoryObject(org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryObject) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

BindingConvertor (org.pentaho.ui.xul.binding.BindingConvertor)17 ArrayList (java.util.ArrayList)10 List (java.util.List)9 Binding (org.pentaho.ui.xul.binding.Binding)5 KettleException (org.pentaho.di.core.exception.KettleException)4 ControllerInitializationException (org.pentaho.di.ui.repository.repositoryexplorer.ControllerInitializationException)4 XulException (org.pentaho.ui.xul.XulException)4 UIRepositoryObjectAcl (org.pentaho.di.ui.repository.pur.repositoryexplorer.model.UIRepositoryObjectAcl)3 UIRepositoryObject (org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryObject)3 GwtBindingFactory (org.pentaho.ui.xul.gwt.binding.GwtBindingFactory)3 Bindable (org.pentaho.ui.xul.stereotype.Bindable)3 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 PropertyChangeListener (java.beans.PropertyChangeListener)2 IAclObject (org.pentaho.di.ui.repository.pur.repositoryexplorer.IAclObject)2 AccessDeniedException (org.pentaho.di.ui.repository.repositoryexplorer.AccessDeniedException)2 UIObjectCreationException (org.pentaho.di.ui.repository.repositoryexplorer.model.UIObjectCreationException)2 UIRepositoryDirectory (org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryDirectory)2 RequestException (com.google.gwt.http.client.RequestException)1 Vector (java.util.Vector)1 Point (org.eclipse.swt.graphics.Point)1