Marko Zadravec
Marko Zadravec

Reputation: 8740

eclipse scout image change

I am trying to change image inside Image view.

I know that getTestImageField().setImageId(Icons.Logo); would not work, because it would not refresh renderer.

Because I need to use setImage(), I need a way to get Image from Icons class.

As Patrick suggested I try

final IconProviderService provider = SERVICES.getService(IconProviderService.class);
final IconSpec ic = provider.getIconSpec(AbstractIcons.StatusError);
final byte[] content = ic.getContent(); 

but my problem is that ic is always null.

While I debug this I notice that inside IconProviderService.class in line 57 :

@Override
protected URL findResource(String fullPath) {
  URL[] entries = FileLocator.findEntries(m_hostBundle, new Path(fullPath));
  if (entries != null && entries.length > 0) {
    URL url = entries[entries.length - 1];
    if (LOG.isDebugEnabled()) {
      LOG.debug("find image " + fullPath + " in bundle " + m_hostBundle.getSymbolicName() + "->" + url);
    }
    return url;
  }
  return null;
}

URL[] entries is always empty no matter witch icon I try to present.

After further debugging I found out that FileLocator tries to find fragments from bundle, and then look for the path inside this fragments. (line 242)

Bundle[] fragments = activator.getFragments(b); 

but Bundle[] fragments is always null.

Normally my bundle b is (Bundle) EquinoxBundle : org.eclipse.scout.rt.ui.rap.mobile_4.0.100.20140829-1424.

I want to try with different bundle so I do :

final BundleContext context = Activator.getDefault().getBundle().getBundleContext();

for (final Bundle b : context.getBundles()) {

    final IconProviderService provider = SERVICES.getService(IconProviderService.class);
    provider.setHostBundle(b);
    final IconSpec ic = provider.getIconSpec(AbstractIcons.StatusError);
    if (ic != null) {
        final byte[] content = ic.getContent();
        imageField().setImage(content);
    }
}

but fragments (from above code) is always null.

Upvotes: 0

Views: 88

Answers (1)

Patrick
Patrick

Reputation: 4870

You can obtain the image content (byte[]) that you can set on the image field as follows:

IconProviderService provider = SERVICES.getService(IconProviderService.class);
byte[] content = provider.getIconSpec(Icons.YourIconName).getContent();
getImageField().setImage(content);

I quickly checked it and it works for me. Please ensure that the icon is available and you set up the icon provider service as explained in this Wiki Article

Upvotes: 1

Related Questions