Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Example on how to use IContextFunction in Eclipse 4

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?

like image 350
Cratylus Avatar asked Dec 04 '25 17:12

Cratylus


1 Answers

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
   }
}
like image 84
erdal.karaca Avatar answered Dec 06 '25 07:12

erdal.karaca