1 | /** | | 1 | /** |
2 | * Returns true if some event is valid. An event is valid if the | | 2 | * Must be different from the extends class because |
3 | * element changed in the event is valid. This is determined via a | | 3 | * when we add a sterotype=> remove from available |
4 | * call to isValidElement. This method can be overriden by | | 4 | * remove a stereotype=> add to available |
5 | * subclasses if they cannot determine if it is a valid event just | | 5 | * Called twices: with a AttributeChangeEvent, and with AddAssociationEvent or RemoveAssociationEvent |
6 | * by checking the changed element. | | 6 | * |
7 | * | | 7 | * @param e |
8 | * @param e the event | | 8 | * |
9 | * @return boolean true if the event is valid | | 9 | * @see org.argouml.uml.ui.UMLStereotypeListModel#propertyChange(PropertyChangeEvent) |
10 | */ | | 10 | * @since 20110215 |
11 | protected boolean isValidEvent(PropertyChangeEvent e) { | | 11 | */ |
12 | boolean valid = false; | | 12 | public void propertyChange(PropertyChangeEvent e) { |
13 | if (!(getChangedElement(e) instanceof Collection)) { | | 13 | if (e instanceof AttributeChangeEvent) { |
14 | if ((e.getNewValue() == null && e.getOldValue() != null) | | 14 | // ignored this event |
15 | // Don't try to test this if we're removing the element | | 15 | } else if (e instanceof AddAssociationEvent) { |
16 | || isValidElement(getChangedElement(e))) { | | 16 | //Remove the element from Available List |
17 | valid = true; // we tried to remove a value | | 17 | boolean valid = false; |
18 | } | | 18 | if (!(getChangedElement(e) instanceof Collection)) { |
19 | } else { | | 19 | valid = contains(getChangedElement(e)); |
20 | Collection col = (Collection) getChangedElement(e); | | 20 | } else { |
21 | if (!col.isEmpty()) { | | 21 | Collection col = (Collection) getChangedElement(e); |
22 | valid = true; | | 22 | Iterator it = col.iterator(); |
23 | for (Object o : col) { | | 23 | valid = true; |
24 | if (!isValidElement(o)) { | | 24 | while (it.hasNext()) { |
25 | valid = false; | | 25 | Object o = it.next(); |
26 | break; | | 26 | if (!contains(o)) { |
27 | } | | 27 | valid = false; |
28 | } | | 28 | break; |
29 | } else { | | 29 | } |
30 | if (e.getOldValue() instanceof Collection | | 30 | } |
31 | && !((Collection) e.getOldValue()).isEmpty()) { | | 31 | } |
32 | valid = true; | | 32 | if (valid) { |
33 | } | | 33 | Object o = getChangedElement(e); |
34 | } | | 34 | if (o instanceof Collection) { |
35 | } | | 35 | Iterator it = ((Collection) o).iterator(); |
36 | return valid; | | 36 | while (it.hasNext()) { |
37 | } | | 37 | Object o3 = it.next(); |
| | | 38 | removeElement(o3); |
| | | 39 | } |
| | | 40 | } else { |
| | | 41 | removeElement(o); |
| | | 42 | } |
| | | 43 | } |
| | | 44 | |
| | | 45 | |
| | | 46 | |
| | | 47 | } else if (e instanceof RemoveAssociationEvent) { |
| | | 48 | if (isValidEventRemove(e)) { |
| | | 49 | Object o = getChangedElement(e); |
| | | 50 | if (o instanceof Collection) { |
| | | 51 | ArrayList tempList = new ArrayList((Collection) o); |
| | | 52 | Iterator it = tempList.iterator(); |
| | | 53 | while (it.hasNext()) { |
| | | 54 | Object o2 = it.next(); |
| | | 55 | addElement(o2); |
| | | 56 | } |
| | | 57 | } else { |
| | | 58 | addElement(o); |
| | | 59 | } |
| | | 60 | } |
| | | 61 | |
| | | 62 | } |
| | | 63 | } |