001: //** Copyright Statement ***************************************************
002: //The Salmon Open Framework for Internet Applications (SOFIA)
003: //Copyright (C) 1999 - 2002, Salmon LLC
004: //
005: //This program is free software; you can redistribute it and/or
006: //modify it under the terms of the GNU General Public License version 2
007: //as published by the Free Software Foundation;
008: //
009: //This program is distributed in the hope that it will be useful,
010: //but WITHOUT ANY WARRANTY; without even the implied warranty of
011: //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: //GNU General Public License for more details.
013: //
014: //You should have received a copy of the GNU General Public License
015: //along with this program; if not, write to the Free Software
016: //Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: //
018: //For more information please visit http://www.salmonllc.com
019: //** End Copyright Statement ***************************************************
020: package com.salmonllc.sql;
021:
022: /**
023: * Event object that gets passed to ModelChangedListeners when data in a model changes.
024: */
025: public class ModelChangedEvent extends java.awt.AWTEvent {
026:
027: public static final int TYPE_ROW_FOCUS_CHANGED = 0;
028: public static final int TYPE_DATA_CHANGED = 1;
029: public static final int TYPE_ROW_INSERTED_OR_DELETED = 2;
030: public static final int TYPE_DATA_SORTED = 3;
031: public static final int TYPE_DATA_FILTERED = 4;
032: public static final int TYPE_DATA_LOADED = 5;
033: public static final int TYPE_RESET = 6;
034: public static final int TYPE_DATA_SORTING = 7;
035:
036: private DataStoreBuffer _ds;
037: private int _type;
038: private int _oldRow, _newRow;
039: private Object _oldData, _newData;
040: private int _colNo = -1;
041:
042: /**
043: * Creates a row focused changed event
044: */
045: public ModelChangedEvent(DataStoreBuffer ds, int oldRow, int newRow) {
046: super (ds, 0);
047: _ds = ds;
048: _type = TYPE_ROW_FOCUS_CHANGED;
049: _oldRow = oldRow;
050: _newRow = newRow;
051: }
052:
053: /**
054: * Creates a data changed event
055: */
056: public ModelChangedEvent(DataStoreBuffer ds, int colNo,
057: Object oldData, Object newData) {
058: super (ds, 0);
059: _ds = ds;
060: _type = TYPE_DATA_CHANGED;
061: _oldData = oldData;
062: _newData = newData;
063: _colNo = colNo;
064: }
065:
066: /**
067: * For an insert or delete row event
068: */
069: public ModelChangedEvent(DataStoreBuffer ds, int newRow) {
070: super (ds, 0);
071: _ds = ds;
072: _type = TYPE_ROW_INSERTED_OR_DELETED;
073: _newRow = newRow;
074: }
075:
076: /**
077: * For an sort,filter or load event
078: */
079: public ModelChangedEvent(int type, DataStoreBuffer ds) {
080: super (ds, 0);
081: _ds = ds;
082: _type = type;
083: }
084:
085: /**
086: * Returns the DataStore that generated the event.
087: * @return DataStoreBuffer
088: */
089: public DataStoreBuffer getDataStore() {
090: return _ds;
091: }
092:
093: /**
094: * For Row Focus Changed Event, Returns the new row.
095: * @return int
096: */
097: public int getNewRow() {
098: return _newRow;
099: }
100:
101: /**
102: * For Row Focus Changed Event, Returns the old row.
103: * @return int
104: */
105: public int getOldRow() {
106: return _oldRow;
107: }
108:
109: /**
110: * Returns the type of event.
111: * @return int
112: */
113: public int getType() {
114: return _type;
115: }
116:
117: /**
118: * Returns the new data for a data changed event.
119: * @return Object
120: */
121: public Object getNewData() {
122: return _newData;
123: }
124:
125: /**
126: * Returns the old data for a data changed event.
127: * @return Object
128: */
129: public Object getOldData() {
130: return _oldData;
131: }
132:
133: /**
134: * Returns the col number changed for a data changed event.
135: * @return int
136: */
137: public int getColNo() {
138: return _colNo;
139: }
140:
141: /**
142: * Returns true if the event caused the whole table to change or false if only a part changed
143: */
144: public boolean isAllDataChanged() {
145: return _type >= 3;
146: }
147:
148: }
|