1 | /** | | 1 | /** |
2 | * Returns true if some event is valid. An event is valid if the | | 2 | * @param e |
3 | * element changed in the event is valid. This is determined via a | | 3 | * @return |
4 | * call to isValidElement. This method can be overriden by | | 4 | * @see org.argouml.uml.ui.UMLStereotypeListModel#isValidEvent(java.beans.PropertyChangeEvent) |
5 | * subclasses if they cannot determine if it is a valid event just | | 5 | * @since 20110215 |
6 | * by checking the changed element. | | 6 | */ |
7 | * | | 7 | private boolean isValidEventRemove(PropertyChangeEvent e) { |
8 | * @param e the event | | 8 | boolean valid = false; |
9 | * @return boolean true if the event is valid | | 9 | if (!(getChangedElement(e) instanceof Collection)) { |
10 | */ | | 10 | |
11 | protected boolean isValidEvent(PropertyChangeEvent e) { | | 11 | if ((e.getNewValue() != null && e.getOldValue() == null) |
12 | boolean valid = false; | | 12 | || isValidElement(getChangedElement(e))) { |
13 | if (!(getChangedElement(e) instanceof Collection)) { | | 13 | valid = true; // we tried to remove a value |
14 | if ((e.getNewValue() == null && e.getOldValue() != null) | | 14 | } |
15 | // Don't try to test this if we're removing the element | | 15 | } else { |
16 | || isValidElement(getChangedElement(e))) { | | 16 | Collection col = (Collection) getChangedElement(e); |
17 | valid = true; // we tried to remove a value | | 17 | Iterator it = col.iterator(); |
18 | } | | 18 | if (!col.isEmpty()) { |
19 | } else { | | 19 | valid = true; |
20 | Collection col = (Collection) getChangedElement(e); | | 20 | while (it.hasNext()) { |
21 | if (!col.isEmpty()) { | | 21 | Object o = it.next(); |
22 | valid = true; | | 22 | if (!isValidElement(o)) { |
23 | for (Object o : col) { | | 23 | valid = false; |
24 | if (!isValidElement(o)) { | | 24 | break; |
25 | valid = false; | | 25 | } |
26 | break; | | 26 | } |
27 | } | | 27 | } else { |
28 | } | | 28 | if (e.getOldValue() instanceof Collection |
29 | } else { | | 29 | && !((Collection) e.getOldValue()).isEmpty()) { |
30 | if (e.getOldValue() instanceof Collection | | 30 | valid = true; |
31 | && !((Collection) e.getOldValue()).isEmpty()) { | | 31 | } |
32 | valid = true; | | 32 | } |
33 | } | | 33 | } |
34 | } | | 34 | return valid; |
35 | } | | 35 | } |
36 | return valid; | | | |
37 | } | | | |