public void updateSystemControlledColumnValues() {

    final DynamicData data = widget.getGridWidget().getData();
    final List<DynamicColumn<DTColumnConfig>> columns = widget.getGridWidget().getColumns();

    for (DynamicColumn<DTColumnConfig> col : columns) {

      DTColumnConfig modelColumn = col.getModelColumn();

      if (modelColumn instanceof RowNumberCol) {
        updateRowNumberColumnValues(data, col.getColumnIndex());

      } else if (modelColumn instanceof AttributeCol) {

        // Update Salience values
        AttributeCol attrCol = (AttributeCol) modelColumn;
        if (attrCol.getAttribute().equals(RuleAttributeWidget.SALIENCE_ATTR)) {
          if (attrCol.isUseRowNumber()) {
            updateSalienceColumnValues(data, col.getColumnIndex(), attrCol.isReverseOrder());
          }

          // Ensure Salience cells are rendered with the correct Cell
          col.setCell(cellFactory.getCell(attrCol));
          col.setSystemControlled(attrCol.isUseRowNumber());
          col.setSortable(!attrCol.isUseRowNumber());
        }
      }
    }
  }
  /**
   * Update an ActionSetFieldCol column
   *
   * @param origCol The existing column in the grid
   * @param editColumn A copy (not clone) of the original column containing the modified values
   */
  public void updateColumn(final ActionSetFieldCol origColumn, final ActionSetFieldCol editColumn) {
    if (origColumn == null) {
      throw new IllegalArgumentException("origColumn cannot be null");
    }
    if (editColumn == null) {
      throw new IllegalArgumentException("editColumn cannot be null");
    }

    boolean bRedrawColumn = false;
    boolean bRedrawHeader = false;
    DynamicColumn<DTColumnConfig> column = getDynamicColumn(origColumn);

    // Update column's visibility
    if (origColumn.isHideColumn() != editColumn.isHideColumn()) {
      setColumnVisibility(origColumn, !editColumn.isHideColumn());
    }

    // Change in column's binding forces an update and redraw if FactField
    // is different; otherwise only need to update and redraw if the
    // FieldType has changed
    if (!isEqualOrNull(origColumn.getBoundName(), editColumn.getBoundName())) {
      if (!isEqualOrNull(origColumn.getFactField(), editColumn.getFactField())) {
        bRedrawColumn = true;
        updateCellsForDataType(editColumn, column);
      }

    } else if (!isEqualOrNull(origColumn.getFactField(), editColumn.getFactField())) {
      bRedrawColumn = true;
      updateCellsForDataType(editColumn, column);
    }

    // Update column's cell content if the Optional Value list has changed
    if (!isEqualOrNull(origColumn.getValueList(), editColumn.getValueList())) {
      bRedrawColumn = updateCellsForOptionValueList(editColumn, column);
    }

    // Update column header in Header Widget
    if (!origColumn.getHeader().equals(editColumn.getHeader())) {
      bRedrawHeader = true;
    }

    // Copy new values into original column definition
    populateModelColumn(origColumn, editColumn);

    if (bRedrawColumn) {
      int maxColumnIndex = widget.getGridWidget().getColumns().size() - 1;
      widget.getGridWidget().redrawColumns(column.getColumnIndex(), maxColumnIndex);
    }
    if (bRedrawHeader) {
      // Schedule redraw event after column has been redrawn
      Scheduler.get()
          .scheduleFinally(
              new ScheduledCommand() {
                public void execute() {
                  widget.getHeaderWidget().redraw();
                }
              });
    }
  }
  // Ensure the Column cell type and corresponding values are correct
  private void updateCellsForDataType(
      final DTColumnConfig editColumn, final DynamicColumn<DTColumnConfig> column) {

    // Grouping needs to be removed
    if (widget.getGridWidget().getData().isMerged()) {
      widget.getGridWidget().toggleMerging();
    }

    DynamicData data = widget.getGridWidget().getData();
    column.setCell(cellFactory.getCell(editColumn));
    for (int iRow = 0; iRow < data.size(); iRow++) {
      DynamicDataRow row = data.get(iRow);
      row.set(
          column.getColumnIndex(),
          cellValueFactory.makeCellValue(editColumn, iRow, column.getColumnIndex()));
    }
  }
  public void setColumnVisibility(DTColumnConfig modelColumn, boolean isVisible) {
    if (modelColumn == null) {
      throw new IllegalArgumentException("modelColumn cannot be null");
    }

    DynamicColumn<DTColumnConfig> col = getDynamicColumn(modelColumn);
    widget.setColumnVisibility(col.getColumnIndex(), isVisible);
  }
  // Remove Otherwise state from column cells
  private void removeOtherwiseStates(final DynamicColumn<DTColumnConfig> column) {

    // Grouping needs to be removed
    if (widget.getGridWidget().getData().isMerged()) {
      widget.getGridWidget().toggleMerging();
    }

    DynamicData data = widget.getGridWidget().getData();
    for (int iRow = 0; iRow < data.size(); iRow++) {
      DynamicDataRow row = data.get(iRow);
      CellValue<?> cv = row.get(column.getColumnIndex());
      cv.removeState(CellState.OTHERWISE);
    }
  }
 // Ensure the values in a column are within the Value List
 private boolean updateCellsForOptionValueList(
     final DTColumnConfig editColumn, final DynamicColumn<DTColumnConfig> column) {
   boolean bRedrawRequired = false;
   DynamicData data = widget.getGridWidget().getData();
   List<String> vals = Arrays.asList(model.getValueList(editColumn, sce));
   column.setCell(cellFactory.getCell(editColumn));
   int iCol = column.getColumnIndex();
   for (int iRow = 0; iRow < data.size(); iRow++) {
     DynamicDataRow row = data.get(iRow);
     if (!vals.contains(row.get(iCol).getValue())) {
       row.get(iCol).setValue(null);
       bRedrawRequired = true;
     }
   }
   return bRedrawRequired;
 }
  /**
   * Update a Condition column
   *
   * @param origCol The existing column in the grid
   * @param editColumn A copy (not clone) of the original column containing the modified values
   */
  public void updateColumn(final ConditionCol origColumn, final ConditionCol editColumn) {
    if (origColumn == null) {
      throw new IllegalArgumentException("origColumn cannot be null");
    }
    if (editColumn == null) {
      throw new IllegalArgumentException("editColumn cannot be null");
    }

    boolean bRedrawColumn = false;
    boolean bRedrawHeader = false;
    DynamicColumn<DTColumnConfig> column = getDynamicColumn(origColumn);

    // Update column's visibility
    if (origColumn.isHideColumn() != editColumn.isHideColumn()) {
      setColumnVisibility(origColumn, !editColumn.isHideColumn());
    }

    // Change in operator
    if (!isEqualOrNull(origColumn.getOperator(), editColumn.getOperator())) {
      bRedrawHeader = true;

      // Clear otherwise if column cannot accept them
      if (!canAcceptOtherwiseValues(editColumn)) {
        removeOtherwiseStates(column);
        bRedrawColumn = true;
      }
    }

    if (!isEqualOrNull(origColumn.getBoundName(), editColumn.getBoundName())) {
      // Change in bound name requires column to be repositioned
      bRedrawHeader = true;
      addColumn(editColumn, false);
      DynamicColumn<DTColumnConfig> origCol = getDynamicColumn(origColumn);
      DynamicColumn<DTColumnConfig> editCol = getDynamicColumn(editColumn);
      int origColIndex = widget.getGridWidget().getColumns().indexOf(origCol);
      int editColIndex = widget.getGridWidget().getColumns().indexOf(editCol);

      // If the FactType, FieldType and ConstraintValueType are unchanged
      // we can copy cell values from the old column into the new
      if (isEqualOrNull(origColumn.getFactType(), editColumn.getFactType())
          && isEqualOrNull(origColumn.getFactField(), editColumn.getFactField())
          && origColumn.getConstraintValueType() == editColumn.getConstraintValueType()) {

        final DynamicData data = widget.getGridWidget().getData();
        for (int iRow = 0; iRow < data.size(); iRow++) {
          DynamicDataRow row = data.get(iRow);
          CellValue<?> oldCell = row.get(origColIndex);
          CellValue<?> newCell = row.get(editColIndex);
          newCell.setValue(oldCell.getValue());
        }
      }

      // Delete old column and redraw
      widget.deleteColumn(origCol);
      editColIndex = Math.min(widget.getGridWidget().getColumns().size() - 1, editColIndex);
      if (editColIndex > origColIndex) {
        int temp = origColIndex;
        origColIndex = editColIndex;
        editColIndex = temp;
      }
      widget.getGridWidget().redrawColumns(editColIndex, origColIndex);

    } else if (!isEqualOrNull(origColumn.getFactType(), editColumn.getFactType())
        || !isEqualOrNull(origColumn.getFactField(), editColumn.getFactField())
        || origColumn.getConstraintValueType() != editColumn.getConstraintValueType()) {

      // Update column's Cell type
      bRedrawColumn = true;
      updateCellsForDataType(editColumn, column);
    }

    // Update column's cell content if the Optional Value list has changed
    if (!isEqualOrNull(origColumn.getValueList(), editColumn.getValueList())) {
      bRedrawColumn = updateCellsForOptionValueList(editColumn, column);
    }

    // Update column header in Header Widget
    if (!origColumn.getHeader().equals(editColumn.getHeader())) {
      bRedrawHeader = true;
    }

    // Copy new values into original column definition
    populateModelColumn(origColumn, editColumn);

    if (bRedrawColumn) {
      int maxColumnIndex = widget.getGridWidget().getColumns().size() - 1;
      widget.getGridWidget().redrawColumns(column.getColumnIndex(), maxColumnIndex);
    }
    if (bRedrawHeader) {
      // Schedule redraw event after column has been redrawn
      Scheduler.get()
          .scheduleFinally(
              new ScheduledCommand() {
                public void execute() {
                  widget.getHeaderWidget().redraw();
                }
              });
    }
  }