View Javadoc

1   /* (c) Copyright 2003 Caleigo AB, All rights reserved. 
2    * 
3    * This library is free software; you can redistribute it and/or
4    * modify it under the terms of the GNU Lesser General Public
5    * License as published by the Free Software Foundation; either
6    * version 2.1 of the License, or (at your option) any later version.
7    * 
8    * This library is distributed in the hope that it will be useful,
9    * but WITHOUT ANY WARRANTY; without even the implied warranty of
10   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11   * Lesser General Public License for more details.
12   * 
13   * You should have received a copy of the GNU Lesser General Public
14   * License along with this library; if not, write to the Free Software
15   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16   *  
17   */
18  
19  package org.caleigo.core.event;
20  
21  import org.caleigo.core.*;
22  
23  /*** Event for relaying changes in the content of EntityCollection Objects.
24   *
25   * @author  Dennis Zikovic
26   * @version 1.00
27   *
28   *//* 
29   *
30   * WHEN        WHO               WHY & WHAT
31   * ------------------------------------------------------------------------------
32   * 2001-10-23  Dennis Zikovic    Creation
33   */
34  public class SelectionEvent extends java.util.EventObject 
35  {
36      // Constants ---------------------------------------------------------------
37      public static final int CONTENTS_CHANGED = 1;
38      public static final int ENTITY_ADDED = 3;
39      public static final int ENTITY_REMOVED = 4;
40      
41      // Data members ------------------------------------------------------------
42      private int mEventType;
43      private IEntity mEntity;
44      private int mRowIndex;
45      
46      // Constructors ------------------------------------------------------------
47      
48      /*** Creates new EntityCollectionEvent with the type CONTENTS_CHANGED.
49       */
50      public SelectionEvent(ISelection source) 
51      {
52          super(source);
53          mEventType = CONTENTS_CHANGED;
54      }
55      
56      /*** Creates new EntityCollectionEvent with the specified type and entity.
57       */
58      public SelectionEvent(ISelection source, int eventType, IEntity entity, int row) 
59      {
60          super(source);
61          mEventType = eventType;
62          mEntity = entity;
63          mRowIndex = row;
64      }
65      
66      // Superclass overrides ----------------------------------------------------
67      public String toString()
68      {
69          String params = null;
70          switch(mEventType) 
71          {
72              case CONTENTS_CHANGED: 
73                  params = "CONTENTS_CHANGED"; 
74                  break;
75              case ENTITY_ADDED: 
76                  params = "ENTITY_ADDED"; 
77                  break;
78              case ENTITY_REMOVED: 
79                  params = "ENTITY_REMOVED"; 
80                  break;
81              default: 
82                  params = "UNKNOWN_TYPE"; 
83                  break;
84          }
85  	return getClass().getName()+"["+params+"] on "+source.toString();
86      }
87      
88      // Access methods ----------------------------------------------------------
89      public ISelection getSourceSelection()
90      {
91          return (ISelection)this.getSource();
92      }    
93      
94      public int getEventType()
95      {
96          return mEventType;
97      }    
98      
99      public IEntity getEntity()
100     {
101         return mEntity;
102     }    
103     
104     public int getRowIndex()
105     {
106         return mRowIndex;
107     }    
108 }