I read about org.eclipse.e4.core.contexts.IContextFunction but could not find online an actual example.
My understanding is that a component implements an IContextFunction and on calling compute another object is lazily created.
But how/when the compute method is called it is not clear to me.
For example with the following:
<?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>
someone must call for the com.example.e4.rcp.todo.contextservice.test for compute to be called but it is unclear to me how this is used.
Does anyone have an example reference?
It is what gets injected into your pojos. E.g.
public class YourPojo {
@Inject
@Named("com.example.e4.rcp.todo.contextservice.test")
private Object yourObject;
}
OR
public class YourPojo {
@Inject
public void test(IEclipseContext ctx) {
Object yourObject = ctx.get("com.example.e4.rcp.todo.contextservice.test");
}
}
OR
public class YourPojo {
@Inject
public void test(@Named("com.example.e4.rcp.todo.contextservice.test") Object yourObject) {
// consume yourObject
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With