Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Sending events to single window only(Event broker in context of a multi-window application)
Sending events to single window only [message #1810163] Fri, 02 August 2019 06:38
Guido Schnepp is currently offline Guido SchneppFriend
Messages: 13
Registered: March 2013
Junior Member
Hello,

is there any good way to limit sent or posted events to be received by the active window only? In E4 the event bus is a global construct and events are sent around to every possible i.e. part. But I'd like to receive such an event by the most active window only. It's a multi-window application with shared and individual parts in each window here, and my problem is that all windows receive all events. Just think on log messages for a specific process in one of the active windows only.

For now I'm sending a Map containing two values inside, the attribute/value to transport and MTrimmedWindow target as reference which isn't a really nice solution:

The sender:
Map<Class<?>, Object> values = new HashMap<>();
values.put(String.class, "NewValue");
values.put(MTrimmedWindow.class, getActiveWindow());
eventBrroker.post(Constants.VALUE_CHANGED, values);

and the receiver:
@Inject @Optional
public void showNewValue(@UIEventTopic(Constants.VALUE_CHANGED) Map<Class<?>, Object> values, @Active MTrimmedWindow window) {
  if (values == null)
    return;

  String         newValue      = (String) values.get(String.class);
  MTrimmedWindow desiredWindow = (MTrimmedWindow) values.get(MTrimmedWindow.class);
  if (window == desiredWindow) {
    System.out.println(newValue);
  }
}


One way I can image is to create a special event marker containing i.e. the window hashcode (something like "VALUE_CHANGED + window.hashcode()"), and send this to a receiver being subscribed to this one event individually at runtime. Well, subscription and unsubscription of specific events for every window is neither better readable nor less complex than my solution.

Direct write to the specific EclipseContext of that window is not a solution either because of the singular or one-time character of such a message. Think of a log message to be sent to window... you know. It's nothing which needs to be stored.

Best would be to have a window or thread specific event bus. It may exist already, but I don't have a clue where. Any idea?

Thanks a lot in advance!

Guido
Previous Topic:Adding Help to an E4 RPC application
Next Topic:Is deferring method injection after PostConstruct possible?
Goto Forum:
  


Current Time: Sun Dec 08 20:48:55 GMT 2019

Powered by FUDForum. Page generated in 0.01975 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top