Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 313072

Summary: Support absolute (workspace-relative) icon paths
Product: [Modeling] TMF Reporter: Ed Willink <ed>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: enhancement    
Priority: P3 CC: sebastian.zarnekow
Version: unspecifiedFlags: sebastian.zarnekow: indigo+
Target Milestone: ---   
Hardware: PC   
OS: Windows Vista   
Whiteboard:

Description Ed Willink CLA 2010-05-17 02:12:40 EDT
DefaultLabelProvider currently supports icon paths relative to icons in the current plugin.

It would be helpful to facilitate use of icons in other plugins by recognising a first character in the icon name as an absolute indicator. Thus the following override could be incorporated in the String case.

	
	@Override
	protected Image convertToImage(Object imageDescription) {
		if (imageDescription instanceof String) {
			String imagePath = (String)imageDescription;
			if (imagePath.startsWith("/")) {	
				int index = imagePath.indexOf('/', 1);
				if (index > 1) {
					String bundlePath = imagePath.substring(1, index);
					Bundle bundle = Platform.getBundle(bundlePath);
					if (bundle != null) {
						String imageFile = imagePath.substring(index+1);
						Path path = new Path(imageFile);
						URL imgUrl = FileLocator.find(bundle, path, null);
						if (imgUrl != null) {
							return super.convertToImage(ImageDescriptor.createFromURL(imgUrl));
						}
					}
				}
			}				
		}
		return super.convertToImage(imageDescription);
	}
Comment 1 Sebastian Zarnekow CLA 2010-12-06 03:46:28 EST
Removed target milestone M3.
Comment 2 Sven Efftinge CLA 2012-11-14 04:04:13 EST
Please bind a custom IImageHelper that does that for you.
Comment 3 Sebastian Zarnekow CLA 2019-11-27 02:58:07 EST
see also bug 404741 which was fixed in 2.14

It allows image paths of the shape 'platform:/plugin/...'