|
2 | 2 |
|
3 | 3 | import org.eclipse.core.runtime.Platform; |
4 | 4 | import org.eclipse.jface.resource.ImageDescriptor; |
| 5 | +import org.eclipse.jface.resource.ImageRegistry; |
| 6 | +import org.eclipse.swt.widgets.Display; |
5 | 7 | import org.eclipse.ui.plugin.AbstractUIPlugin; |
6 | 8 | import org.osgi.framework.BundleContext; |
7 | 9 |
|
| 10 | +import io.snyk.eclipse.plugin.preferences.Preferences; |
| 11 | +import io.snyk.eclipse.plugin.utils.SnykIcons; |
| 12 | + |
8 | 13 | /** |
9 | 14 | * The activator class controls the plug-in life cycle |
10 | 15 | */ |
11 | 16 | public class Activator extends AbstractUIPlugin { |
12 | | - // The plug-in ID |
13 | | - public static final String PLUGIN_ID = "io.snyk.eclipse.plugin"; //$NON-NLS-1$ |
14 | | - public static final String PLUGIN_VERSION = Platform.getBundle(Activator.PLUGIN_ID).getVersion().toString(); |
15 | | - public static final String INTEGRATION_NAME = "ECLIPSE"; |
16 | | - |
17 | | - // The shared instance |
18 | | - private static Activator plugin; |
19 | | - |
20 | | - @Override |
21 | | - public void start(BundleContext context) throws Exception { |
22 | | - super.start(context); |
23 | | - plugin = this; |
24 | | - } |
25 | | - |
26 | | - @Override |
27 | | - public void stop(BundleContext context) throws Exception { |
28 | | - plugin = null; |
29 | | - super.stop(context); |
30 | | - } |
31 | | - |
32 | | - /** |
33 | | - * Returns the shared instance |
34 | | - * |
35 | | - * @return the shared instance |
36 | | - */ |
37 | | - public static Activator getDefault() { |
38 | | - return plugin; |
39 | | - } |
40 | | - |
41 | | - /** |
42 | | - * Returns an image descriptor for the image file at the given plug-in relative |
43 | | - * path |
44 | | - * |
45 | | - * @param path the path |
46 | | - * @return the image descriptor |
47 | | - */ |
48 | | - public static ImageDescriptor getImageDescriptor(String path) { |
49 | | - return imageDescriptorFromPlugin(PLUGIN_ID, path); |
50 | | - } |
| 17 | + private static final String ICONS_TRANSPARENT_PNG = "/icons/transparent.png"; |
| 18 | + private static final String ICONS_ENABLED_PNG = "/icons/enabled.png"; |
| 19 | + private static final String ICONS_SEVERITY_LOW_PNG = "/icons/severity_low.png"; |
| 20 | + private static final String ICONS_SEVERITY_MEDIUM_PNG = "/icons/severity_medium.png"; |
| 21 | + private static final String ICONS_SEVERITY_HIGH_PNG = "/icons/severity_high.png"; |
| 22 | + private static final String ICONS_SEVERITY_CRITICAL_PNG = "/icons/severity_critical.png"; |
| 23 | + private static final String ICONS_IAC_DISABLED_PNG = "/icons/iac_disabled.png"; |
| 24 | + private static final String ICONS_IAC_PNG = "/icons/iac.png"; |
| 25 | + private static final String ICONS_OSS_DISABLED_PNG = "/icons/oss_disabled.png"; |
| 26 | + private static final String ICONS_OSS_PNG = "/icons/oss.png"; |
| 27 | + private static final String ICONS_CODE_DISABLED_PNG = "/icons/code_disabled.png"; |
| 28 | + private static final String ICONS_CODE_PNG = "/icons/code.png"; |
| 29 | + // The plug-in ID |
| 30 | + public static final String PLUGIN_ID = "io.snyk.eclipse.plugin"; //$NON-NLS-1$ |
| 31 | + public static final String PLUGIN_VERSION = Platform.getBundle(Activator.PLUGIN_ID).getVersion().toString(); |
| 32 | + public static final String INTEGRATION_NAME = "ECLIPSE"; |
| 33 | + |
| 34 | + // The shared instance |
| 35 | + private static Activator plugin; |
| 36 | + |
| 37 | + @Override |
| 38 | + public void start(BundleContext context) throws Exception { |
| 39 | + super.start(context); |
| 40 | + plugin = this; |
| 41 | + } |
| 42 | + |
| 43 | + @Override |
| 44 | + public void stop(BundleContext context) throws Exception { |
| 45 | + super.stop(context); |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * Returns the shared instance |
| 50 | + * |
| 51 | + * @return the shared instance |
| 52 | + */ |
| 53 | + public static Activator getDefault() { |
| 54 | + return plugin; |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * Returns an image descriptor for the image file at the given plug-in relative |
| 59 | + * path |
| 60 | + * |
| 61 | + * @param path the path |
| 62 | + * @return the image descriptor |
| 63 | + */ |
| 64 | + public ImageDescriptor getImageDescriptor(String key) { |
| 65 | + if (Preferences.getInstance().isTest()) return null; |
| 66 | + // Use syncExec to invoke code on the SWT thread and wait for it to finish |
| 67 | + return Display.getDefault().syncCall(() -> { |
| 68 | + var imageDescriptor = getImageRegistry().getDescriptor(key); |
| 69 | + if (imageDescriptor == null) { |
| 70 | + imageDescriptor = ImageDescriptor.getMissingImageDescriptor(); |
| 71 | + } |
| 72 | + return imageDescriptor; |
| 73 | + }); |
| 74 | + } |
| 75 | + |
| 76 | + @Override |
| 77 | + protected void initializeImageRegistry(ImageRegistry registry) { |
| 78 | + addImageDescriptorToRegistry(registry, SnykIcons.CODE_ID, ICONS_CODE_PNG); |
| 79 | + addImageDescriptorToRegistry(registry, SnykIcons.CODE_DISABLED_ID, ICONS_CODE_DISABLED_PNG); |
| 80 | + addImageDescriptorToRegistry(registry, SnykIcons.OSS_ID, ICONS_OSS_PNG); |
| 81 | + addImageDescriptorToRegistry(registry, SnykIcons.OSS_DISABLED_ID, ICONS_OSS_DISABLED_PNG); |
| 82 | + addImageDescriptorToRegistry(registry, SnykIcons.IAC_ID, ICONS_IAC_PNG); |
| 83 | + addImageDescriptorToRegistry(registry, SnykIcons.IAC_DISABLED_ID, ICONS_IAC_DISABLED_PNG); |
| 84 | + addImageDescriptorToRegistry(registry, SnykIcons.SEVERITY_CRITICAL_ID, ICONS_SEVERITY_CRITICAL_PNG); |
| 85 | + addImageDescriptorToRegistry(registry, SnykIcons.SEVERITY_HIGH_ID, ICONS_SEVERITY_HIGH_PNG); |
| 86 | + addImageDescriptorToRegistry(registry, SnykIcons.SEVERITY_MEDIUM_ID, ICONS_SEVERITY_MEDIUM_PNG); |
| 87 | + addImageDescriptorToRegistry(registry, SnykIcons.SEVERITY_LOW_ID, ICONS_SEVERITY_LOW_PNG); |
| 88 | + addImageDescriptorToRegistry(registry, SnykIcons.ENABLED_ID, ICONS_ENABLED_PNG); |
| 89 | + addImageDescriptorToRegistry(registry, SnykIcons.DISABLED_ID, ICONS_TRANSPARENT_PNG); |
| 90 | + } |
| 91 | + |
| 92 | + private void addImageDescriptorToRegistry(ImageRegistry registry, String key, String path) { |
| 93 | + ImageDescriptor descriptor = imageDescriptorFromPlugin(PLUGIN_ID, path); |
| 94 | + registry.put(key, descriptor); |
| 95 | + } |
51 | 96 | } |
0 commit comments