Skip to content

Commit e027045

Browse files
committed
fix: added handlers for each severity
1 parent 9bf0b02 commit e027045

8 files changed

Lines changed: 277 additions & 75 deletions

File tree

plugin/plugin.xml

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,30 +69,25 @@
6969
name="Open Snyk Preferences"
7070
defaultHandler="io.snyk.eclipse.plugin.views.snyktoolview.handlers.OpenSnykPreferencesHandler">
7171
</command>
72-
<command
73-
id="io.snyk.eclipse.plugin.commands.filter"
74-
name="Filter"
75-
defaultHandler="io.snyk.eclipse.plugin.views.snyktoolview.handlers.FilterHandler">
76-
</command>
7772
<command
7873
id="io.snyk.eclipse.plugin.commands.snykFilterCritical"
7974
name="Critical Severity"
80-
defaultHandler="io.snyk.eclipse.plugin.views.snyktoolview.handlers.FilterHandler">
75+
defaultHandler="io.snyk.eclipse.plugin.views.snyktoolview.handlers.FilterCriticalHandler">
8176
</command>
8277
<command
8378
id="io.snyk.eclipse.plugin.commands.snykFilterHigh"
8479
name="High Severity"
85-
defaultHandler="io.snyk.eclipse.plugin.views.snyktoolview.handlers.FilterHandler">
80+
defaultHandler="io.snyk.eclipse.plugin.views.snyktoolview.handlers.FilterHighHandler">
8681
</command>
8782
<command
8883
id="io.snyk.eclipse.plugin.commands.snykFilterMedium"
8984
name="Medium Severity"
90-
defaultHandler="io.snyk.eclipse.plugin.views.snyktoolview.handlers.FilterHandler">
85+
defaultHandler="io.snyk.eclipse.plugin.views.snyktoolview.handlers.FilterMediumHandler">
9186
</command>
9287
<command
9388
id="io.snyk.eclipse.plugin.commands.snykFilterLow"
9489
name="Low Severity"
95-
defaultHandler="io.snyk.eclipse.plugin.views.snyktoolview.handlers.FilterHandler">
90+
defaultHandler="io.snyk.eclipse.plugin.views.snyktoolview.handlers.FilterLowHandler">
9691
</command>
9792
<command
9893
id="io.snyk.eclipse.plugin.commands.enableOSS"
@@ -127,7 +122,7 @@
127122
<command
128123
id="io.snyk.eclipse.plugin.commands.snykFilterDelta"
129124
name="Delta findings"
130-
defaultHandler="io.snyk.eclipse.plugin.views.snyktoolview.handlers.FilterHandler">
125+
defaultHandler="io.snyk.eclipse.plugin.views.snyktoolview.handlers.FilterDeltaHandler">
131126
</command>
132127
<command
133128
id="io.snyk.eclipse.plugin.commands.snykHideIgnored"

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public static synchronized Preferences getInstance(PreferenceStore store) {
5050
public static final String FILTER_HIGH = "FILTER_SNYK_HIGH";
5151
public static final String FILTER_MEDIUM = "FILTER_SNYK_MEDIUM";
5252
public static final String FILTER_LOW = "FILTER_SNYK_LOW";
53+
public static final String FILTER_DELTA = "FILTER_SNYK_DELTA";
5354

5455
// This is a bit confusing - CLI takes DISABLE as env variable, but we ask for
5556
// ENABLE, so we need to revert it
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package io.snyk.eclipse.plugin.views.snyktoolview.handlers;
2+
3+
import java.util.Map;
4+
5+
import org.eclipse.core.commands.AbstractHandler;
6+
import org.eclipse.core.commands.ExecutionEvent;
7+
import org.eclipse.core.commands.ExecutionException;
8+
import org.eclipse.jface.resource.ImageDescriptor;
9+
import org.eclipse.ui.PlatformUI;
10+
import org.eclipse.ui.commands.ICommandService;
11+
import org.eclipse.ui.commands.IElementUpdater;
12+
import org.eclipse.ui.menus.UIElement;
13+
14+
import io.snyk.eclipse.plugin.Activator;
15+
import io.snyk.eclipse.plugin.properties.preferences.Preferences;
16+
17+
public class FilterCriticalHandler extends AbstractHandler implements IElementUpdater {
18+
19+
//TODO should we replace the filter button with a filter applied button icon?
20+
protected static ImageDescriptor FILTER_ENABLE = Activator.getImageDescriptor("/icons/severity-critical.png");
21+
protected static ImageDescriptor FILTER_DISABLE = Activator.getImageDescriptor("/icons/oss_disabled.png");
22+
protected static String FILTER = Preferences.FILTER_CRITICAL;
23+
24+
@Override
25+
public Object execute(ExecutionEvent event) throws ExecutionException {
26+
String commandId = event.getCommand().getId();
27+
28+
ICommandService commandService = PlatformUI.getWorkbench().getService(ICommandService.class);
29+
if (commandService != null) {
30+
commandService.refreshElements(commandId, null);
31+
}
32+
33+
return null;
34+
}
35+
36+
@Override
37+
public void updateElement(UIElement element, @SuppressWarnings("rawtypes") Map map) {
38+
39+
String preference = Preferences.getInstance().getPref(FILTER);
40+
41+
// Toggle the value, if it was true, it should be set to false
42+
if (Boolean.parseBoolean(preference)) {
43+
// element.setIcon(FILTER_DISABLE);
44+
Preferences.getInstance().store(FILTER, "false");
45+
46+
} else {
47+
48+
// element.setIcon(FILTER_ENABLE);
49+
Preferences.getInstance().store(FILTER, "true");
50+
51+
}
52+
53+
}
54+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package io.snyk.eclipse.plugin.views.snyktoolview.handlers;
2+
3+
import java.util.Map;
4+
5+
import org.eclipse.core.commands.AbstractHandler;
6+
import org.eclipse.core.commands.ExecutionEvent;
7+
import org.eclipse.core.commands.ExecutionException;
8+
import org.eclipse.jface.resource.ImageDescriptor;
9+
import org.eclipse.ui.PlatformUI;
10+
import org.eclipse.ui.commands.ICommandService;
11+
import org.eclipse.ui.commands.IElementUpdater;
12+
import org.eclipse.ui.menus.UIElement;
13+
14+
import io.snyk.eclipse.plugin.Activator;
15+
import io.snyk.eclipse.plugin.properties.preferences.Preferences;
16+
17+
public class FilterDeltaHandler extends AbstractHandler implements IElementUpdater {
18+
19+
// TODO should we replace the filter button with a filter applied button icon?
20+
protected static ImageDescriptor FILTER_ENABLE = Activator.getImageDescriptor("/icons/severity-medium.png");
21+
protected static ImageDescriptor FILTER_DISABLE = Activator.getImageDescriptor("/icons/oss_disabled.png");
22+
protected static String FILTER = Preferences.FILTER_DELTA;
23+
24+
@Override
25+
public Object execute(ExecutionEvent event) throws ExecutionException {
26+
String commandId = event.getCommand().getId();
27+
28+
ICommandService commandService = PlatformUI.getWorkbench().getService(ICommandService.class);
29+
if (commandService != null) {
30+
commandService.refreshElements(commandId, null);
31+
}
32+
33+
return null;
34+
}
35+
36+
@Override
37+
public void updateElement(UIElement element, @SuppressWarnings("rawtypes") Map map) {
38+
39+
String preference = Preferences.getInstance().getPref(FILTER);
40+
41+
// Toggle the value, if it was true, it should be set to false
42+
if (Boolean.parseBoolean(preference)) {
43+
// element.setIcon(FILTER_DISABLE);
44+
Preferences.getInstance().store(FILTER, "false");
45+
46+
} else {
47+
48+
// element.setIcon(FILTER_ENABLE);
49+
Preferences.getInstance().store(FILTER, "true");
50+
51+
}
52+
53+
}
54+
}

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

Lines changed: 0 additions & 65 deletions
This file was deleted.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package io.snyk.eclipse.plugin.views.snyktoolview.handlers;
2+
3+
import java.util.Map;
4+
5+
import org.eclipse.core.commands.AbstractHandler;
6+
import org.eclipse.core.commands.ExecutionEvent;
7+
import org.eclipse.core.commands.ExecutionException;
8+
import org.eclipse.jface.resource.ImageDescriptor;
9+
import org.eclipse.ui.PlatformUI;
10+
import org.eclipse.ui.commands.ICommandService;
11+
import org.eclipse.ui.commands.IElementUpdater;
12+
import org.eclipse.ui.menus.UIElement;
13+
14+
import io.snyk.eclipse.plugin.Activator;
15+
import io.snyk.eclipse.plugin.properties.preferences.Preferences;
16+
17+
public class FilterHighHandler extends AbstractHandler implements IElementUpdater {
18+
19+
// TODO should we replace the filter button with a filter applied button icon?
20+
protected static ImageDescriptor FILTER_ENABLE = Activator.getImageDescriptor("/icons/severity-high.png");
21+
protected static ImageDescriptor FILTER_DISABLE = Activator
22+
.getImageDescriptor("platform:/plugin/org.eclipse.ui/icons/full/etool16/delete_edit.png");
23+
protected static String FILTER = Preferences.FILTER_HIGH;
24+
25+
@Override
26+
public Object execute(ExecutionEvent event) throws ExecutionException {
27+
String commandId = event.getCommand().getId();
28+
29+
ICommandService commandService = PlatformUI.getWorkbench().getService(ICommandService.class);
30+
if (commandService != null) {
31+
commandService.refreshElements(commandId, null);
32+
}
33+
34+
return null;
35+
}
36+
37+
@Override
38+
public void updateElement(UIElement element, @SuppressWarnings("rawtypes") Map map) {
39+
40+
String preference = Preferences.getInstance().getPref(FILTER);
41+
42+
// Toggle the value, if it was true, it should be set to false
43+
if (Boolean.parseBoolean(preference)) {
44+
element.setIcon(FILTER_DISABLE);
45+
Preferences.getInstance().store(FILTER, "false");
46+
47+
} else {
48+
49+
element.setIcon(FILTER_ENABLE);
50+
Preferences.getInstance().store(FILTER, "true");
51+
52+
}
53+
54+
}
55+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package io.snyk.eclipse.plugin.views.snyktoolview.handlers;
2+
3+
import java.util.Map;
4+
5+
import org.eclipse.core.commands.AbstractHandler;
6+
import org.eclipse.core.commands.ExecutionEvent;
7+
import org.eclipse.core.commands.ExecutionException;
8+
import org.eclipse.jface.resource.ImageDescriptor;
9+
import org.eclipse.ui.PlatformUI;
10+
import org.eclipse.ui.commands.ICommandService;
11+
import org.eclipse.ui.commands.IElementUpdater;
12+
import org.eclipse.ui.menus.UIElement;
13+
14+
import io.snyk.eclipse.plugin.Activator;
15+
import io.snyk.eclipse.plugin.properties.preferences.Preferences;
16+
17+
public class FilterLowHandler extends AbstractHandler implements IElementUpdater {
18+
19+
// TODO should we replace the filter button with a filter applied button icon?
20+
protected static ImageDescriptor FILTER_ENABLE = Activator.getImageDescriptor("/icons/severity-low.png");
21+
protected static ImageDescriptor FILTER_DISABLE = Activator.getImageDescriptor("/icons/oss_disabled.png");
22+
protected static String FILTER = Preferences.FILTER_LOW;
23+
24+
@Override
25+
public Object execute(ExecutionEvent event) throws ExecutionException {
26+
String commandId = event.getCommand().getId();
27+
28+
ICommandService commandService = PlatformUI.getWorkbench().getService(ICommandService.class);
29+
if (commandService != null) {
30+
commandService.refreshElements(commandId, null);
31+
}
32+
33+
return null;
34+
}
35+
36+
@Override
37+
public void updateElement(UIElement element, @SuppressWarnings("rawtypes") Map map) {
38+
39+
String preference = Preferences.getInstance().getPref(FILTER);
40+
41+
// Toggle the value, if it was true, it should be set to false
42+
if (Boolean.parseBoolean(preference)) {
43+
// element.setIcon(FILTER_DISABLE);
44+
Preferences.getInstance().store(FILTER, "false");
45+
46+
} else {
47+
48+
// element.setIcon(FILTER_ENABLE);
49+
Preferences.getInstance().store(FILTER, "true");
50+
51+
}
52+
53+
}
54+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package io.snyk.eclipse.plugin.views.snyktoolview.handlers;
2+
3+
import java.util.Map;
4+
5+
import org.eclipse.core.commands.AbstractHandler;
6+
import org.eclipse.core.commands.ExecutionEvent;
7+
import org.eclipse.core.commands.ExecutionException;
8+
import org.eclipse.jface.resource.ImageDescriptor;
9+
import org.eclipse.ui.PlatformUI;
10+
import org.eclipse.ui.commands.ICommandService;
11+
import org.eclipse.ui.commands.IElementUpdater;
12+
import org.eclipse.ui.menus.UIElement;
13+
14+
import io.snyk.eclipse.plugin.Activator;
15+
import io.snyk.eclipse.plugin.properties.preferences.Preferences;
16+
17+
public class FilterMediumHandler extends AbstractHandler implements IElementUpdater {
18+
19+
// TODO should we replace the filter button with a filter applied button icon?
20+
protected static ImageDescriptor FILTER_ENABLE = Activator.getImageDescriptor("/icons/severity-medium.png");
21+
protected static ImageDescriptor FILTER_DISABLE = Activator.getImageDescriptor("/icons/oss_disabled.png");
22+
protected static String FILTER = Preferences.FILTER_MEDIUM;
23+
24+
@Override
25+
public Object execute(ExecutionEvent event) throws ExecutionException {
26+
String commandId = event.getCommand().getId();
27+
28+
ICommandService commandService = PlatformUI.getWorkbench().getService(ICommandService.class);
29+
if (commandService != null) {
30+
commandService.refreshElements(commandId, null);
31+
}
32+
33+
return null;
34+
}
35+
36+
@Override
37+
public void updateElement(UIElement element, @SuppressWarnings("rawtypes") Map map) {
38+
39+
String preference = Preferences.getInstance().getPref(FILTER);
40+
41+
// Toggle the value, if it was true, it should be set to false
42+
if (Boolean.parseBoolean(preference)) {
43+
// element.setIcon(FILTER_DISABLE);
44+
Preferences.getInstance().store(FILTER, "false");
45+
46+
} else {
47+
48+
// element.setIcon(FILTER_ENABLE);
49+
Preferences.getInstance().store(FILTER, "true");
50+
51+
}
52+
53+
}
54+
}

0 commit comments

Comments
 (0)