77import org .eclipse .jface .viewers .TreeNode ;
88
99import io .snyk .eclipse .plugin .domain .ProductConstants ;
10+ import io .snyk .eclipse .plugin .properties .preferences .Preferences ;
1011import io .snyk .eclipse .plugin .utils .SnykIcons ;
1112
1213public class ProductTreeNode extends BaseTreeNode {
1314
1415 private String product ;
1516 private String errorMessage ;
17+ private String prefEnablementKey ;
1618
1719 public ProductTreeNode (String value ) {
1820 super (value );
@@ -21,17 +23,40 @@ public ProductTreeNode(String value) {
2123 switch (value ) {
2224 case ProductConstants .DISPLAYED_OSS :
2325 setImageDescriptor (SnykIcons .OSS );
26+ prefEnablementKey = Preferences .ACTIVATE_SNYK_OPEN_SOURCE ;
2427 break ;
2528 case ProductConstants .DISPLAYED_IAC :
2629 setImageDescriptor (SnykIcons .IAC );
30+ prefEnablementKey = Preferences .ACTIVATE_SNYK_IAC ;
2731 break ;
2832 case ProductConstants .DISPLAYED_CODE_QUALITY :
2933 setImageDescriptor (SnykIcons .CODE );
34+ prefEnablementKey = Preferences .ACTIVATE_SNYK_CODE_QUALITY ;
3035 break ;
3136 case ProductConstants .DISPLAYED_CODE_SECURITY :
3237 setImageDescriptor (SnykIcons .CODE );
38+ prefEnablementKey = Preferences .ACTIVATE_SNYK_CODE_SECURITY ;
3339 break ;
3440 }
41+
42+
43+ }
44+
45+
46+
47+ @ Override
48+ public String getText () {
49+ if (!isEnabled ()) {
50+ return super .getText () + " (disabled)" ;
51+ }
52+ return super .getText ();
53+ }
54+
55+
56+
57+ private boolean isEnabled () {
58+ Preferences pref = Preferences .getInstance ();
59+ return pref .getBooleanPref (this .prefEnablementKey );
3560 }
3661
3762 @ Override
@@ -56,11 +81,14 @@ public void removeInfoNodes() {
5681
5782 setChildren (newList .toArray (new BaseTreeNode [0 ]));
5883 }
59-
84+
6085 @ Override
6186 public void setValue (Object value ) {
6287 if (!(value instanceof String ))
6388 throw new IllegalArgumentException ("value of product node must be a string" );
89+ if (!isEnabled ()) {
90+ value = "(disabled)" ;
91+ }
6492 var cleanedValue = removePrefix (value .toString ());
6593
6694 // we don't want to override the product text
@@ -75,6 +103,7 @@ public void setValue(Object value) {
75103
76104 @ Override
77105 public void addChild (BaseTreeNode child ) {
106+ if (!isEnabled ()) return ;
78107 if (child instanceof FileTreeNode ) {
79108 var ftNode = (FileTreeNode ) child ;
80109 var crNode = (ContentRootNode ) this .getParent ();
0 commit comments