Skip to content

Commit 5fc6f71

Browse files
committed
feat: enable/disable products, viewmenu buttons and preferencepage
1 parent 3173105 commit 5fc6f71

File tree

12 files changed

+586
-142
lines changed

12 files changed

+586
-142
lines changed

.classpath

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<classpath>
3-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
44
<attributes>
55
<attribute name="module" value="true"/>
66
</attributes>

plugin/META-INF/MANIFEST.MF

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %Bundle-Name
4-
Bundle-RequiredExecutionEnvironment: JavaSE-17
4+
Bundle-RequiredExecutionEnvironment: JavaSE-17,
5+
JavaSE-21
56
Bundle-SymbolicName: io.snyk.eclipse.plugin;singleton:=true
67
Bundle-Version: 2.2.0.qualifier
78
Bundle-Activator: io.snyk.eclipse.plugin.Activator
@@ -22,7 +23,9 @@ Require-Bundle: org.eclipse.ui,
2223
org.eclipse.lsp4j.jsonrpc,
2324
org.eclipse.text,
2425
org.eclipse.ui.editors,
25-
org.eclipse.ui.genericeditor
26+
org.eclipse.ui.genericeditor,
27+
org.eclipse.swt,
28+
org.eclipse.jface
2629
Automatic-Module-Name: io.snyk.eclipse.plugin.tests
2730
Bundle-ActivationPolicy: lazy
2831
Bundle-ClassPath: .,

plugin/icons/code.svg

Lines changed: 13 additions & 19 deletions
Loading

plugin/icons/code_disabled.svg

Lines changed: 13 additions & 21 deletions
Loading

plugin/plugin.xml

Lines changed: 22 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -261,29 +261,7 @@
261261
name="FilterSeparator"
262262
visible="true">
263263
</separator>
264-
<command
265-
commandId="io.snyk.eclipse.plugin.commands.enableOSS"
266-
icon="platform:/plugin/io.snyk.eclipse.plugin/icons/oss.png"
267-
style="push"
268-
tooltip="Enable/disable OSS scans">
269-
</command>
270-
<command
271-
commandId="io.snyk.eclipse.plugin.commands.enableCode"
272-
icon="platform:/plugin/io.snyk.eclipse.plugin/icons/code.png"
273-
style="push"
274-
tooltip="Enable/disable Code scans">
275-
</command>
276-
<command
277-
commandId="io.snyk.eclipse.plugin.commands.enableIAC"
278-
icon="platform:/plugin/io.snyk.eclipse.plugin/icons/iac.png"
279-
style="push"
280-
tooltip="Enable/disable IAC scans">
281-
</command>
282264
<!-- Add a separator -->
283-
<separator
284-
name="ProductChooserSeparator"
285-
visible="true">
286-
</separator>
287265
</menuContribution>
288266
<menuContribution
289267
allPopups="false"
@@ -303,28 +281,6 @@
303281
name="RunScanSeparator"
304282
visible="true">
305283
</separator>
306-
<command
307-
commandId="io.snyk.eclipse.plugin.commands.enableOSS"
308-
icon="platform:/plugin/io.snyk.eclipse.plugin/icons/oss.png"
309-
style="push"
310-
tooltip="Enable/disable OSS scans">
311-
</command>
312-
<command
313-
commandId="io.snyk.eclipse.plugin.commands.enableCode"
314-
icon="platform:/plugin/io.snyk.eclipse.plugin/icons/code.png"
315-
style="push"
316-
tooltip="Enable/disable Code scans">
317-
</command>
318-
<command
319-
commandId="io.snyk.eclipse.plugin.commands.enableIAC"
320-
icon="platform:/plugin/io.snyk.eclipse.plugin/icons/iac.png"
321-
style="push"
322-
tooltip="Enable/disable IAC scans">
323-
</command>
324-
<separator
325-
name="ProductChooserSeparator"
326-
visible="true">
327-
</separator>
328284
<command
329285
commandId="io.snyk.eclipse.plugin.commands.snykFilterCritical"
330286
icon="platform:/plugin/io.snyk.eclipse.plugin/icons/severity-critical.png"
@@ -373,6 +329,28 @@
373329
style="push"
374330
tooltip="Show Ignored">
375331
</command>
332+
<separator
333+
name="ProductChooserSeparator"
334+
visible="true">
335+
</separator>
336+
<command
337+
commandId="io.snyk.eclipse.plugin.commands.enableOSS"
338+
icon="platform:/plugin/io.snyk.eclipse.plugin/icons/oss.png"
339+
style="push"
340+
tooltip="Enable/disable OSS scans">
341+
</command>
342+
<command
343+
commandId="io.snyk.eclipse.plugin.commands.enableCode"
344+
icon="icons/code.png"
345+
style="push"
346+
tooltip="Enable/disable Code scans">
347+
</command>
348+
<command
349+
commandId="io.snyk.eclipse.plugin.commands.enableIAC"
350+
icon="platform:/plugin/io.snyk.eclipse.plugin/icons/iac.png"
351+
style="push"
352+
tooltip="Enable/disable IAC scans">
353+
</command>
376354
</menuContribution>
377355
<menuContribution
378356
locationURI="popup:io.snyk.eclipse.plugin.views.snyktoolview#PopupTreeMenu">

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,16 @@
33
import java.util.ArrayList;
44
import java.util.List;
55

6-
import org.eclipse.jface.resource.ImageDescriptor;
76
import org.eclipse.jface.viewers.TreeNode;
8-
import org.eclipse.swt.SWT;
9-
import org.eclipse.swt.graphics.Image;
10-
import org.eclipse.swt.widgets.TreeItem;
11-
import io.snyk.eclipse.plugin.Activator;
127

138
public class RootObject {
149
private List<TreeNode> children;
1510

1611
public RootObject() {
1712
children = new ArrayList<>();
13+
1814
// Initialize with some data
19-
TreeNode node = new TreeNode("Open Source");
20-
children.add(node);
15+
children.add(new TreeNode("Open Source"));
2116
children.add(new TreeNode("Code Security"));
2217
children.add(new TreeNode("Configuration"));
2318
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ public void createPartControl(Composite parent) {
6969
// Set up the tree content (replace with your own content provider)
7070
treeViewer.setContentProvider(new TreeContentProvider());
7171
treeViewer.setLabelProvider(new TreeLabelProvider());
72-
// treeViewer.setInput(createTreeInput());
7372

7473
// Create and set the root object
7574
RootObject rootObject = new RootObject();

plugin/src/main/java/io/snyk/eclipse/plugin/views/snyktoolview/handlers/EnableCodeProductHandler.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,23 @@
66
import org.eclipse.core.commands.ExecutionEvent;
77
import org.eclipse.core.commands.ExecutionException;
88
import org.eclipse.jface.resource.ImageDescriptor;
9-
import org.eclipse.swt.widgets.Shell;
109
import org.eclipse.ui.PlatformUI;
1110
import org.eclipse.ui.commands.ICommandService;
1211
import org.eclipse.ui.commands.IElementUpdater;
1312
import org.eclipse.ui.menus.UIElement;
1413

1514
import io.snyk.eclipse.plugin.Activator;
16-
import io.snyk.eclipse.plugin.utils.SnykMessageDialog;
15+
import io.snyk.eclipse.plugin.properties.preferences.Preferences;
1716

1817
public class EnableCodeProductHandler extends AbstractHandler implements IElementUpdater {
1918

20-
protected static ImageDescriptor IMAGE_CODE_ENABLE = Activator.getImageDescriptor("/icons/code.png");
21-
protected static ImageDescriptor IMAGE_CODE_DISABLE = Activator.getImageDescriptor("/icons/code_disabled.png");
19+
protected static ImageDescriptor IMAGE_ENABLE = Activator.getImageDescriptor("/icons/code.png");
20+
protected static ImageDescriptor IMAGE_DISABLE = Activator.getImageDescriptor("/icons/code_disabled.svg");
2221

2322
@Override
2423
public Object execute(ExecutionEvent event) throws ExecutionException {
25-
2624
String commandId = event.getCommand().getId();
2725

28-
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
29-
SnykMessageDialog.showOkDialog(shell, commandId);
30-
3126
ICommandService commandService = PlatformUI.getWorkbench().getService(ICommandService.class);
3227
if (commandService != null) {
3328
commandService.refreshElements(commandId, null);
@@ -38,14 +33,19 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
3833

3934
@Override
4035
public void updateElement(UIElement element, @SuppressWarnings("rawtypes") Map map) {
41-
boolean condition = true;
4236

43-
// TODO check the configuration is we should enable or disable the product scan.
44-
45-
// if (condition) {
46-
// element.setIcon(IMAGE_OSS_ENABLE);
47-
// } else {
48-
// element.setIcon(IMAGE_OSS_DISABLE);
49-
// }
37+
String enableScanPreference = Preferences.getInstance().getPref(Preferences.ACTIVATE_SNYK_CODE_SECURITY);
38+
39+
//Toggle the value, if it was true, it should be set to false
40+
if (Boolean.parseBoolean(enableScanPreference)) {
41+
element.setIcon(IMAGE_DISABLE);
42+
Preferences.getInstance().store(Preferences.ACTIVATE_SNYK_CODE_SECURITY, "false");
43+
44+
} else {
45+
46+
element.setIcon(IMAGE_ENABLE);
47+
Preferences.getInstance().store(Preferences.ACTIVATE_SNYK_CODE_SECURITY, "true");
48+
49+
}
5050
}
5151
}

0 commit comments

Comments
 (0)