Along with the options described above, you can also use any graphic you
want from the local image storage location of another plug-in, or store it in your
own plug-in. In these cases the plug-in is itself an image provider. This
procedure may be useful if you need additional icons for your application,
which are not available in the standard Eclipse or SAP icon sets. You may also
want to display larger graphics in a UI area of your plug-in (for example, on a
canvas). To implement this local access, simply call the getImageFromIconsDirectory() method from the
utility class SapIdeUtilImages.
|
public static Image getImageFromIconsDirectory(String pluginId, String filePath) |
|
|
|
If you specify a plug-in ID and the name of
the graphic file you want, this method returns an SWT image. However, this only works if the graphic file
is stored in the icons folder of
the addressed plug-in (that is, the image provider). |
Procedure
1. Import the graphics into the icons
folder or a subfolder
The icons
plug-in folder is used as a local storage location for icons.
After you have created your graphics (either
graphic files or icons) as .gif files, import them into the icons folder, or in a suborder that you
have created for the purpose, such as icons/xyz.
![]()
If you use your icons to represent actions in toolbars or similar, note
that you should save them as 16 x 16
pixel files in the .gif format.
You should also make sure that your design is consistent.
2. Get the image instance
If you have stored your graphics in the icons plug-in folder, you need only specify the plug-in ID and the
name of the file you want as parameters when you call the getImageFromIconsDirectory() method.
|
Image myImage =
SapIdeUtilImages.getImageFromIconsDirectory("plugin
ID","my_icon.gif")); |
If on the other hand, your graphic files are stored in a subfolder –
such as icons/xyz – the parameter is
made up of a combination of this sub-folder and the file name (where the file
name is separated from the subfolder name using a forward slash (/).
|
Image myImage =
SapIdeUtilImages.getImageFromIconsDirectory("plugin
ID","xyz/my_icon.gif"); |
We will now show you how to use any plug-in you want as an image provider,
using icons form the Java Development Tooling plug-in (JDT), which are a part
of the JDT Image Registry.
Prerequisites
Note that, in general, you can only access
graphic resources if the relevant plug-in providing the image is also loaded at
the runtime of the user plug-in. This is why you must enter the provider
plug-in as a Required Plug-In in the
plugin.xml file.
Procedure
1. Add dependencies
Add the image provider plug-in ( org.eclipse.jdt.ui in our example) to the plugin.xml file as a Required plug-in. Then verify this
project dependency by calling the Update
Classpath … function in the Packages
view. Finally you need only import the plug-in class (JavaPlugin in our example).
2. Identify the graphics you want to use
All plug-in-specific graphic files are stored
in the icons plug-in folder.
3. Get the image instance
Simply call the method getImageFromIconsDirectory(), as you would when accessing local
graphic resources in your own plug-in.
Example
The following lines of code display three icons from the JDT plug-in as
elements in a toolbar.
![]()
|
myToolbar.addToolBarButton(SapIdeUtilImages.getImageFromIconsDirectory( "org.eclipse.jdt.ui" ,"full/ctool16/java_app.gif")); myToolbar.addToolBarButton(SapIdeUtilImages.getImageFromIconsDirectory( "org.eclipse.jdt.ui", "full/ctool16/newsbook_wiz.gif")); myToolbar.addToolBarButton(SapIdeUtilImages.getImageFromIconsDirectory( "org.eclipse.jdt.ui", "full/ctool16/run_sbook.gif")); |