1 | @Override | | 1 | @Override |
2 | protected void updateListeners(Object oldOwner, Object newOwner) { | | 2 | protected void updateListeners(Object oldOwner, Object newOwner) { |
3 | Set<Object[]> l = new HashSet<Object[]>(); | | 3 | Set<Object[]> listeners = new HashSet<Object[]>(); |
4 | if (newOwner != null) { | | 4 | |
5 | // add the listeners to the newOwner | | 5 | // Collect the set of model elements that we want to listen to |
6 | l.add(new Object[] {newOwner, null}); | | 6 | if (newOwner != null) { |
7 | | | 7 | // TODO: Because we get called on each and every change event, when |
8 | Collection c = Model.getFacade().getStereotypes(newOwner); | | 8 | // the model is in a state of flux, we'll often get an |
9 | Iterator i = c.iterator(); | | 9 | // InvalidElementException before we finish this collection. The |
10 | while (i.hasNext()) { | | 10 | // only saving grace is that we're called SO many times that on the |
11 | Object st = i.next(); | | 11 | // last time, things should be stable again and we'll get a good set |
12 | l.add(new Object[] {st, "name"}); | | 12 | // of elements for the final update. We need a better mechanism. |
13 | } | | 13 | |
14 | } | | 14 | // add the listeners to the newOwner |
15 | updateElementListeners(l); | | 15 | listeners.add(new Object[] {newOwner, null}); |
16 | } | | 16 | |
| | | 17 | // and its stereotypes |
| | | 18 | // TODO: Aren't stereotypes handled elsewhere? |
| | | 19 | for (Object stereotype |
| | | 20 | : Model.getFacade().getStereotypes(newOwner)) { |
| | | 21 | listeners.add(new Object[] {stereotype, null}); |
| | | 22 | } |
| | | 23 | |
| | | 24 | // and its features |
| | | 25 | for (Object feat : Model.getFacade().getFeatures(newOwner)) { |
| | | 26 | listeners.add(new Object[] {feat, null}); |
| | | 27 | // and the stereotypes of its features |
| | | 28 | for (Object stereotype |
| | | 29 | : Model.getFacade().getStereotypes(feat)) { |
| | | 30 | listeners.add(new Object[] {stereotype, null}); |
| | | 31 | } |
| | | 32 | // and the parameter of its operations |
| | | 33 | if (Model.getFacade().isAOperation(feat)) { |
| | | 34 | for (Object param : Model.getFacade().getParameters(feat)) { |
| | | 35 | listeners.add(new Object[] {param, null}); |
| | | 36 | /* Testing: Add a parameter to an operation on an Interface. |
| | | 37 | * Does the Interface Fig adapt its width? */ |
| | | 38 | } |
| | | 39 | } |
| | | 40 | } |
| | | 41 | } |
| | | 42 | |
| | | 43 | // Update the listeners to match the desired set using the minimal |
| | | 44 | // update facility |
| | | 45 | updateElementListeners(listeners); |
| | | 46 | } |