Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » e(fx)clipse » Publishing to the Eclipse context using @ContextValue(Using ContextBoundValue.publish() twice results in an error)
Publishing to the Eclipse context using @ContextValue [message #1289478] Wed, 09 April 2014 11:08 Go to next message
Uwe San is currently offline Uwe SanFriend
Messages: 119
Registered: January 2012
Senior Member
Hi,

I'm getting familiar with the @ContextValue annotation for publishing objects to the Eclipse context as described on this e(fx)clipse wiki page.

I wrote a small handler class that follows the code sample in the wiki:

public class MyHandler {

   @Inject
   @ContextValue(contextKey = "item")
   ContextBoundValue<String> value;

   @Execute
   public void execute(@Named(IServiceConstants.ACTIVE_SELECTION) @Optional Object selection) {
      if (selection instanceof String) {
         value.publish((String) selection);
      }
   }
}


This works fine when the handler is called once, but if I execute the handler twice, I get the following error:

Caused by: java.lang.IllegalArgumentException: Variable item is not modifiable in the context WorkbenchContext
	at org.eclipse.e4.core.internal.contexts.EclipseContext.internalModify(EclipseContext.java:376)
	at org.eclipse.e4.core.internal.contexts.EclipseContext.modify(EclipseContext.java:366)
	at org.eclipse.fx.core.di.context.internal.EclipseContextBoundValue.publish(EclipseContextBoundValue.java:100)
	at foo.MyHandler.execute(CopyHandler.java:21)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)


The same happens when I use a Property<String> object instead of the ContextBoundValue<String> type.

Am I using the @ContextValue mechanism in wrong way or is this a bug in e(fx)clipse?

Thanks.
Uwe
Re: Publishing to the Eclipse context using @ContextValue [message #1289485 is a reply to message #1289478] Wed, 09 April 2014 11:13 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Well the handler instance is created on the WorkbenchContext so did you
declare the variable in your MApplication-Element?

Tom

On 09.04.14 13:08, Uwe San wrote:
> Hi,
>
> I'm getting familiar with the @ContextValue annotation for publishing
> objects to the Eclipse context as described on
> https://wiki.eclipse.org/Efxclipse/Runtime/Recipes#Publishing_to_the_IEclipseContext.
>
>
> I wrote a small handler class that follows the code sample in the wiki:
>
>
> public class MyHandler {
>
> @Inject
> @ContextValue(contextKey = "item")
> ContextBoundValue<String> value;
>
> @Execute
> public void execute(@Named(IServiceConstants.ACTIVE_SELECTION)
> @Optional Object selection) {
> if (selection instanceof String) {
> value.publish((String) selection);
> }
> }
> }
>
>
> This works fine when the handler is called once, but if I execute the
> handler twice, I get the following error:
>
>
> Caused by: java.lang.IllegalArgumentException: Variable item is not
> modifiable in the context WorkbenchContext
> at
> org.eclipse.e4.core.internal.contexts.EclipseContext.internalModify(EclipseContext.java:376)
>
> at
> org.eclipse.e4.core.internal.contexts.EclipseContext.modify(EclipseContext.java:366)
>
> at
> org.eclipse.fx.core.di.context.internal.EclipseContextBoundValue.publish(EclipseContextBoundValue.java:100)
>
> at foo.MyHandler.execute(CopyHandler.java:21)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
> at java.lang.reflect.Method.invoke(Unknown Source)
> at
> org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)
>
>
>
> The same happens when I use a Property<String> object instead of the
> ContextBoundValue<String> type.
>
> Am I using the @ContextValue mechanism in wrong way or is this a bug in
> e(fx)clipse?
>
> Thanks.
> Uwe
Re: Publishing to the Eclipse context using @ContextValue [message #1289501 is a reply to message #1289485] Wed, 09 April 2014 11:29 Go to previous messageGo to next message
Uwe San is currently offline Uwe SanFriend
Messages: 119
Registered: January 2012
Senior Member
Thomas Schindl wrote on Wed, 09 April 2014 07:13
Well the handler instance is created on the WorkbenchContext so did you
declare the variable in your MApplication-Element?



I guess I did not. Could you give a small example for this?

Uwe
Re: Publishing to the Eclipse context using @ContextValue [message #1289506 is a reply to message #1289501] Wed, 09 April 2014 11:33 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
To make the publishing work you need to call
IEclipseContext#declareModifiable() on the context you are publishing to.

In your case it is the context of the MApplication so you need to make
your e4xmi look like this:

<?xml version="1.0" encoding="UTF-8"?>
<application:Application xmi:version="2.0" >
<!-- ... -->
<variables>item</variables>
<!-- ... -->
</application:Application>

In the e4xmi-Editor you find the variables on the Supplementary-Tab.

Tom


On 09.04.14 13:29, Uwe San wrote:
> Thomas Schindl wrote on Wed, 09 April 2014 07:13
>> Well the handler instance is created on the WorkbenchContext so did you
>> declare the variable in your MApplication-Element?
>
>
>
> I guess I did not. Could you give a small example for this?
>
> Uwe
Re: Publishing to the Eclipse context using @ContextValue [message #1289520 is a reply to message #1289506] Wed, 09 April 2014 11:47 Go to previous message
Uwe San is currently offline Uwe SanFriend
Messages: 119
Registered: January 2012
Senior Member
This worked, thanks. I added the item variable to my Part element since this was the context in which my handler was defined.
Previous Topic:Jar file with all it's dependencies
Next Topic:How do configure ANT PDE build for plugin which consumes e(fx)clipse runtime
Goto Forum:
  


Current Time: Thu Apr 18 02:14:14 GMT 2024

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

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

Back to the top