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 | |
4 | | | 4 | if (isCompartmentVisible(Model.getMetaTypes().getAttribute())) { |
5 | if (newOwner != null) { | | 5 | Set<Object[]> listeners = new HashSet<Object[]>(); |
6 | /* Don't listen to all property names | | 6 | |
7 | * We only need to listen to its "type", and "remove". */ | | 7 | // Collect the set of model elements that we want to listen to |
8 | l.add(new Object[] {newOwner, new String[] {"type", "remove"}}); | | 8 | if (newOwner != null) { |
9 | // register for events from the type | | 9 | // TODO: Because we get called on each and every change event, when |
10 | Object type = Model.getFacade().getType(newOwner); | | 10 | // the model is in a state of flux, we'll often get an |
11 | if (Model.getFacade().isAClassifier(type)) { | | 11 | // InvalidElementException before we finish this collection. The |
12 | if (Model.getFacade().isAClassifierInState(type)) { | | 12 | // only saving grace is that we're called SO many times that on the |
13 | Object classifier = Model.getFacade().getType(type); | | 13 | // last time, things should be stable again and we'll get a good set |
14 | l.add(new Object[] {classifier, "name"}); | | 14 | // of elements for the final update. We need a better mechanism. |
15 | l.add(new Object[] {type, "inState"}); | | 15 | |
16 | Collection states = Model.getFacade().getInStates(type); | | 16 | // add the listeners to the newOwner |
17 | Iterator i = states.iterator(); | | 17 | listeners.add(new Object[] {newOwner, null}); |
18 | while (i.hasNext()) { | | 18 | |
19 | l.add(new Object[] {i.next(), "name"}); | | 19 | // and its stereotypes |
20 | } | | 20 | // TODO: Aren't stereotypes handled elsewhere? |
21 | } else { | | 21 | for (Object stereotype |
22 | l.add(new Object[] {type, "name"}); | | 22 | : Model.getFacade().getStereotypes(newOwner)) { |
23 | } | | 23 | listeners.add(new Object[] {stereotype, null}); |
24 | } | | 24 | } |
25 | } | | 25 | |
26 | | | 26 | // and its features |
27 | updateElementListeners(l); | | 27 | for (Object feat : Model.getFacade().getFeatures(newOwner)) { |
28 | } | | 28 | listeners.add(new Object[] {feat, null}); |
| | | 29 | // and the stereotypes of its features |
| | | 30 | for (Object stereotype |
| | | 31 | : Model.getFacade().getStereotypes(feat)) { |
| | | 32 | listeners.add(new Object[] {stereotype, null}); |
| | | 33 | } |
| | | 34 | // and the parameter of its operations |
| | | 35 | if (Model.getFacade().isAOperation(feat)) { |
| | | 36 | for (Object param : Model.getFacade().getParameters(feat)) { |
| | | 37 | listeners.add(new Object[] {param, null}); |
| | | 38 | } |
| | | 39 | } |
| | | 40 | } |
| | | 41 | } |
| | | 42 | |
| | | 43 | // Update the listeners to match the desired set using the minimal |
| | | 44 | // update facility |
| | | 45 | updateElementListeners(listeners); |
| | | 46 | } else { |
| | | 47 | super.updateListeners(oldOwner, newOwner); |
| | | 48 | } |
| | | 49 | } |