Skip to content

Commit

Permalink
fix: added handlers for each severity
Browse files Browse the repository at this point in the history
  • Loading branch information
acke committed Nov 13, 2024
1 parent 9bf0b02 commit 27789d2
Show file tree
Hide file tree
Showing 7 changed files with 272 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public static synchronized Preferences getInstance(PreferenceStore store) {
public static final String FILTER_HIGH = "FILTER_SNYK_HIGH";
public static final String FILTER_MEDIUM = "FILTER_SNYK_MEDIUM";
public static final String FILTER_LOW = "FILTER_SNYK_LOW";
public static final String FILTER_DELTA = "FILTER_SNYK_DELTA";

// This is a bit confusing - CLI takes DISABLE as env variable, but we ask for
// ENABLE, so we need to revert it
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package io.snyk.eclipse.plugin.views.snyktoolview.handlers;

import java.util.Map;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;
import org.eclipse.ui.commands.IElementUpdater;
import org.eclipse.ui.menus.UIElement;

import io.snyk.eclipse.plugin.Activator;
import io.snyk.eclipse.plugin.properties.preferences.Preferences;

public class FilterCriticalHandler extends AbstractHandler implements IElementUpdater {

//TODO should we replace the filter button with a filter applied button icon?
protected static ImageDescriptor FILTER_ENABLE = Activator.getImageDescriptor("/icons/severity-critical.png");
protected static ImageDescriptor FILTER_DISABLE = Activator.getImageDescriptor("/icons/oss_disabled.png");
protected static String FILTER = Preferences.FILTER_CRITICAL;

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
String commandId = event.getCommand().getId();

ICommandService commandService = PlatformUI.getWorkbench().getService(ICommandService.class);
if (commandService != null) {
commandService.refreshElements(commandId, null);
}

return null;
}

@Override
public void updateElement(UIElement element, @SuppressWarnings("rawtypes") Map map) {

String preference = Preferences.getInstance().getPref(FILTER);

// Toggle the value, if it was true, it should be set to false
if (Boolean.parseBoolean(preference)) {
// element.setIcon(FILTER_DISABLE);
Preferences.getInstance().store(FILTER, "false");

} else {

// element.setIcon(FILTER_ENABLE);
Preferences.getInstance().store(FILTER, "true");

}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package io.snyk.eclipse.plugin.views.snyktoolview.handlers;

import java.util.Map;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;
import org.eclipse.ui.commands.IElementUpdater;
import org.eclipse.ui.menus.UIElement;

import io.snyk.eclipse.plugin.Activator;
import io.snyk.eclipse.plugin.properties.preferences.Preferences;

public class FilterDeltaHandler extends AbstractHandler implements IElementUpdater {

// TODO should we replace the filter button with a filter applied button icon?
protected static ImageDescriptor FILTER_ENABLE = Activator.getImageDescriptor("/icons/severity-medium.png");
protected static ImageDescriptor FILTER_DISABLE = Activator.getImageDescriptor("/icons/oss_disabled.png");
protected static String FILTER = Preferences.FILTER_DELTA;

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
String commandId = event.getCommand().getId();

ICommandService commandService = PlatformUI.getWorkbench().getService(ICommandService.class);
if (commandService != null) {
commandService.refreshElements(commandId, null);
}

return null;
}

@Override
public void updateElement(UIElement element, @SuppressWarnings("rawtypes") Map map) {

String preference = Preferences.getInstance().getPref(FILTER);

// Toggle the value, if it was true, it should be set to false
if (Boolean.parseBoolean(preference)) {
// element.setIcon(FILTER_DISABLE);
Preferences.getInstance().store(FILTER, "false");

} else {

// element.setIcon(FILTER_ENABLE);
Preferences.getInstance().store(FILTER, "true");

}

}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package io.snyk.eclipse.plugin.views.snyktoolview.handlers;

import java.util.Map;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;
import org.eclipse.ui.commands.IElementUpdater;
import org.eclipse.ui.menus.UIElement;

import io.snyk.eclipse.plugin.Activator;
import io.snyk.eclipse.plugin.properties.preferences.Preferences;

public class FilterHighHandler extends AbstractHandler implements IElementUpdater {

// TODO should we replace the filter button with a filter applied button icon?
protected static ImageDescriptor FILTER_ENABLE = Activator.getImageDescriptor("/icons/severity-high.png");
protected static ImageDescriptor FILTER_DISABLE = Activator
.getImageDescriptor("platform:/plugin/org.eclipse.ui/icons/full/etool16/delete_edit.png");
protected static String FILTER = Preferences.FILTER_HIGH;

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
String commandId = event.getCommand().getId();

ICommandService commandService = PlatformUI.getWorkbench().getService(ICommandService.class);
if (commandService != null) {
commandService.refreshElements(commandId, null);
}

return null;
}

@Override
public void updateElement(UIElement element, @SuppressWarnings("rawtypes") Map map) {

String preference = Preferences.getInstance().getPref(FILTER);

// Toggle the value, if it was true, it should be set to false
if (Boolean.parseBoolean(preference)) {
element.setIcon(FILTER_DISABLE);
Preferences.getInstance().store(FILTER, "false");

} else {

element.setIcon(FILTER_ENABLE);
Preferences.getInstance().store(FILTER, "true");

}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package io.snyk.eclipse.plugin.views.snyktoolview.handlers;

import java.util.Map;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;
import org.eclipse.ui.commands.IElementUpdater;
import org.eclipse.ui.menus.UIElement;

import io.snyk.eclipse.plugin.Activator;
import io.snyk.eclipse.plugin.properties.preferences.Preferences;

public class FilterLowHandler extends AbstractHandler implements IElementUpdater {

// TODO should we replace the filter button with a filter applied button icon?
protected static ImageDescriptor FILTER_ENABLE = Activator.getImageDescriptor("/icons/severity-low.png");
protected static ImageDescriptor FILTER_DISABLE = Activator.getImageDescriptor("/icons/oss_disabled.png");
protected static String FILTER = Preferences.FILTER_LOW;

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
String commandId = event.getCommand().getId();

ICommandService commandService = PlatformUI.getWorkbench().getService(ICommandService.class);
if (commandService != null) {
commandService.refreshElements(commandId, null);
}

return null;
}

@Override
public void updateElement(UIElement element, @SuppressWarnings("rawtypes") Map map) {

String preference = Preferences.getInstance().getPref(FILTER);

// Toggle the value, if it was true, it should be set to false
if (Boolean.parseBoolean(preference)) {
// element.setIcon(FILTER_DISABLE);
Preferences.getInstance().store(FILTER, "false");

} else {

// element.setIcon(FILTER_ENABLE);
Preferences.getInstance().store(FILTER, "true");

}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package io.snyk.eclipse.plugin.views.snyktoolview.handlers;

import java.util.Map;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;
import org.eclipse.ui.commands.IElementUpdater;
import org.eclipse.ui.menus.UIElement;

import io.snyk.eclipse.plugin.Activator;
import io.snyk.eclipse.plugin.properties.preferences.Preferences;

public class FilterMediumHandler extends AbstractHandler implements IElementUpdater {

// TODO should we replace the filter button with a filter applied button icon?
protected static ImageDescriptor FILTER_ENABLE = Activator.getImageDescriptor("/icons/severity-medium.png");
protected static ImageDescriptor FILTER_DISABLE = Activator.getImageDescriptor("/icons/oss_disabled.png");
protected static String FILTER = Preferences.FILTER_MEDIUM;

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
String commandId = event.getCommand().getId();

ICommandService commandService = PlatformUI.getWorkbench().getService(ICommandService.class);
if (commandService != null) {
commandService.refreshElements(commandId, null);
}

return null;
}

@Override
public void updateElement(UIElement element, @SuppressWarnings("rawtypes") Map map) {

String preference = Preferences.getInstance().getPref(FILTER);

// Toggle the value, if it was true, it should be set to false
if (Boolean.parseBoolean(preference)) {
// element.setIcon(FILTER_DISABLE);
Preferences.getInstance().store(FILTER, "false");

} else {

// element.setIcon(FILTER_ENABLE);
Preferences.getInstance().store(FILTER, "true");

}

}
}

0 comments on commit 27789d2

Please sign in to comment.