IV. SAP standard icons

SAP already offers a wide range of standard icons. To use these graphic resources in the UI for your plug-in, simply call the method getSapImage():

 

Public static Image getSapImage(SapImage sapImage)

 

 

This method returns an image instance of a standard SAP icon. Every standard SAP icon has an associated constant stored either in the SapImage class or in an image class you have defined yourself. You can then obtain the icon you want from this resource pool using the constant. The getSapImage method first access an image registry and creates a new instance of the image if there is none available in this registry.

If the access to the physical resource fails, a default image is returned. It is displayed as a red rectangle in the UI.

 

 

When you use SAP standard graphics, you have two options: You can either access the image constants already defined in SapImage (the default situation), or you create your own image class and define its associated image constants yourself. This new image class can either implement the ISapImage interface directly or be derived from the SapImage class. This separate image class can then provide a single definition for several images in a (relatively large) project.

 

Option A: Using Predefined Constants for Images

 

Procedure

 

1. Identify appropriate icons

Note, that icons belong to the standard set only if there is a constant stored for them in SapImage class.

 

If you want to use icons that do not belong to the SAP standard, you can import them into the icons folder of your plug-in and then treat them like plug-in-specific icons.

If, however, you want to reuse some icons frequently (as well as in other plug-ins), you can then request that the relevant icons are copied to the SAP standard, by contacting the Java IDE Core Group.

 

2. Create image instances

To create an image object, simply call the getSapImage() method from the UI Toolkit class SapIdeUtilImages. Identify the resource you want by specifying the appropriate SAP image constant as a parameter.

 

 

Image myImage = SapIdeUtilImages.getSapImage(SapImage.<IMAGE_CONSTANT>);

 

 

Example

 

The following lines of code display two SAP standard icons as elements in a toolbar. The result looks like this:

 

 

 

myToolbar.addToolBarButton(

         SapIdeUtilImages.getSapImage(SapImage.ICON_REFERENCE_LIST));

 

myToolbar.addToolBarButton(

         SapIdeUtilImages.getSapImage(SapImage.ICON_FILTER));

 

 

 

Option B: Defining Your Own Image Class

 

 

Procedure

 

1. Identify appropriate icons

 

Choose the appropriate icons from the SAP standard set and store them in the plug-in provided. You can later access these icons by specifying the plug-in ID and file folder.

 

2. Define a new image class

Create a separate image class, which either extends the class SapImage or implements the ISapImage interface directly. In the case, if you extend SapImage, you are able to use suitable protected constructors from SapImage to create the images. You need only to pass the identifying parameters for the plugin ID, the file directory and the file name.

 

 

protected static class MyImageClass extends SapImage {

   public MyImageClass(String fileName) {

     super("pluginID", "fileDirectory", fileName, "shortText")

   }

}

 

 

3. Define the image Constants

Call the constructor of the new image class and define the constants with the type ISapImage.

 

 

public static final ISapImage IMAGE_CONSTANT = new MyImageClass("fileName");

 

 

4. Retrieve the image instance

In order to display the image in the UI, call simply the getSapImage() method from the UI Toolkit class SapIdeUtilImages and pass the corresponding image constant as parameter.

 

 

Image myImage = SapIdeUtilImages.getSapImage(<IMAGE_CONSTANT>);

 

 

 

Example

The following lines of code display SAP standard icons that defined in a separate image class MyImageClass. In the UI they are displayed as elements in a toolbar.

 

 

 

public class MySampleView extends ViewPart {

 

  // ...

 

  public void createPartControl(Composite parent) {

 

    // Additional code

 

    public static final ISapImage RED_LIGHT     = new MyImageClass("red.gif");

    public static final ISapImage GREEN_LIGHT   = new MyImageClass("green.gif");

    public static final ISapImage YELLOW_LIGHT  = new MyImageClass("yellow.gif");

 

    myToolbar.addToolBarButton(SapIdeUtilImages.getSapImage(RED_LIGHT));

    myToolbar.addToolBarButton(SapIdeUtilImages.getSapImage(YELLOW_LIGHT));

    myToolbar.addToolBarButton(SapIdeUtilImages.getSapImage(GREEN_LIGHT));

 

    // Additional code

  }

  protected static class MyImageClass extends SapImage {

    public MyImageClass(String fileName) {

       super("com.tssap.util.examples", "icons/lights/", fileName, "");

    }

  }

}