Skip to content

Commit 9bf0b02

Browse files
committed
fix: added filters to preferencesstore
1 parent 5fc6f71 commit 9bf0b02

7 files changed

Lines changed: 62 additions & 48 deletions

File tree

.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">
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
44
<attributes>
55
<attribute name="module" value="true"/>
66
</attributes>

plugin/src/main/java/io/snyk/eclipse/plugin/properties/PreferencesPage.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
package io.snyk.eclipse.plugin.properties;
22

3-
import java.beans.PropertyChangeListener;
43
import java.io.File;
54
import java.util.concurrent.CompletableFuture;
65

7-
import org.eclipse.core.runtime.IProgressMonitor;
8-
import org.eclipse.core.runtime.IStatus;
9-
import org.eclipse.core.runtime.jobs.Job;
106
import org.eclipse.jface.preference.BooleanFieldEditor;
117
import org.eclipse.jface.preference.ComboFieldEditor;
128
import org.eclipse.jface.preference.FieldEditor;
139
import org.eclipse.jface.preference.FieldEditorPreferencePage;
1410
import org.eclipse.jface.preference.FileFieldEditor;
1511
import org.eclipse.jface.preference.StringFieldEditor;
16-
import org.eclipse.jface.util.IPropertyChangeListener;
1712
import org.eclipse.jface.util.PropertyChangeEvent;
18-
import org.eclipse.lsp4j.jsonrpc.CompletableFutures;
1913
import org.eclipse.swt.widgets.Display;
2014
import org.eclipse.ui.IWorkbench;
2115
import org.eclipse.ui.IWorkbenchPreferencePage;
@@ -24,8 +18,6 @@
2418
import io.snyk.eclipse.plugin.properties.preferences.Preferences;
2519
import io.snyk.eclipse.plugin.utils.SnykLogger;
2620
import io.snyk.languageserver.LsConfigurationUpdater;
27-
import io.snyk.languageserver.SnykLanguageServer;
28-
import io.snyk.languageserver.download.LsDownloader;
2921
import io.snyk.languageserver.protocolextension.SnykExtendedLanguageClient;
3022

3123
public class PreferencesPage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {

plugin/src/main/java/io/snyk/eclipse/plugin/properties/preferences/Preferences.java

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
package io.snyk.eclipse.plugin.properties.preferences;
22

3-
import org.apache.commons.lang3.SystemUtils;
4-
import org.eclipse.jface.preference.IPreferenceStore;
5-
6-
import io.snyk.eclipse.plugin.EnvironmentConstants;
7-
import io.snyk.languageserver.LsRuntimeEnvironment;
3+
import static io.snyk.eclipse.plugin.utils.FileSystemUtil.getBinaryDirectory;
84

95
import java.io.File;
106
import java.util.Optional;
117
import java.util.UUID;
128

13-
import static io.snyk.eclipse.plugin.utils.FileSystemUtil.getBinaryDirectory;
9+
import org.apache.commons.lang3.SystemUtils;
10+
import org.eclipse.jface.preference.IPreferenceStore;
11+
12+
import io.snyk.eclipse.plugin.EnvironmentConstants;
13+
import io.snyk.languageserver.LsRuntimeEnvironment;
1414

1515
public class Preferences {
1616
static Preferences CURRENT_PREFERENCES;
@@ -46,6 +46,10 @@ public static synchronized Preferences getInstance(PreferenceStore store) {
4646
public static final String LSP_VERSION = "LSP_VERSION";
4747
public static final String USE_TOKEN_AUTH = "useTokenAuth";
4848
public static final String ANALYTICS_PLUGIN_INSTALLED_SENT = "analyticsPluginInstalledSent";
49+
public static final String FILTER_CRITICAL = "FILTER_SNYK_CRITICAL";
50+
public static final String FILTER_HIGH = "FILTER_SNYK_HIGH";
51+
public static final String FILTER_MEDIUM = "FILTER_SNYK_MEDIUM";
52+
public static final String FILTER_LOW = "FILTER_SNYK_LOW";
4953

5054
// This is a bit confusing - CLI takes DISABLE as env variable, but we ask for
5155
// ENABLE, so we need to revert it
@@ -74,6 +78,22 @@ public static synchronized Preferences getInstance(PreferenceStore store) {
7478
if (getPref(ACTIVATE_SNYK_IAC) == null) {
7579
store(ACTIVATE_SNYK_IAC, "true");
7680
}
81+
if (getPref(FILTER_CRITICAL) == null) {
82+
store(FILTER_CRITICAL, "false");
83+
}
84+
if (getPref(FILTER_HIGH) == null) {
85+
store(FILTER_HIGH, "false");
86+
}
87+
if (getPref(FILTER_MEDIUM) == null) {
88+
store(FILTER_MEDIUM, "false");
89+
}
90+
if (getPref(FILTER_LOW) == null) {
91+
store(FILTER_LOW, "false");
92+
}
93+
if (getPref(FILTER_CRITICAL) == null) {
94+
store(FILTER_CRITICAL, "false");
95+
}
96+
7797
if (getPref(SEND_ERROR_REPORTS) == null) {
7898
store(SEND_ERROR_REPORTS, "true");
7999
}
@@ -133,7 +153,7 @@ public static synchronized Preferences getInstance(PreferenceStore store) {
133153
if (deviceId == null || deviceId.isBlank()) {
134154
store.put(DEVICE_ID, UUID.randomUUID().toString());
135155
}
136-
156+
137157
String releaseChannel = getPref(RELEASE_CHANNEL);
138158
if (releaseChannel == null || releaseChannel.isBlank()) {
139159
store.put(RELEASE_CHANNEL, "stable");
@@ -212,7 +232,7 @@ public String getReleaseChannel() {
212232
public void setTest(boolean b) {
213233
store.put("isTesting", Boolean.toString(b));
214234
}
215-
235+
216236
public boolean isTest() {
217237
return getBooleanPref("isTesting");
218238
}

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

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -140,26 +140,6 @@ private void initBrowserText() {
140140
+ " <p>\n" + snykWarningText + "</body>\n" + "</html>");
141141
}
142142

143-
private Object createTreeInput() {
144-
// Create and return your tree structure here
145-
TreeNode root = new TreeNode("Root");
146-
147-
TreeNode[] nodeList = new TreeNode[10];
148-
149-
nodeList[0] = new TreeNode("Node 1");
150-
nodeList[1] = new TreeNode("Node 2");
151-
nodeList[2] = new TreeNode("Node 3");
152-
nodeList[3] = new TreeNode("Node 4");
153-
nodeList[4] = new TreeNode("Node 5");
154-
nodeList[5] = new TreeNode("Node 6");
155-
nodeList[6] = new TreeNode("Node 7");
156-
nodeList[7] = new TreeNode("Node 8");
157-
nodeList[8] = new TreeNode("Node 9");
158-
nodeList[9] = new TreeNode("Node 10");
159-
160-
return root;
161-
}
162-
163143
private void makeActions() {
164144
openPrefPage = new Action() {
165145

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

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

3+
import java.util.Map;
4+
35
import org.eclipse.core.commands.AbstractHandler;
46
import org.eclipse.core.commands.ExecutionEvent;
57
import org.eclipse.core.commands.ExecutionException;
6-
import org.eclipse.swt.widgets.Shell;
7-
import org.eclipse.ui.PlatformUI;
8+
import org.eclipse.ui.commands.IElementUpdater;
9+
import org.eclipse.ui.menus.UIElement;
810

9-
import io.snyk.eclipse.plugin.utils.SnykMessageDialog;
11+
import io.snyk.eclipse.plugin.properties.preferences.Preferences;
1012

11-
public class FilterHandler extends AbstractHandler {
13+
public class FilterHandler extends AbstractHandler implements IElementUpdater {
1214
@Override
1315
public Object execute(ExecutionEvent event) throws ExecutionException {
1416

1517
String commandId = event.getCommand().getId();
1618

17-
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
18-
SnykMessageDialog.showOkDialog(shell, commandId);
19-
2019
switch (commandId) {
2120
case "io.snyk.eclipse.plugin.commands.snykFilterCritical":
22-
// Implement behavior for command1
21+
toggleFilter(Preferences.FILTER_CRITICAL);
2322
break;
2423
case "io.snyk.eclipse.plugin.commands.snykFilterHigh":
2524
// Implement behavior for command2
@@ -40,4 +39,27 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
4039

4140
return null;
4241
}
42+
43+
@Override
44+
public void updateElement(UIElement element, @SuppressWarnings("rawtypes") Map map) {
45+
// TODO update the filter buttons when state changed.
46+
}
47+
48+
private void toggleFilter(String filter) {
49+
String preference = getPreference(filter);
50+
51+
// Toggle the value, if it was true, it should be set to false
52+
if (Boolean.parseBoolean(preference)) {
53+
Preferences.getInstance().store(filter, "false");
54+
55+
} else {
56+
Preferences.getInstance().store(filter, "true");
57+
58+
}
59+
}
60+
61+
private String getPreference(String preference) {
62+
return Preferences.getInstance().getPref(preference);
63+
}
64+
4365
}

plugin/src/main/java/io/snyk/eclipse/plugin/views/snyktoolview/providers/TreeLabelProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88

99
import io.snyk.eclipse.plugin.Activator;
1010

11-
//TODO move this provider into a provider package
1211
public class TreeLabelProvider implements ILabelProvider {
1312

1413
public static final ImageDescriptor OSS = Activator.getImageDescriptor("/icons/oss.png");
14+
public static final ImageDescriptor Code = Activator.getImageDescriptor("/icons/code.png");
15+
public static final ImageDescriptor IAC = Activator.getImageDescriptor("/icons/iac.png");
1516

1617
private Image ossImage;
1718

1819
public TreeLabelProvider() {
19-
// Create the image once
2020
ossImage = OSS.createImage();
2121
}
2222

plugin/src/main/java/io/snyk/languageserver/download/LsBinaries.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
public class LsBinaries {
1010
private static final Preferences PREFERENCES = Preferences.getInstance();
11-
public static final String REQUIRED_LS_PROTOCOL_VERSION = "16";
11+
public static final String REQUIRED_LS_PROTOCOL_VERSION = "17";
1212

1313
public static URI getBaseUri() {
1414
return URI.create(PREFERENCES.getPref(CLI_BASE_URL));

0 commit comments

Comments
 (0)