View Javadoc

1   /*
2    * $Id: ElementEvent.java 20320 2010-11-24 15:03:31Z dfeist $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.module.launcher.util;
12  
13  import java.beans.PropertyChangeEvent;
14  
15  /**
16  *
17  */
18  public abstract class ElementEvent<E> extends PropertyChangeEvent {
19  
20      public static final int ADDED = 0;
21      public static final int UPDATED = 1;
22      public static final int REMOVED = 2;
23      public static final int CLEARED = 3;
24      public static final int MULTI_ADD = 4;
25      public static final int MULTI_REMOVE = 5;
26  
27      private static final String PROPERTY_NAME = "ObservableList__element";
28      protected static final Object OLDVALUE = new Object();
29      protected static final Object NEWVALUE = new Object();
30  
31      private int type;
32      private int index;
33  
34      public ElementEvent(Object source, Object oldValue, Object newValue, int index, int type) {
35          super(source, PROPERTY_NAME, oldValue, newValue);
36          switch (type) {
37              case ADDED:
38              case UPDATED:
39              case REMOVED:
40              case CLEARED:
41              case MULTI_ADD:
42              case MULTI_REMOVE:
43                  this.type = type;
44                  break;
45              default:
46                  this.type = UPDATED;
47                  break;
48          }
49          this.index = index;
50      }
51  
52      public int getIndex() {
53          return index;
54      }
55  
56      public int getType() {
57          return type;
58      }
59  
60      public String getTypeAsString() {
61          switch (type) {
62              case ADDED:
63                  return "ADDED";
64              case UPDATED:
65                  return "UPDATED";
66              case REMOVED:
67                  return "REMOVED";
68              case CLEARED:
69                  return "CLEARED";
70              case MULTI_ADD:
71                  return "MULTI_ADD";
72              case MULTI_REMOVE:
73                  return "MULTI_REMOVE";
74              default:
75                  return "UPDATED";
76          }
77      }
78  }