2015-08-18 20 views
0

我想改變圖像視圖內的圖像。日食偵察圖像變化

我知道getTestImageField().setImageId(Icons.Logo);不起作用,因爲它不會刷新渲染器。

因爲我需要使用setImage(),所以我需要一種方法從Icons類中獲取圖像。

帕特里克建議我嘗試

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(從上面的代碼)始終爲空。

+0

這聽起來像是一件難事。您能否請添加以下信息: 圖標是否適合您? (例如,在表格列上的getConfiguredIconId) 您想要顯示的圖標文件(png)在哪裏? 位於相應的圖標類(java文件)在哪裏? 你在哪個包中檢索圖標? 在調用檢索IconSpec期間,AbstractIconProviderService中的m_hostBundle的值是什麼? – Patrick

+1

是設置圖標正在工作。如果我設置了getConfiguredIconId,它可以工作,如果在代碼集setIconId和更新頁面中,它也可以。圖標是Scout內部的默認圖標,或我添加的圖標(客戶端/資源/圖標/ ...)。 Icons.class位於共享文件夾(根目錄)中。我發佈的包是:org.eclipse.scout.rt.ui.rap.mobile。 –

+0

我嘗試設置不同的包provider.setHostBundle(Activator.getDefault()。getBundle());但它也沒有工作。 –

回答

1

您可以獲取圖像內容(byte[]),您可在圖像字段設置如下:

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

我趕緊檢查,它爲我工作。 請確保圖標可用,並按照此說明設置了圖標提供程序服務Wiki Article

+1

謝謝你的回答,但是當我嘗試這個時,我得到了provider.getIconSpec(Icons.YourIconName)= null;代碼最終IconProviderService provider = SERVICES.getService(IconProviderService.class); final byte [] content = provider.getIconSpec(AbstractIcons.StatusError).getContent();給我一個nullPointer異常 –

+0

我編輯問題(編輯2) –