1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.caleigo.core.event;
20
21 import org.caleigo.core.*;
22
23 /*** Event for relaying value and status changes in IEntity objects.
24 *
25 * @author Dennis Zikovic
26 * @version 1.00
27 *
28 *//*
29 *
30 * WHEN WHO WHY & WHAT
31 * ------------------------------------------------------------------------------
32 * 2001-07-12 Dennis Zikovic Creation
33 * 2001-10-23 Dennis Zikovic Changed superclass to EntityEvent.
34 */
35 public class EntityChangeEvent extends EntityEvent
36 {
37
38 private IFieldDescriptor mFieldDescriptor;
39 private int mStatusType;
40 private Object mOldValue;
41 private Object mNewValue;
42
43
44
45 /*** Use this costructor for specified data content changes specified
46 * by an IFieldDescriptor.
47 */
48 public EntityChangeEvent(IEntity entity, IFieldDescriptor descriptor, Object oldValue, Object newValue)
49 {
50 super(entity, DATA_CHANGED);
51 mFieldDescriptor = descriptor;
52 mStatusType = -1;
53 mOldValue = oldValue;
54 mNewValue = newValue;
55 }
56
57 /*** Use this costructor for logic state changes.
58 */
59 public EntityChangeEvent(IEntity entity, int statusType, boolean newState)
60 {
61 super(entity, STATUS_CHANGED);
62 mFieldDescriptor = null;
63 mStatusType = statusType;
64 mNewValue = new Boolean(newState);
65 }
66
67
68 public String toString()
69 {
70 String params = null;
71 if(this.isDataChange())
72 {
73 params = "DATA_CHANGED, "+mFieldDescriptor;
74 params += ", "+mFieldDescriptor.getDataType().makeLogString(this.getOldValue())
75 +" -> "+mFieldDescriptor.getDataType().makeLogString(this.getNewValue());
76 }
77 else
78 {
79 if((mStatusType & IEntity.DIRTY)!=0)
80 params = "DIRTY";
81 if((mStatusType & IEntity.EMPTY)!=0)
82 params = params==null ? "EMPTY" : params+"+EMPTY";
83 if((mStatusType & IEntity.PERSISTENT)!=0)
84 params = params==null ? "PERSISTENT" : params+"+PERSISTENT";
85 if(params==null)
86 params = "UNKNOWN_STATUS";
87 params = "STATUS_CHANGED, "+params;
88 params += ", "+this.getOldValue()+" -> "+this.getNewValue();
89 }
90 return getClass().getName()+"["+params+"] on "+source.toString();
91 }
92
93
94 public boolean isDataChange()
95 {
96 return mFieldDescriptor!=null;
97 }
98
99 public boolean isStatusChange()
100 {
101 return mFieldDescriptor==null;
102 }
103
104 public int getStatusType()
105 {
106 return mStatusType;
107 }
108
109 public IFieldDescriptor getFieldDescriptor()
110 {
111 return mFieldDescriptor;
112 }
113
114 public Object getOldValue()
115 {
116 if(isStatusChange() && mOldValue==null)
117 mOldValue = new Boolean(!((Boolean)mNewValue).booleanValue());
118 return mOldValue;
119 }
120
121 public Object getNewValue()
122 {
123 return mNewValue;
124 }
125 }