Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » HowTo reference images/icons in e4
HowTo reference images/icons in e4 [message #647142] Tue, 04 January 2011 13:11 Go to next message
St Clair Clarke is currently offline St Clair Clarke
Messages: 118
Registered: March 2010
Senior Member
Hello,

I am seeking help as to reference icons/images in my e4 project.

Here are my scenarios:
1. The image is in the same package as the xwt file
In this case my xwt code would be:
<Button text="Icon in the same package as xwt file" image="demo.gif"/>


2. Image is in a different package from the xwt file:
In this case I have attempted to use the URI:
 image="platform:/plugin/plugin-name/package-containing-icon/iconname.gif"

This does not work

I am just thinking that using this would means the plugin would have to be executed. B
ut suppose I am creating a small stand-alone XWT application - no plugin would be involved here and this URI does not work

3. Image is in icons directory on the root of the plugin
This is where I would like to keep my images/icons, but I do not know how to reference this folder.

I would appreciate any pointers I can get.

Thanks
Re: HowTo reference images/icons in e4 [message #647780 is a reply to message #647142] Sat, 08 January 2011 17:04 Go to previous messageGo to next message
Yves YANG is currently offline Yves YANG
Messages: 687
Registered: July 2009
Senior Member
"St Clair Clarke" <st_clair@flowja.com> wrote in message
news:ifvnid$5dp$1@news.eclipse.org...
> Hello,
> I am seeking help as to reference icons/images in my e4 project.
>
> Here are my scenarios:
> 1. The image is in the same package as the xwt file
> In this case my xwt code would be:
> <Button text="Icon in the same package as xwt file" image="demo.gif"/>
>
> 2. Image is in a different package from the xwt file:
> In this case I have attempted to use the URI:
>
> image=" platform:/plugin/plugin-name/package-containing-icon/iconnam e.gif "
> This does not work
>
> I am just thinking that using this would means the plugin would have to
> be executed. B
> ut suppose I am creating a small stand-alone XWT application - no plugin
> would be involved here and this URI does not work
>
> 3. Image is in icons directory on the root of the plugin
> This is where I would like to keep my images/icons, but I do not know
> how to reference this folder.
>
> I would appreciate any pointers I can get.

It is good point. By now, XWT is independ of the Eclipse Platform. So the
URI is not supported. You can use only Java resources.

As for the Eclipse platform or OSGi bundle support, please fill a bug.

Best regards
Yves YANG
>
> Thanks
>
Re: HowTo reference images/icons in e4 [message #647782 is a reply to message #647780] Sat, 08 January 2011 18:01 Go to previous messageGo to next message
Erdal Karaca is currently offline Erdal Karaca
Messages: 701
Registered: July 2009
Senior Member
I was able to achieve a "flexible solution" by implementing a String to Image converter, see:

org.eclipse.e4.xwt.XWT.registerConvertor(IConverter)

Example:

XWT.registerConvertor(new IConverter() {
public Object getFromType() {
return String.class;
}

public Object getToType() {
return Image.class;
}

public Object convert(Object fromObject) {
String path = (String) fromObject;
return ImageDescriptor.createFromURL(new URL(path)).createImage();
}
});

Of course, you must not forget to dispose the created image...
Re: HowTo reference images/icons in e4 [message #647783 is a reply to message #647782] Sat, 08 January 2011 18:03 Go to previous messageGo to next message
Erdal Karaca is currently offline Erdal Karaca
Messages: 701
Registered: July 2009
Senior Member
Note: that solution works because the default cconverters fail to create an image...
Re: HowTo reference images/icons in e4 [message #647797 is a reply to message #647782] Sun, 09 January 2011 06:22 Go to previous messageGo to next message
Erdal Karaca is currently offline Erdal Karaca
Messages: 701
Registered: July 2009
Senior Member
If you want the converter to be only available when osgi is running, you could use a declarative services component (component.xml, see PDE's "new component" wizard)...

Note: in e4 the declarative services plugin has to be running anyways.
Re: HowTo reference images/icons in e4 [message #648041 is a reply to message #647782] Mon, 10 January 2011 17:37 Go to previous messageGo to next message
Yves YANG is currently offline Yves YANG
Messages: 687
Registered: July 2009
Senior Member
Splendid! I forget this one.

yves
"Erdal Karaca" <erdal.karaca.de@googlemail.com> wrote in message
news:igaq2k$qmh$1@news.eclipse.org...
> I was able to achieve a "flexible solution" by implementing a String to
> Image converter, see:
>
> org.eclipse.e4.xwt.XWT.registerConvertor(IConverter)
>
> Example:
>
> XWT.registerConvertor(new IConverter() {
> public Object getFromType() {
> return String.class;
> }
>
> public Object getToType() {
> return Image.class;
> }
>
> public Object convert(Object fromObject) {
> String path = (String) fromObject;
> return ImageDescriptor.createFromURL(new URL(path)).createImage();
> }
> });
>
> Of course, you must not forget to dispose the created image...
>
Re: HowTo reference images/icons in e4 [message #648189 is a reply to message #648041] Tue, 11 January 2011 12:04 Go to previous messageGo to next message
St Clair Clarke is currently offline St Clair Clarke
Messages: 118
Registered: March 2010
Senior Member
Hello Yves,

It would be intersting to know how topics are chosen for answering.

Could you/someone review these two topics for me:
1.http:// www.eclipse.org/forums/index.php?t=msg&th=202351&sta rt=0&S=be0aec32fefccce6118e0cb39f9f806c

2. http:// www.eclipse.org/forums/index.php?t=msg&th=202409&sta rt=0&S=be0aec32fefccce6118e0cb39f9f806c

Thank you very much. The Trigger seems to have a problem cycling.

Thaks
Re: HowTo reference images/icons in e4 [message #648226 is a reply to message #648189] Tue, 11 January 2011 16:32 Go to previous message
Erdal Karaca is currently offline Erdal Karaca
Messages: 701
Registered: July 2009
Senior Member
I am sure that if someone knows the answer to your other questions, they will be answered. Though, I am not sure whether insisting on this is the right way...
Previous Topic:e4 still broken on Ubuntu Linux
Next Topic:Remote javascript debugger
Goto Forum:
  


Current Time: Mon Apr 21 08:52:26 EDT 2014

Powered by FUDForum. Page generated in 0.01803 seconds