TableChangeEvent.java
上传用户:zhengdagz
上传日期:2014-03-06
资源大小:1956k
文件大小:5k
源码类别:

xml/soap/webservice

开发平台:

Java

  1. /*
  2.  * $Id: TableChangeEvent.java,v 1.4 2005/10/15 11:43:21 pdoubleya Exp $
  3.  *
  4.  * Copyright 2005 Sun Microsystems, Inc., 4150 Network Circle,
  5.  * Santa Clara, California 95054, U.S.A. All rights reserved.
  6.  *
  7.  * This library is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU Lesser General Public
  9.  * License as published by the Free Software Foundation; either
  10.  * version 2.1 of the License, or (at your option) any later version.
  11.  * 
  12.  * This library is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.  * Lesser General Public License for more details.
  16.  * 
  17.  * You should have received a copy of the GNU Lesser General Public
  18.  * License along with this library; if not, write to the Free Software
  19.  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  20.  */
  21. package org.jdesktop.dataset.event;
  22. import java.util.EventObject;
  23. import org.jdesktop.dataset.DataColumn;
  24. import org.jdesktop.dataset.DataRow;
  25. import org.jdesktop.dataset.DataSelector;
  26. import org.jdesktop.dataset.DataTable;
  27. /**
  28.  * <P>A <CODE>TableChangeEvent</CODE> is broadcast when a {@link DataTable} is changed--either structurally, or 
  29.  * has data modified.  Events are identified by an <CODE>EventType</CODE> enumeration in the class. <CODE>LOAD_STARTED</CODE> 
  30.  * and <CODE>LOAD_COMPLETE</CODE> are broadcast at the start and end of a {@link DataTable#load()}, respectively,
  31.  * while <CODE>SAVE_STARTED</CODE> and <CODE>SAVE_COMPLETE</CODE> notify on {@link DataTable#save()}. 
  32.  * <CODE>TABLE_CLEARED</CODE> is broadcast when a table is cleared out completely.
  33.  * <CODE>ROW_ADDED</CODE>, <CODE>ROW_DELETED</CODE> and <CODE>ROW_DISCARDED</CODE> are broadcast per-row
  34.  * for add, delete and discard operations. <CODE>COLUMN_ADDED</CODE> and <CODE>COLUMN_REMOVED</CODE>
  35.  * are broadcast per-column for add or remove operations on columns. To track row status changes, or changes to column values, see
  36.  * {@link RowChangeEvent}.
  37.  *
  38.  * <P>TableChangeEvents instances are re-sent to all listeners on a table, and are unmodifiable.
  39.  *
  40.  * @author Richard Bair
  41.  * @author Patrick Wright
  42.  */
  43. public class TableChangeEvent extends EventObject {
  44.     public enum EventType {
  45.         LOAD_STARTED,
  46.         LOAD_COMPLETE,
  47.         SAVE_STARTED,
  48.         SAVE_COMPLETE,
  49.         TABLE_CLEARED,
  50.         ROW_ADDED,
  51.         ROW_DELETED,
  52.         ROW_DISCARDED,
  53.         COLUMN_ADDED,
  54.         COLUMN_REMOVED
  55.     };
  56.     
  57.     private EventType eventType;
  58.     private DataColumn columnAffected;
  59.     private DataRow rowAffected;
  60.     
  61.     private TableChangeEvent(DataTable source) { super(source); }
  62.     
  63.     /** Creates a new instance of TableChangeEvent; for whole-table events */
  64.     private TableChangeEvent(DataTable source, EventType what ) {
  65.         super(source);
  66.         eventType = what;
  67.     }
  68.     
  69.     /** Creates a new instance of TableChangeEvent; for events involving DataRows */
  70.     private TableChangeEvent(DataTable source, EventType what, DataRow row ) {
  71.         this(source, what);
  72.         rowAffected = row;
  73.     }
  74.     
  75.     /** Creates a new instance of TableChangeEvent; for events involving DataColumns */
  76.     private TableChangeEvent(DataTable source, EventType what, DataColumn column ) {
  77.         this(source, what);
  78.         columnAffected = column;
  79.     }
  80.     
  81.     public static TableChangeEvent newLoadStartEvent(DataTable source) { 
  82.         return new TableChangeEvent(source, EventType.LOAD_STARTED);
  83.     }
  84.     
  85.     public static TableChangeEvent newLoadCompleteEvent(DataTable source) { 
  86.         return new TableChangeEvent(source, EventType.LOAD_COMPLETE);
  87.     }
  88.     public static TableChangeEvent newSaveStartEvent(DataTable source) { 
  89.         return new TableChangeEvent(source, EventType.SAVE_STARTED);
  90.     }
  91.     
  92.     public static TableChangeEvent newSaveCompleteEvent(DataTable source) { 
  93.         return new TableChangeEvent(source, EventType.SAVE_COMPLETE);
  94.     }
  95.     public static TableChangeEvent newTableClearedEvent(DataTable source) { 
  96.         return new TableChangeEvent(source, EventType.TABLE_CLEARED);
  97.     }
  98.     
  99.     public static TableChangeEvent newColumnAddedEvent(DataTable source, DataColumn col) { 
  100.         return new TableChangeEvent(source, EventType.COLUMN_ADDED, col);
  101.     }
  102.     public static TableChangeEvent newColumnRemovedEvent(DataTable source, DataColumn col) { 
  103.         return new TableChangeEvent(source, EventType.COLUMN_REMOVED, col);
  104.     }
  105.     public static TableChangeEvent newRowAddedEvent(DataTable source, DataRow row) { 
  106.         return new TableChangeEvent(source, EventType.ROW_ADDED, row);
  107.     }
  108.     public static TableChangeEvent newRowDeletedEvent(DataTable source, DataRow row) { 
  109.         return new TableChangeEvent(source, EventType.ROW_DELETED, row);
  110.     }
  111.     public static TableChangeEvent newRowDiscardedEvent(DataTable source, DataRow row) { 
  112.         return new TableChangeEvent(source, EventType.ROW_DISCARDED, row);
  113.     }
  114.     /** Returns the EventType enumerated value for this event, never null.  */
  115.     public TableChangeEvent.EventType getEventType() {
  116.         return eventType;
  117.     }
  118.     
  119.     /** Returns the DataRow affected by this event, or null if no row was involved. */
  120.     public DataRow getRowAffected() {
  121.         return rowAffected;
  122.     }
  123.     
  124.     /** Returns the DataColumn affected by this event, or null if no column was involved. */
  125.     public DataColumn getColumnAffected() {
  126.         return columnAffected;
  127.     }
  128. }