Scout/HowTo/3.9/Add an icon
Scout |
Wiki Home |
Website |
Download • Git |
Community |
Forums • Blog • Twitter • G+ |
Bugzilla |
Bugzilla |
Contents
Add the Icon File to the Project
In the Client Plug-In (e.g. org.eclipse.scout.helloworld.client
) add the icon file to the resources/icons
folder.
Scout supports many different picture formats. You can e.g. use a PNG file that has a size of 16*16 pixels.
Link your File to the Application
Open the Icons class in the Shared Plug-In (e.g.org.eclipse.scout.helloworld.shared.Icons
) and add a new line like this: public static final String UserHome = "home_red";
- The name of the constant is the name that you will use in your application. (e.g. UserHome)
- The value is the name of your file without the extension. (e.g. home_red.png)
Use your icon
When you need to provide an Icon you can now use the Icons class. For example:@Override protected String getConfiguredIconId() { return Icons.UserHome; }
import org.eclipse.scout.helloworld.shared.Icons;
It is also available in the icon chooser field in order to configure quickly your UI.
Sub-icons
Eclipse Scout supports sub-icons for some states. Sub-icons are defined with their suffix:
_open
: for expanded / collapsed node-state (for example for pages in the page tree)._mouse_over
or_rollover
: for hoover effect on buttons (e.g. ToolButton)_active
or_pressed
or_selected
: for pressed-state on buttons (e.g. ToolButton with toggle action)_disabled
: for disabled icons
If no such icons are provided for the given state, the fallback icon without suffix is used instead. For disabled state, the icon is simply greyed out if missing.
Providing an IconProviderService
Normally an internal icon service provider is used to resolve images and icons in your client. However, if you explicitely provide a CustomIconProviderService as described in the how-to Display_images_in_a_table_page, this new service will replace the internal service. This means, that the above mechanism to show icons will no longer work, because the CustomIconProviderService will be used, which will not find those icons.
The solution to this problem is to add another IconProviderService to resovle these icons.
Create a new class ClientIconProviderService in your client plugin:
package org.eclipse.minicrm.client.services; import org.eclipse.minicrm.client.Activator; import org.eclipse.scout.rt.client.services.common.icon.IconProviderService; import org.eclipse.scout.rt.client.services.common.icon.IconSpec; public class ClientIconProviderService extends IconProviderService { public ClientIconProviderService() { setHostBundle(Activator.getDefault().getBundle()); } @Override public int getRanking() { return -20; } @Override public IconSpec getIconSpec(String iconName) { IconSpec result = super.getIconSpec(iconName); return result; } }
In your client's plugin.xml add the following code (the same place where you already added the CustomIconProviderService):
<service factory="org.eclipse.scout.rt.client.services.ClientServiceFactory" class="org.eclipse.minicrm.client.services.ClientIconProviderService" session="org.eclipse.minicrm.client.ClientSession"> </service>
You should now be able to use both the custom icons described above as well as the table icons described in the linked how-to.