1 | /** | | 1 | /** |
2 | * Returns true if some event is valid. An event is valid if the | | 2 | * Returns true if some event is valid. An event is valid if the |
3 | * element changed in the event is valid. This is determined via a | | 3 | * element changed in the event is valid. This is determined via a |
4 | * call to isValidElement. This method can be overriden by | | 4 | * call to isValidElement. This method can be overriden by |
5 | * subclasses if they cannot determine if it is a valid event just | | 5 | * subclasses if they cannot determine if it is a valid event just |
6 | * by checking the changed element. | | 6 | * by checking the changed element. |
7 | * | | 7 | * |
8 | * @param e the event | | 8 | * @param e the event |
9 | * @return boolean true if the event is valid | | 9 | * @return boolean true if valid |
10 | */ | | 10 | */ |
11 | protected boolean isValidEvent(PropertyChangeEvent e) { | | 11 | protected boolean isValidEvent(PropertyChangeEvent e) { |
12 | boolean valid = false; | | 12 | boolean valid = false; |
13 | if (!(getChangedElement(e) instanceof Collection)) { | | 13 | if (!(getChangedElement(e) instanceof Collection)) { |
14 | if ((e.getNewValue() == null && e.getOldValue() != null) | | 14 | // TODO: Considering all delete events to be valid like below |
15 | // Don't try to test this if we're removing the element | | 15 | // is going to cause lots of unecessary work and some problems |
16 | || isValidElement(getChangedElement(e))) { | | 16 | if ((e.getNewValue() == null && e.getOldValue() != null) |
17 | valid = true; // we tried to remove a value | | 17 | // Don't test changed element if it was deleted |
18 | } | | 18 | || isValidElement(getChangedElement(e))) { |
19 | } else { | | 19 | valid = true; // we tried to remove a value |
20 | Collection col = (Collection) getChangedElement(e); | | 20 | } |
21 | if (!col.isEmpty()) { | | 21 | } else { |
22 | valid = true; | | 22 | Collection col = (Collection) getChangedElement(e); |
23 | for (Object o : col) { | | 23 | Iterator it = col.iterator(); |
24 | if (!isValidElement(o)) { | | 24 | if (!col.isEmpty()) { |
25 | valid = false; | | 25 | valid = true; |
26 | break; | | 26 | while (it.hasNext()) { |
27 | } | | 27 | Object o = it.next(); |
28 | } | | 28 | if (!isValidElement(o)) { |
29 | } else { | | 29 | valid = false; |
30 | if (e.getOldValue() instanceof Collection | | 30 | break; |
31 | && !((Collection) e.getOldValue()).isEmpty()) { | | 31 | } |
32 | valid = true; | | 32 | } |
33 | } | | 33 | } else { |
34 | } | | 34 | if (e.getOldValue() instanceof Collection |
35 | } | | 35 | && !((Collection) e.getOldValue()).isEmpty()) { |
36 | return valid; | | 36 | valid = true; |
37 | } | | 37 | } |
| | | 38 | } |
| | | 39 | } |
| | | 40 | return valid; |
| | | 41 | } |