Skip to content

Commit

Permalink
Merge pull request #216 from snyk/feat/IDE-711_icon-chooser
Browse files Browse the repository at this point in the history
chore: UI cleanup [IDE-711 ]
  • Loading branch information
acke authored Nov 18, 2024
2 parents e5a630a + 8f2893e commit eee6fb0
Show file tree
Hide file tree
Showing 23 changed files with 435 additions and 380 deletions.
39 changes: 39 additions & 0 deletions plugin/OSGI-INF/l10n/bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,50 @@ category.name=Snyk
view.name=Snyk Results
toolView.name=Snyk
page.name=Snyk

command.name=Run
command.label=Snyk Test
command.label.0=Snyk Test Project
command.stopScan=Stop Scan
command.clearCache=Clear Cache
command.openSnykPreferences=Open Snyk Preferences
command.criticalSeverity=Critical Severity
command.highSeverity=High Severity
command.mediumSeverity=Medium Severity
command.lowSeverity=Low Severity
command.openSource=Open Source
command.codeSecurity=Code Security
command.codeQuality=Code Quality
command.infrastructureAsCode=Infrastructure as Code
command.collapseTree=Collapse Tree
command.expandTree=Expand Tree
command.allIssues=All Issues
command.netNewIssues=Net New Issues
command.openIssues=Open Issues
command.ignoredIssues=Ignored Issues

tooltip.scan=Scan
tooltip.stopScan=Stop Scan
tooltip.collapseAll=Collapse all tree nodes
tooltip.expandAll=Expand all tree nodes
tooltip.emptyScanResults=Empty Scan Results Cache
tooltip.criticalSeverity=Critical Severity
tooltip.highSeverity=High Severity
tooltip.mediumSeverity=Medium Severity
tooltip.lowSeverity=Low Severity
tooltip.openPreferences=Open Snyk Preferences
tooltip.enableOSS=Enable/disable OSS scans
tooltip.enableCodeSecurity=Enable/disable Code scans
tooltip.enableCodeQuality=Enable/disable Code scans
tooltip.enableIAC=Enable/disable IAC scans
tooltip.hideIgnored=Hide Ignored
tooltip.showIgnored=Show Ignored
tooltip.showAllIssues=Show All Issues
tooltip.showNetNewIssues=Show Only Net New Issues

scanWorkspace.name=snykWorkspaceScan
scanWorkspace.label=Snyk Test Workspace

snyk.trust.dialog.warning.text=When scanning project files for vulnerabilities, Snyk may automatically execute code such as invoking the package manager to get dependency information.<br><br>You should only scan projects you trust.<br><br>


456 changes: 217 additions & 239 deletions plugin/plugin.xml

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions plugin/src/main/java/io/snyk/eclipse/plugin/utils/SnykIcons.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.snyk.eclipse.plugin.utils;

import org.eclipse.jface.resource.ImageDescriptor;

import io.snyk.eclipse.plugin.Activator;

public class SnykIcons {
public static final ImageDescriptor CODE = Activator.getImageDescriptor("/icons/code.png");
public static final ImageDescriptor CODE_DISABLED = Activator.getImageDescriptor("/icons/code_disabled.png");

public static final ImageDescriptor OSS = Activator.getImageDescriptor("/icons/oss.png");
public static final ImageDescriptor OSS_DISABLED = Activator.getImageDescriptor("/icons/oss_disabled.png");

public static final ImageDescriptor IAC = Activator.getImageDescriptor("/icons/iac.png");
public static final ImageDescriptor IAC_DISABLED = Activator.getImageDescriptor("/icons/iac_disabled.png");

public static final ImageDescriptor SEVERITY_CRITICAL = Activator
.getImageDescriptor("/icons/severity-critical.png");
public static final ImageDescriptor SEVERITY_HIGH = Activator.getImageDescriptor("/icons/severity-high.png");
public static final ImageDescriptor SEVERITY_MEDIUM = Activator.getImageDescriptor("/icons/severity-medium.png");
public static final ImageDescriptor SEVERITY_LOW = Activator.getImageDescriptor("/icons/severity-low.png");

public static final ImageDescriptor ENABLED = Activator.getImageDescriptor("/icons/enabled.png");
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ public ImageDescriptor getImageDescriptor() {
public String getText() {
return this.text;
}

public void setText(String text) {
this.text = text;
}

@Override
public String toString() {
return this.value.toString();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.snyk.eclipse.plugin.views.snyktoolview;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.TreeViewer;

/**
* This interface captures the externally used methods with the tool window.
Expand All @@ -12,7 +13,7 @@ public interface ISnykToolView {
String NO_FIXABLE_ISSUES = "There are no issues automatically fixable.";
String IGNORED_ISSUES_FILTERED_BUT_AVAILABLE = "Adjust your Issue View Options to see ignored issues.";
String OPEN_ISSUES_FILTERED_BUT_AVAILABLE = "Adjust your Issue View Options to open issues.";

String NODE_TEXT_SCANNING = "Scanning...";
String NODE_TEXT_NO_ISSUES_FOUND = "No issues found";
String NODE_TEXT_EROR = "An error occurred";
Expand Down Expand Up @@ -63,27 +64,35 @@ public interface ISnykToolView {
* @return
*/
abstract BaseTreeNode getProductNode(String product);

/**
* Resets a product node
*/
abstract void resetNode(BaseTreeNode node);


/**
* Refreshes the tree display
*/
abstract void refreshTree();

/**
* Returns the tree root
*
* @return
*/
abstract BaseTreeNode getRoot();

/**
* Clears all nodes in the tree
*
* @return
*/
abstract void clearTree();

static String getPlural(long count) {
return count > 1 ? "s" : "";
}


abstract TreeViewer getTreeViewer();

}
Original file line number Diff line number Diff line change
@@ -1,54 +1,46 @@
package io.snyk.eclipse.plugin.views.snyktoolview;

import org.eclipse.jface.resource.ImageDescriptor;

import io.snyk.eclipse.plugin.Activator;
import io.snyk.eclipse.plugin.domain.ProductConstants;
import io.snyk.eclipse.plugin.utils.SnykIcons;

public class ProductTreeNode extends BaseTreeNode {

public class ProductTreeNode extends BaseTreeNode {
public static final ImageDescriptor OSS = Activator.getImageDescriptor("/icons/oss.png");
public static final ImageDescriptor CODE = Activator.getImageDescriptor("/icons/code.png");
public static final ImageDescriptor IAC = Activator.getImageDescriptor("/icons/iac.png");

private String product;

public ProductTreeNode(Object value) {
super(value);
this.setProduct(value.toString());

switch (value.toString()) {
case ProductConstants.DISPLAYED_OSS:
setImageDescriptor(OSS);
setImageDescriptor(SnykIcons.OSS);
break;
case ProductConstants.DISPLAYED_IAC:
setImageDescriptor(IAC);
setImageDescriptor(SnykIcons.IAC);
break;
case ProductConstants.DISPLAYED_CODE_QUALITY:
setImageDescriptor(CODE);
setImageDescriptor(SnykIcons.CODE);
break;
case ProductConstants.DISPLAYED_CODE_SECURITY:
setImageDescriptor(CODE);
setImageDescriptor(SnykIcons.CODE);
break;
}
}



@Override
public void setText(String text) {
this.setValue(text);
}



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

// we don't want to override the product text
if (!cleanedValue.isBlank()) {
cleanedValue = product + " - " + cleanedValue;
cleanedValue = product + " - " + cleanedValue;
} else {
cleanedValue = product;
}
Expand All @@ -68,14 +60,10 @@ public void reset() {
this.setValue(product);
}



public String getProduct() {
return product;
}



public void setProduct(String product) {
this.product = product;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public RootNode() {
codeQualityRootNode = new ProductTreeNode(DISPLAYED_CODE_QUALITY);
iacRootNode = new ProductTreeNode(DISPLAYED_IAC);

BaseTreeNode[] children = new BaseTreeNode[] { ossRootNode, codeSecurityRootNode, codeQualityRootNode, iacRootNode, };
BaseTreeNode[] children = new BaseTreeNode[] { ossRootNode, codeSecurityRootNode, codeQualityRootNode,
iacRootNode, };
setChildren(children);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.preference.PreferenceDialog;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
Expand All @@ -25,7 +24,6 @@
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.PreferencesUtil;
import org.eclipse.ui.part.ViewPart;
import org.osgi.framework.Bundle;

Expand Down Expand Up @@ -96,8 +94,6 @@ public void selectionChanged(SelectionChangedEvent event) {
}
}
});

makeActions();
}

private void registerTreeContextMeny(Composite parent) {
Expand Down Expand Up @@ -142,27 +138,6 @@ private void initBrowserText() {
+ " <p>\n" + snykWarningText + "</body>\n" + "</html>");
}

private void makeActions() {
openPrefPage = new Action() {

@Override
public void run() {
PreferenceDialog pref = PreferencesUtil.createPreferenceDialogOn(getShell(),
"io.snyk.eclipse.plugin.properties.preferencespage", null, null);
if (pref != null)
pref.open();
}
};
openPrefPage.setText("Preferences");
}

private static Shell getShell() {
var activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (activeWorkbenchWindow == null)
return SHELL;
return activeWorkbenchWindow.getShell();
}

@Override
public void setFocus() {
treeViewer.getControl().setFocus();
Expand All @@ -172,34 +147,34 @@ public void setFocus() {
public void setNodeText(BaseTreeNode node, String text) {
node.setText(text);
Display.getDefault().asyncExec(() -> {
this.treeViewer.refresh(node, true);
this.treeViewer.refresh(node, true);
});
}

@Override
public void setNodeIcon(ImageDescriptor icon) {
// TODO Auto-generated method stub

}

@Override
public void addIssueNode(BaseTreeNode parent, BaseTreeNode toBeAdded) {
// TODO Auto-generated method stub

}

@Override
public void addFileNode(BaseTreeNode parent, BaseTreeNode toBeAdded) {
// TODO Auto-generated method stub

}

@Override
public void addInfoNode(BaseTreeNode parent, BaseTreeNode toBeAdded) {
toBeAdded.setParent(parent);
parent.addChild(toBeAdded);
Display.getDefault().asyncExec(() -> {
this.treeViewer.refresh(parent, true);
this.treeViewer.refresh(parent, true);
});
}

Expand All @@ -226,15 +201,38 @@ public BaseTreeNode getRoot() {
@Override
public void refreshTree() {
Display.getDefault().asyncExec(() -> {
this.treeViewer.refresh(true);
this.treeViewer.refresh(true);
});
}

@Override
public void resetNode(BaseTreeNode node) {
node.reset();
Display.getDefault().asyncExec(() -> {
this.treeViewer.refresh(node, true);
this.treeViewer.refresh(node, true);
});
}

public void clearTree() {
clearRoot();
Display.getDefault().asyncExec(() -> {
if (this.treeViewer != null && !this.treeViewer.getTree().isDisposed()) {
this.treeViewer.refresh();
this.treeViewer.expandAll(); // Optional: if you want to expand all nodes after clearing
}
});
}

private void clearRoot() {
if (this.rootObject != null) {
this.rootObject.removeChildren();
this.rootObject.reset();
}
}

@Override
public TreeViewer getTreeViewer() {
return this.treeViewer;
}

}
Loading

0 comments on commit eee6fb0

Please sign in to comment.