2009年7月21日

Show Eclipse Plug-in Icons

// New Plug-in Project with a view Templement
public void createPartControl(Composite parent) {
viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
Table table = viewer.getTable();
AbstractUIPlugin plugin = Activator.getDefault();
ImageRegistry imageRegistry = plugin.getImageRegistry();
Bundle[] bundles = WorkbenchPlugin.getDefault().getBundles();
for (Bundle bundle : bundles) {
Enumeration<URL> entries = bundle.findEntries("icons", "*.gif", true);
if (entries != null) {
while (entries.hasMoreElements()) {
URL element = entries.nextElement();
String path = element.getPath();
String symbolicName = bundle.getSymbolicName();
String key = symbolicName + path;
try {
Image image = imageRegistry.get(key);
if (image == null) {
ImageDescriptor imageDescriptor = AbstractUIPlugin
.imageDescriptorFromPlugin(symbolicName, path);
imageRegistry.put(key, imageDescriptor);
image = imageRegistry.get(key);
}
TableItem ti = new TableItem(table, SWT.NONE);
ti.setImage(imageRegistry.get(key));
ti.setText(key);
} catch (Exception e) {

}
}
}
}
}

沒有留言:

網誌存檔