/** * Constructor. * @param record My owner (usually passed as null, and set on addListener in setOwner()). * @param recordToUpdate Record to update on close. */ public void init(Record record, Record recordToUpdate, boolean bRefreshAfterUpdate, boolean bUpdateOnClose, boolean bUpdateOnUpdate) { super.init(record, recordToUpdate, bRefreshAfterUpdate, bUpdateOnClose, bUpdateOnUpdate); } }
/** * Add all the screen listeners. */ public void addListeners() { super.addListeners(); Booking recBooking = (Booking)this.getRecord(Booking.BOOKING_FILE); Profile recProfile = (Profile)this.getRecord(Profile.PROFILE_FILE); recBooking.addSecondProfile(recProfile); // Agency Secondary logic recProfile.setOpenMode(DBConstants.OPEN_REFRESH_AND_LOCK_ON_CHANGE_STRATEGY); recProfile.addListener(new UpdateOnCloseHandler(null)); // Make sure profile information is updated } /**
/** * Add this listener to a record (only if it doesn't already exist) * @param record * @param recordToUpdate * @param bRefreshAfterUpdate * @param bUpdateOnClose * @param bUpdateOnUpdate * @return */ public static UpdateOnCloseHandler addUpdateOnCloseHandler(Record record, Record recordToUpdate, boolean bRefreshAfterUpdate, boolean bUpdateOnClose, boolean bUpdateOnUpdate) { UpdateOnCloseHandler listener = (UpdateOnCloseHandler)record.getListener(UpdateOnCloseHandler.class); while (listener != null) { if (listener.getRecordToUpdate() == recordToUpdate) break; // Found, don't add again listener = (UpdateOnCloseHandler)listener.getListener(UpdateOnCloseHandler.class); } if (listener == null) record.addListener(listener = new UpdateOnCloseHandler(recordToUpdate, bRefreshAfterUpdate, bUpdateOnClose, bUpdateOnUpdate)); // Make sure this is updated with booking return listener; } }
/** * Set the field or file that owns this listener. * @param owner My owner. */ public void setOwner(ListenerOwner owner) { super.setOwner(owner); if (m_recordToUpdate == null) m_recordToUpdate = this.getOwner(); // Defaults to this file if (owner != null) if (this.getOwner() != m_recordToUpdate) m_recordToUpdate.addListener(new FileRemoveBOnCloseHandler(this)); if (m_recordToUpdate != null) m_recordToUpdate.setOpenMode((m_recordToUpdate.getOpenMode() | DBConstants.OPEN_LOCK_ON_CHANGE_STRATEGY) & ~(DBConstants.OPEN_READ_ONLY | DBConstants.OPEN_APPEND_ONLY)); // Lock the record if any changes if (owner != null) if (this.getOwner() == m_recordToUpdate) if (this.getOwner().getListener() != this) // Prevents endless loop (listener is already the first in the list) { // This is special weird logic - This must be the first in the listener list this.getOwner().removeListener(this, false); super.setOwner(owner); // Set it back this.setNextListener(this.getOwner().getListener()); this.getOwner().setListener(this); // This MUST be the first listener on the list. } } /**
/** * Called when a change in the record status is about to happen/has happened. * @param field If this file change is due to a field, this is the field. * @param changeType The type of change that occurred. * @param bDisplayOption If true, display any changes. * @return an error code. * Synchronize records after an update or add. */ public int doRecordChange(FieldInfo field, int iChangeType, boolean bDisplayOption) { // Read a valid record int iErrorCode = super.doRecordChange(field, iChangeType, bDisplayOption); // Initialize the record if (iErrorCode != DBConstants.NORMAL_RETURN) return iErrorCode; if (m_bUpdateOnUpdate) if ((iChangeType == DBConstants.AFTER_UPDATE_TYPE) || (iChangeType == DBConstants.AFTER_ADD_TYPE)) return this.writeAndRefresh(); if (iChangeType == DBConstants.BEFORE_FREE_TYPE) if (m_bUpdateOnClose) this.writeAndRefresh(); return iErrorCode; } /**
/** * AddDetailBehaviors Method. */ public void addDetailBehaviors(BookingModel recBooking, TourModel recTour) { super.addDetailBehaviors(recBooking, recTour); if (recBooking != null) { this.addListener(new SubCountHandler((BaseField)recBooking.getField(Booking.GROSS), BookingLine.GROSS, true, true)); this.addListener(new SubCountHandler((BaseField)recBooking.getField(Booking.COMMISSION), BookingLine.COMMISSION, true, true)); this.addListener(new SubCountHandler((BaseField)recBooking.getField(Booking.NET), BookingLine.NET, true, true)); ((Record)recBooking).getField(Booking.NET).addListener(new SetDirtyOnChangeHandler((BaseField)recBooking.getField(Booking.BOOKING_STATUS_ID), true, true)); // This makes sure the booking will update which will trigger an A/R update ((Record)recBooking).addListener(new UpdateOnCloseHandler(null)); this.addSubListeners((Booking)recBooking); } } /**
/** * Add this listener to a record (only if it doesn't already exist) * @param record * @param recordToUpdate * @param bRefreshAfterUpdate * @param bUpdateOnClose * @param bUpdateOnUpdate * @return */ public static UpdateOnCloseHandler addUpdateOnCloseHandler(Record record, Record recordToUpdate, boolean bRefreshAfterUpdate, boolean bUpdateOnClose, boolean bUpdateOnUpdate) { UpdateOnCloseHandler listener = (UpdateOnCloseHandler)record.getListener(UpdateOnCloseHandler.class); while (listener != null) { if (listener.getRecordToUpdate() == recordToUpdate) break; // Found, don't add again listener = (UpdateOnCloseHandler)listener.getListener(UpdateOnCloseHandler.class); } if (listener == null) record.addListener(listener = new UpdateOnCloseHandler(recordToUpdate, bRefreshAfterUpdate, bUpdateOnClose, bUpdateOnUpdate)); // Make sure this is updated with booking return listener; } }
/** * Set the field or file that owns this listener. * @param owner My owner. */ public void setOwner(ListenerOwner owner) { super.setOwner(owner); if (m_recordToUpdate == null) m_recordToUpdate = this.getOwner(); // Defaults to this file if (owner != null) if (this.getOwner() != m_recordToUpdate) m_recordToUpdate.addListener(new FileRemoveBOnCloseHandler(this)); if (m_recordToUpdate != null) m_recordToUpdate.setOpenMode((m_recordToUpdate.getOpenMode() | DBConstants.OPEN_LOCK_ON_CHANGE_STRATEGY) & ~(DBConstants.OPEN_READ_ONLY | DBConstants.OPEN_APPEND_ONLY)); // Lock the record if any changes if (owner != null) if (this.getOwner() == m_recordToUpdate) if (this.getOwner().getListener() != this) // Prevents endless loop (listener is already the first in the list) { // This is special weird logic - This must be the first in the listener list this.getOwner().removeListener(this, false); super.setOwner(owner); // Set it back this.setNextListener(this.getOwner().getListener()); this.getOwner().setListener(this); // This MUST be the first listener on the list. } } /**
/** * Called when a new blank record is required for the table/query. * @param bDisplayOption If true, display any changes. */ public void doNewRecord(boolean bDisplayOption) // init this field override for other value { super.doNewRecord(bDisplayOption); if (m_bUpdateOnUpdate) this.writeAndRefresh(); // If there are any changes waiting, write them! } /**
/** * AddDetailBehaviors Method. */ public void addDetailBehaviors(BookingModel recBooking, TourModel recTour) { super.addDetailBehaviors(recBooking, recTour); if (recBooking != null) { this.addListener(new SubCountHandler((BaseField)recBooking.getField(Booking.GROSS), BookingLine.GROSS, true, true)); this.addListener(new SubCountHandler((BaseField)recBooking.getField(Booking.COMMISSION), BookingLine.COMMISSION, true, true)); this.addListener(new SubCountHandler((BaseField)recBooking.getField(Booking.NET), BookingLine.NET, true, true)); ((Record)recBooking).getField(Booking.NET).addListener(new SetDirtyOnChangeHandler((BaseField)recBooking.getField(Booking.BOOKING_STATUS_ID), true, true)); // This makes sure the booking will update which will trigger an A/R update ((Record)recBooking).addListener(new UpdateOnCloseHandler(null)); this.addSubListeners((Booking)recBooking); } } /**
/** * Add this listener to a record (only if it doesn't already exist) * @param record * @param recordToUpdate * @param bRefreshAfterUpdate * @param bUpdateOnClose * @param bUpdateOnUpdate * @return */ public static UpdateOnCloseHandler addUpdateOnCloseHandler(Record record, Record recordToUpdate, boolean bRefreshAfterUpdate, boolean bUpdateOnClose, boolean bUpdateOnUpdate) { UpdateOnCloseHandler listener = (UpdateOnCloseHandler)record.getListener(UpdateOnCloseHandler.class); while (listener != null) { if (listener.getRecordToUpdate() == recordToUpdate) break; // Found, don't add again listener = (UpdateOnCloseHandler)listener.getListener(UpdateOnCloseHandler.class); } if (listener == null) record.addListener(listener = new UpdateOnCloseHandler(recordToUpdate, bRefreshAfterUpdate, bUpdateOnClose, bUpdateOnUpdate)); // Make sure this is updated with booking return listener; } }
/** * Constructor. * @param recordToUpdate Record to update on close (if null, defaults to this file). */ public UpdateOnCloseHandler(Record recordToUpdate, boolean bRefreshAfterUpdate) { this(); this.init(null, recordToUpdate, bRefreshAfterUpdate, true, false); } /**
/** * Set the field or file that owns this listener. * @param owner My owner. */ public void setOwner(ListenerOwner owner) { super.setOwner(owner); if (m_recordToUpdate == null) m_recordToUpdate = this.getOwner(); // Defaults to this file if (owner != null) if (this.getOwner() != m_recordToUpdate) m_recordToUpdate.addListener(new FileRemoveBOnCloseHandler(this)); if (m_recordToUpdate != null) m_recordToUpdate.setOpenMode((m_recordToUpdate.getOpenMode() | DBConstants.OPEN_LOCK_ON_CHANGE_STRATEGY) & ~(DBConstants.OPEN_READ_ONLY | DBConstants.OPEN_APPEND_ONLY)); // Lock the record if any changes if (owner != null) if (this.getOwner() == m_recordToUpdate) if (this.getOwner().getListener() != this) // Prevents endless loop (listener is already the first in the list) { // This is special weird logic - This must be the first in the listener list this.getOwner().removeListener(this, false); super.setOwner(owner); // Set it back this.setNextListener(this.getOwner().getListener()); this.getOwner().setListener(this); // This MUST be the first listener on the list. } } /**
/** * free this listener and update/add the target record. */ public void free() { if (m_bUpdateOnClose) this.writeAndRefresh(); super.free(); } /**
recHeader.addListener(new org.jbundle.base.db.event.UpdateOnCloseHandler(null));
/** * Constructor. * @param recordToUpdate Record to update on close (if null, defaults to this file). */ public UpdateOnCloseHandler(Record recordToUpdate, boolean bRefreshAfterUpdate, boolean bUpdateOnUpdate) { this(); this.init(null, recordToUpdate, bRefreshAfterUpdate, true, bUpdateOnUpdate); } /**
/** * Called when a new blank record is required for the table/query. * @param bDisplayOption If true, display any changes. */ public void doNewRecord(boolean bDisplayOption) // init this field override for other value { super.doNewRecord(bDisplayOption); if (m_bUpdateOnUpdate) this.writeAndRefresh(); // If there are any changes waiting, write them! } /**
recHeader.addListener(new org.jbundle.base.db.event.UpdateOnCloseHandler((Record)null));
/** * Constructor. * @param recordToUpdate Record to update on close (if null, defaults to this file). */ public UpdateOnCloseHandler(Record recordToUpdate) { this(); this.init(null, recordToUpdate, false, true, false); } /**
/** * Called when a change in the record status is about to happen/has happened. * @param field If this file change is due to a field, this is the field. * @param changeType The type of change that occurred. * @param bDisplayOption If true, display any changes. * @return an error code. * Synchronize records after an update or add. */ public int doRecordChange(FieldInfo field, int iChangeType, boolean bDisplayOption) { // Read a valid record int iErrorCode = super.doRecordChange(field, iChangeType, bDisplayOption); // Initialize the record if (iErrorCode != DBConstants.NORMAL_RETURN) return iErrorCode; if (m_bUpdateOnUpdate) if ((iChangeType == DBConstants.AFTER_UPDATE_TYPE) || (iChangeType == DBConstants.AFTER_ADD_TYPE)) return this.writeAndRefresh(); if (iChangeType == DBConstants.BEFORE_FREE_TYPE) if (m_bUpdateOnClose) this.writeAndRefresh(); return iErrorCode; } /**