Skip to content

Commit eee6fb0

Browse files
authored
Merge pull request #216 from snyk/feat/IDE-711_icon-chooser
chore: UI cleanup [IDE-711 ]
2 parents e5a630a + 8f2893e commit eee6fb0

23 files changed

Lines changed: 435 additions & 380 deletions

plugin/OSGI-INF/l10n/bundle.properties

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,50 @@ category.name=Snyk
66
view.name=Snyk Results
77
toolView.name=Snyk
88
page.name=Snyk
9+
910
command.name=Run
1011
command.label=Snyk Test
1112
command.label.0=Snyk Test Project
13+
command.stopScan=Stop Scan
14+
command.clearCache=Clear Cache
15+
command.openSnykPreferences=Open Snyk Preferences
16+
command.criticalSeverity=Critical Severity
17+
command.highSeverity=High Severity
18+
command.mediumSeverity=Medium Severity
19+
command.lowSeverity=Low Severity
20+
command.openSource=Open Source
21+
command.codeSecurity=Code Security
22+
command.codeQuality=Code Quality
23+
command.infrastructureAsCode=Infrastructure as Code
24+
command.collapseTree=Collapse Tree
25+
command.expandTree=Expand Tree
26+
command.allIssues=All Issues
27+
command.netNewIssues=Net New Issues
28+
command.openIssues=Open Issues
29+
command.ignoredIssues=Ignored Issues
30+
31+
tooltip.scan=Scan
32+
tooltip.stopScan=Stop Scan
33+
tooltip.collapseAll=Collapse all tree nodes
34+
tooltip.expandAll=Expand all tree nodes
35+
tooltip.emptyScanResults=Empty Scan Results Cache
36+
tooltip.criticalSeverity=Critical Severity
37+
tooltip.highSeverity=High Severity
38+
tooltip.mediumSeverity=Medium Severity
39+
tooltip.lowSeverity=Low Severity
40+
tooltip.openPreferences=Open Snyk Preferences
41+
tooltip.enableOSS=Enable/disable OSS scans
42+
tooltip.enableCodeSecurity=Enable/disable Code scans
43+
tooltip.enableCodeQuality=Enable/disable Code scans
44+
tooltip.enableIAC=Enable/disable IAC scans
45+
tooltip.hideIgnored=Hide Ignored
46+
tooltip.showIgnored=Show Ignored
47+
tooltip.showAllIssues=Show All Issues
48+
tooltip.showNetNewIssues=Show Only Net New Issues
1249

1350
scanWorkspace.name=snykWorkspaceScan
1451
scanWorkspace.label=Snyk Test Workspace
1552

1653
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>
54+
55+

plugin/plugin.xml

Lines changed: 217 additions & 239 deletions
Large diffs are not rendered by default.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package io.snyk.eclipse.plugin.utils;
2+
3+
import org.eclipse.jface.resource.ImageDescriptor;
4+
5+
import io.snyk.eclipse.plugin.Activator;
6+
7+
public class SnykIcons {
8+
public static final ImageDescriptor CODE = Activator.getImageDescriptor("/icons/code.png");
9+
public static final ImageDescriptor CODE_DISABLED = Activator.getImageDescriptor("/icons/code_disabled.png");
10+
11+
public static final ImageDescriptor OSS = Activator.getImageDescriptor("/icons/oss.png");
12+
public static final ImageDescriptor OSS_DISABLED = Activator.getImageDescriptor("/icons/oss_disabled.png");
13+
14+
public static final ImageDescriptor IAC = Activator.getImageDescriptor("/icons/iac.png");
15+
public static final ImageDescriptor IAC_DISABLED = Activator.getImageDescriptor("/icons/iac_disabled.png");
16+
17+
public static final ImageDescriptor SEVERITY_CRITICAL = Activator
18+
.getImageDescriptor("/icons/severity-critical.png");
19+
public static final ImageDescriptor SEVERITY_HIGH = Activator.getImageDescriptor("/icons/severity-high.png");
20+
public static final ImageDescriptor SEVERITY_MEDIUM = Activator.getImageDescriptor("/icons/severity-medium.png");
21+
public static final ImageDescriptor SEVERITY_LOW = Activator.getImageDescriptor("/icons/severity-low.png");
22+
23+
public static final ImageDescriptor ENABLED = Activator.getImageDescriptor("/icons/enabled.png");
24+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ public ImageDescriptor getImageDescriptor() {
5050
public String getText() {
5151
return this.text;
5252
}
53-
53+
5454
public void setText(String text) {
5555
this.text = text;
5656
}
57-
57+
5858
@Override
5959
public String toString() {
6060
return this.value.toString();

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.snyk.eclipse.plugin.views.snyktoolview;
22

33
import org.eclipse.jface.resource.ImageDescriptor;
4+
import org.eclipse.jface.viewers.TreeViewer;
45

56
/**
67
* This interface captures the externally used methods with the tool window.
@@ -12,7 +13,7 @@ public interface ISnykToolView {
1213
String NO_FIXABLE_ISSUES = "There are no issues automatically fixable.";
1314
String IGNORED_ISSUES_FILTERED_BUT_AVAILABLE = "Adjust your Issue View Options to see ignored issues.";
1415
String OPEN_ISSUES_FILTERED_BUT_AVAILABLE = "Adjust your Issue View Options to open issues.";
15-
16+
1617
String NODE_TEXT_SCANNING = "Scanning...";
1718
String NODE_TEXT_NO_ISSUES_FOUND = "No issues found";
1819
String NODE_TEXT_EROR = "An error occurred";
@@ -63,27 +64,35 @@ public interface ISnykToolView {
6364
* @return
6465
*/
6566
abstract BaseTreeNode getProductNode(String product);
66-
67+
6768
/**
6869
* Resets a product node
6970
*/
7071
abstract void resetNode(BaseTreeNode node);
7172

72-
7373
/**
7474
* Refreshes the tree display
7575
*/
7676
abstract void refreshTree();
77-
77+
7878
/**
7979
* Returns the tree root
8080
*
8181
* @return
8282
*/
8383
abstract BaseTreeNode getRoot();
8484

85+
/**
86+
* Clears all nodes in the tree
87+
*
88+
* @return
89+
*/
90+
abstract void clearTree();
91+
8592
static String getPlural(long count) {
8693
return count > 1 ? "s" : "";
8794
}
88-
95+
96+
abstract TreeViewer getTreeViewer();
97+
8998
}

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

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,46 @@
11
package io.snyk.eclipse.plugin.views.snyktoolview;
22

3-
import org.eclipse.jface.resource.ImageDescriptor;
4-
5-
import io.snyk.eclipse.plugin.Activator;
63
import io.snyk.eclipse.plugin.domain.ProductConstants;
4+
import io.snyk.eclipse.plugin.utils.SnykIcons;
5+
6+
public class ProductTreeNode extends BaseTreeNode {
77

8-
public class ProductTreeNode extends BaseTreeNode {
9-
public static final ImageDescriptor OSS = Activator.getImageDescriptor("/icons/oss.png");
10-
public static final ImageDescriptor CODE = Activator.getImageDescriptor("/icons/code.png");
11-
public static final ImageDescriptor IAC = Activator.getImageDescriptor("/icons/iac.png");
12-
138
private String product;
149

1510
public ProductTreeNode(Object value) {
1611
super(value);
1712
this.setProduct(value.toString());
18-
13+
1914
switch (value.toString()) {
2015
case ProductConstants.DISPLAYED_OSS:
21-
setImageDescriptor(OSS);
16+
setImageDescriptor(SnykIcons.OSS);
2217
break;
2318
case ProductConstants.DISPLAYED_IAC:
24-
setImageDescriptor(IAC);
19+
setImageDescriptor(SnykIcons.IAC);
2520
break;
2621
case ProductConstants.DISPLAYED_CODE_QUALITY:
27-
setImageDescriptor(CODE);
22+
setImageDescriptor(SnykIcons.CODE);
2823
break;
2924
case ProductConstants.DISPLAYED_CODE_SECURITY:
30-
setImageDescriptor(CODE);
25+
setImageDescriptor(SnykIcons.CODE);
3126
break;
3227
}
3328
}
34-
35-
3629

3730
@Override
3831
public void setText(String text) {
3932
this.setValue(text);
4033
}
4134

42-
43-
4435
@Override
4536
public void setValue(Object value) {
46-
if (!(value instanceof String)) throw new IllegalArgumentException("value of product node must be a string");
37+
if (!(value instanceof String))
38+
throw new IllegalArgumentException("value of product node must be a string");
4739
var cleanedValue = removePrefix(value.toString());
48-
40+
4941
// we don't want to override the product text
5042
if (!cleanedValue.isBlank()) {
51-
cleanedValue = product + " - " + cleanedValue;
43+
cleanedValue = product + " - " + cleanedValue;
5244
} else {
5345
cleanedValue = product;
5446
}
@@ -68,14 +60,10 @@ public void reset() {
6860
this.setValue(product);
6961
}
7062

71-
72-
7363
public String getProduct() {
7464
return product;
7565
}
7666

77-
78-
7967
public void setProduct(String product) {
8068
this.product = product;
8169
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ public RootNode() {
1919
codeQualityRootNode = new ProductTreeNode(DISPLAYED_CODE_QUALITY);
2020
iacRootNode = new ProductTreeNode(DISPLAYED_IAC);
2121

22-
BaseTreeNode[] children = new BaseTreeNode[] { ossRootNode, codeSecurityRootNode, codeQualityRootNode, iacRootNode, };
22+
BaseTreeNode[] children = new BaseTreeNode[] { ossRootNode, codeSecurityRootNode, codeQualityRootNode,
23+
iacRootNode, };
2324
setChildren(children);
2425
}
2526
}

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

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import org.eclipse.core.runtime.Platform;
77
import org.eclipse.jface.action.Action;
88
import org.eclipse.jface.action.MenuManager;
9-
import org.eclipse.jface.preference.PreferenceDialog;
109
import org.eclipse.jface.resource.ImageDescriptor;
1110
import org.eclipse.jface.viewers.ISelectionChangedListener;
1211
import org.eclipse.jface.viewers.IStructuredSelection;
@@ -25,7 +24,6 @@
2524
import org.eclipse.swt.widgets.Shell;
2625
import org.eclipse.swt.widgets.Tree;
2726
import org.eclipse.ui.PlatformUI;
28-
import org.eclipse.ui.dialogs.PreferencesUtil;
2927
import org.eclipse.ui.part.ViewPart;
3028
import org.osgi.framework.Bundle;
3129

@@ -96,8 +94,6 @@ public void selectionChanged(SelectionChangedEvent event) {
9694
}
9795
}
9896
});
99-
100-
makeActions();
10197
}
10298

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

145-
private void makeActions() {
146-
openPrefPage = new Action() {
147-
148-
@Override
149-
public void run() {
150-
PreferenceDialog pref = PreferencesUtil.createPreferenceDialogOn(getShell(),
151-
"io.snyk.eclipse.plugin.properties.preferencespage", null, null);
152-
if (pref != null)
153-
pref.open();
154-
}
155-
};
156-
openPrefPage.setText("Preferences");
157-
}
158-
159-
private static Shell getShell() {
160-
var activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
161-
if (activeWorkbenchWindow == null)
162-
return SHELL;
163-
return activeWorkbenchWindow.getShell();
164-
}
165-
166141
@Override
167142
public void setFocus() {
168143
treeViewer.getControl().setFocus();
@@ -172,34 +147,34 @@ public void setFocus() {
172147
public void setNodeText(BaseTreeNode node, String text) {
173148
node.setText(text);
174149
Display.getDefault().asyncExec(() -> {
175-
this.treeViewer.refresh(node, true);
150+
this.treeViewer.refresh(node, true);
176151
});
177152
}
178153

179154
@Override
180155
public void setNodeIcon(ImageDescriptor icon) {
181156
// TODO Auto-generated method stub
182-
157+
183158
}
184159

185160
@Override
186161
public void addIssueNode(BaseTreeNode parent, BaseTreeNode toBeAdded) {
187162
// TODO Auto-generated method stub
188-
163+
189164
}
190165

191166
@Override
192167
public void addFileNode(BaseTreeNode parent, BaseTreeNode toBeAdded) {
193168
// TODO Auto-generated method stub
194-
169+
195170
}
196171

197172
@Override
198173
public void addInfoNode(BaseTreeNode parent, BaseTreeNode toBeAdded) {
199174
toBeAdded.setParent(parent);
200175
parent.addChild(toBeAdded);
201176
Display.getDefault().asyncExec(() -> {
202-
this.treeViewer.refresh(parent, true);
177+
this.treeViewer.refresh(parent, true);
203178
});
204179
}
205180

@@ -226,15 +201,38 @@ public BaseTreeNode getRoot() {
226201
@Override
227202
public void refreshTree() {
228203
Display.getDefault().asyncExec(() -> {
229-
this.treeViewer.refresh(true);
204+
this.treeViewer.refresh(true);
230205
});
231206
}
232207

233208
@Override
234209
public void resetNode(BaseTreeNode node) {
235210
node.reset();
236211
Display.getDefault().asyncExec(() -> {
237-
this.treeViewer.refresh(node, true);
212+
this.treeViewer.refresh(node, true);
238213
});
239214
}
215+
216+
public void clearTree() {
217+
clearRoot();
218+
Display.getDefault().asyncExec(() -> {
219+
if (this.treeViewer != null && !this.treeViewer.getTree().isDisposed()) {
220+
this.treeViewer.refresh();
221+
this.treeViewer.expandAll(); // Optional: if you want to expand all nodes after clearing
222+
}
223+
});
224+
}
225+
226+
private void clearRoot() {
227+
if (this.rootObject != null) {
228+
this.rootObject.removeChildren();
229+
this.rootObject.reset();
230+
}
231+
}
232+
233+
@Override
234+
public TreeViewer getTreeViewer() {
235+
return this.treeViewer;
236+
}
237+
240238
}

0 commit comments

Comments
 (0)