/** * Convert a Model cell to one that can be used in the UI * * @param cell * @return */ @Override public CellValue<? extends Comparable<?>> convertModelCellValue( BaseColumn column, DTCellValue52 dcv) { // Analysis cells do not use data-type if (column instanceof AnalysisCol52) { return makeNewAnalysisCellValue(); } // Other cells do use data-type DTDataTypes52 dataType = getDataType(column); assertDTCellValue(dataType, dcv); CellValue<? extends Comparable<?>> cell = null; switch (dataType) { case BOOLEAN: cell = makeNewBooleanCellValue(dcv.getBooleanValue()); break; case DATE: cell = makeNewDateCellValue(dcv.getDateValue()); break; case NUMERIC: if (column instanceof RowNumberCol52) { cell = makeNewRowNumberCellValue(dcv.getNumericValue()); } else { cell = makeNewNumericCellValue(dcv.getNumericValue()); if (column instanceof AttributeCol52) { AttributeCol52 at = (AttributeCol52) column; if (at.getAttribute().equals(RuleAttributeWidget.SALIENCE_ATTR)) { if (at.isUseRowNumber()) { cell = makeNewRowNumberCellValue(dcv.getNumericValue()); } } } } break; default: cell = makeNewStringCellValue(dcv.getStringValue()); if (column instanceof AttributeCol52) { AttributeCol52 ac = (AttributeCol52) column; if (ac.getAttribute().equals(RuleAttributeWidget.DIALECT_ATTR)) { cell = makeNewDialectCellValue(dcv.getStringValue()); } } } if (dcv.isOtherwise()) { cell.addState(CellState.OTHERWISE); } return cell; }
/** * Convert a type-safe UI CellValue into a type-safe Model CellValue * * @param column Model column from which data-type can be derived * @param cell UI CellValue to convert into Model CellValue * @return */ public DTCellValue52 convertToModelCell(BaseColumn column, CellValue<?> cell) { DTDataTypes52 dt = getDataType(column); DTCellValue52 dtCell = null; switch (dt) { case BOOLEAN: dtCell = new DTCellValue52((Boolean) cell.getValue()); break; case DATE: dtCell = new DTCellValue52((Date) cell.getValue()); break; case NUMERIC: dtCell = new DTCellValue52((BigDecimal) cell.getValue()); break; default: dtCell = new DTCellValue52((String) cell.getValue()); } dtCell.setOtherwise(cell.isOtherwise()); return dtCell; }
private DTCellValue52 cloneLimitedEntryValue(DTCellValue52 dcv) { if (dcv == null) { return null; } DTCellValue52 clone = new DTCellValue52(); switch (dcv.getDataType()) { case BOOLEAN: clone.setBooleanValue(dcv.getBooleanValue()); break; case DATE: clone.setDateValue(dcv.getDateValue()); break; case NUMERIC: clone.setNumericValue(dcv.getNumericValue()); break; case STRING: clone.setStringValue(dcv.getStringValue()); } return clone; }
// If the Decision Table model has been converted from the legacy text based // class then all values are held in the DTCellValue's StringValue. This // function attempts to set the correct DTCellValue property based on // the DTCellValue's data type. private void assertDTCellValue(DTDataTypes52 dataType, DTCellValue52 dcv) { // If already converted exit if (dataType.equals(dcv.getDataType())) { return; } String text = dcv.getStringValue(); switch (dataType) { case BOOLEAN: dcv.setBooleanValue((text == null ? false : Boolean.valueOf(text))); break; case DATE: Date d = null; try { if (text != null) { if (DATE_CONVERTOR == null) { throw new IllegalArgumentException("DATE_CONVERTOR has not been initialised."); } d = DATE_CONVERTOR.parse(text); } } catch (IllegalArgumentException e) { } dcv.setDateValue(d); break; case NUMERIC: BigDecimal bd = null; try { if (text != null) { bd = new BigDecimal(text); } } catch (NumberFormatException e) { } dcv.setNumericValue(bd); break; } }