Skip to content

Commit 1f18607

Browse files
committed
fix: use basehandler for handlers
1 parent c220898 commit 1f18607

11 files changed

Lines changed: 121 additions & 827 deletions

plugin/plugin.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@
3434
relationship="right"
3535
ratio="0.5">
3636
</view>
37+
<!--
3738
<view
3839
id="io.snyk.eclipse.plugin.views.snyktoolview"
3940
relative="org.eclipse.ui.views.ProblemView"
4041
relationship="right"
4142
ratio="0.5">
4243
</view>
44+
-->
4345
</perspectiveExtension>
4446
</extension>
4547
<extension point="org.eclipse.help.contexts">
@@ -117,7 +119,7 @@
117119
<command
118120
defaultHandler="io.snyk.eclipse.plugin.views.snyktoolview.providers.ViewMenuHandler"
119121
id="io.snyk.eclipse.plugin.commands.viewmenu"
120-
name="snykViewMenuHandler">
122+
name="Show View Menu">
121123
</command>
122124
<command
123125
id="io.snyk.eclipse.plugin.commands.snykFilterDelta"
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 BaseHandler extends AbstractHandler implements IElementUpdater {
18+
19+
//TODO should we replace the filter button with a filter applied button icon?
20+
protected ImageDescriptor iconEnabled = null;
21+
protected ImageDescriptor iconDisabled = null;
22+
protected String preferenceKey = null;
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(preferenceKey);
40+
41+
// Toggle the value, if it was true, it should be set to false
42+
if (Boolean.parseBoolean(preference)) {
43+
element.setIcon(iconDisabled);
44+
Preferences.getInstance().store(preferenceKey, "false");
45+
46+
} else {
47+
48+
element.setIcon(iconEnabled);
49+
Preferences.getInstance().store(preferenceKey, "true");
50+
51+
}
52+
53+
}
54+
}
Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,18 @@
11
package io.snyk.eclipse.plugin.views.snyktoolview.handlers;
22

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;
113
import org.eclipse.ui.commands.IElementUpdater;
12-
import org.eclipse.ui.menus.UIElement;
134

145
import io.snyk.eclipse.plugin.Activator;
156
import io.snyk.eclipse.plugin.properties.preferences.Preferences;
167

17-
public class EnableCodeProductHandler extends AbstractHandler implements IElementUpdater {
18-
19-
protected static ImageDescriptor IMAGE_ENABLE = Activator.getImageDescriptor("/icons/code.png");
20-
protected static ImageDescriptor IMAGE_DISABLE = Activator.getImageDescriptor("/icons/code_disabled.svg");
21-
22-
@Override
23-
public Object execute(ExecutionEvent event) throws ExecutionException {
24-
String commandId = event.getCommand().getId();
25-
26-
ICommandService commandService = PlatformUI.getWorkbench().getService(ICommandService.class);
27-
if (commandService != null) {
28-
commandService.refreshElements(commandId, null);
29-
}
30-
31-
return null;
8+
public class EnableCodeProductHandler extends BaseHandler implements IElementUpdater {
9+
10+
public EnableCodeProductHandler() {
11+
super();
12+
// TODO should we replace the filter button with a filter applied button icon?
13+
iconEnabled = Activator.getImageDescriptor("/icons/code.png");
14+
iconDisabled = Activator.getImageDescriptor("/icons/code_disabled.png");
15+
preferenceKey = Preferences.ACTIVATE_SNYK_CODE_SECURITY;
3216
}
3317

34-
@Override
35-
public void updateElement(UIElement element, @SuppressWarnings("rawtypes") Map map) {
36-
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-
}
50-
}
5118
}
Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,18 @@
11
package io.snyk.eclipse.plugin.views.snyktoolview.handlers;
22

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;
113
import org.eclipse.ui.commands.IElementUpdater;
12-
import org.eclipse.ui.menus.UIElement;
134

145
import io.snyk.eclipse.plugin.Activator;
156
import io.snyk.eclipse.plugin.properties.preferences.Preferences;
167

17-
public class EnableIacProductHandler extends AbstractHandler implements IElementUpdater {
18-
19-
protected static ImageDescriptor IMAGE_ENABLE = Activator.getImageDescriptor("/icons/iac.png");
20-
protected static ImageDescriptor IMAGE_DISABLE = Activator.getImageDescriptor("/icons/iac_disabled.png");
21-
22-
@Override
23-
public Object execute(ExecutionEvent event) throws ExecutionException {
24-
String commandId = event.getCommand().getId();
25-
26-
ICommandService commandService = PlatformUI.getWorkbench().getService(ICommandService.class);
27-
if (commandService != null) {
28-
commandService.refreshElements(commandId, null);
29-
}
30-
31-
return null;
8+
public class EnableIacProductHandler extends BaseHandler implements IElementUpdater {
9+
10+
public EnableIacProductHandler() {
11+
super();
12+
// TODO should we replace the filter button with a filter applied button icon?
13+
iconEnabled = Activator.getImageDescriptor("/icons/iac.png");
14+
iconDisabled = Activator.getImageDescriptor("/icons/iac_disabled.png");
15+
preferenceKey = Preferences.ACTIVATE_SNYK_IAC;
3216
}
3317

34-
@Override
35-
public void updateElement(UIElement element, @SuppressWarnings("rawtypes") Map map) {
36-
37-
String enableScanPreference = Preferences.getInstance().getPref(Preferences.ACTIVATE_SNYK_IAC);
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_IAC, "false");
43-
44-
} else {
45-
46-
element.setIcon(IMAGE_ENABLE);
47-
Preferences.getInstance().store(Preferences.ACTIVATE_SNYK_IAC, "true");
48-
49-
}
50-
}
5118
}
Lines changed: 8 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,18 @@
11
package io.snyk.eclipse.plugin.views.snyktoolview.handlers;
22

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;
113
import org.eclipse.ui.commands.IElementUpdater;
12-
import org.eclipse.ui.menus.UIElement;
134

145
import io.snyk.eclipse.plugin.Activator;
156
import io.snyk.eclipse.plugin.properties.preferences.Preferences;
167

17-
public class EnableOssProductHandler extends AbstractHandler implements IElementUpdater {
18-
19-
protected static ImageDescriptor IMAGE_ENABLE = Activator.getImageDescriptor("/icons/oss.png");
20-
protected static ImageDescriptor IMAGE_DISABLE = Activator.getImageDescriptor("/icons/oss_disabled.png");
21-
22-
@Override
23-
public Object execute(ExecutionEvent event) throws ExecutionException {
24-
String commandId = event.getCommand().getId();
25-
26-
ICommandService commandService = PlatformUI.getWorkbench().getService(ICommandService.class);
27-
if (commandService != null) {
28-
commandService.refreshElements(commandId, null);
29-
}
30-
31-
return null;
8+
public class EnableOssProductHandler extends BaseHandler implements IElementUpdater {
9+
10+
public EnableOssProductHandler() {
11+
super();
12+
// TODO should we replace the filter button with a filter applied button icon?
13+
iconEnabled = Activator.getImageDescriptor("/icons/oss.png");
14+
iconDisabled = Activator.getImageDescriptor("/icons/oss_disabled.png");
15+
preferenceKey = Preferences.ACTIVATE_SNYK_OPEN_SOURCE;
3216
}
3317

34-
@Override
35-
public void updateElement(UIElement element, @SuppressWarnings("rawtypes") Map map) {
36-
37-
String enableScanPreference = Preferences.getInstance().getPref(Preferences.ACTIVATE_SNYK_OPEN_SOURCE);
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_OPEN_SOURCE, "false");
43-
44-
} else {
45-
46-
element.setIcon(IMAGE_ENABLE);
47-
Preferences.getInstance().store(Preferences.ACTIVATE_SNYK_OPEN_SOURCE, "true");
48-
49-
}
50-
51-
}
5218
}
Lines changed: 8 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,18 @@
11
package io.snyk.eclipse.plugin.views.snyktoolview.handlers;
22

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;
113
import org.eclipse.ui.commands.IElementUpdater;
12-
import org.eclipse.ui.menus.UIElement;
134

145
import io.snyk.eclipse.plugin.Activator;
156
import io.snyk.eclipse.plugin.properties.preferences.Preferences;
167

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;
8+
public class FilterCriticalHandler extends BaseHandler implements IElementUpdater {
9+
10+
public FilterCriticalHandler() {
11+
super();
12+
// TODO should we replace the filter button with a filter applied button icon?
13+
iconEnabled = Activator.getImageDescriptor("/icons/severity-critical.png");
14+
iconDisabled = Activator.getImageDescriptor("/icons/severity-critical.png");
15+
preferenceKey = Preferences.FILTER_CRITICAL;
3416
}
3517

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-
}
5418
}
Lines changed: 8 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,19 @@
11
package io.snyk.eclipse.plugin.views.snyktoolview.handlers;
22

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;
113
import org.eclipse.ui.commands.IElementUpdater;
12-
import org.eclipse.ui.menus.UIElement;
134

145
import io.snyk.eclipse.plugin.Activator;
156
import io.snyk.eclipse.plugin.properties.preferences.Preferences;
167

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();
8+
public class FilterDeltaHandler extends BaseHandler implements IElementUpdater {
279

28-
ICommandService commandService = PlatformUI.getWorkbench().getService(ICommandService.class);
29-
if (commandService != null) {
30-
commandService.refreshElements(commandId, null);
31-
}
32-
33-
return null;
10+
public FilterDeltaHandler() {
11+
super();
12+
// TODO should we replace the filter button with a filter applied button icon?
13+
// TODO update to the actual Delta findings icons, if needed.
14+
iconEnabled = Activator.getImageDescriptor("/icons/code.png");
15+
iconDisabled = Activator.getImageDescriptor("/icons/code_disabled.png");
16+
preferenceKey = Preferences.FILTER_DELTA;
3417
}
3518

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-
}
5419
}

0 commit comments

Comments
 (0)