You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the payload of the send or post command is a regular Java object, the payload is attached to the OSGi event as a property with the key IEventBroker.DATA. If the payload is a Dictionary or a Map, all the values from the collection are added as properties with their associated keys.
50
53
@@ -58,10 +61,12 @@ Dependency Injection
58
61
59
62
Whenever possible you should use dependency injection to register and respond to events. This technique results in less code, is easier to read and maintain and has fewer anonymous inner classes. Internally, the E4 code base does not currently use this technique for subscribing to its own events. However, this is the result of a limitation that was late in the M4 cycle. Early in the M5 cycle, we will be changing our implementations to use the dependency injection technique for UI event handling.
// Useful work that has access to payload. The instance of foo.Bar that the event poster placed on the global event bus with the topic ''TOPIC_STRING''
64
68
}
69
+
```
65
70
66
71
A quick note on the visibility of the injected handler methods.
67
72
@@ -77,7 +82,7 @@ In some circumstances you will not be able to use dependency injection and must
77
82
You also can not use dependency injection if the topic string you are registering is constructed at run time. The annotation strings need to be available and complete at compile time to be used by @UIEventTopic() (This is the reason we have not previously used dependency injection internally to subscribe to UIEvents ... but that will be changing in M5)
78
83
79
84
80
-
85
+
```java
81
86
IEventBroker eventBroker;
82
87
…
83
88
void addSubscribers() {
@@ -97,6 +102,7 @@ You also can not use dependency injection if the topic string you are registerin
Each EMF model element has a corresponding interfacedefined in UIEvents. Each interfacehas two constants defined for each attribute of the model element.
114
120
115
121
Here is the example for the UILabel model element
116
-
122
+
```java
117
123
publicstaticinterfaceUILabel {
118
124
119
125
// Topics that can be subscribed to
@@ -127,13 +133,16 @@ Here is the example for the UILabel model element
TheTOPIC_* constants are used to subscribe to events generated when the corresponding attribute changes. The constant can be used by either the dependency injection technique or the IEventBroker.subscribe() technique described above. TheTOPIC_ALL constant is used to register for changes on all the attributes of a model element. If the dependency injection technique is used, the event payload is the event itself.
The constants named directly for the element attribute (LABEL, TOOLTIP and ICONURI from the example above) are used in event handlers if you need to inspect the event and determine which attributes have actually changed. This works because UIEventPublisher adds the attribute name from the source EMF event to the OSGi event with the property key UIEvents.EventTags.ATTNAME. The other UIEvents.EventTags.* constants list other values that may be published in an event depending on the event type. Different event types will store different tags in the event.
0 commit comments