1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
package org.argouml.model.euml; |
13 | |
|
14 | |
import java.util.ArrayList; |
15 | |
import java.util.List; |
16 | |
|
17 | |
import org.eclipse.emf.common.notify.Notification; |
18 | |
import org.eclipse.emf.common.notify.Notifier; |
19 | |
import org.eclipse.emf.ecore.util.EContentAdapter; |
20 | |
|
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
public class RootContainerAdapter extends EContentAdapter { |
28 | |
|
29 | 0 | private List<Notifier> notifiers = new ArrayList<Notifier>(); |
30 | |
|
31 | 0 | private List<Notification> events = new ArrayList<Notification>(); |
32 | |
|
33 | |
private Notifier rootContainer; |
34 | |
|
35 | |
private ModelEventPumpEUMLImpl pump; |
36 | |
|
37 | 0 | private boolean deliverEvents = true; |
38 | |
|
39 | 0 | private boolean holdEvents = false; |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
public RootContainerAdapter(ModelEventPumpEUMLImpl pump) { |
46 | 0 | super(); |
47 | 0 | this.pump = pump; |
48 | 0 | } |
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
public void setDeliverEvents(boolean value) { |
55 | 0 | deliverEvents = value; |
56 | 0 | } |
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
public void setRootContainer(Notifier n) { |
63 | 0 | if (n == rootContainer) { |
64 | 0 | return; |
65 | |
} |
66 | |
|
67 | 0 | removeAllAdapters(); |
68 | 0 | if (n != null) { |
69 | 0 | rootContainer = n; |
70 | 0 | rootContainer.eAdapters().add(this); |
71 | |
} |
72 | 0 | } |
73 | |
|
74 | |
@Override |
75 | |
protected void addAdapter(Notifier notifier) { |
76 | 0 | notifiers.add(notifier); |
77 | 0 | super.addAdapter(notifier); |
78 | 0 | } |
79 | |
|
80 | |
@Override |
81 | |
protected void removeAdapter(Notifier notifier) { |
82 | 0 | notifiers.remove(notifier); |
83 | 0 | super.removeAdapter(notifier); |
84 | 0 | } |
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
public void removeAllAdapters() { |
90 | 0 | List<Notifier> notifiersToRemove = new ArrayList<Notifier>(notifiers); |
91 | 0 | for (Notifier n : notifiersToRemove) { |
92 | 0 | super.removeAdapter(n); |
93 | |
} |
94 | 0 | if (rootContainer != null) { |
95 | 0 | super.removeAdapter(rootContainer); |
96 | 0 | rootContainer = null; |
97 | |
} |
98 | 0 | notifiers.clear(); |
99 | 0 | } |
100 | |
|
101 | |
@Override |
102 | |
public void notifyChanged(Notification notification) { |
103 | 0 | super.notifyChanged(notification); |
104 | 0 | if (deliverEvents) { |
105 | 0 | if (holdEvents) { |
106 | 0 | events.add(notification); |
107 | |
} else { |
108 | 0 | pump.notifyChanged(notification); |
109 | |
} |
110 | |
} |
111 | 0 | } |
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
public void clearHeldEvents() { |
117 | 0 | events.clear(); |
118 | 0 | } |
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
public void setHoldEvents(boolean value) { |
125 | 0 | if (value == false) { |
126 | 0 | if (deliverEvents) { |
127 | 0 | for (Notification n : events) { |
128 | 0 | pump.notifyChanged(n); |
129 | |
} |
130 | |
} |
131 | 0 | events.clear(); |
132 | |
} |
133 | 0 | holdEvents = value; |
134 | 0 | } |
135 | |
|
136 | |
} |