Use SVG icons in EMF
The EMF code generated for metamodels only supports bitmap formats by default. Modern, web-based applications usually need scalable SVG icons, which requires a few tweaks.
-
Override the default
doGetImagein the mainEditPluginclass (the one extendingEMFPlugin) so it knows the.svgextension:@Override protected Object doGetImage(String key) throws IOException { URL url = new URL(this.getBaseURL() + "icons/" + key + extensionFor(key)); try (InputStream inputStream = url.openStream()) { // Just ensure we can open/close the resource } return url; } protected static String extensionFor(String key) { String result = ".gif"; int index = key.lastIndexOf('.'); if (index != -1) { String extension = key.substring(index + 1); if ("png".equalsIgnoreCase(extension) || "gif".equalsIgnoreCase(extension) || "bmp".equalsIgnoreCase(extension) || "ico".equalsIgnoreCase(extension) || "jpg".equalsIgnoreCase(extension) || "jpeg".equalsIgnoreCase(extension) || "tif".equalsIgnoreCase(extension) || "tiff".equalsIgnoreCase(extension) || "svg".equalsIgnoreCase(extension)) { result = ""; } } return result; } -
Place the SVG icon(s) under
icons/full/obj16in the generated.editplug-in/project. -
For each type with an SVG icon, customize the
ItemProvider#getImagemethod to reference the file (including the extension) and mark it as@generated NOT:/** @generated NOT */ @Override public Object getImage(Object object) { return this.overlayImage(object, this.getResourceLocator().getImage("full/obj16/SliderDescription.svg")); }