예제 #1
0
 public void setModels(Map<?, ?> valueMap) {
   ListGridField field = treeSelector.getField(RelationDataSource.FIELD_MODEL);
   field.setValueMap(valueMap);
 }
예제 #2
0
  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;
  }