/**
   * Get the Data Type corresponding to a given column. If the column is a ConditonCol52 and it is
   * not associated with a Pattern52 in the decision table (e.g. it has been cloned) the overloaded
   * method getDataType(Pattern52, ConditionCol52) should be used.
   *
   * @param column
   * @return
   */
  public DataType.DataTypes getDataType(BaseColumn column) {

    // Limited Entry are simply boolean
    if (column instanceof LimitedEntryCol) {
      return DataType.DataTypes.BOOLEAN;
    }

    // Action Work Items are always boolean
    if (column instanceof ActionWorkItemCol52) {
      return DataType.DataTypes.BOOLEAN;
    }

    // Actions setting Field Values from Work Item Result Parameters are always boolean
    if (column instanceof ActionWorkItemSetFieldCol52
        || column instanceof ActionWorkItemInsertFactCol52) {
      return DataType.DataTypes.BOOLEAN;
    }

    // Operators "is null" and "is not null" require a boolean cell
    if (column instanceof ConditionCol52) {
      ConditionCol52 cc = (ConditionCol52) column;
      if (cc.getOperator() != null
          && (cc.getOperator().equals("== null") || cc.getOperator().equals("!= null"))) {
        return DataType.DataTypes.BOOLEAN;
      }
    }

    // Extended Entry...
    return utils.getTypeSafeType(column);
  }
 @Override
 public void assertDefaultValue(
     final Pattern52 selectedPattern, final ConditionCol52 selectedCondition) {
   final List<String> valueList = Arrays.asList(modelUtils.getValueList(selectedCondition));
   if (valueList.size() > 0) {
     final String defaultValue = cellUtils.asString(selectedCondition.getDefaultValue());
     if (!valueList.contains(defaultValue)) {
       selectedCondition.getDefaultValue().clearValues();
     }
   } else {
     // Ensure the Default Value has been updated to represent the column's data-type.
     final DTCellValue52 defaultValue = selectedCondition.getDefaultValue();
     final DataType.DataTypes dataType = cellUtils.getDataType(selectedPattern, selectedCondition);
     cellUtils.assertDTCellValue(dataType, defaultValue);
   }
 }
  @Override
  public void getOperatorCompletions(
      final Pattern52 selectedPattern,
      final ConditionCol52 selectedCondition,
      final Callback<String[]> callback) {

    final String factType = selectedPattern.getFactType();
    final String factField = selectedCondition.getFactField();
    this.oracle.getOperatorCompletions(
        factType,
        factField,
        new Callback<String[]>() {
          @Override
          public void callback(final String[] ops) {
            // Operators "in" and "not in" are only allowed if the Calculation Type is a Literal
            final List<String> filteredOps = new ArrayList<String>();
            for (String op : ops) {
              filteredOps.add(op);
            }
            if (BaseSingleFieldConstraint.TYPE_LITERAL
                != selectedCondition.getConstraintValueType()) {
              filteredOps.remove("in");
              filteredOps.remove("not in");
            }

            final String[] displayOps = new String[filteredOps.size()];
            filteredOps.toArray(displayOps);
            callback.callback(displayOps);
          }
        });
  }
  /**
   * Get the Data Type corresponding to a given column
   *
   * @param pattern Pattern52
   * @param condition ConditionCol52
   * @return
   */
  public DataType.DataTypes getDataType(Pattern52 pattern, ConditionCol52 condition) {

    // Limited Entry are simply boolean
    if (condition instanceof LimitedEntryCol) {
      return DataType.DataTypes.BOOLEAN;
    }

    // Operators "is null" and "is not null" require a boolean cell
    if (condition.getOperator() != null
        && (condition.getOperator().equals("== null")
            || condition.getOperator().equals("!= null"))) {
      return DataType.DataTypes.BOOLEAN;
    }

    // Extended Entry...
    return utils.getTypeSafeType(pattern, condition);
  }
  private String getType(final Pattern52 pattern, final ConditionCol52 col) {

    // Columns with "Value Lists" etc are always Text (for now)
    if (hasValueList(col)) {
      return DataType.TYPE_STRING;
    }

    // Operator "in" and "not in" requires a List as the value. These are always Text (for now)
    if (OperatorsOracle.operatorRequiresList(col.getOperator())) {
      return DataType.TYPE_STRING;
    }

    // Literals without operators are always Text (as the user can specify the operator "in cell")
    if (col.getConstraintValueType() == BaseSingleFieldConstraint.TYPE_LITERAL) {
      if (col.getOperator() == null || "".equals(col.getOperator())) {
        return DataType.TYPE_STRING;
      }
    }

    // Formula are always Text (as the user can specify anything "in cell")
    if (col.getConstraintValueType() == BaseSingleFieldConstraint.TYPE_PREDICATE) {
      return DataType.TYPE_STRING;
    }

    // Predicates are always Text (as the user can specify anything "in cell")
    if (col.getConstraintValueType() == BaseSingleFieldConstraint.TYPE_RET_VALUE) {
      return DataType.TYPE_STRING;
    }

    // Otherwise lookup from SuggestionCompletionEngine
    final String factType = pattern.getFactType();
    final String fieldName = col.getFactField();
    return getTypeFromDataOracle(factType, fieldName);
  }
 public boolean isConstraintValid(final DTColumnConfig52 col) {
   if (col instanceof RowNumberCol52) {
     return true;
   }
   if (col instanceof DescriptionCol52) {
     return true;
   }
   if (col instanceof MetadataCol52) {
     return true;
   }
   if (col instanceof AttributeCol52) {
     return true;
   }
   if (col instanceof ConditionCol52) {
     final ConditionCol52 c = (ConditionCol52) col;
     if (c.getConstraintValueType() == BaseSingleFieldConstraint.TYPE_LITERAL) {
       if (c.getFactField() == null || c.getFactField().equals("")) {
         return false;
       }
       if (c.getOperator() == null || c.getOperator().equals("")) {
         return false;
       }
       return true;
     }
     return true;
   }
   if (col instanceof ActionCol52) {
     return true;
   }
   return false;
 }
  @Override
  public boolean requiresValueList(
      final Pattern52 selectedPattern, final ConditionCol52 selectedCondition) {
    // Don't show a Value List if either the Fact\Field is empty
    final String factType = selectedPattern.getFactType();
    final String factField = selectedCondition.getFactField();
    boolean enableValueList =
        !((factType == null || "".equals(factType)) || (factField == null || "".equals(factField)));

    // Don't show Value List if operator does not accept one
    if (enableValueList) {
      enableValueList = validator.doesOperatorAcceptValueList(selectedCondition);
    }

    // Don't show a Value List if the Fact\Field has an enumeration
    if (enableValueList) {
      enableValueList = !oracle.hasEnums(factType, factField);
    }
    return enableValueList;
  }
 @Override
 public boolean hasEnum(final Pattern52 selectedPattern, final ConditionCol52 selectedCondition) {
   final String factType = selectedPattern.getFactType();
   final String factField = selectedCondition.getFactField();
   return oracle.hasEnums(factType, factField);
 }
 public boolean hasValueList(final ConditionCol52 col) {
   if (col.getValueList() != null && !"".equals(col.getValueList())) {
     return true;
   }
   return false;
 }
 private String[] getValueList(final ConditionCol52 col) {
   if (col.getValueList() != null && !"".equals(col.getValueList())) {
     return col.getValueList().split(",");
   }
   return new String[0];
 }