Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Get IEventBroker instance at app start-up
Get IEventBroker instance at app start-up [message #996691] Wed, 02 January 2013 17:23 Go to next message
Joel Becker is currently offline Joel Becker
Messages: 14
Registered: December 2012
Junior Member
Hi! How do I get the IEventBroker instance at app start-up? I know I can't inject it into an Activator.

I want to subscribe to shell resize events so i can resize a background image on it. There is a lot of helpful info on e4 injections, but little info on how to get started: where things can be injected (or what objects are created by the framework), how to get the main IEventBroker or EclipseContext (without arbitrarily creating a new one).

-Joel

[Updated on: Wed, 02 January 2013 19:30]

Report message to a moderator

Re: Get IEventBroker instance at app start-up [message #996795 is a reply to message #996691] Wed, 02 January 2013 23:08 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5330
Registered: July 2009
Senior Member
Use an addon?

Tom

Am 02.01.13 18:23, schrieb Joel Becker:
> Hi! How do I get the IEventBroker instance at app start-up? I know I
> can't inject it into an Activator.
>
> I want to subscribe to shell resize events so i can resize a background
> image on it. There is a lot of helpful info on e4 injections, but little
> info on how to get started: where things can be injected (or what
> objects are created by the framework), how to get the main IEventBroker
> or EclipseContext (without arbitrarily creating a new one).
>
> -Joel
>
Re: Get IEventBroker instance at app start-up [message #997240 is a reply to message #996795] Fri, 04 January 2013 15:32 Go to previous messageGo to next message
Joel Becker is currently offline Joel Becker
Messages: 14
Registered: December 2012
Junior Member
Can you please explain how I would use an addon to get the IEventBroker instance at app start-up? I was able to find only little information on an e4 "addon", namely I found the MAddon and AddonImpl classes.

Thanks,
Joel
Re: Get IEventBroker instance at app start-up [message #997257 is a reply to message #997240] Fri, 04 January 2013 18:47 Go to previous messageGo to next message
Joel Becker is currently offline Joel Becker
Messages: 14
Registered: December 2012
Junior Member
I figured out Tom's suggestion. You can add an "Addon" model object to your Application.e4xmi and specify your own regular Java class, which can then be injected by the framework since it is a model object. So I created my "ShellAddon":

public class ShellAddon {

	private IEventBroker broker;
	
	@Inject
	public ShellAddon(IEventBroker broker) {
		this.broker = broker;
	}

	@Inject
	public void onWindowResize(@UIEventTopic(UIEvents.Window.TOPIC_HEIGHT) Object value) {
		System.out.println("value = " + value.toString());
	}
}


The onWindowResize() method was my attempt to bypass my need for the IEventBroker altogether by subscribing directly to a resize event on the main shell; the problem currently is that this method is only called once upon app startup, but not whenever the window height changes as one might suspect. However, an IEventBroker is indeed injected into the constructor, so my original question is solved. Thanks, Tom.
Re: Get IEventBroker instance at app start-up [message #997261 is a reply to message #996691] Fri, 04 January 2013 19:11 Go to previous messageGo to next message
Frank Benoit is currently offline Frank Benoit
Messages: 47
Registered: July 2009
Member
Hi Joel

I think it should look like

@Inject
public void onWindowResize( @Optional @UIEventTopic(UIEvents.Window.TOPIC_HEIGHT) Event ev) {
	if( ev == null ) return;
	System.out.println("value = " + ev.toString());
}


at the moment the object is created, no event topic is available for inject, so it has to be optional. The type should be org.osgi.service.event.Event

cu
Frank

Re: Get IEventBroker instance at app start-up [message #1004101 is a reply to message #997261] Tue, 22 January 2013 15:20 Go to previous message
Joel Becker is currently offline Joel Becker
Messages: 14
Registered: December 2012
Junior Member
Much cleaner that way, thanks.
Previous Topic:Do Addons have another Context, than the parts?
Next Topic:Eclipse Preferences Import Export
Goto Forum:
  


Current Time: Sun Sep 21 04:26:45 GMT 2014

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

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