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