Hi,
In your book in 57.6 you mention about Context Functions but no concrete example has been given. Do you have one online?
I tried using it in combination with paragraph 56.3 but was not succesfull.
Specifically I did the following:
public class MyProvider extends ContextFunction {
@Override
public Object compute(IEclipseContext context) {
System.out.println("Called compute!");
ContextInjectionFactory.make(TestClass1.class, context);
return ContextInjectionFactory.make(TestClass2.class, context);
}
}
and in one of my parts I used DI:
@Optional
@Inject
IEclipseContext ctx;
and in createControls I did:
TestClass1 class1 = (TestClass1) ctx.get(TestClass1.class);
TestClass2 class2 = (TestClass2)ctx.get("
com.example.e4.rcp.todo.contextservice.test");
And class1 is
ALWAYS null while class2 is
ok!
Used this from your example:
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0"
name="com.example.e4.rcp.todo.contextservice.translate">
<implementation class="com.example.e4.rcp.todo.contextservice.Test"/>
<service>
<provide interface="org.eclipse.e4.core.contexts.IContextFunction"/>
</service>
<property name="service.context.key" type="String"
value="com.example.e4.rcp.todo.contextservice.test"/>
</scr:component>
Am I doing it wrong? Do you have another of your tutorials as a reference on this?