Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/gopas/rt/model/BOListEvent.java


1   
2   package com.gopas.rt.model;
3   
4   import java.util.EventObject;
5   import javax.swing.table.*;
6   import java.beans.*;
7   
8   /**
9    * BOListEvent is used to notify listeners that a BOList
10   * has changed. The model event describes changes to a BOList
11   *
12   * Depending on the parameters used in the constructors, the BOListEvent
13   * can be used to specify the following types of changes: <p>
14   *
15   * <pre>
16   * BOListEvent(source);              //  The data, ie. all rows changed 
17   * BOListEvent(source, HEADER_ROW);  //  Structure change
18   * BOListEvent(source, 1);           //  Row 1 changed
19   * BOListEvent(source, 3, 6);        //  Rows 3 to 6 inclusive changed
20   * BOListEvent(source, 2, 2, 6);     //  Cell at (2, 6) changed
21   * BOListEvent(source, 3, 6, INSERT); // Rows (3, 6) were inserted
22   * BOListEvent(source, 3, 6, DELETE); // Rows (3, 6) were deleted
23   * </pre>
24   *
25   * It is possible to use other combinations of the parameters, not all of them 
26   * are meaningful. By subclassing, you can add other information, for example: 
27   * whether the event WILL happen or DID happen. This makes the specification 
28   * of rows in DELETE events more useful but has not been included in 
29   * the swing package as the JTable only needs post-event notification. 
30   * <p>
31   *
32   */
33  public class BOListEvent extends PropertyChangeEvent
34  {
35      /** Identifies the addtion of new rows. */
36      public static final int INSERT =  1;
37      /** Identifies a change to existing data. */
38      public static final int UPDATE =  0;
39      /** Identifies the removal of rows. */
40      public static final int DELETE = -1;
41      
42      /** Identifies the header row. */
43      public static final int HEADER_ROW = -1;
44      
45  
46    //
47    // Constructors
48    //
49  
50    /** 
51     *  All row data in the table has changed, listeners should discard any state 
52     *  that was based on the rows and requery the TableModel to get the new 
53     *  row count and all the appropriate values. 
54     *  The JTable will repaint the entire visible region on recieving 
55     *  this event, querying the model for the cell values that are visble. 
56     *  The structure of the table ie, the column names, types and order 
57     *  have not changed.  
58     * (Using Integer.MAX_VALUE instead of getRowCount() in case rows were
59     * deleted.  
60     */
61    public BOListEvent(
62        Object source, 
63        String propName,
64        BOList psrcList) {
65      this(source, propName, psrcList, 0, Integer.MAX_VALUE, UPDATE);
66      }
67      
68    /**
69     *  This row of data has been updated. 
70     *  To denote the arrival of a completely new table with a different structure 
71     *  use <code>HEADER_ROW</code> as the value for the <I>row</I>. 
72     */
73    public BOListEvent(
74        Object source, 
75        String propName, 
76        BOList psrcList,
77        int row) {
78      this(source, propName, psrcList, row, row, UPDATE);
79    }
80      
81    /**
82     *  The data in rows [<I>firstRow</I>, <I>lastRow</I>] have been updated. 
83     */
84    public BOListEvent(
85        Object source, 
86        String propName, 
87        BOList psrcList,
88        int firstRow, 
89        int lastRow) {
90      this(source, propName, psrcList, firstRow, lastRow, UPDATE);
91    }
92      
93    /**
94     *  The cells from (firstRow) to (lastRow) have been changed. 
95     *  <p>
96     *  The <I>type</I> should be one of: INSERT, UPDATE and DELETE. 
97     */
98    public BOListEvent(
99        Object source, 
100       String propName, 
101       BOList psrcList,
102       int pfirstRow, 
103       int plastRow, 
104       int ptype) {
105     super(source, propName, null, new Object());
106     this.srcList = psrcList;
107     this.firstRow = pfirstRow;
108     this.lastRow = plastRow;
109     this.type = ptype;
110     this.removedObjects = null;
111   }
112     
113   /**
114    *  The cells from (firstRow) to (lastRow) have been deleted. 
115    *  <p>
116    *  The <I>type</I> should be: DELETE. 
117    */
118   public BOListEvent(
119       Object source, 
120       String propName,
121       BOList psrcList,
122       int pfirstRow, 
123       int plastRow, 
124       Object[] premovedArr) {
125     super(source, propName, null, new Object());
126     this.srcList = psrcList;
127     this.firstRow = pfirstRow;
128     this.lastRow = plastRow;
129     this.type = DELETE;
130     this.removedObjects = premovedArr;
131   }
132 
133   //
134   // Querying Methods
135   //
136 
137   /** Returns the first row that changed.  HEADER_ROW means the meta data, 
138    * ie. names, types and order of the columns. 
139    */
140   public int getFirstRow() { return firstRow; };
141   
142   /** Returns the last row that changed. */
143   public int getLastRow() { return lastRow; };
144   
145   /**
146    *  Returns the type of event - one of: INSERT, UPDATE and DELETE.
147    */
148   public int getType() { return type; }
149   
150   /**
151    *  Returns the List in which the event occurred.
152    */
153   public BOList getSrcList() { return srcList; }
154   
155   /**
156    *  Returns the removed objects.
157    */
158   public Object[] getRemovedObjects() { return removedObjects; }
159 
160   public String toString() {
161     return "BOListEvent source= " + getSource()
162       + " property " + getPropertyName()
163       + " type " + type 
164       + " rows " + firstRow + ".." + lastRow;
165   }
166 
167   //
168   //  Instance Variables
169   //
170 
171   protected final BOList srcList;
172   protected final int type;
173   protected final int  firstRow;
174   protected final int  lastRow;
175   protected final Object[] removedObjects;
176 }