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 valid
| | 9 | * @return boolean true if the event is 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 | // TODO: Considering all delete events to be valid like below
| | 14 | if ((e.getNewValue() == null && e.getOldValue() != null) |
15 | // is going to cause lots of unecessary work and some problems
| | 15 | // Don't try to test this if we're removing the element |
16 | if ((e.getNewValue() == null && e.getOldValue() != null)
| | 16 | || isValidElement(getChangedElement(e))) { |
17 | // Don't test changed element if it was deleted
| | 17 | valid = true; // we tried to remove a value |
18 | || isValidElement(getChangedElement(e))) {
| | 18 | } |
19 | valid = true; // we tried to remove a value
| | 19 | } else { |
20 | }
| | 20 | Collection col = (Collection) getChangedElement(e); |
21 | } else {
| | 21 | if (!col.isEmpty()) { |
22 | Collection col = (Collection) getChangedElement(e);
| | 22 | valid = true; |
23 | Iterator it = col.iterator();
| | 23 | for (Object o : col) { |
24 | if (!col.isEmpty()) {
| | 24 | if (!isValidElement(o)) { |
25 | valid = true;
| | 25 | valid = false; |
26 | while (it.hasNext()) {
| | 26 | break; |
27 | Object o = it.next();
| | 27 | } |
28 | if (!isValidElement(o)) {
| | 28 | } |
29 | valid = false;
| | 29 | } else { |
30 | break;
| | 30 | if (e.getOldValue() instanceof Collection |
31 | }
| | 31 | && !((Collection) e.getOldValue()).isEmpty()) { |
32 | }
| | 32 | valid = true; |
33 | } else {
| | 33 | } |
34 | if (e.getOldValue() instanceof Collection
| | 34 | } |
35 | && !((Collection) e.getOldValue()).isEmpty()) {
| | 35 | } |
36 | valid = true;
| | 36 | return valid; |
37 | }
| | 37 | } |
38 | }
| | | |
39 | }
| | | |
40 | return valid;
| | | |
41 | } | | | |