Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Trying to use eclipse dependency injection of a service from a non-eclipse bundle
Trying to use eclipse dependency injection of a service from a non-eclipse bundle [message #1720764] Wed, 20 January 2016 18:27 Go to next message
Steinar Bang is currently offline Steinar BangFriend
Messages: 108
Registered: July 2009
Senior Member
I am trying to use eclipse dependency injection to get a service from a
non-eclipse OSGi bundle injected into eclipse components.

What I'm wondering, is: is this supposed to work?
What classes in eclipse can accept such injections?

The documentation I've been able to google up hasn't been clear (to me
at least) on this:
http://eclipsesource.com/blogs/tutorials/eclipse-4-e4-tutorial-part-4-dependency-injection-basics/
https://wiki.eclipse.org/Eclipse4/RCP/Dependency_Injection

The second figure in the tutorial seems to indicate that services
registered by OSGi bundles should be possible to inject, but I may have
been trying to inject in the wrong classes? Or the service may not be
in the OSGi context of the editor? (is some special magic required to
accomplish this?)


This is what I've done:
1. Created an OSGi bundle with a bundle activator, that registers
no.priv.bang.modeling.modelstore.Modelstore as an OSGi service
https://github.com/steinarb/modelstore
2. Created a tycho project for a GEF editor plugin, with a target
platform that includes the modelstore bundle from a maven
dependency:
https://github.com/steinarb/modeler/tree/using-modelstore
https://github.com/steinarb/modeler/tree/using-modelstore/modeler.target
(Note! This editor was intented for a different backend, that's why
the links above are to the "using-modelstore" branch)
3. Tried adding @Inject of the Modelstore service in both the Model
(currently just a small mock model)
https://github.com/steinarb/modeler/commit/f2e157093d31e51302de5d1bca96840738da6e02
and tried adding @Inject of the Modelstore into the GEF Editor
https://github.com/steinarb/modeler/commit/7def11350f221470fb7d672dac4f8b6891d24239
but as far as can tell, these are not called (breakpoints in these
methods are not hit, and the println() texts don't show up in the
console)

I have started an "eclipse application" run configuration that starts
the application with the "-console" argument, and when I run the 'lb'
command I see this:
126|Active | 4|modeler Core Plugin (1.0.0.qualifier)
127|Active | 4|modelstore OSGi Bundle (1.0.0.SNAPSHOT)

Ie. both the modeler.core plugin (the eclipse plugin containing the GEF
editor) and the OSGi bundle are present and are started.

I can also list the available service in the modelstore bundle:
osgi> inspect service capability 127
modelstore OSGi Bundle (127) provides services:
-----------------------------------------------
objectClass = no.priv.bang.modeling.modelstore.Modelstore
service.id = 67

But there is no requirement for the service in the modeler.core bundle:
osgi> inspect service requirement 126
modeler Core Plugin (126) requires services:
--------------------------------------------
Nothing

I have added a bundle dependency to the modelstore bundle, to be able to
use types from the modelstore bundle in the injections.

Hope somebody has some idea on what I'm doing wrong?

Thanks!


- Steinar
Re: Trying to use eclipse dependency injection of a service from a non-eclipse bundle [message #1720924 is a reply to message #1720764] Thu, 21 January 2016 20:36 Go to previous messageGo to next message
Steinar Bang is currently offline Steinar BangFriend
Messages: 108
Registered: July 2009
Senior Member
>>>>> Steinar Bang <sb@xxxxxxxx>:

> I am trying to use eclipse dependency injection to get a service from a
> non-eclipse OSGi bundle injected into eclipse components.

> What I'm wondering, is: is this supposed to work?
> What classes in eclipse can accept such injections?

> The documentation I've been able to google up hasn't been clear (to me
> at least) on this:
> http://eclipsesource.com/blogs/tutorials/eclipse-4-e4-tutorial-part-4-dependency-injection-basics/
> https://wiki.eclipse.org/Eclipse4/RCP/Dependency_Injection

> The second figure in the tutorial seems to indicate that services
> registered by OSGi bundles should be possible to inject, but I may have
> been trying to inject in the wrong classes? Or the service may not be
> in the OSGi context of the editor? (is some special magic required to
> accomplish this?)

According to this article https://wiki.eclipse.org/Efxclipse/Runtime/Recipes#Injection_of_OSGi-Services :

"By default the DI container of Eclipse will inject you a service found in the OSGi-Registry but this default comes with a few restrictions who might cause you troubles:
- you can only inject one instance (the one with the highest rank in the OSGi-Service-Registry)
- you won't get a new instance reinjected if a new service instance with a higher ranking is registered on the OSGi-Service-Registry"


Neither of the two restrictions are a problem for me (at least not for
the time being). I just need to inject a "hook" that eclipse can work
with.

But why don't I see any injections of my service, I wonder...?
Re: Trying to use eclipse dependency injection of a service from a non-eclipse bundle [message #1720932 is a reply to message #1720924] Thu, 21 January 2016 21:39 Go to previous messageGo to next message
Steinar Bang is currently offline Steinar BangFriend
Messages: 108
Registered: July 2009
Senior Member
>>>>> Steinar Bang <sb@xxxxxxxx>:

> According to this article https://wiki.eclipse.org/Efxclipse/Runtime/Recipes#Injection_of_OSGi-Services :

> "By default the DI container of Eclipse will inject you a service found in the OSGi-Registry but this default comes with a few restrictions who might cause you troubles:
> - you can only inject one instance (the one with the highest rank in the OSGi-Service-Registry)
> - you won't get a new instance reinjected if a new service instance with a higher ranking is registered on the OSGi-Service-Registry"

> Neither of the two restrictions are a problem for me (at least not for
> the time being). I just need to inject a "hook" that eclipse can work
> with.

> But why don't I see any injections of my service, I wonder...?

My problem could be bundle activation order, perhaps...?

See https://wiki.eclipse.org/Eclipse4/RCP/Dependency_Injection#Current_Caveats :

Although E4AP's DI will inject OSGi services, it does not currently
track changes to the service. This means that if the service is not
available at time of initial injection, but subsequently becomes
available, existing requestors for the the service are not
notified. Nor are receivers notified should the service
disappear. This work is being tracked across several bugs: bug 331235,
bug 330865, bug 317706.

The eclipse plugin modeler.core is bundle number 126, while the bundle
providing the service is 127.

I also found something here:
https://wiki.eclipse.org/Eclipse4/RCP/FAQ#Why_isn.27t_my_.40Inject-able.2F.40PostConstruct_methods_being_injected.3F

When I did what's suggested in the link above, ie. added
Import-Package: javax.annotation; version="1.1.0"
to the MANIFEST.MF of the eclipse plugin, then:
1. the bundle id of the eclipse plugin changed from 126 to 328
2. bundle 127 (the OSGi bundle) is still listed as ACTIVE
3. none of the inject points where called

So no luck yet.
Re: Trying to use eclipse dependency injection of a service from a non-eclipse bundle [message #1720976 is a reply to message #1720932] Fri, 22 January 2016 09:33 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
So the let's start from the beginning. Who is creating an instance of
your object? Is it the eclipse framework? If you register your service
through DS the activation order does not matter as DS runs at start level 2.

Tom

On 21.01.16 22:39, Steinar Bang wrote:
>>>>>> Steinar Bang <sb@xxxxxxxx>:
>
>> According to this article https://wiki.eclipse.org/Efxclipse/Runtime/Recipes#Injection_of_OSGi-Services :
>
>> "By default the DI container of Eclipse will inject you a service found in the OSGi-Registry but this default comes with a few restrictions who might cause you troubles:
>> - you can only inject one instance (the one with the highest rank in the OSGi-Service-Registry)
>> - you won't get a new instance reinjected if a new service instance with a higher ranking is registered on the OSGi-Service-Registry"
>
>> Neither of the two restrictions are a problem for me (at least not for
>> the time being). I just need to inject a "hook" that eclipse can work
>> with.
>
>> But why don't I see any injections of my service, I wonder...?
>
> My problem could be bundle activation order, perhaps...?
>
> See https://wiki.eclipse.org/Eclipse4/RCP/Dependency_Injection#Current_Caveats :
>
> Although E4AP's DI will inject OSGi services, it does not currently
> track changes to the service. This means that if the service is not
> available at time of initial injection, but subsequently becomes
> available, existing requestors for the the service are not
> notified. Nor are receivers notified should the service
> disappear. This work is being tracked across several bugs: bug 331235,
> bug 330865, bug 317706.
>
> The eclipse plugin modeler.core is bundle number 126, while the bundle
> providing the service is 127.
>
> I also found something here:
> https://wiki.eclipse.org/Eclipse4/RCP/FAQ#Why_isn.27t_my_.40Inject-able.2F.40PostConstruct_methods_being_injected.3F
>
> When I did what's suggested in the link above, ie. added
> Import-Package: javax.annotation; version="1.1.0"
> to the MANIFEST.MF of the eclipse plugin, then:
> 1. the bundle id of the eclipse plugin changed from 126 to 328
> 2. bundle 127 (the OSGi bundle) is still listed as ACTIVE
> 3. none of the inject points where called
>
> So no luck yet.
>
Re: Trying to use eclipse dependency injection of a service from a non-eclipse bundle [message #1721035 is a reply to message #1720976] Fri, 22 January 2016 20:53 Go to previous messageGo to next message
Steinar Bang is currently offline Steinar BangFriend
Messages: 108
Registered: July 2009
Senior Member
>>>>> Tom Schindl <tom.schindl@xxxxxxxx>:

> So the let's start from the beginning. Who is creating an instance of
> your object?

The bundle activator of the OSGi bundle creates an instance and
registers it as a service.

> Is it the eclipse framework?

No, bundle activators are pure OSGi, aren't they...?

> If you register your service through DS the activation order does not
> matter as DS runs at start level 2.

Ok, unfortunately I'm not using Eclipse Declarative Services.

Thanks!


- Steinar
Re: Trying to use eclipse dependency injection of a service from a non-eclipse bundle [message #1721039 is a reply to message #1721035] Fri, 22 January 2016 22:25 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
On 22.01.16 21:53, Steinar Bang wrote:
>>>>>> Tom Schindl <tom.schindl@xxxxxxxx>:
>
>> So the let's start from the beginning. Who is creating an instance of
>> your object?
>
> The bundle activator of the OSGi bundle creates an instance and
> registers it as a service.
>

I referred here to the object where you expect the service to be injected!

Tom
Re: Trying to use eclipse dependency injection of a service from a non-eclipse bundle [message #1721055 is a reply to message #1721039] Sat, 23 January 2016 07:35 Go to previous messageGo to next message
Steinar Bang is currently offline Steinar BangFriend
Messages: 108
Registered: July 2009
Senior Member
>>>>> Tom Schindl <tom.schindl@xxxxxxxx>:

> On 22.01.16 21:53, Steinar Bang wrote:
>>>>>>> Tom Schindl <tom.schindl@xxxxxxxx>:

>>> So the let's start from the beginning. Who is creating an instance of
>>> your object?

>> The bundle activator of the OSGi bundle creates an instance and
>> registers it as a service.

> I referred here to the object where you expect the service to be injected!

Ah, right! Sorry!

Here's the source code for the eclipse plugin: https://github.com/steinarb/modeler/tree/using-modelstore/modeler.core

I have tried injecting in three places:
- A GEF Editor
https://github.com/steinarb/modeler/blob/using-modelstore/modeler.core/src/main/java/no/priv/bang/modeler/core/gef/editor/Editor.java
that is opened from a menu entry, by this Action
https://github.com/steinarb/modeler/blob/using-modelstore/modeler.core/src/main/java/no/priv/bang/modeler/core/OpenGefEditorAction.java
- A View, that was initially opened using "Window->Show View->Other..."
and later automatically opened when the run configuration was started
https://github.com/steinarb/modeler/blob/using-modelstore/modeler.core/src/main/java/no/priv/bang/modeler/core/gef/View.java
- The model used by both the GEF editor and the view, and currently
created in the constructor of the View and the Editor
https://github.com/steinarb/modeler/blob/using-modelstore/modeler.core/src/main/java/no/priv/bang/modeler/core/model/Model.java

(The Model class is where I eventually want to put the injected
reference)


Thanks again!


- Steinar
Re: Trying to use eclipse dependency injection of a service from a non-eclipse bundle [message #1721056 is a reply to message #1721055] Sat, 23 January 2016 07:38 Go to previous messageGo to next message
Steinar Bang is currently offline Steinar BangFriend
Messages: 108
Registered: July 2009
Senior Member
>>>>> Steinar Bang <sb@xxxxxxxx>:

> Here's the source code for the eclipse plugin: https://github.com/steinarb/modeler/tree/using-modelstore/modeler.core

> I have tried injecting in three places:
> - A GEF Editor
> https://github.com/steinarb/modeler/blob/using-modelstore/modeler.core/src/main/java/no/priv/bang/modeler/core/gef/editor/Editor.java
> that is opened from a menu entry, by this Action
> https://github.com/steinarb/modeler/blob/using-modelstore/modeler.core/src/main/java/no/priv/bang/modeler/core/OpenGefEditorAction.java
> - A View, that was initially opened using "Window->Show View->Other..."
> and later automatically opened when the run configuration was started
> https://github.com/steinarb/modeler/blob/using-modelstore/modeler.core/src/main/java/no/priv/bang/modeler/core/gef/View.java
> - The model used by both the GEF editor and the view, and currently
> created in the constructor of the View and the Editor
> https://github.com/steinarb/modeler/blob/using-modelstore/modeler.core/src/main/java/no/priv/bang/modeler/core/model/Model.java

> (The Model class is where I eventually want to put the injected
> reference)

(and the Editor, the View and the Action are all registered as eclipse
extensions in the plugin.xml file of the plugin https://github.com/steinarb/modeler/blob/using-modelstore/modeler.core/plugin.xml )
Re: Trying to use eclipse dependency injection of a service from a non-eclipse bundle [message #1721076 is a reply to message #1721055] Sat, 23 January 2016 11:14 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
DI works not if you create the instance yourself by calling new. You
need to instruct the DI-Container to create the instance with
ContextInjectionFactory.make(), use @Createable or a IContextFunction.

What I don't get beside that is that if you create 2 Model-Instance you
are not sharing the state between the Editor and View.

Tom

On 23.01.16 08:35, Steinar Bang wrote:
>>>>>> Tom Schindl <tom.schindl@xxxxxxxx>:
>
>> On 22.01.16 21:53, Steinar Bang wrote:
>>>>>>>> Tom Schindl <tom.schindl@xxxxxxxx>:
>
>>>> So the let's start from the beginning. Who is creating an instance of
>>>> your object?
>
>>> The bundle activator of the OSGi bundle creates an instance and
>>> registers it as a service.
>
>> I referred here to the object where you expect the service to be injected!
>
> Ah, right! Sorry!
>
> Here's the source code for the eclipse plugin: https://github.com/steinarb/modeler/tree/using-modelstore/modeler.core
>
> I have tried injecting in three places:
> - A GEF Editor
> https://github.com/steinarb/modeler/blob/using-modelstore/modeler.core/src/main/java/no/priv/bang/modeler/core/gef/editor/Editor.java
> that is opened from a menu entry, by this Action
> https://github.com/steinarb/modeler/blob/using-modelstore/modeler.core/src/main/java/no/priv/bang/modeler/core/OpenGefEditorAction.java
> - A View, that was initially opened using "Window->Show View->Other..."
> and later automatically opened when the run configuration was started
> https://github.com/steinarb/modeler/blob/using-modelstore/modeler.core/src/main/java/no/priv/bang/modeler/core/gef/View.java
> - The model used by both the GEF editor and the view, and currently
> created in the constructor of the View and the Editor
> https://github.com/steinarb/modeler/blob/using-modelstore/modeler.core/src/main/java/no/priv/bang/modeler/core/model/Model.java
>
> (The Model class is where I eventually want to put the injected
> reference)
>
>
> Thanks again!
>
>
> - Steinar
>
>
Re: Trying to use eclipse dependency injection of a service from a non-eclipse bundle [message #1721122 is a reply to message #1721076] Sun, 24 January 2016 22:21 Go to previous messageGo to next message
Steinar Bang is currently offline Steinar BangFriend
Messages: 108
Registered: July 2009
Senior Member
>>>>> Tom Schindl <tom.schindl@xxxxxxxx>:

> DI works not if you create the instance yourself by calling new.

Ie. the Model itself will never get injection.

The GEF Editor is created with
window.getActivePage().openEditor(new StringEditorInput("Here we can put the connection string for a Neo4J database later"), editorId);

Should that have been good enough?

The view is created completely by the eclipse framework, so I have no
idea how it is created...

> You need to instruct the DI-Container to create the instance with
> ContextInjectionFactory.make(), use @Createable or a IContextFunction.

Hm... the only of my "trial parts" it made sense to do this with, was
the Model, so I made the Model @Creatable and used
ContextInjectionFactory.make() to create the Model in the Editor:
https://github.com/steinarb/modeler/commit/5ba65d9a0cdea4748ab3bbb366515045a8e27917

The creation of the Model object fails, because the creator can't
satisfy the Modelstore injection:
org.eclipse.e4.core.di.InjectionException: Unable to process "Model#setModelstore()": no actual value was found for the argument "Modelstore".
at org.eclipse.e4.core.internal.di.InjectorImpl.reportUnresolvedArgument(InjectorImpl.java:412)
at org.eclipse.e4.core.internal.di.InjectorImpl.resolveRequestorArgs(InjectorImpl.java:403)
at org.eclipse.e4.core.internal.di.InjectorImpl.inject(InjectorImpl.java:108)
at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:333)
at org.eclipse.e4.core.internal.di.InjectorImpl.make(InjectorImpl.java:254)
at org.eclipse.e4.core.contexts.ContextInjectionFactory.make(ContextInjectionFactory.java:162)
at no.priv.bang.modeler.core.gef.editor.Editor.configureGraphicalViewer(Editor.java:45)
at org.eclipse.gef.ui.parts.GraphicalEditor.createGraphicalViewer(GraphicalEditor.java:156)
at org.eclipse.gef.ui.parts.GraphicalEditor.createPartControl(GraphicalEditor.java:171)
at org.eclipse.gef.ui.parts.GraphicalEditorWithFlyoutPalette.createPartControl(GraphicalEditorWithFlyoutPalette.java:75)
at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.createPartControl(CompatibilityPart.java:142)
at org.eclipse.ui.internal.e4.compatibility.CompatibilityEditor.createPartControl(CompatibilityEditor.java:96)
at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.create(CompatibilityPart.java:323)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:56)
at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:877)
at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:857)
at org.eclipse.e4.core.internal.di.InjectorImpl.inject(InjectorImpl.java:119)
at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:333)
at org.eclipse.e4.core.internal.di.InjectorImpl.make(InjectorImpl.java:254)
at org.eclipse.e4.core.contexts.ContextInjectionFactory.make(ContextInjectionFactory.java:162)
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.createFromBundle(ReflectionContributionFactory.java:102)
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.doCreate(ReflectionContributionFactory.java:71)
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.create(ReflectionContributionFactory.java:53)
at org.eclipse.e4.ui.workbench.renderers.swt.ContributedPartRenderer.createWidget(ContributedPartRenderer.java:129)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createWidget(PartRenderingEngine.java:949)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:633)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:735)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.access$2(PartRenderingEngine.java:706)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$7.run(PartRenderingEngine.java:700)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:685)
at org.eclipse.e4.ui.internal.workbench.PartServiceImpl$1.handleEvent(PartServiceImpl.java:90)
at org.eclipse.e4.ui.services.internal.events.UIEventHandler$1.run(UIEventHandler.java:41)
at org.eclipse.swt.widgets.Synchronizer.syncExec(Synchronizer.java:180)
at org.eclipse.ui.internal.UISynchronizer.syncExec(UISynchronizer.java:150)
at org.eclipse.swt.widgets.Display.syncExec(Display.java:4688)
at org.eclipse.e4.ui.internal.workbench.swt.E4Application$1.syncExec(E4Application.java:205)
at org.eclipse.e4.ui.services.internal.events.UIEventHandler.handleEvent(UIEventHandler.java:38)
at org.eclipse.equinox.internal.event.EventHandlerWrapper.handleEvent(EventHandlerWrapper.java:197)
at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:197)
at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:1)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148)
at org.eclipse.equinox.internal.event.EventAdminImpl.dispatchEvent(EventAdminImpl.java:135)
at org.eclipse.equinox.internal.event.EventAdminImpl.sendEvent(EventAdminImpl.java:78)
at org.eclipse.equinox.internal.event.EventComponent.sendEvent(EventComponent.java:39)
at org.eclipse.e4.ui.services.internal.events.EventBroker.send(EventBroker.java:80)
at org.eclipse.e4.ui.internal.workbench.UIEventPublisher.notifyChanged(UIEventPublisher.java:58)
at org.eclipse.emf.common.notify.impl.BasicNotifierImpl.eNotify(BasicNotifierImpl.java:374)
at org.eclipse.e4.ui.model.application.ui.impl.ElementContainerImpl.setSelectedElement(ElementContainerImpl.java:171)
at org.eclipse.e4.ui.internal.workbench.ModelServiceImpl.showElementInWindow(ModelServiceImpl.java:576)
at org.eclipse.e4.ui.internal.workbench.ModelServiceImpl.bringToTop(ModelServiceImpl.java:543)
at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.delegateBringToTop(PartServiceImpl.java:619)
at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.bringToTop(PartServiceImpl.java:331)
at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.showPart(PartServiceImpl.java:1046)
at org.eclipse.ui.internal.WorkbenchPage.busyOpenEditor(WorkbenchPage.java:3112)
at org.eclipse.ui.internal.WorkbenchPage.access$21(WorkbenchPage.java:3034)
at org.eclipse.ui.internal.WorkbenchPage$8.run(WorkbenchPage.java:3016)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:3012)
at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:2976)
at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:2959)
at no.priv.bang.modeler.core.OpenGefEditorAction.run(OpenGefEditorAction.java:19)
at org.eclipse.ui.internal.PluginAction.runWithEvent(PluginAction.java:251)
at org.eclipse.ui.internal.WWinPluginAction.runWithEvent(WWinPluginAction.java:229)
at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:584)
at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:501)
at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:411)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1057)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4170)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3759)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1113)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:997)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:140)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:611)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:567)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:124)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:354)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:181)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:636)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:591)
at org.eclipse.equinox.launcher.Main.run(Main.java:1450)
at org.eclipse.equinox.launcher.Main.main(Main.java:1426)


> What I don't get beside that is that if you create 2 Model-Instance you
> are not sharing the state between the Editor and View.

The current Editor and view are just for experimentations with
dependency injection and not the way things will be in the actual
editor.
Re: Trying to use eclipse dependency injection of a service from a non-eclipse bundle [message #1721125 is a reply to message #1721122] Sun, 24 January 2016 23:41 Go to previous messageGo to next message
Steinar Bang is currently offline Steinar BangFriend
Messages: 108
Registered: July 2009
Senior Member
>>>>> Steinar Bang <sb@xxxxxxxx>:
>>>>> Tom Schindl <tom.schindl@xxxxxxxx>:

>> You need to instruct the DI-Container to create the instance with
>> ContextInjectionFactory.make(), use @Createable or a IContextFunction.

> Hm... the only of my "trial parts" it made sense to do this with, was
> the Model, so I made the Model @Creatable and used
> ContextInjectionFactory.make() to create the Model in the Editor:
> https://github.com/steinarb/modeler/commit/5ba65d9a0cdea4748ab3bbb366515045a8e27917

> The creation of the Model object fails, because the creator can't
> satisfy the Modelstore injection:
> org.eclipse.e4.core.di.InjectionException: Unable to process "Model#setModelstore()": no actual value was found for the argument "Modelstore".
[snip!]

Typed the command 'lb" in the OSGi console and found that the modelstore
bundle was only RESOLVED, and not STARTED:

327|Resolved | 1|modeler Test Fragment (1.0.0.qualifier)
330|Resolved | 4|modelstore OSGi Bundle (1.0.0.SNAPSHOT)
331|Active | 4|modeler Core Plugin (1.0.0.qualifier)

So I gave the command 'start 330' in the OSGi console, and then tried
opening the GEF Editor again, and this time the dependency injection of
the OSGi service worked! :-)

I got the long awaited debug trace:
Opening GEF editor
Configuring the GEF editor
Model: A ModelContext has been injected
Called GraphicalPartFactory.createEditPart(null,no.priv.bang.modeler.core.model.Model@765611c9)
...

Thanks again! :-)


- Steinar
Re: Trying to use eclipse dependency injection of a service from a non-eclipse bundle [message #1721126 is a reply to message #1721122] Sun, 24 January 2016 23:41 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
[...]

> Hm... the only of my "trial parts" it made sense to do this with, was
> the Model, so I made the Model @Creatable and used
> ContextInjectionFactory.make() to create the Model in the Editor:
> https://github.com/steinarb/modeler/commit/5ba65d9a0cdea4748ab3bbb366515045a8e27917

No need to use @Creatable if you use CIF#make(). The exception you get
means that there's no ModelStore found in your OSGi-Service-Registry (at
least not at time you try creating the Model-Instance).

if you query the OSGi-Registry before the call by using the
BundleContext of your plugin, do you find the ModelStore?

Tom
Re: Trying to use eclipse dependency injection of a service from a non-eclipse bundle [message #1721127 is a reply to message #1721126] Sun, 24 January 2016 23:50 Go to previous messageGo to next message
Steinar Bang is currently offline Steinar BangFriend
Messages: 108
Registered: July 2009
Senior Member
>>>>> Tom Schindl <tom.schindl@xxxxxxxx>:

> No need to use @Creatable if you use CIF#make().

Hm... so just marking the Model @Creatable and @Injecting it into the
Editor should work...?

> The exception you get means that there's no ModelStore found in your
> OSGi-Service-Registry (at least not at time you try creating the
> Model-Instance).

> if you query the OSGi-Registry before the call by using the
> BundleContext of your plugin, do you find the ModelStore?

The problem was that the Modelstore bundle was only RESOLVED and not
ACTIVE, possibly because I switched target platform looking for the
IEclipseContext...? (I swithched from the custom target platform to the
Eclipse Mars target platform and back to the custom platform).

(But this means that bundles with bundle activators aren't
auto-activated in an eclipse target platform, and that was
unexcpected. I noticed that Modelstore started out as RESOLVED, but
after my initial start of the bundle it stayed STARTED, so I forgot.
So: bundles aren't autostarted, unless they were started in the previous
invocation of the runtime)
Re: Trying to use eclipse dependency injection of a service from a non-eclipse bundle [message #1721133 is a reply to message #1721127] Mon, 25 January 2016 05:53 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
On 25.01.16 00:50, Steinar Bang wrote:
>>>>>> Tom Schindl <tom.schindl@xxxxxxxx>:
>
>> No need to use @Creatable if you use CIF#make().
>
> Hm... so just marking the Model @Creatable and @Injecting it into the
> Editor should work...?

Yes but your are using the 3.x API and there you can't simply put
@Inject Model model into your code

>
>> The exception you get means that there's no ModelStore found in your
>> OSGi-Service-Registry (at least not at time you try creating the
>> Model-Instance).
>
>> if you query the OSGi-Registry before the call by using the
>> BundleContext of your plugin, do you find the ModelStore?
>
> The problem was that the Modelstore bundle was only RESOLVED and not
> ACTIVE, possibly because I switched target platform looking for the
> IEclipseContext...? (I swithched from the custom target platform to the
> Eclipse Mars target platform and back to the custom platform).
>
> (But this means that bundles with bundle activators aren't
> auto-activated in an eclipse target platform, and that was
> unexcpected. I noticed that Modelstore started out as RESOLVED, but
> after my initial start of the bundle it stayed STARTED, so I forgot.
> So: bundles aren't autostarted, unless they were started in the previous
> invocation of the runtime)
>

this is right if your bundle is marked as lazy. I really would start
using DS then this is a none problem because DS will register the
service in OSGi-Start-Level 2 and your bundles normally start at 4.

Tom
Trying to use GEF4 on e4 (Was: Trying to use eclipse dependency injection of a service from a non-ec [message #1728347 is a reply to message #1721133] Sat, 02 April 2016 20:41 Go to previous message
Steinar Bang is currently offline Steinar BangFriend
Messages: 108
Registered: July 2009
Senior Member
>>>>> Tom Schindl <tom.schindl@xxxxxxxx>:

> Yes but your are using the 3.x API and there you can't simply put
> @Inject Model model into your code

Since I have no actual dependencies on existing eclipse code, I would
love to transition my projects to GEF4 on e4.

However I haven't been able to google up something that give me a
working setup yet.

E.g. this one stops in the target platform definition stage:
http://wiki.eclipse.org/GEF/Adopter_Guide#Define_and_Set_Target_Platform

The target platform file I ended up with says "Unable to locate
installable unit" for everything listed.
Previous Topic:Debbuging Java Stored Procedure ?
Next Topic:Tab Sequence properties is not working properly
Goto Forum:
  


Current Time: Tue Mar 19 09:23:09 GMT 2024

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

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

Back to the top