public VoteListGrid() { super(); // initialize the List Grid fields ListGridField iconField = new ListGridField(ICON, ICON_DISPLAY_NAME, ICON_COLUMN_LENGTH); iconField.setImageSize(16); iconField.setAlign(Alignment.CENTER); iconField.setType(ListGridFieldType.IMAGE); iconField.setImageURLPrefix(URL_PREFIX); iconField.setImageURLSuffix(URL_SUFFIX); ListGridField voteCodeField = new ListGridField(VOTE_CODE, VOTE_CODE_DISPLAY); voteCodeField.setWidth("20%"); ListGridField voteNameField = new ListGridField(VOTE_NAME, VOTE_NAME_DISPLAY); voteNameField.setWidth("20%"); ListGridField voteIDField = new ListGridField(VOTE_ID, VOTE_ID_DISPLAY); voteIDField.setHidden(true); ListGridField createdByField = new ListGridField(CREATED_BY, CREATED_BY_DISPLAY); createdByField.setWidth("20%"); ListGridField changedByField = new ListGridField(CHANGED_BY, CHANGED_BY_DISPLAY); changedByField.setWidth("20%"); ListGridField emptyField = new ListGridField(EMPTY_FIELD, EMPTY_FIELD_DISPLAY_NAME); this.setCanPickFields(false); this.setShowRowNumbers(true); this.setFields(voteIDField, voteNameField, voteCodeField, createdByField, changedByField); }
private ListGridField createAuthorizedField( String name, String title, final String nameField, final ListGrid grid, boolean readOnlyColumn) { final ListGridField authorizedField = new ListGridField(name, title, 65); // Show images rather than true/false. authorizedField.setType(ListGridFieldType.IMAGE); authorizedField.setImageSize(11); LinkedHashMap<String, String> valueMap = new LinkedHashMap<String, String>(2); // set the proper images different for read-only column if (readOnlyColumn) { valueMap.put(Boolean.TRUE.toString(), "global/permission_checked_disabled_11.png"); valueMap.put(Boolean.FALSE.toString(), "global/permission_disabled_11.png"); } else { valueMap.put(Boolean.TRUE.toString(), "global/permission_enabled_11.png"); valueMap.put(Boolean.FALSE.toString(), "global/permission_disabled_11.png"); } authorizedField.setValueMap(valueMap); authorizedField.setCanEdit(true); CheckboxItem editor = new CheckboxItem(); authorizedField.setEditorType(editor); if (!this.isReadOnly) { grid.setEditEvent(ListGridEditEvent.CLICK); final Record[] recordBeingEdited = {null}; authorizedField.addRecordClickHandler( new RecordClickHandler() { public void onRecordClick(RecordClickEvent event) { recordBeingEdited[0] = event.getRecord(); } }); authorizedField.addChangedHandler( new ChangedHandler() { public void onChanged(ChangedEvent event) { Boolean authorized = (Boolean) event.getValue(); int recordNum = event.getRowNum(); ListGridRecord record = grid.getRecord(recordNum); String permissionName = record.getAttribute(nameField); Permission permission = Permission.valueOf(permissionName); String permissionDisplayName = record.getAttribute("displayName"); if (permission == Permission.VIEW_RESOURCE) { String messageString = MSG.view_adminRoles_permissions_readAccessImplied(permissionDisplayName); handleIllegalPermissionSelection(event, messageString); } else if (!authorized && selectedPermissions.contains(Permission.MANAGE_SECURITY) && permission != Permission.MANAGE_SECURITY) { String messageString = MSG.view_adminRoles_permissions_illegalDeselectionDueToManageSecuritySelection( permissionDisplayName); handleIllegalPermissionSelection(event, messageString); } else if (!authorized && selectedPermissions.contains(Permission.MANAGE_INVENTORY) && permission.getTarget() == Permission.Target.RESOURCE) { String messageString = MSG.view_adminRoles_permissions_illegalDeselectionDueToManageInventorySelection( permissionDisplayName); handleIllegalPermissionSelection(event, messageString); } else if (!authorized && selectedPermissions.contains(Permission.CONFIGURE_WRITE) && permission == Permission.CONFIGURE_READ) { String messageString = MSG .view_adminRoles_permissions_illegalDeselectionDueToCorrespondingWritePermSelection( permissionDisplayName); handleIllegalPermissionSelection(event, messageString); } else { updatePermissions(authorized, permission); // Let our parent role editor know the permissions have been changed, so it can // update the // enablement of its Save and Reset buttons. PermissionsEditor.this.roleEditView.onItemChanged(); } } }); } return authorizedField; }