66import org .eclipse .core .commands .ExecutionEvent ;
77import org .eclipse .core .commands .ExecutionException ;
88import org .eclipse .jface .resource .ImageDescriptor ;
9- import org .eclipse .swt .widgets .Shell ;
109import org .eclipse .ui .PlatformUI ;
1110import org .eclipse .ui .commands .ICommandService ;
1211import org .eclipse .ui .commands .IElementUpdater ;
1312import org .eclipse .ui .menus .UIElement ;
1413
1514import io .snyk .eclipse .plugin .Activator ;
16- import io .snyk .eclipse .plugin .utils . SnykMessageDialog ;
15+ import io .snyk .eclipse .plugin .properties . preferences . Preferences ;
1716
1817public class EnableCodeProductHandler extends AbstractHandler implements IElementUpdater {
1918
20- protected static ImageDescriptor IMAGE_CODE_ENABLE = Activator .getImageDescriptor ("/icons/code.png" );
21- protected static ImageDescriptor IMAGE_CODE_DISABLE = Activator .getImageDescriptor ("/icons/code_disabled.png " );
19+ protected static ImageDescriptor IMAGE_ENABLE = Activator .getImageDescriptor ("/icons/code.png" );
20+ protected static ImageDescriptor IMAGE_DISABLE = Activator .getImageDescriptor ("/icons/code_disabled.svg " );
2221
2322 @ Override
2423 public Object execute (ExecutionEvent event ) throws ExecutionException {
25-
2624 String commandId = event .getCommand ().getId ();
2725
28- Shell shell = PlatformUI .getWorkbench ().getActiveWorkbenchWindow ().getShell ();
29- SnykMessageDialog .showOkDialog (shell , commandId );
30-
3126 ICommandService commandService = PlatformUI .getWorkbench ().getService (ICommandService .class );
3227 if (commandService != null ) {
3328 commandService .refreshElements (commandId , null );
@@ -38,14 +33,19 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
3833
3934 @ Override
4035 public void updateElement (UIElement element , @ SuppressWarnings ("rawtypes" ) Map map ) {
41- boolean condition = true ;
4236
43- // TODO check the configuration is we should enable or disable the product scan.
44-
45- // if (condition) {
46- // element.setIcon(IMAGE_OSS_ENABLE);
47- // } else {
48- // element.setIcon(IMAGE_OSS_DISABLE);
49- // }
37+ String enableScanPreference = Preferences .getInstance ().getPref (Preferences .ACTIVATE_SNYK_CODE_SECURITY );
38+
39+ //Toggle the value, if it was true, it should be set to false
40+ if (Boolean .parseBoolean (enableScanPreference )) {
41+ element .setIcon (IMAGE_DISABLE );
42+ Preferences .getInstance ().store (Preferences .ACTIVATE_SNYK_CODE_SECURITY , "false" );
43+
44+ } else {
45+
46+ element .setIcon (IMAGE_ENABLE );
47+ Preferences .getInstance ().store (Preferences .ACTIVATE_SNYK_CODE_SECURITY , "true" );
48+
49+ }
5050 }
5151}
0 commit comments