Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 319024

Summary: [DI] @[UI]EventTopic: it should be possible to specify where the user data is held
Product: z_Archived Reporter: Simon Chemouil <eclipse>
Component: E4Assignee: Project Inbox <e4.runtime-inbox>
Status: NEW --- QA Contact:
Severity: enhancement    
Priority: P3 CC: davymeers, ob1.eclipse
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Allows users to set the property used for the data + fix for Bug 319022
none
Draft patch - not meant to be used as-is none

Description Simon Chemouil CLA 2010-07-06 11:49:20 EDT
Build Identifier: I20100705-2033

The EventHandler service received an org.osgi.service.event.Event object which is a has several properties. Currently, the @EventTopic (and @UIEventTopic) annotations allow to have one of the properties directly injected, but this property must be EventUtils.DATA ("org.eclipse.e4.data")

This facility is very useful, often more than the Event object, but it forces the event sender to use this property "org.eclipse.e4.data". When it's a bundle coming from a non-Eclipse/E4 context, this property is inappropriate.

It should be possible by clients (that is, within the @EventTopic annotation) to specify which property is holding the data, and the default should be set to EventUtils.DATA for backwards-compatibility and simplicity.


Reproducible: Always
Comment 1 Simon Chemouil CLA 2010-07-06 11:54:56 EDT
Created attachment 173574 [details]
Allows users to set the property used for the data + fix for Bug 319022

NOTE: This is patched WITH the proposed patch for Bug 319022... Sorry I forgot to revert, and I have little time to do it.

This patch fixes the problem by adding a "data" field to the @EventTopic annotation (@UIEventTopic is not patched by this, but the solution is similar). This field defaults to EventUtils.DATA, and this is backwards compatible with previous uses of the annotation.

With this patch, given a property named "data" in the Event, it is possible for clients to write:
-------------------8<---------------------
  @Inject
  synchronized void listenForEvent(
    @Optional
    @EventTopic(value = MyEVENTS.EVENT_ALL, data = "data") MyDataObject data) {
   // do something
  }
-------------------8<---------------------

If the data is held is the property EventUtils.DATA, it is still possible to write:
-------------------8<---------------------
  @Inject
  synchronized void listenForEvent(
    @Optional
    @EventTopic(MyEVENTS.EVENT_ALL) MyDataObject data) {
   // do something
  }
-------------------8<---------------------

And whatever the property is, it's still possible to write:
-------------------8<---------------------
  @Inject
  synchronized void listenForEvent(
    @Optional
    @EventTopic(MyEVENTS.EVENT_ALL) Event event) {
   // do something
  }
-------------------8<---------------------
Comment 2 Oleg Besedin CLA 2010-07-06 15:48:27 EDT
Also has to be updated:
 - UIEventTopic
 - UIEventObjectSupplier
 - JUnits
 - Docs

We are in Release Candidate 2 now; I'll set the target to post-1.0.
Comment 3 Oleg Besedin CLA 2010-07-06 15:52:18 EDT
Created attachment 173592 [details]
Draft patch - not meant to be used as-is

Draft patch for future use; not meant to be applied.