Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Annotatoin @UIEventHandler and @EventHandler(Annotations cannot be resolved)
Annotatoin @UIEventHandler and @EventHandler [message #532185] Fri, 07 May 2010 09:06 Go to next message
Artur Kronenberg is currently offline Artur Kronenberg
Messages: 159
Registered: August 2009
Senior Member
Hi,

I am playing around with the EclipseCon example of the e4 client.
So far I resolved all the errors and recreated the UI. I am able to start the client and see a basic UI however no images, since e.g. in the WebCamView the redraw method is never called because I had to remove the @UIEventHandler methods.

Apparently the @UIEventHandler and @EventHandler methods are gone. Is there a substitute for those annotations? A workaround maybe? Something I missed?

Thanks for any help.

Regards,
Artur
Re: Annotatoin @UIEventHandler and @EventHandler [message #532234 is a reply to message #532185] Fri, 07 May 2010 11:51 Go to previous messageGo to next message
Oleg Besedin is currently offline Oleg Besedin
Messages: 41
Registered: July 2009
Member
They mutated into @UIEventTopic and @EventTopic located in the
"org.eclipse.e4.core.di.extensions" bunde. A class that wants to receive an
event creates an optional injected value with @[UI]EventTopic; no special
method or interface is required.

The sender can either use EventAdmin directly or use helper methods on the
EventUtils class.

- Example of usage in the JUnits: InjectionEventTest
- Example of usage in the photo demo:
Receiver example: Location#setInput(@UIEventTopic)
Sender example: ExifTable: EventUtils.post()

There was a lot churn in this area; I hope this helps a bit.

Sincerely,
Oleg Besedin

"Artur Kronenberg" <addur737@yahoo.de> wrote in message
news:hs138h$df5$1@build.eclipse.org...
> Hi,
>
> I am playing around with the EclipseCon example of the e4 client. So far I
> resolved all the errors and recreated the UI. I am able to start the
> client and see a basic UI however no images, since e.g. in the WebCamView
> the redraw method is never called because I had to remove the
> @UIEventHandler methods.
>
> Apparently the @UIEventHandler and @EventHandler methods are gone. Is
> there a substitute for those annotations? A workaround maybe? Something I
> missed?
>
> Thanks for any help.
>
> Regards,
> Artur
Re: Annotatoin @UIEventHandler and @EventHandler [message #532531 is a reply to message #532234] Mon, 10 May 2010 08:03 Go to previous messageGo to next message
Artur Kronenberg is currently offline Artur Kronenberg
Messages: 159
Registered: August 2009
Senior Member
Hi,

Thanks for the response.
I was able to annotate the methods like this:

void arenaCamViewUpdated(@Optional @UIEventTopic(IArenaCamImage.TOPIC) IArenaCamImage img) {
		if (parent.isDisposed()) {
			return;
		}
		System.out.println("IMG changed");
		Image newImage = new Image(parent.getDisplay(), new ByteArrayInputStream(img.getImage()));
		if (image != null && !image.isDisposed()) {
			Image toBeDisposed = image;
			image = newImage;
			toBeDisposed.dispose();
		} else {
			image = newImage;
		}
		redraw();
	}


however, the method doesn't seem to get called. I debugged the code where the event gets sent and it works (no exception and fire event method is called successfully).

Do you have an idea why my method doesn't receive the event?

Kind regards,
Artur
Re: Annotatoin @UIEventHandler and @EventHandler [message #532552 is a reply to message #532531] Mon, 10 May 2010 08:54 Go to previous messageGo to next message
Artur Kronenberg is currently offline Artur Kronenberg
Messages: 159
Registered: August 2009
Senior Member
I created a workaround for that problem:

So for some reason, like described previously, I am not able to get the Event by annotating the variable in my method, however:

I can inject an EventBroker into my class and subscribe to the EventTopic I need in order to get notified when a certain event appears.

Does that sound like a normal solution?

I unfortunately couldn't find any documentation about the annotations online and referring to this wiki page:

http://wiki.eclipse.org/E4/EAS/Eventing_System

Kind regards,
Artur
Re: Annotatoin @UIEventHandler and @EventHandler [message #532572 is a reply to message #532531] Mon, 10 May 2010 09:32 Go to previous messageGo to next message
Sebastian is currently offline Sebastian
Messages: 61
Registered: March 2010
Member
maybe, this helps bug 304945

[Updated on: Mon, 10 May 2010 09:43]

Report message to a moderator

Re: Annotatoin @UIEventHandler and @EventHandler [message #532675 is a reply to message #532572] Mon, 10 May 2010 15:12 Go to previous messageGo to next message
Artur Kronenberg is currently offline Artur Kronenberg
Messages: 159
Registered: August 2009
Senior Member
Hi,

thanks for the Link - I checked out the latest packages but the annotation still didn't work. Don't know if I am doing it wrong or if it's a bug.

Here is my code:

Annotated handler:

	void arenaCamViewUpdated(@Optional @EventTopic(IArenaCamImage.TOPIC) IArenaCamImage img) {
		if (parent.isDisposed()) {
			return;
		}
		Image newImage = new Image(parent.getDisplay(), new ByteArrayInputStream(img.getImage()));
		if (image != null && !image.isDisposed()) {
			Image toBeDisposed = image;
			image = newImage;
			toBeDisposed.dispose();
		} else {
			image = newImage;
		}
		redraw();
	}


Sending event:

	private void fireArenaCamViewUpdated(IArenaCamImage img) {
		if (eventAdmin != null) {
			eventAdmin.sendEvent(new Event(IArenaCamImage.TOPIC, Collections.singletonMap(IEventBroker.DATA, img)));
		}
	}


Regards,
Artur
Re: Annotatoin @UIEventHandler and @EventHandler [message #532694 is a reply to message #532531] Mon, 10 May 2010 17:04 Go to previous messageGo to next message
Oleg Besedin is currently offline Oleg Besedin
Messages: 41
Registered: July 2009
Member
Did you add "@Inject" qualifier to the methods? (arenaCamViewUpdated in
your example.)

The "@Inject" tells DI that this method needs to be injected. The
"@UIEventTopic(abc)" tells DI where to get values to be injected, in this
case from the event bus. The "@Optional" is required as during the initial
object construciton there is no event, so "null" gets injected during
initial call.

Hope this helps.

Sincerely,
Oleg Besedin


"Artur Kronenberg" <addur737@yahoo.de> wrote in message
news:hs8smc$j68$1@build.eclipse.org...
> Hi,
>
> Thanks for the response. I was able to annotate the methods like this:
>
> void arenaCamViewUpdated(@Optional @UIEventTopic(IArenaCamImage.TOPIC)
> IArenaCamImage img) {
> if (parent.isDisposed()) {
> return;
> }
> System.out.println("IMG changed");
> Image newImage = new Image(parent.getDisplay(), new
> ByteArrayInputStream(img.getImage()));
> if (image != null && !image.isDisposed()) {
> Image toBeDisposed = image;
> image = newImage;
> toBeDisposed.dispose();
> } else {
> image = newImage;
> }
> redraw();
> }
>
> however, the method doesn't seem to get called. I debugged the code where
> the event gets sent and it works (no exception and fire event method is
> called successfully).
> Do you have an idea why my method doesn't receive the event?
>
> Kind regards,
> Artur
Re: Annotatoin @UIEventHandler and @EventHandler [message #533132 is a reply to message #532694] Wed, 12 May 2010 07:14 Go to previous messageGo to next message
Artur Kronenberg is currently offline Artur Kronenberg
Messages: 159
Registered: August 2009
Senior Member
Hi Oleg,

the @Inject did the trick. I didn't think that I have to add that too. I though the @EventTopic would tell DI that an Injection is needed at that point. Thanks for your help.

Kind regards,
Artur
Re: Annotatoin @UIEventHandler and @EventHandler [message #575700 is a reply to message #532234] Mon, 10 May 2010 08:03 Go to previous messageGo to next message
Artur Kronenberg is currently offline Artur Kronenberg
Messages: 159
Registered: August 2009
Senior Member
Hi,

Thanks for the response.
I was able to annotate the methods like this:

void arenaCamViewUpdated(@Optional @UIEventTopic(IArenaCamImage.TOPIC) IArenaCamImage img) {
if (parent.isDisposed()) {
return;
}
System.out.println("IMG changed");
Image newImage = new Image(parent.getDisplay(), new ByteArrayInputStream(img.getImage()));
if (image != null && !image.isDisposed()) {
Image toBeDisposed = image;
image = newImage;
toBeDisposed.dispose();
} else {
image = newImage;
}
redraw();
}

however, the method doesn't seem to get called. I debugged the code where the event gets sent and it works (no exception and fire event method is called successfully).

Do you have an idea why my method doesn't receive the event?

Kind regards,
Artur
Re: Annotatoin @UIEventHandler and @EventHandler [message #575721 is a reply to message #575700] Mon, 10 May 2010 08:54 Go to previous messageGo to next message
Artur Kronenberg is currently offline Artur Kronenberg
Messages: 159
Registered: August 2009
Senior Member
I created a workaround for that problem:

So for some reason, like described previously, I am not able to get the Event by annotating the variable in my method, however:

I can inject an EventBroker into my class and subscribe to the EventTopic I need in order to get notified when a certain event appears.

Does that sound like a normal solution?

I unfortunately couldn't find any documentation about the annotations online and referring to this wiki page:

http://wiki.eclipse.org/E4/EAS/Eventing_System

Kind regards,
Artur
Re: Annotatoin @UIEventHandler and @EventHandler [message #575742 is a reply to message #575700] Mon, 10 May 2010 09:32 Go to previous messageGo to next message
Sebastian is currently offline Sebastian
Messages: 61
Registered: March 2010
Member
Currently, it seems like the eventing annotations are not processed yet.

That is, the UIEventHandler/EventHandler is not created, when adding the @UIEventTopic/@EventTopic annotations.

The UIEventObjectSupplier is present, but not invoked yet.

So this is under development, yet.
There's been a short "how it could be" in April, afaik.
I remember, the question was about unsubscribing the handler subscribed via the annotation, due to the lack of knowledge.

Sebastian
Re: Annotatoin @UIEventHandler and @EventHandler [message #575757 is a reply to message #532572] Mon, 10 May 2010 15:12 Go to previous messageGo to next message
Artur Kronenberg is currently offline Artur Kronenberg
Messages: 159
Registered: August 2009
Senior Member
Hi,

thanks for the Link - I checked out the latest packages but the annotation still didn't work. Don't know if I am doing it wrong or if it's a bug.

Here is my code:

Annotated handler:

void arenaCamViewUpdated(@Optional @EventTopic(IArenaCamImage.TOPIC) IArenaCamImage img) {
if (parent.isDisposed()) {
return;
}
Image newImage = new Image(parent.getDisplay(), new ByteArrayInputStream(img.getImage()));
if (image != null && !image.isDisposed()) {
Image toBeDisposed = image;
image = newImage;
toBeDisposed.dispose();
} else {
image = newImage;
}
redraw();
}

Sending event:

private void fireArenaCamViewUpdated(IArenaCamImage img) {
if (eventAdmin != null) {
eventAdmin.sendEvent(new Event(IArenaCamImage.TOPIC, Collections.singletonMap(IEventBroker.DATA, img)));
}
}

Regards,
Artur
Re: Annotatoin @UIEventHandler and @EventHandler [message #575770 is a reply to message #575700] Mon, 10 May 2010 17:04 Go to previous messageGo to next message
Oleg Besedin is currently offline Oleg Besedin
Messages: 41
Registered: July 2009
Member
Did you add "@Inject" qualifier to the methods? (arenaCamViewUpdated in
your example.)

The "@Inject" tells DI that this method needs to be injected. The
"@UIEventTopic(abc)" tells DI where to get values to be injected, in this
case from the event bus. The "@Optional" is required as during the initial
object construciton there is no event, so "null" gets injected during
initial call.

Hope this helps.

Sincerely,
Oleg Besedin


"Artur Kronenberg" <addur737@yahoo.de> wrote in message
news:hs8smc$j68$1@build.eclipse.org...
> Hi,
>
> Thanks for the response. I was able to annotate the methods like this:
>
> void arenaCamViewUpdated(@Optional @UIEventTopic(IArenaCamImage.TOPIC)
> IArenaCamImage img) {
> if (parent.isDisposed()) {
> return;
> }
> System.out.println("IMG changed");
> Image newImage = new Image(parent.getDisplay(), new
> ByteArrayInputStream(img.getImage()));
> if (image != null && !image.isDisposed()) {
> Image toBeDisposed = image;
> image = newImage;
> toBeDisposed.dispose();
> } else {
> image = newImage;
> }
> redraw();
> }
>
> however, the method doesn't seem to get called. I debugged the code where
> the event gets sent and it works (no exception and fire event method is
> called successfully).
> Do you have an idea why my method doesn't receive the event?
>
> Kind regards,
> Artur
Re: Annotatoin @UIEventHandler and @EventHandler [message #575900 is a reply to message #532694] Wed, 12 May 2010 07:14 Go to previous message
Artur Kronenberg is currently offline Artur Kronenberg
Messages: 159
Registered: August 2009
Senior Member
Hi Oleg,

the @Inject did the trick. I didn't think that I have to add that too. I though the @EventTopic would tell DI that an Injection is needed at that point. Thanks for your help.

Kind regards,
Artur
Previous Topic:XWT. Composite with XWT UI.
Next Topic:Workbench freezes when opening XWT file
Goto Forum:
  


Current Time: Sat Aug 30 08:32:21 EDT 2014

Powered by FUDForum. Page generated in 0.02641 seconds