| 1 | /** |
| 2 | * Copyright 2005-2011 Steve McDuff d-duff@users.sourceforge.net |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.deduced.viewer.web.shared; |
| 17 | |
| 18 | import java.io.Serializable; |
| 19 | |
| 20 | /** |
| 21 | * Change Event |
| 22 | * |
| 23 | * @author Steve McDuff |
| 24 | * |
| 25 | */ |
| 26 | public class ChangeEvent implements Serializable |
| 27 | { |
| 28 | /** |
| 29 | * serialVersionUID |
| 30 | */ |
| 31 | private static final long serialVersionUID = 5465033588038309696L; |
| 32 | |
| 33 | /** |
| 34 | * object ID that was changed |
| 35 | */ |
| 36 | private String id; |
| 37 | |
| 38 | /** |
| 39 | * type of change |
| 40 | */ |
| 41 | private String type; |
| 42 | |
| 43 | /** |
| 44 | * name of the property that was changed |
| 45 | */ |
| 46 | private String name; |
| 47 | |
| 48 | /** |
| 49 | * value that was changed |
| 50 | */ |
| 51 | private SerializedValue value; |
| 52 | |
| 53 | /** |
| 54 | * flag indicating if the changed property is a sorting instance in an |
| 55 | * ordered list |
| 56 | */ |
| 57 | private boolean isSortingInstance; |
| 58 | |
| 59 | /** |
| 60 | * |
| 61 | * ChangeEvent constructor |
| 62 | */ |
| 63 | public ChangeEvent() |
| 64 | { |
| 65 | |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * @param setId the id to set |
| 70 | */ |
| 71 | public void setId( |
| 72 | String setId) |
| 73 | { |
| 74 | id = setId; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * @return the id |
| 79 | */ |
| 80 | public String getId() |
| 81 | { |
| 82 | return id; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * @param setType the type to set |
| 87 | */ |
| 88 | public void setType( |
| 89 | String setType) |
| 90 | { |
| 91 | type = setType; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * @return the type |
| 96 | */ |
| 97 | public String getType() |
| 98 | { |
| 99 | return type; |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * @param setName the name to set |
| 104 | */ |
| 105 | public void setName( |
| 106 | String setName) |
| 107 | { |
| 108 | name = setName; |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * @return the name |
| 113 | */ |
| 114 | public String getName() |
| 115 | { |
| 116 | return name; |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * @param setValue the value to set |
| 121 | */ |
| 122 | public void setValue( |
| 123 | SerializedValue setValue) |
| 124 | { |
| 125 | value = setValue; |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * @return the value |
| 130 | */ |
| 131 | public SerializedValue getValue() |
| 132 | { |
| 133 | return value; |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * set Serializable Value |
| 138 | * |
| 139 | * @param newValue the Serializable value |
| 140 | */ |
| 141 | public void setSerializableValue( |
| 142 | Serializable newValue) |
| 143 | { |
| 144 | setValue(Serializer.serialize(newValue)); |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * get Serializable Value |
| 149 | * |
| 150 | * @return the Serializable value |
| 151 | */ |
| 152 | public Serializable getSerializableValue() |
| 153 | { |
| 154 | if (value != null) |
| 155 | { |
| 156 | return value.getValue(); |
| 157 | } |
| 158 | return null; |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * @param setIsSortingInstance the isSortingInstance to set |
| 163 | */ |
| 164 | public void setSortingInstance( |
| 165 | boolean setIsSortingInstance) |
| 166 | { |
| 167 | isSortingInstance = setIsSortingInstance; |
| 168 | } |
| 169 | |
| 170 | /** |
| 171 | * @return the isSortingInstance |
| 172 | */ |
| 173 | public boolean isSortingInstance() |
| 174 | { |
| 175 | return isSortingInstance; |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * (non-JSDoc) |
| 180 | * |
| 181 | * @see java.lang.Object#equals(java.lang.Object) |
| 182 | */ |
| 183 | @Override |
| 184 | public boolean equals( |
| 185 | Object obj) |
| 186 | { |
| 187 | if (obj == this) |
| 188 | { |
| 189 | return true; |
| 190 | } |
| 191 | |
| 192 | if (!(obj instanceof ChangeEvent)) |
| 193 | { |
| 194 | return false; |
| 195 | } |
| 196 | |
| 197 | ChangeEvent other = (ChangeEvent) obj; |
| 198 | |
| 199 | return Utilities.equals(id, other.id) |
| 200 | && Utilities.equals(name, other.name) |
| 201 | && Utilities.equals(type, other.type) |
| 202 | && Utilities.equals(value, other.value) |
| 203 | && isSortingInstance == other.isSortingInstance; |
| 204 | } |
| 205 | |
| 206 | /** |
| 207 | * (non-JSDoc) |
| 208 | * |
| 209 | * @see java.lang.Object#hashCode() |
| 210 | */ |
| 211 | @Override |
| 212 | public int hashCode() |
| 213 | { |
| 214 | int hash = HashCodeUtilities.SEED; |
| 215 | |
| 216 | hash = HashCodeUtilities.hash(hash, id); |
| 217 | hash = HashCodeUtilities.hash(hash, name); |
| 218 | hash = HashCodeUtilities.hash(hash, type); |
| 219 | hash = HashCodeUtilities.hash(hash, value); |
| 220 | hash = HashCodeUtilities.hash(hash, isSortingInstance); |
| 221 | |
| 222 | return hash; |
| 223 | } |
| 224 | |
| 225 | /** |
| 226 | * (non-JSDoc) |
| 227 | * |
| 228 | * @see java.lang.Object#toString() |
| 229 | */ |
| 230 | @Override |
| 231 | public String toString() |
| 232 | { |
| 233 | return "Change Event of type : " + type + ", on object ID : " + id |
| 234 | + ", on property : " + name + ", with value : " + value; |
| 235 | } |
| 236 | } |