我正在尝试更改图像视图中的图像。
我知道那getTestImageField().setImageId(Icons.Logo);
行不通,因为它不会刷新渲染器。
因为我需要使用setImage()
,所以我需要一种从Icons
类中获取 Image 的方法。
正如帕特里克建议我尝试
final IconProviderService provider = SERVICES.getService(IconProviderService.class);
final IconSpec ic = provider.getIconSpec(AbstractIcons.StatusError);
final byte[] content = ic.getContent();
但我的问题是ic
总是这样null
。
当我调试这个时,我注意到IconProviderService.class
在第 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[]
无论我尝试呈现女巫图标,条目始终为空。
经过进一步调试,我发现它FileLocator
试图从bundle中找到片段,然后在这个片段中寻找路径。( line 242
)
Bundle[] fragments = activator.getFragments(b);
但Bundle[] fragments
始终为空。
通常我的捆绑包b
是(Bundle) EquinoxBundle : org.eclipse.scout.rt.ui.rap.mobile_4.0.100.20140829-1424
.
我想尝试使用不同的捆绑包,所以我这样做:
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);
}
}
但是fragments
(从上面的代码)总是空的。