Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » e4 Tools Services ResourceProvider(Getting ResourceProvider to work)
e4 Tools Services ResourceProvider [message #1052791] Tue, 30 April 2013 14:35 Go to next message
Joshua Street is currently offline Joshua StreetFriend
Messages: 4
Registered: April 2013
Junior Member
I've been trying for the last two days to get a resource pool to be injected into my part. At first, I was confused as to how to specify the OSGI component but that has been taken care of (at least, I think so).

The problem I have right now is that attempting to use the injected resource pool results in an IllegalArgumentException being thrown because no provider could be found for any of the images I've placed in the resources properties file.

Heres the relevant code:

OSGI-INF/resourceprovider.xml
*Note: the xmlns attribute was removed to meet the forum guides to posting links
<?xml version="1.0" encoding="UTF-8"?>
<scr:component immediate="true" name="com.streetj.erp.ui.resourceprovider">
   <implementation class="com.streetj.erp.ui.ResourceProvider"/>
   <service>
      <provide interface="org.eclipse.e4.tools.services.IResourceProviderService"/>
   </service>
   <properties entry="OSGI-INF/resources.properties"/>
</scr:component>


OSGI-INF/resources.properties
IMG_add=/icons/add.png
IMG_remove=/icons/remove.png
IMG_insert_column=/icons/insert_column.png
IMG_remove_column=/icons/remove_column.png


ResourceProvider.java
package com.streetj.erp.ui;

import org.eclipse.e4.tools.services.BasicResourceProvider;

public class ResourceProvider extends BasicResourceProvider {

    public static final String IMG_ADD = "IMG_add";
    public static final String IMG_REMOVE = "IMG_remove";
    public static final String IMG_INSERT_COLUMN = "IMG_insert_column";
    public static final String IMG_REMOVE_COLUMN = "IMG_remove_column";
}


FooPart.java
public class FooPart {

    @Inject
    IResourcePool resourcePool;
    
    private Button button;
    
    @PostConstruct
    public void createComposite(Composite parent) {
        button = new Button(parent, SWT.PUSH);
        button.setText("foo");
        button.setImage(resourcePool.getImageUnchecked(ResourceProvider.IMG_ADD));
    }
    
    @Focus
    public void setFocus() {
        button.setFocus();
    }
}


Finally, here's the exception being thrown:
org.eclipse.e4.core.di.InjectionException: java.lang.IllegalArgumentException: No provider known for 'IMG_add'.

/* Lines removed */

Caused by: java.lang.IllegalArgumentException: No provider known for 'IMG_add'.
    at org.eclipse.e4.tools.services.impl.ResourceService.lookupResource(ResourceService.java:319)
    at org.eclipse.e4.tools.services.impl.ResourceService.loadResource(ResourceService.java:279)
    at org.eclipse.e4.tools.services.impl.ResourceService.getImage(ResourceService.java:367)
    at org.eclipse.e4.tools.services.impl.ResourceService.getImage(ResourceService.java:1)
    at org.eclipse.e4.tools.services.impl.ResourceService$ResourcePool.getImage(ResourceService.java:115)
    at org.eclipse.e4.tools.services.impl.ResourceService$ResourcePool.getImageUnchecked(ResourceService.java:168)
    at com.streetj.erp.ui.parts.FooPart.createComposite(FooPart.java:26)


I've been searching all over the net/forums, and finally gave in to ask the question to you folks directly. Is there something I'm missing to get this to work?
Re: e4 Tools Services ResourceProvider [message #1052907 is a reply to message #1052791] Wed, 01 May 2013 09:13 Go to previous messageGo to next message
Christophe Bouhier is currently offline Christophe BouhierFriend
Messages: 937
Registered: July 2009
Senior Member
On 30-04-13 17:01, Joshua Street wrote:
> I've been trying for the last two days to get a resource pool to be
> injected into my part.

In this bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=404727
there is a plugin attached, with an example of using a ResourcePool.
Perhaps usefull for you.
Rgds Christophe


At first, I was confused as to how to specify the
> OSGI component but that has been taken care of (at least, I think so).
>
> The problem I have right now is that attempting to use the injected
> resource pool results in an IllegalArgumentException being thrown
> because no provider could be found for any of the images I've placed in
> the resources properties file.
>
> Heres the relevant code:
>
> OSGI-INF/resourceprovider.xml
> *Note: the xmlns attribute was removed to meet the forum guides to
> posting links
> <?xml version="1.0" encoding="UTF-8"?>
> <scr:component immediate="true" name="com.streetj.erp.ui.resourceprovider">
> <implementation class="com.streetj.erp.ui.ResourceProvider"/>
> <service>
> <provide
> interface="org.eclipse.e4.tools.services.IResourceProviderService"/>
> </service>
> <properties entry="OSGI-INF/resources.properties"/>
> </scr:component>
>
> OSGI-INF/resources.properties
> IMG_add=/icons/add.png
> IMG_remove=/icons/remove.png
> IMG_insert_column=/icons/insert_column.png
> IMG_remove_column=/icons/remove_column.png
>
> ResourceProvider.java
> package com.streetj.erp.ui;
>
> import org.eclipse.e4.tools.services.BasicResourceProvider;
>
> public class ResourceProvider extends BasicResourceProvider {
>
> public static final String IMG_ADD = "IMG_add";
> public static final String IMG_REMOVE = "IMG_remove";
> public static final String IMG_INSERT_COLUMN = "IMG_insert_column";
> public static final String IMG_REMOVE_COLUMN = "IMG_remove_column";
> }
>
> FooPart.java
> public class FooPart {
>
> @Inject
> IResourcePool resourcePool;
> private Button button;
> @PostConstruct
> public void createComposite(Composite parent) {
> button = new Button(parent, SWT.PUSH);
> button.setText("foo");
>
> button.setImage(resourcePool.getImageUnchecked(ResourceProvider.IMG_ADD));
> }
> @Focus
> public void setFocus() {
> button.setFocus();
> }
> }
>
> Finally, here's the exception being thrown:
> org.eclipse.e4.core.di.InjectionException:
> java.lang.IllegalArgumentException: No provider known for 'IMG_add'.
>
> /* Lines removed */
>
> Caused by: java.lang.IllegalArgumentException: No provider known for
> 'IMG_add'.
> at
> org.eclipse.e4.tools.services.impl.ResourceService.lookupResource(ResourceService.java:319)
>
> at
> org.eclipse.e4.tools.services.impl.ResourceService.loadResource(ResourceService.java:279)
>
> at
> org.eclipse.e4.tools.services.impl.ResourceService.getImage(ResourceService.java:367)
>
> at
> org.eclipse.e4.tools.services.impl.ResourceService.getImage(ResourceService.java:1)
>
> at
> org.eclipse.e4.tools.services.impl.ResourceService$ResourcePool.getImage(ResourceService.java:115)
>
> at
> org.eclipse.e4.tools.services.impl.ResourceService$ResourcePool.getImageUnchecked(ResourceService.java:168)
>
> at com.streetj.erp.ui.parts.FooPart.createComposite(FooPart.java:26)
>
> I've been searching all over the net/forums, and finally gave in to ask
> the question to you folks directly. Is there something I'm missing to
> get this to work?
Re: e4 Tools Services ResourceProvider [message #1052927 is a reply to message #1052907] Wed, 01 May 2013 13:01 Go to previous messageGo to next message
Joshua Street is currently offline Joshua StreetFriend
Messages: 4
Registered: April 2013
Junior Member
Thanks Christophe, appreciate the response.

I actually followed this and another blog post I found through google initially to create what I've got now.

I even went through an E4 plugin (I think it was the Application Model editor) to try and find some examples.

No such luck in getting it to work however.

I've verified that the injected resource pool is not null (though the exception also confirms that).

I've attempted to trace why the exception is being thrown. It looks like its a result of a method within the services plugin called "lookupOSGI(String key)" returning null.

It's got to be something fundamental that I'm missing.
Re: e4 Tools Services ResourceProvider [message #1053029 is a reply to message #1052927] Thu, 02 May 2013 06:35 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 1405
Registered: July 2012
Senior Member
Could be maybe just a simple configuration issue.

1. Is your plugin that uses the ResourcePool configured to be loaded lazy?
2. Did you ensure in your product configuration that org.eclipse.equinox.ds is started before your plugin?

Greez,
Dirk
Re: e4 Tools Services ResourceProvider [message #1053107 is a reply to message #1053029] Thu, 02 May 2013 13:33 Go to previous messageGo to next message
Joshua Street is currently offline Joshua StreetFriend
Messages: 4
Registered: April 2013
Junior Member
I copied the o.e.e4.tools.services bundle into my workspace to investigate a bit how the plugin works.

From what I can see, it is expected you use a OSGI component that provides a properties file and a ResoureProvider that extends BasicResourceProvider. The lookupOSGI(String key) looks through the bundle context for a class that has the key provided as part of its properties file.

I had my program list off all the services and the keys associated with them and could not find my resource provider.

So is it that my provider somehow not registering?

My plugin is actually the main application. So its configured as a singleton. I am not sure if it is loaded before or after o.e.equinox.ds though.

I was hoping Tom Schindl could weigh in, since its his api.

In the meantime, I'll look into the configuration suggested.
Re: e4 Tools Services ResourceProvider [message #1053147 is a reply to message #1052791] Thu, 02 May 2013 17:04 Go to previous messageGo to next message
Joshua Street is currently offline Joshua StreetFriend
Messages: 4
Registered: April 2013
Junior Member
Dirk,

You nailed it on the head!

I'm newish to RCP in general and forgot how to set something as being lazily loaded. I went back in my plugin and set it to Activate on class use and viola! The resource pool works like a charm!

I've been scratching my head over this all week! Glad to have you guys to help me through this seemingly difficult (but really simple in actuality) issue!
Re: e4 Tools Services ResourceProvider [message #1073996 is a reply to message #1052791] Thu, 25 July 2013 22:53 Go to previous messageGo to next message
Ralf Heydenreich is currently offline Ralf HeydenreichFriend
Messages: 131
Registered: July 2009
Senior Member
Hi,
I've the same error but I can't fix it... I've looked through my configurations but everything seems to be ok. Can you please give me a hint which plugins has to be started / configured in which order?

I've an rcp plugin and a resource plugin (which contains the ResourceProvider). The resources plugin is loaded lazily ("Activate this plugin if one of its classes is loaded").

In my launch configuration I set org.eclipse.equinox.ds to start level 2 and Autostart to true. The resources plugin has Start Level 3 and Autostart set to true.

Do I have to set the same levels in my product configuration?

TIA,
Ralf.
Re: e4 Tools Services ResourceProvider [message #1074007 is a reply to message #1073996] Thu, 25 July 2013 23:26 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 5462
Registered: July 2009
Senior Member
Have you tried querying the the OSGi-Registry when you launch -console?
What services are registered? Is your ResourceProvider part of it?

Tom

On 26.07.13 00:53, Ralf Heydenreich wrote:
> Hi,
> I've the same error but I can't fix it... I've looked through my
> configurations but everything seems to be ok. Can you please give me a
> hint which plugins has to be started / configured in which order?
>
> I've an rcp plugin and a resource plugin (which contains the
> ResourceProvider). The resources plugin is loaded lazily ("Activate this
> plugin if one of its classes is loaded").
> In my launch configuration I set org.eclipse.equinox.ds to start level 2
> and Autostart to true. The resources plugin has Start Level 3 and
> Autostart set to true.
> Do I have to set the same levels in my product configuration?
>
> TIA,
> Ralf.
Re: e4 Tools Services ResourceProvider [message #1074029 is a reply to message #1074007] Fri, 26 July 2013 00:40 Go to previous messageGo to next message
Ralf Heydenreich is currently offline Ralf HeydenreichFriend
Messages: 131
Registered: July 2009
Senior Member
Am 26.07.2013 01:26, schrieb Tom Schindl:
> Have you tried querying the the OSGi-Registry when you launch -console?
> What services are registered? Is your ResourceProvider part of it?
>
> Tom

Hi Tom,
thanks for your fast answer. I've started the application with -console
switch and saw that the resource bundle was active. In debug mode I see
that the resourcePool is injected.

Regards,
Ralf


>
> On 26.07.13 00:53, Ralf Heydenreich wrote:
>> Hi,
>> I've the same error but I can't fix it... I've looked through my
>> configurations but everything seems to be ok. Can you please give me a
>> hint which plugins has to be started / configured in which order?
>>
>> I've an rcp plugin and a resource plugin (which contains the
>> ResourceProvider). The resources plugin is loaded lazily ("Activate this
>> plugin if one of its classes is loaded").
>> In my launch configuration I set org.eclipse.equinox.ds to start level 2
>> and Autostart to true. The resources plugin has Start Level 3 and
>> Autostart set to true.
>> Do I have to set the same levels in my product configuration?
>>
>> TIA,
>> Ralf.
>
Re: e4 Tools Services ResourceProvider [message #1074040 is a reply to message #1074007] Fri, 26 July 2013 01:20 Go to previous messageGo to next message
Ralf Heydenreich is currently offline Ralf HeydenreichFriend
Messages: 131
Registered: July 2009
Senior Member
Am 26.07.2013 01:26, schrieb Tom Schindl:
> Have you tried querying the the OSGi-Registry when you launch -console?
> What services are registered? Is your ResourceProvider part of it?
>
> Tom
>


Problem solved. As stated earlier in this thread the problem often sits
in front of the screen... I forgot to set Service-Component:
OSGI-INF/resourceprovider.xml in META-INF. Sorry.

But now - since I'm using maven for build, I have to address the
resources (i.e. my icons) with prefix "/src/main/resources". That works,
but I don't know if it works outside Eclipse (and it's very ugly). How
can I use the correct path (starting with the /icons resources directory)?

TIA,
Ralf.
Re: e4 Tools Services ResourceProvider [message #1074178 is a reply to message #1074040] Fri, 26 July 2013 08:26 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 5462
Registered: July 2009
Senior Member
Well you are using maven to manage your classpath or are you simply
using maven-tycho for the build?

Have you tried simply setting /icons/Bla.png as a path? I also don't
really get your comment about outside Eclipse because this stuff can
only run inside an OSGi-Container and is of no use outside it.

Tom

On 26.07.13 03:25, Ralf Heydenreich wrote:
> Am 26.07.2013 01:26, schrieb Tom Schindl:
>> Have you tried querying the the OSGi-Registry when you launch -console?
>> What services are registered? Is your ResourceProvider part of it?
>>
>> Tom
>>
>
>
> Problem solved. As stated earlier in this thread the problem often sits
> in front of the screen... I forgot to set Service-Component:
> OSGI-INF/resourceprovider.xml in META-INF. Sorry.
>
> But now - since I'm using maven for build, I have to address the
> resources (i.e. my icons) with prefix "/src/main/resources". That works,
> but I don't know if it works outside Eclipse (and it's very ugly). How
> can I use the correct path (starting with the /icons resources directory)?
>
> TIA,
> Ralf.
>
Re: e4 Tools Services ResourceProvider [message #1074200 is a reply to message #1074178] Fri, 26 July 2013 09:15 Go to previous messageGo to next message
Ralf Heydenreich is currently offline Ralf HeydenreichFriend
Messages: 131
Registered: July 2009
Senior Member
Am 26.07.2013 10:26, schrieb Tom Schindl:
> Well you are using maven to manage your classpath or are you simply
> using maven-tycho for the build?
>
> Have you tried simply setting /icons/Bla.png as a path? I also don't
> really get your comment about outside Eclipse because this stuff can
> only run inside an OSGi-Container and is of no use outside it.


Hi Tom,
I use maven-tcho for the build. If I set /src/main/resources as build
path (via "Configure Build Path...") then it has no impact. Same error
occurs if I try to set /icons/app.png as path inside my plugin:

platform:/plugin/de.my.resources/icons/16/app_16.png

Can I somehow tell Eclipse that /src/main/resources/icons should be
substituted with /icons? The resulting Jar has the right structure.

My comment about running "outside" Eclipse was pointing to use my
product as a standalone application without Eclipse IDE.

Regards,
Ralf.

>
> Tom
>> But now - since I'm using maven for build, I have to address the
>> resources (i.e. my icons) with prefix "/src/main/resources". That works,
>> but I don't know if it works outside Eclipse (and it's very ugly). How
>> can I use the correct path (starting with the /icons resources directory)?
>>
>> TIA,
>> Ralf.
>>
>
Re: e4 Tools Services ResourceProvider [message #1074207 is a reply to message #1074200] Fri, 26 July 2013 09:27 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 5462
Registered: July 2009
Senior Member
Ok - then please put your icons in a folder directly below the
plugin-root, this is the default in OSGi and maven-tycho understands
this layout (only make sure that you added it to your build.properties).

This will also solve your other problem with e4xmi!

Tom

On 26.07.13 11:19, Ralf Heydenreich wrote:
> Am 26.07.2013 10:26, schrieb Tom Schindl:
>> Well you are using maven to manage your classpath or are you simply
>> using maven-tycho for the build?
>>
>> Have you tried simply setting /icons/Bla.png as a path? I also don't
>> really get your comment about outside Eclipse because this stuff can
>> only run inside an OSGi-Container and is of no use outside it.
>
>
> Hi Tom,
> I use maven-tcho for the build. If I set /src/main/resources as build
> path (via "Configure Build Path...") then it has no impact. Same error
> occurs if I try to set /icons/app.png as path inside my plugin:
>
> platform:/plugin/de.my.resources/icons/16/app_16.png
>
> Can I somehow tell Eclipse that /src/main/resources/icons should be
> substituted with /icons? The resulting Jar has the right structure.
>
> My comment about running "outside" Eclipse was pointing to use my
> product as a standalone application without Eclipse IDE.
>
> Regards,
> Ralf.
>
>>
>> Tom
>>> But now - since I'm using maven for build, I have to address the
>>> resources (i.e. my icons) with prefix "/src/main/resources". That works,
>>> but I don't know if it works outside Eclipse (and it's very ugly). How
>>> can I use the correct path (starting with the /icons resources directory)?
>>>
>>> TIA,
>>> Ralf.
>>>
>>
>
Re: e4 Tools Services ResourceProvider [message #1074247 is a reply to message #1074207] Fri, 26 July 2013 11:15 Go to previous messageGo to next message
Ralf Heydenreich is currently offline Ralf HeydenreichFriend
Messages: 131
Registered: July 2009
Senior Member
Am 26.07.2013 11:27, schrieb Tom Schindl:
> Ok - then please put your icons in a folder directly below the
> plugin-root, this is the default in OSGi and maven-tycho understands
> this layout (only make sure that you added it to your build.properties).
>
> This will also solve your other problem with e4xmi!
>
> Tom
>


ok, thanks.

Ralf.
Re: e4 Tools Services ResourceProvider [message #1174767 is a reply to message #1074247] Thu, 07 November 2013 09:52 Go to previous message
Kanchan Thukral is currently offline Kanchan ThukralFriend
Messages: 5
Registered: November 2013
Location: India
Junior Member
I have tried the same sample for the resource pool as mentioned in the forum and it is working fine.

What I'm missing from Image Registry to Resource pool is:
I can add the image details and remove the image details from Image Registry but in the resource pool i'm not getting any option to add and remove image details from the image Registry.

Or I'm asking a wrong question?
Can anybody tell me about this?
Previous Topic:PartSashContainer inside Part
Next Topic:How to use same model fragment in different e4 applications
Goto Forum:
  


Current Time: Fri Nov 21 10:40:00 GMT 2014

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

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