Context Functions in paragraph 57.6. Any concrete example?

56 views
Skip to first unread message

Java Dev

unread,
Oct 21, 2012, 10:59:37 AM10/21/12
to vog...@googlegroups.com
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?

Lars Vogel

unread,
Oct 21, 2012, 4:41:04 PM10/21/12
to vog...@googlegroups.com
Hello,

the best place to ask such questions in the Eclipse 4 forum:
http://www.eclipse.org/forums/index.php/f/12/

See also http://www.vogella.com/faq.html

Best regards, Lars


2012/10/21 Java Dev <flying...@yahoo.com>:
> --
> You received this message because you are subscribed to the Google Groups
> "vogella" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/vogella/-/c--q6Eg_eckJ.
> To post to this group, send email to vog...@googlegroups.com.
> To unsubscribe from this group, send email to
> vogella+u...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/vogella?hl=en.

Java Dev

unread,
Oct 21, 2012, 4:44:21 PM10/21/12
to vog...@googlegroups.com
Ok! Will do that. Thank you for your time. Wasn't sure if those forums were active.
Thanks again
Reply all
Reply to author
Forward
0 new messages