Skip to content

feat: mark disabled product nodes as disabled #242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -7,14 +7,10 @@

import java.nio.file.Path;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.model.WorkbenchLabelProvider;

import io.snyk.eclipse.plugin.domain.ProductConstants;
import io.snyk.eclipse.plugin.properties.preferences.Preferences;
import io.snyk.eclipse.plugin.utils.ResourceUtils;

public class ContentRootNode extends BaseTreeNode {
Original file line number Diff line number Diff line change
@@ -7,12 +7,14 @@
import org.eclipse.jface.viewers.TreeNode;

import io.snyk.eclipse.plugin.domain.ProductConstants;
import io.snyk.eclipse.plugin.properties.preferences.Preferences;
import io.snyk.eclipse.plugin.utils.SnykIcons;

public class ProductTreeNode extends BaseTreeNode {

private String product;
private String errorMessage;
private String prefEnablementKey;

public ProductTreeNode(String value) {
super(value);
@@ -21,17 +23,40 @@ public ProductTreeNode(String value) {
switch (value) {
case ProductConstants.DISPLAYED_OSS:
setImageDescriptor(SnykIcons.OSS);
prefEnablementKey = Preferences.ACTIVATE_SNYK_OPEN_SOURCE;
break;
case ProductConstants.DISPLAYED_IAC:
setImageDescriptor(SnykIcons.IAC);
prefEnablementKey = Preferences.ACTIVATE_SNYK_IAC;
break;
case ProductConstants.DISPLAYED_CODE_QUALITY:
setImageDescriptor(SnykIcons.CODE);
prefEnablementKey = Preferences.ACTIVATE_SNYK_CODE_QUALITY;
break;
case ProductConstants.DISPLAYED_CODE_SECURITY:
setImageDescriptor(SnykIcons.CODE);
prefEnablementKey = Preferences.ACTIVATE_SNYK_CODE_SECURITY;
break;
}


}



@Override
public String getText() {
if (!isEnabled()) {
return super.getText() + " (disabled)";
}
return super.getText();
}



private boolean isEnabled() {
Preferences pref = Preferences.getInstance();
return pref.getBooleanPref(this.prefEnablementKey);
}

@Override
@@ -56,11 +81,14 @@ public void removeInfoNodes() {

setChildren(newList.toArray(new BaseTreeNode[0]));
}

@Override
public void setValue(Object value) {
if (!(value instanceof String))
throw new IllegalArgumentException("value of product node must be a string");
if (!isEnabled()) {
value = "(disabled)";
}
var cleanedValue = removePrefix(value.toString());

// we don't want to override the product text
@@ -75,6 +103,7 @@ public void setValue(Object value) {

@Override
public void addChild(BaseTreeNode child) {
if (!isEnabled()) return;
if (child instanceof FileTreeNode) {
var ftNode = (FileTreeNode) child;
var crNode = (ContentRootNode) this.getParent();