Skip to content

Commit 96052ec

Browse files
feat: mark disabled product nodes as disabled (#242)
1 parent e28040e commit 96052ec

2 files changed

Lines changed: 31 additions & 6 deletions

File tree

plugin/src/main/java/io/snyk/eclipse/plugin/views/snyktoolview/ContentRootNode.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,10 @@
77

88
import java.nio.file.Path;
99

10-
import org.eclipse.core.resources.IProject;
11-
import org.eclipse.core.resources.IResource;
1210
import org.eclipse.jface.resource.ImageDescriptor;
13-
import org.eclipse.jface.viewers.ILabelProvider;
14-
import org.eclipse.swt.graphics.Image;
15-
import org.eclipse.ui.model.WorkbenchLabelProvider;
1611

1712
import io.snyk.eclipse.plugin.domain.ProductConstants;
13+
import io.snyk.eclipse.plugin.properties.preferences.Preferences;
1814
import io.snyk.eclipse.plugin.utils.ResourceUtils;
1915

2016
public class ContentRootNode extends BaseTreeNode {

plugin/src/main/java/io/snyk/eclipse/plugin/views/snyktoolview/ProductTreeNode.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
import org.eclipse.jface.viewers.TreeNode;
88

99
import io.snyk.eclipse.plugin.domain.ProductConstants;
10+
import io.snyk.eclipse.plugin.properties.preferences.Preferences;
1011
import io.snyk.eclipse.plugin.utils.SnykIcons;
1112

1213
public 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

Comments
 (0)