/** * Constructor. * @param field The basefield owner of this listener (usually null and set on setOwner()). */ public void init(BaseField field, boolean bChangeDataOnRefresh) { super.init(field, bChangeDataOnRefresh); } /**
/** * Constructor. * @param field The basefield owner of this listener (usually null and set on setOwner()). */ public void init(BaseField field, boolean bChangeDataOnRefresh) { super.init(field); m_objOriginalData = null; m_bAlwaysEnabled = false; m_bChangeDataOnRefresh = bChangeDataOnRefresh; this.setRespondsToMode(DBConstants.SCREEN_MOVE, false); } /**
/** * Free this listener (and the field copy). */ public void free() { super.free(); } /**
if (listener == null) return super.doMergeData(objData); String strOrigProperties = (String)listener.getOriginalData(); Map<String,Object> propRead = this.getProperties(); // Disk image (with updates from others) Map<String,Object> propOrig = this.internalStringToProperties(strOrigProperties); // Before I made any changes listener.setOriginalData(this.propertiesToInternalString(propOrig)); Utility.getLogger().info("propNew: " + propNew); return this.setProperties(propNew);
/** * Set up/do the remote criteria. * @param strbFilter The SQL query string to add to. * @param bIncludeFileName Include the file name with this query? * @param vParamList The param list to add the raw data to (for prepared statements). * @return True if you should not skip this record (does a check on the local data). */ public void setTemporaryKeyField() { FieldDataScratchHandler fieldDataScratchHandler = (FieldDataScratchHandler)m_field.getListener(FieldDataScratchHandler.class); Record record = this.getOwner(); KeyArea keyArea = record.getKeyArea(0); if (keyArea.getKeyFields(false, true) == 1) { if (m_fakeKeyField == null) { m_fakeKeyField = new KeyField(keyArea, m_field, DBConstants.ASCENDING); m_fakeKeyField.setIsTemporary(true); } else keyArea.addKeyField(m_fakeKeyField); } BaseField paramField = m_fakeKeyField.getField(DBConstants.TEMP_KEY_AREA); paramField.setData(fieldDataScratchHandler.getOriginalData()); Utility.getLogger().info("Set temp key field: " + paramField.toString()); } /**
this.getField(BookingDetail.DETAIL_DATE).addListener(new FieldDataScratchHandler(null, false)); // Don't change on refresh this.getField(BookingDetail.DETAIL_DATE).addListener(new CopyDataHandler(this.getField(BookingDetail.INFO_STATUS_REQUEST), boolRequestRequiredFlag, converterNotInfoManualTransport)); this.getField(BookingDetail.INFO_STATUS_REQUEST).addListener(new CheckRequestRequiredHandler(BookingDetail.INFO_STATUS_ID)); this.getField(BookingDetail.MARKUP_FROM_LAST).addListener(fieldListener = new FieldDataScratchHandler(null) fieldListener.setRespondsToMode(DBConstants.SCREEN_MOVE, true);
/** * Constructor. * @param record My owner (usually passed as null, and set on addListener in setOwner()). * @param iMainFilesField The sequence of the date changed field in this record. * @param field The date changed field in this record. */ public void init(Record record, DateTimeField field) { super.init(record); m_field = field; FieldDataScratchHandler listener = new FieldDataScratchHandler(null); listener.setAlwaysEnabled(true); // Since this holds the current key m_field.addListener(listener); // I will need the original value for the sql update this.setMasterSlaveFlag(FileListener.RUN_IN_SLAVE | FileListener.RUN_IN_MASTER); // Set date key in slave code, check for error in master code } /**
public int fieldChanged(boolean bDisplayOption, int iMoveMode) { if (iMoveMode != DBConstants.SCREEN_MOVE) // This is necessary if an override change the repondsTo. // Also, if just refreshing the record, don't change this if set if ((m_bChangeDataOnRefresh) || ((this.getOwner().getRecord().getOpenMode() & DBConstants.OPEN_DONT_CHANGE_CURRENT_LOCK_TYPE) != DBConstants.OPEN_DONT_CHANGE_CURRENT_LOCK_TYPE)) if ((this.getOwner().getRecord().getOpenMode() & DBConstants.OPEN_DONT_UPDATE_LAST_READ) != DBConstants.OPEN_DONT_UPDATE_LAST_READ) // This is a special case where I want a subsequent write to get an error if changed this.setOriginalData(this.getOwner().getData()); return super.fieldChanged(bDisplayOption, iMoveMode); } /**
/** * Initialize this object. * @param record The parent record. * @param strName The field name. * @param iDataLength The maximum string length (pass -1 for default). * @param strDesc The string description (usually pass null, to use the resource file desc). * @param strDefault The default value (if object, this value is the default value, if string, the string is the default). */ public void init(Record record, String strName, int iDataLength, String strDesc, Object strDefault) { super.init(record, strName, iDataLength, strDesc, strDefault); if (iDataLength == DBConstants.DEFAULT_FIELD_LENGTH) m_iMaxLength = BIG_DEFAULT_LENGTH; if (this.getListener(FieldDataScratchHandler.class.getName()) == null) this.addListener(new FieldDataScratchHandler(null)); // This is needed for any merge operation } /**
/** * SetRecordDataStatus Method. */ public int setRecordDataStatus(Record record, String iFieldSeq, int iStatus, ProductMessageData productRequest) { if (iStatus == BaseDataStatus.OKAY) { FieldDataScratchHandler fieldDataScratchHandler = (FieldDataScratchHandler)record.getField(BookingDetail.DETAIL_DATE).getListener(FieldDataScratchHandler.class, false); if (fieldDataScratchHandler != null) { // Always Date dateOriginal = (Date)productRequest.get(ProductMessageData.OLD_DETAIL_DATE); fieldDataScratchHandler.setOriginalData(dateOriginal); // Make sure you know the original date } } return super.setRecordDataStatus(record, iFieldSeq, iStatus, productRequest); }
/** * Merge my changed data back into field that I just restored from disk. * @param objData The value this field held before I refreshed from disk. * @return The setData error code. */ public int doMergeData(Object objData) { double dOrigData = ((Double)this.getOriginalData()).doubleValue(); double dMergeData = ((Double)objData).doubleValue(); double dCurrentData = this.getOwner().getValue(); double dMergeAmount = dMergeData - dOrigData; double dNewAmount = dCurrentData + dMergeAmount; objData = new Double(dNewAmount); this.setOriginalData(new Double(dCurrentData)); // Just in case I come through here again return super.doMergeData(objData); } }
if (iMoveMode == DBConstants.READ_MOVE) // Very obscure - Make sure this fake read move does not change the scratch area if (fldDest.getNextValidListener(iMoveMode) instanceof FieldDataScratchHandler) // Always enable would have to be true since listeners have been disabled (listenerScratchData = ((FieldDataScratchHandler)fldDest.getNextValidListener(iMoveMode))).setAlwaysEnabled(false); listenerScratchData.setAlwaysEnabled(true);
if (listener == null) return super.doMergeData(objData); String strOrigProperties = (String)listener.getOriginalData(); Map<String,Object> propRead = this.getProperties(); // Disk image (with updates from others) Map<String,Object> propOrig = this.internalStringToProperties(strOrigProperties); // Before I made any changes listener.setOriginalData(this.propertiesToInternalString(propOrig)); Utility.getLogger().info("propNew: " + propNew); return this.setProperties(propNew);
/** * Set up/do the remote criteria. * @param strbFilter The SQL query string to add to. * @param bIncludeFileName Include the file name with this query? * @param vParamList The param list to add the raw data to (for prepared statements). * @return True if you should not skip this record (does a check on the local data). */ public void setTemporaryKeyField() { FieldDataScratchHandler fieldDataScratchHandler = (FieldDataScratchHandler)m_field.getListener(FieldDataScratchHandler.class); Record record = this.getOwner(); KeyArea keyArea = record.getKeyArea(0); if (keyArea.getKeyFields(false, true) == 1) { if (m_fakeKeyField == null) { m_fakeKeyField = new KeyField(keyArea, m_field, DBConstants.ASCENDING); m_fakeKeyField.setIsTemporary(true); } else keyArea.addKeyField(m_fakeKeyField); } BaseField paramField = m_fakeKeyField.getField(DBConstants.TEMP_KEY_AREA); paramField.setData(fieldDataScratchHandler.getOriginalData()); Utility.getLogger().info("Set temp key field: " + paramField.toString()); } /**
this.getField(BookingDetail.DETAIL_DATE).addListener(new FieldDataScratchHandler(null, false)); // Don't change on refresh this.getField(BookingDetail.DETAIL_DATE).addListener(new CopyDataHandler(this.getField(BookingDetail.INFO_STATUS_REQUEST), boolRequestRequiredFlag, converterNotInfoManualTransport)); this.getField(BookingDetail.INFO_STATUS_REQUEST).addListener(new CheckRequestRequiredHandler(BookingDetail.INFO_STATUS_ID)); this.getField(BookingDetail.MARKUP_FROM_LAST).addListener(fieldListener = new FieldDataScratchHandler(null) fieldListener.setRespondsToMode(DBConstants.SCREEN_MOVE, true);
/** * Constructor. * @param record My owner (usually passed as null, and set on addListener in setOwner()). * @param iMainFilesField The sequence of the date changed field in this record. * @param field The date changed field in this record. */ public void init(Record record, DateTimeField field) { super.init(record); m_field = field; FieldDataScratchHandler listener = new FieldDataScratchHandler(null); listener.setAlwaysEnabled(true); // Since this holds the current key m_field.addListener(listener); // I will need the original value for the sql update this.setMasterSlaveFlag(FileListener.RUN_IN_SLAVE | FileListener.RUN_IN_MASTER); // Set date key in slave code, check for error in master code } /**
public int fieldChanged(boolean bDisplayOption, int iMoveMode) { if (iMoveMode != DBConstants.SCREEN_MOVE) // This is necessary if an override change the repondsTo. // Also, if just refreshing the record, don't change this if set if ((m_bChangeDataOnRefresh) || ((this.getOwner().getRecord().getOpenMode() & DBConstants.OPEN_DONT_CHANGE_CURRENT_LOCK_TYPE) != DBConstants.OPEN_DONT_CHANGE_CURRENT_LOCK_TYPE)) if ((this.getOwner().getRecord().getOpenMode() & DBConstants.OPEN_DONT_UPDATE_LAST_READ) != DBConstants.OPEN_DONT_UPDATE_LAST_READ) // This is a special case where I want a subsequent write to get an error if changed this.setOriginalData(this.getOwner().getData()); return super.fieldChanged(bDisplayOption, iMoveMode); } /**
/** * Initialize this object. * @param record The parent record. * @param strName The field name. * @param iDataLength The maximum string length (pass -1 for default). * @param strDesc The string description (usually pass null, to use the resource file desc). * @param strDefault The default value (if object, this value is the default value, if string, the string is the default). */ public void init(Record record, String strName, int iDataLength, String strDesc, Object strDefault) { super.init(record, strName, iDataLength, strDesc, strDefault); if (iDataLength == DBConstants.DEFAULT_FIELD_LENGTH) m_iMaxLength = BIG_DEFAULT_LENGTH; if (this.getListener(FieldDataScratchHandler.class.getName()) == null) this.addListener(new FieldDataScratchHandler(null)); // This is needed for any merge operation } /**
/** * Merge my changed data back into field that I just restored from disk. * @param objData The value this field held before I refreshed from disk. * @return The setData error code. */ public int doMergeData(Object objData) { double dOrigData = ((Double)this.getOriginalData()).doubleValue(); double dMergeData = ((Double)objData).doubleValue(); double dCurrentData = this.getOwner().getValue(); double dMergeAmount = dMergeData - dOrigData; double dNewAmount = dCurrentData + dMergeAmount; objData = new Double(dNewAmount); this.setOriginalData(new Double(dCurrentData)); // Just in case I come through here again return super.doMergeData(objData); } }
if (iMoveMode == DBConstants.READ_MOVE) // Very obscure - Make sure this fake read move does not change the scratch area if (fldDest.getNextValidListener(iMoveMode) instanceof FieldDataScratchHandler) // Always enable would have to be true since listeners have been disabled (listenerScratchData = ((FieldDataScratchHandler)fldDest.getNextValidListener(iMoveMode))).setAlwaysEnabled(false); listenerScratchData.setAlwaysEnabled(true);