Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » E4 contexts and injection decouple.(Minimize dependencies on e4 framework)
E4 contexts and injection decouple. [message #896540] Wed, 18 July 2012 18:57 Go to next message
Shumy Mising name is currently offline Shumy Mising nameFriend
Messages: 24
Registered: March 2010
Location: Aveiro, Portugal
Junior Member
I was trying to build a application with an eclipse product.
My intention was not to use the complete e4 framework (I use extensions, not the e4xmi).

I only need to add objects to the IEclipseContext, and use the injection libs.
But getting IEclipseContext from E4Workbench.getServiceContext() ties my project to the
org.eclipse.e4.ui.workbench bundle, and with that allot of other dependencies I don't want (emf, com.ibm.icu, e4). Makes my project large and heavy for what I want.

Eclipse context and dependency injection is a good functionality that IMHO could be decoupled from the e4 framework.

It seams to me that for using eclipse contexts and DI I need to use all the e4 framework. But I have to say honestly, I don't like it.
Re: E4 contexts and injection decouple. [message #896545 is a reply to message #896540] Wed, 18 July 2012 19:28 Go to previous messageGo to next message
Erdal Karaca is currently offline Erdal KaracaFriend
Messages: 854
Registered: July 2009
Senior Member
I already used e4's DI/IEclipseContext in a 3.x RCP app.

If you just want the DI and IEclipseContext, then you would only need e4.core.contexts and e4.core.di.
Have a look at ContextInjectionFactory and EclipseContextFactory.

Re: E4 contexts and injection decouple. [message #896549 is a reply to message #896545] Wed, 18 July 2012 20:02 Go to previous messageGo to next message
Shumy Mising name is currently offline Shumy Mising nameFriend
Messages: 24
Registered: March 2010
Location: Aveiro, Portugal
Junior Member
Yes, but how do I get the IEclipseContext?
I try to use EclipseContextFactory.getServiceContext(bundleContext) but the instance of IApplicationContext.getBrandingBundle().getBundleContext() returns null, and I have to use E4Workbench.getServiceContext().
Re: E4 contexts and injection decouple. [message #896550 is a reply to message #896549] Wed, 18 July 2012 20:11 Go to previous messageGo to next message
Erdal Karaca is currently offline Erdal KaracaFriend
Messages: 854
Registered: July 2009
Senior Member
I am not sure you really need to provide the branding bundle.
Any BundleContext would be usable as the root IEclipseContext.

E.g.:

IEclipseContext rootContext = EclipseContextFactory.getServiceContext(FrameworkUtil.getBundle(YourClassWhichIsInsideYourBrandingBundle.class).getBundleContext())


Shumy Mising name wrote on Wed, 18 July 2012 16:02
Yes, but how do I get the IEclipseContext?
I try to use EclipseContextFactory.getServiceContext(bundleContext) but the instance of IApplicationContext.getBrandingBundle().getBundleContext() returns null, and I have to use E4Workbench.getServiceContext().

Re: E4 contexts and injection decouple. [message #896551 is a reply to message #896550] Wed, 18 July 2012 20:16 Go to previous messageGo to next message
Shumy Mising name is currently offline Shumy Mising nameFriend
Messages: 24
Registered: March 2010
Location: Aveiro, Portugal
Junior Member
I will try that code tomorrow, thanks.
Re: E4 contexts and injection decouple. [message #896606 is a reply to message #896540] Thu, 19 July 2012 07:08 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
If you want an IEclipseContext let the framework inject it.

public class MyDIClass {

@Inject
public MyDIClass(IEclipseContext ctx) {

}
}

=> you only get a dependency on need e4.core.contexts and e4.core.di

I'm not sure what you mean with extensions.

Tom

Am 18.07.12 20:57, schrieb Shumy Mising name:
> I was trying to build a application with an eclipse product.
> My intention was not to use the complete e4 framework (I use extensions,
> not the e4xmi).
>
> I only need to add objects to the IEclipseContext, and use the injection
> libs.
> But getting IEclipseContext from E4Workbench.getServiceContext() ties my
> project to the org.eclipse.e4.ui.workbench bundle, and with that allot
> of other dependencies I don't want (emf, com.ibm.icu, e4). Makes my
> project large and heavy for what I want.
>
> Eclipse context and dependency injection is a good functionality that
> IMHO could be decoupled from the e4 framework.
>
> It seams to me that for using eclipse contexts and DI I need to use all
> the e4 framework. But I have to say honestly, I don't like it.
Re: E4 contexts and injection decouple. [message #896608 is a reply to message #896551] Thu, 19 July 2012 07:13 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 482
Registered: December 2010
Location: Germany
Senior Member
If you just want an empty context you can also
IEclipseContext rootContext = EclipseContextFactory.create()

The main difference to getServiceContext is, that with getServiceContext all the OSGi services are avaiblable in the context.
Re: E4 contexts and injection decouple. [message #896640 is a reply to message #896608] Thu, 19 July 2012 08:49 Go to previous messageGo to next message
Shumy Mising name is currently offline Shumy Mising nameFriend
Messages: 24
Registered: March 2010
Location: Aveiro, Portugal
Junior Member
Erdal Karaca: your solution is not working, return null BundleContext.
//inside the start method of an javafx.application.Application implementation.
final BundleContext bContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext();		
context = EclipseContextFactory.getServiceContext(bContext);


Thomas Schindl: injection by ContextInjectionFactory needs an IEclipseContext already available!

Christoph Keimel: I have tried that solution, yes I need the OSGi services.

You see that there is no way to get the proper IEclipseContext without calling E4Workbench.getServiceContext() !!

Re: E4 contexts and injection decouple. [message #896643 is a reply to message #896640] Thu, 19 July 2012 09:01 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 482
Registered: December 2010
Location: Germany
Senior Member
I am using it like this (so I am sure this works):

1) Create an Activator for your Bundle
public class YourActivator implements BundleActivator {
	private static BundleContext bundleContext;
	
	public static BundleContext getContext() {
		return bundleContext;
	}
	
	@Override
	public void start(BundleContext bundleContext) throws Exception {
		YourActivator.bundleContext = bundleContext;
	}

	@Override
	public void stop(BundleContext bundleContext) throws Exception {
		YourActivator.bundleContext = null;
	}
}


2) Tell the Bundle to use the Activator in MANIFEST.MF:
Bundle-Activator: your.bundle.YourActivator


3) Use the saved BundleContext to create your IEclipseContext
BundleContext bundleContext = YourActivator.getContext();
IEclipseContext eclipseContext = EclipseContextFactory.getServiceContext(bundleContext);
Re: E4 contexts and injection decouple. [message #896649 is a reply to message #896640] Thu, 19 July 2012 09:44 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
I'm uncertain what you are doing are you writing a headless e4
application and want to use Eclipse DI? If you are writing a plugin for
an e4 app your root component should be created by the e4 framework.

Tom

Am 19.07.12 10:49, schrieb Shumy Mising name:
> Erdal Karaca: your solution is not working, return null BundleContext.
>
> //inside the start method of an javafx.application.Application
> implementation.
> final BundleContext bContext =
> FrameworkUtil.getBundle(this.getClass()).getBundleContext();
> context = EclipseContextFactory.getServiceContext(bContext);
>
>
> Thomas Schindl: injection by ContextInjectionFactory needs an
> IEclipseContext already available!
>
> Christoph Keimel: I have tried that solution, yes I need the OSGi services.
>
> You see that there is no way to get the proper IEclipseContext without
> calling E4Workbench.getServiceContext() !!
>
>
Re: E4 contexts and injection decouple. [message #896653 is a reply to message #896643] Thu, 19 July 2012 09:53 Go to previous messageGo to next message
Shumy Mising name is currently offline Shumy Mising nameFriend
Messages: 24
Registered: March 2010
Location: Aveiro, Portugal
Junior Member
Christoph Keimel:
It seems a nice solution but... I don't know why is not using the Activator!

My activator:
package fx.osgi;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

public class Activator implements BundleActivator {
	private static BundleContext bundleContext;

	public static BundleContext getContext() {
		return bundleContext;
	}

	@Override
	public void start(BundleContext bundleContext) throws Exception {
		System.out.println("Activator...");
		Activator.bundleContext = bundleContext;
	}

	@Override
	public void stop(BundleContext bundleContext) throws Exception {
		Activator.bundleContext = null;
	}
}


in MANIFEST.MF
Bundle-Activator: fx.osgi.Activator


I'm using a product config, and a org.eclipse.equinox.app.IApplication implementation.
Maybe this is overriding something!!
Re: E4 contexts and injection decouple. [message #896654 is a reply to message #896649] Thu, 19 July 2012 09:53 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Well I see that you are writing a JavaFX application. So are you running
in OSGi?

Do you know about e(fx)clipse? It has an IApplication which has an
implementation which does the IEclipseContext bootstraping for you?

See the impl
https://github.com/tomsontom/e-fx-clipse/blob/master/at.bestsolution.efxclipse.runtime.di/src/at/bestsolution/efxclipse/runtime/di/DIApplication.java

See an example
https://github.com/tomsontom/e-fx-clipse/tree/master/at.bestsolution.efxclipse.runtime.examples.osgi.di

Tom

Am 19.07.12 11:44, schrieb Tom Schindl:
> I'm uncertain what you are doing are you writing a headless e4
> application and want to use Eclipse DI? If you are writing a plugin for
> an e4 app your root component should be created by the e4 framework.
>
> Tom
>
> Am 19.07.12 10:49, schrieb Shumy Mising name:
>> Erdal Karaca: your solution is not working, return null BundleContext.
>>
>> //inside the start method of an javafx.application.Application
>> implementation.
>> final BundleContext bContext =
>> FrameworkUtil.getBundle(this.getClass()).getBundleContext();
>> context = EclipseContextFactory.getServiceContext(bContext);
>>
>>
>> Thomas Schindl: injection by ContextInjectionFactory needs an
>> IEclipseContext already available!
>>
>> Christoph Keimel: I have tried that solution, yes I need the OSGi services.
>>
>> You see that there is no way to get the proper IEclipseContext without
>> calling E4Workbench.getServiceContext() !!
>>
>>
>
>
Re: E4 contexts and injection decouple. [message #896659 is a reply to message #896653] Thu, 19 July 2012 10:16 Go to previous messageGo to next message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 482
Registered: December 2010
Location: Germany
Senior Member
Sorry, I don't know. Sounds good to me, but clearly something is wrong when the Activator isn't used. Maybe this question is better placed in the Equinox Forum ...
Re: E4 contexts and injection decouple. [message #896661 is a reply to message #896653] Thu, 19 July 2012 10:18 Go to previous messageGo to next message
Shumy Mising name is currently offline Shumy Mising nameFriend
Messages: 24
Registered: March 2010
Location: Aveiro, Portugal
Junior Member
Yes I know about the e-fx-clipse project.
Yes I was trying some javafx code, but that is not the final render.
Maybe I use just a custom console (not decided).

Doesn't matter for my problem at the moment. Javafx code is not enabled.
I was not saying nothing about javafx, because I was expecting that kind of answer.

In my point of view is not a headless e4 application. It's just a (OSGi + Equinox + DI) product.
Re: E4 contexts and injection decouple. [message #896667 is a reply to message #896653] Thu, 19 July 2012 10:38 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
You need to set the lazy activation header, else you don't get a
BundleContext!

Tom

Am 19.07.12 11:53, schrieb Shumy Mising name:
> Christoph Keimel:
> It seems a nice solution but... I don't know why is not using the
> Activator!
>
> My activator:
>
> package fx.osgi;
>
> import org.osgi.framework.BundleActivator;
> import org.osgi.framework.BundleContext;
>
> public class Activator implements BundleActivator {
> private static BundleContext bundleContext;
>
> public static BundleContext getContext() {
> return bundleContext;
> }
>
> @Override
> public void start(BundleContext bundleContext) throws Exception {
> System.out.println("Activator...");
> Activator.bundleContext = bundleContext;
> }
>
> @Override
> public void stop(BundleContext bundleContext) throws Exception {
> Activator.bundleContext = null;
> }
> }
>
>
> in MANIFEST.MF
>
> Bundle-Activator: fx.osgi.Activator
>
>
> I'm using a product config, and a org.eclipse.equinox.app.IApplication
> implementation. Maybe this is overriding something!!
>
Re: E4 contexts and injection decouple. [message #896668 is a reply to message #896667] Thu, 19 July 2012 10:45 Go to previous messageGo to next message
Shumy Mising name is currently offline Shumy Mising nameFriend
Messages: 24
Registered: March 2010
Location: Aveiro, Portugal
Junior Member
Yes, I noticed that just now.
It works, now I will try to remove all garbage dependencies.
Re: E4 contexts and injection decouple. [message #896673 is a reply to message #896668] Thu, 19 July 2012 10:59 Go to previous messageGo to next message
Shumy Mising name is currently offline Shumy Mising nameFriend
Messages: 24
Registered: March 2010
Location: Aveiro, Portugal
Junior Member
Nice. Now I'm able to remove dependencies:
com.ibm.icu
org.eclipse.e4.ui.*
org.eclipse.emf.*

More than 8MB I don't use.

I'm able to inject my objects.
Works fine for now. Thank you very much.
Re: E4 contexts and injection decouple. [message #896676 is a reply to message #896673] Thu, 19 July 2012 11:03 Go to previous messageGo to next message
Shumy Mising name is currently offline Shumy Mising nameFriend
Messages: 24
Registered: March 2010
Location: Aveiro, Portugal
Junior Member
Although I still receive:
Forget this message.

[Updated on: Thu, 19 July 2012 11:10]

Report message to a moderator

Re: E4 contexts and injection decouple. [message #896681 is a reply to message #896676] Thu, 19 July 2012 11:20 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
well not sure but are you sure you launch config is not still holding
unneeded ui bundles. There should be no ui stuff at all.

Tom
Am 19.07.12 13:03, schrieb Shumy Mising name:
> Although I still receive:
>
> !ENTRY org.eclipse.osgi 4 0 2012-07-19 11:59:13.378
> !MESSAGE Bundle org.eclipse.e4.ui.workbench not found.
>
> !ENTRY org.eclipse.osgi 4 0 2012-07-19 11:59:13.382
> !MESSAGE Bundle org.eclipse.e4.ui.model.workbench not found.
>
> !ENTRY org.eclipse.osgi 4 0 2012-07-19 11:59:13.384
> !MESSAGE Bundle org.eclipse.e4.ui.services not found.
>
> !ENTRY org.eclipse.osgi 4 0 2012-07-19 11:59:13.385
> !MESSAGE Bundle org.eclipse.emf.ecore.change not found.
>
> !ENTRY org.eclipse.osgi 4 0 2012-07-19 11:59:13.386
> !MESSAGE Bundle org.eclipse.e4.ui.di not found.
>
> !ENTRY org.eclipse.osgi 4 0 2012-07-19 11:59:13.387
> !MESSAGE Bundle org.eclipse.emf.ecore not found.
>
> !ENTRY org.eclipse.osgi 4 0 2012-07-19 11:59:13.388
> !MESSAGE Bundle com.ibm.icu not found.
>
> !ENTRY org.eclipse.osgi 4 0 2012-07-19 11:59:13.389
> !MESSAGE Bundle org.eclipse.emf.common not found.
>
> !ENTRY org.eclipse.osgi 4 0 2012-07-19 11:59:13.390
> !MESSAGE Bundle org.eclipse.emf.ecore.xmi not found.
Re: E4 contexts and injection decouple. [message #896725 is a reply to message #896681] Thu, 19 July 2012 13:53 Go to previous message
Shumy Mising name is currently offline Shumy Mising nameFriend
Messages: 24
Registered: March 2010
Location: Aveiro, Portugal
Junior Member
yes, my mistake now.
Previous Topic:Where is the Equivalent to applicationclass implementing IApplication
Next Topic:E4 how to layout parts in a perspective
Goto Forum:
  


Current Time: Thu Mar 28 23:00:08 GMT 2024

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

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

Back to the top