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

xml/soap/webservice

开发平台:

Java

  1. /*
  2.  * $Id: DataTableEventAdapter.java,v 1.1 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.beans.PropertyChangeListener;
  23. import org.jdesktop.dataset.DataRow;
  24. /**
  25.  * <CODE>DataTableEventAdapter</CODE> is a {@link DataTableListener} that captures {@link TableChangeEvent TableChangeEvents} and 
  26.  * {@link RowChangeEvent RowChangeEvents} and re-directs them to handler methods by event type. For example, you
  27.  * can capture a {@link #rowAdded(TableChangeEvent)} or {@link rowStatusChanged(RowChangeEvent)} event instead of checking for the 
  28.  * event type on capturing an event directly. To use this class, create an instance and assign it to a {@link DataTable} using 
  29.  * {@link DataTable#addDataTableListener(DataTableListener)}.
  30.  *
  31.  * @author Patrick Wright
  32.  */
  33. public abstract class DataTableEventAdapter implements DataTableListener, PropertyChangeListener {
  34.     
  35.     /** Creates a new instance of DataTableEventAdapter */
  36.     public DataTableEventAdapter() {
  37.     }
  38.     
  39.     /** 
  40.      * Fired when a property on the bound object is changed. In this case, we are only interested
  41.      * in status changes on a DataRow; these are forwarded to {@link rowStatusChanged(RowChangeEvent)}. All
  42.      * other property changes are ignored.
  43.      */
  44.     public void propertyChange(java.beans.PropertyChangeEvent evt) {
  45.         System.out.println("propertyChange: " + evt);
  46.         if ( evt.getSource().getClass() == DataRow.class ) {
  47.             System.out.println("  is data row");
  48.             DataRow row = (DataRow)evt.getSource();
  49.             if ( evt.getPropertyName().equals("status")) {
  50.                 System.out.println("  is status change");
  51.                 rowStatusChanged(RowChangeEvent.newRowStatusChangeEvent(row, (DataRow.DataRowStatus)evt.getOldValue()));
  52.             }
  53.         }
  54.     }
  55.     /**
  56.      * Fired when the row is changed, either status change or a cell's value was changed.
  57.      * @param evt The RowChangeEvent capturing the change.
  58.      */
  59.     public void rowChanged(RowChangeEvent evt) {
  60.         switch ( evt.getEventType() ) {
  61.             case ROW_STATUS_CHANGED:
  62.                 rowStatusChanged(evt);
  63.                 break;
  64.             case CELL_CHANGED:
  65.                 cellChanged(evt);
  66.                 break;
  67.             default:
  68.                 throw new RuntimeException("Unknown event type on row change event " + evt.getEventType());
  69.         }
  70.     }
  71.     
  72.     /**
  73.      * Fired when the row's status changes.
  74.      * @param evt The RowChangeEvent capturing the change.
  75.      */
  76.     public void rowStatusChanged(RowChangeEvent evt) {}
  77.     
  78.     /**
  79.      * Fired when a cell's value changes.
  80.      * @param evt The RowChangeEvent capturing the change.
  81.      */
  82.     public void cellChanged(RowChangeEvent evt) {}
  83.     
  84.     /**
  85.      * Fired when the table is changed, either structurally (columns added or removed) or in data (rows added, removed, etc.)
  86.      * @param evt The TableChangeEvent capturing the change.
  87.      */
  88.     public void tableChanged(TableChangeEvent evt) {
  89.         switch ( evt.getEventType()) {
  90.             case LOAD_STARTED:
  91.                 tableLoadStarted(evt);
  92.                 break;
  93.             case LOAD_COMPLETE:
  94.                 tableLoadComplete(evt);
  95.                 break;
  96.             case SAVE_STARTED:
  97.                 tableSaveStarted(evt);
  98.                 break;
  99.             case SAVE_COMPLETE:
  100.                 tableSaveComplete(evt);
  101.                 break;
  102.             case TABLE_CLEARED:
  103.                 tableCleared(evt);
  104.                 break;
  105.             case ROW_ADDED:
  106.                 rowAdded(evt);
  107.                 break;
  108.             case ROW_DELETED:
  109.                 rowDeleted(evt);
  110.                 break;
  111.             case ROW_DISCARDED:
  112.                 rowDiscarded(evt);
  113.                 break;
  114.             case COLUMN_ADDED:
  115.                 columnAdded(evt);
  116.                 break;
  117.             case COLUMN_REMOVED:
  118.                 columnRemoved(evt);
  119.                 break;
  120.             default:
  121.                 throw new RuntimeException("Unknown event type on row change event " + evt.getEventType());
  122.         }
  123.     }
  124.     
  125.     /**
  126.      * Fired right before a DataProvider begins loading the table.
  127.      * @param evt The TableChangeEvent capturing the change.
  128.      */
  129.     public void tableLoadStarted(TableChangeEvent evt) {}
  130.     /**
  131.      * Fired after a DataProvider finishes loading the table.
  132.      * @param evt The TableChangeEvent capturing the change.
  133.      */
  134.     public void tableLoadComplete(TableChangeEvent evt) {}
  135.     /**
  136.      * Fired right before a DataProvider begins saving the table.
  137.      * @param evt The TableChangeEvent capturing the change.
  138.      */
  139.     public void tableSaveStarted(TableChangeEvent evt) {}
  140.     /**
  141.      * Fired after a DataProvider finishes saving the table.
  142.      * @param evt The TableChangeEvent capturing the change.
  143.      */
  144.     public void tableSaveComplete(TableChangeEvent evt) {}
  145.     /**
  146.      * Fired when the table is completely cleared.
  147.      * @param evt The TableChangeEvent capturing the change.
  148.      */
  149.     public void tableCleared(TableChangeEvent evt) {}
  150.     /**
  151.      * Fired when a row is added to the table.
  152.      * @param evt The TableChangeEvent capturing the change.
  153.      */
  154.     public void rowAdded(TableChangeEvent evt) {}
  155.     /**
  156.      * Fired when a row is deleted from the table.
  157.      * @param evt The TableChangeEvent capturing the change.
  158.      */
  159.     public void rowDeleted(TableChangeEvent evt) {}
  160.     /**
  161.      * Fired when a row is discarded from the table.
  162.      * @param evt The TableChangeEvent capturing the change.
  163.      */
  164.     public void rowDiscarded(TableChangeEvent evt) {}
  165.     /**
  166.      * Fired when a column is added to the table.
  167.      * @param evt The TableChangeEvent capturing the change.
  168.      */
  169.     public void columnAdded(TableChangeEvent evt) {}
  170.     /**
  171.      * Fired when a column is removed from the table.
  172.      * @param evt The TableChangeEvent capturing the change.
  173.      */
  174.     public void columnRemoved(TableChangeEvent evt) {}    
  175. }