Skip to content

Commit 2fb730a

Browse files
committed
feat: Added Tree and View Menu
1 parent 008606d commit 2fb730a

14 files changed

Lines changed: 887 additions & 402 deletions

plugin/plugin.xml

Lines changed: 548 additions & 373 deletions
Large diffs are not rendered by default.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package io.snyk.eclipse.plugin.views.snyktoolview;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import org.eclipse.jface.resource.ImageDescriptor;
7+
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;
12+
13+
public class RootObject {
14+
private List<TreeNode> children;
15+
16+
public RootObject() {
17+
children = new ArrayList<>();
18+
// Initialize with some data
19+
TreeNode node = new TreeNode("Open Source");
20+
21+
// node.setImage(OSS);
22+
23+
children.add(node);
24+
children.add(new TreeNode("Code Security"));
25+
children.add(new TreeNode("Configuration"));
26+
}
27+
28+
public List<TreeNode> getChildren() {
29+
return children;
30+
}
31+
}

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

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,9 @@
33
*/
44
package io.snyk.eclipse.plugin.views.snyktoolview;
55

6-
import java.io.ByteArrayOutputStream;
7-
import java.io.InputStream;
8-
import java.net.URL;
9-
import java.util.Base64;
10-
11-
import org.eclipse.core.runtime.FileLocator;
12-
import org.eclipse.core.runtime.Path;
136
import org.eclipse.core.runtime.Platform;
147
import org.eclipse.jface.action.Action;
8+
import org.eclipse.jface.action.MenuManager;
159
import org.eclipse.jface.preference.PreferenceDialog;
1610
import org.eclipse.jface.viewers.ISelectionChangedListener;
1711
import org.eclipse.jface.viewers.IStructuredSelection;
@@ -22,7 +16,10 @@
2216
import org.eclipse.swt.browser.Browser;
2317
import org.eclipse.swt.custom.SashForm;
2418
import org.eclipse.swt.layout.FillLayout;
19+
import org.eclipse.swt.layout.GridData;
20+
import org.eclipse.swt.layout.GridLayout;
2521
import org.eclipse.swt.widgets.Composite;
22+
import org.eclipse.swt.widgets.Menu;
2623
import org.eclipse.swt.widgets.Shell;
2724
import org.eclipse.swt.widgets.Tree;
2825
import org.eclipse.ui.PlatformUI;
@@ -31,6 +28,9 @@
3128
import org.osgi.framework.Bundle;
3229

3330
import io.snyk.eclipse.plugin.utils.ResourceUtils;
31+
import io.snyk.eclipse.plugin.views.SnykView;
32+
import io.snyk.eclipse.plugin.views.snyktoolview.providers.TreeContentProvider;
33+
import io.snyk.eclipse.plugin.views.snyktoolview.providers.TreeLabelProvider;
3434

3535
/**
3636
* TODO This view will replace the old SnykView. Move the snyktoolview classes
@@ -42,7 +42,7 @@ public class SnykToolView extends ViewPart {
4242
/**
4343
* The ID of the view as specified by the extension.
4444
*/
45-
public static final String ID = "io.snyk.eclipse.plugin.views.snyktoolview.SnykToolView";
45+
public static final String ID = "io.snyk.eclipse.plugin.views.snyktoolview";
4646

4747
ResourceUtils data = new ResourceUtils();
4848

@@ -61,14 +61,22 @@ public void createPartControl(Composite parent) {
6161
// Create TreeViewer
6262
treeViewer = new TreeViewer(sashForm, SWT.BORDER);
6363
Tree tree = treeViewer.getTree();
64-
tree.setHeaderVisible(true);
65-
tree.setLinesVisible(true);
64+
tree.setHeaderVisible(false);
65+
tree.setLinesVisible(false);
66+
tree.setLayout(new GridLayout());
67+
tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
6668

6769
// Set up the tree content (replace with your own content provider)
68-
// treeViewer.setContentProvider(new TreeContentProvider());
69-
// treeViewer.setLabelProvider(new TreeLabelProvider());
70+
treeViewer.setContentProvider(new TreeContentProvider());
71+
treeViewer.setLabelProvider(new TreeLabelProvider());
7072
// treeViewer.setInput(createTreeInput());
7173

74+
// Create and set the root object
75+
RootObject rootObject = new RootObject();
76+
treeViewer.setInput(rootObject);
77+
78+
registerTreeContextMeny(parent);
79+
7280
// Create Browser
7381
browser = new Browser(sashForm, SWT.NONE);
7482
initBrowserText();
@@ -91,6 +99,13 @@ public void selectionChanged(SelectionChangedEvent event) {
9199
makeActions();
92100
}
93101

102+
private void registerTreeContextMeny(Composite parent) {
103+
MenuManager menuMgr = new MenuManager("treemenu");
104+
Menu menu = menuMgr.createContextMenu(parent);
105+
getSite().registerContextMenu(menuMgr, null);
106+
parent.setMenu(menu);
107+
}
108+
94109
private void updateBrowserContent(TreeNode node) {
95110
// Generate HTML content based on the selected node
96111
String htmlContent = generateHtmlContent(node);
@@ -116,7 +131,7 @@ private void initBrowserText() {
116131
"%snyk.trust.dialog.warning.text");
117132

118133
Bundle bundle = Platform.getBundle("io.snyk.eclipse.plugin");
119-
String base64Image = ResourceUtils.getBase64Image( bundle, "logo_snyk.png" );
134+
String base64Image = ResourceUtils.getBase64Image(bundle, "logo_snyk.png");
120135

121136
browser.setText("<!DOCTYPE html> <html lang=\"en\"> <head> <meta charset=\"UTF-8\"> "
122137
+ "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"> "
@@ -160,7 +175,6 @@ public void run() {
160175
openPrefPage.setText("Preferences");
161176
}
162177

163-
164178
private static Shell getShell() {
165179
var activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
166180
if (activeWorkbenchWindow == null)

plugin/src/main/java/io/snyk/eclipse/plugin/views/snyktoolview/providers/EnableProductHandler.java renamed to plugin/src/main/java/io/snyk/eclipse/plugin/views/snyktoolview/handlers/CollapseTreeHandler.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
package io.snyk.eclipse.plugin.views.snyktoolview.providers;
1+
package io.snyk.eclipse.plugin.views.snyktoolview.handlers;
22

33
import org.eclipse.core.commands.AbstractHandler;
44
import org.eclipse.core.commands.ExecutionEvent;
55
import org.eclipse.core.commands.ExecutionException;
66
import org.eclipse.swt.widgets.Shell;
77
import org.eclipse.ui.PlatformUI;
8-
import org.eclipse.ui.dialogs.PreferencesUtil;
98

109
import io.snyk.eclipse.plugin.utils.SnykMessageDialog;
1110

12-
public class EnableProductHandler extends AbstractHandler {
11+
public class CollapseTreeHandler extends AbstractHandler {
1312
@Override
1413
public Object execute(ExecutionEvent event) throws ExecutionException {
1514

@@ -19,15 +18,12 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
1918
SnykMessageDialog.showOkDialog(shell, commandId);
2019

2120
switch (commandId) {
22-
case "io.snyk.eclipse.plugin.commands.enableOSS":
21+
case "io.snyk.eclipse.plugin.commands.TreeCollapse":
2322
// Implement behavior for command1
2423
break;
25-
case "io.snyk.eclipse.plugin.commands.enableCode":
24+
case "io.snyk.eclipse.plugin.commands.TreeExpand":
2625
// Implement behavior for command2
2726
break;
28-
case "io.snyk.eclipse.plugin.commands.enableIac":
29-
// Implement behavior for command3
30-
break;
3127
}
3228

3329
return null;
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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.swt.widgets.Shell;
10+
import org.eclipse.ui.PlatformUI;
11+
import org.eclipse.ui.commands.ICommandService;
12+
import org.eclipse.ui.commands.IElementUpdater;
13+
import org.eclipse.ui.menus.UIElement;
14+
15+
import io.snyk.eclipse.plugin.Activator;
16+
import io.snyk.eclipse.plugin.utils.SnykMessageDialog;
17+
18+
public class EnableCodeProductHandler extends AbstractHandler implements IElementUpdater {
19+
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");
22+
23+
@Override
24+
public Object execute(ExecutionEvent event) throws ExecutionException {
25+
26+
String commandId = event.getCommand().getId();
27+
28+
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
29+
SnykMessageDialog.showOkDialog(shell, commandId);
30+
31+
ICommandService commandService = PlatformUI.getWorkbench().getService(ICommandService.class);
32+
if (commandService != null) {
33+
commandService.refreshElements(commandId, null);
34+
}
35+
36+
return null;
37+
}
38+
39+
@Override
40+
public void updateElement(UIElement element, @SuppressWarnings("rawtypes") Map map) {
41+
boolean condition = true;
42+
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+
// }
50+
}
51+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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.swt.widgets.Shell;
10+
import org.eclipse.ui.IWorkbenchPart;
11+
import org.eclipse.ui.PlatformUI;
12+
import org.eclipse.ui.commands.ICommandService;
13+
import org.eclipse.ui.commands.IElementUpdater;
14+
import org.eclipse.ui.handlers.HandlerUtil;
15+
import org.eclipse.ui.menus.UIElement;
16+
17+
import io.snyk.eclipse.plugin.Activator;
18+
import io.snyk.eclipse.plugin.utils.SnykMessageDialog;
19+
20+
public class EnableIacProductHandler extends AbstractHandler implements IElementUpdater {
21+
22+
protected static ImageDescriptor IMAGE_IAC_ENABLE = Activator.getImageDescriptor("/icons/iac.png");
23+
protected static ImageDescriptor IMAGE_IAC_DISABLE = Activator.getImageDescriptor("/icons/iac_disabled.png");
24+
25+
@Override
26+
public Object execute(ExecutionEvent event) throws ExecutionException {
27+
28+
String commandId = event.getCommand().getId();
29+
30+
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
31+
SnykMessageDialog.showOkDialog(shell, commandId);
32+
33+
ICommandService commandService = PlatformUI.getWorkbench().getService(ICommandService.class);
34+
if (commandService != null) {
35+
commandService.refreshElements(commandId, null);
36+
}
37+
38+
return null;
39+
}
40+
41+
@Override
42+
public void updateElement(UIElement element, @SuppressWarnings("rawtypes") Map map) {
43+
boolean condition = true;
44+
45+
// TODO check the configuration is we should enable or disable the product scan.
46+
47+
// if (condition) {
48+
// element.setIcon(IMAGE_OSS_ENABLE);
49+
// } else {
50+
// element.setIcon(IMAGE_OSS_DISABLE);
51+
// }
52+
}
53+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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.swt.widgets.Shell;
10+
import org.eclipse.ui.PlatformUI;
11+
import org.eclipse.ui.commands.ICommandService;
12+
import org.eclipse.ui.commands.IElementUpdater;
13+
import org.eclipse.ui.menus.UIElement;
14+
15+
import io.snyk.eclipse.plugin.Activator;
16+
import io.snyk.eclipse.plugin.utils.SnykMessageDialog;
17+
18+
public class EnableOssProductHandler extends AbstractHandler implements IElementUpdater {
19+
20+
protected static ImageDescriptor IMAGE_OSS_ENABLE = Activator.getImageDescriptor("/icons/oss.png");
21+
protected static ImageDescriptor IMAGE_OSS_DISABLE = Activator.getImageDescriptor("/icons/oss_disabled.png");
22+
23+
@Override
24+
public Object execute(ExecutionEvent event) throws ExecutionException {
25+
26+
String commandId = event.getCommand().getId();
27+
28+
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
29+
SnykMessageDialog.showOkDialog(shell, commandId);
30+
31+
ICommandService commandService = PlatformUI.getWorkbench().getService(ICommandService.class);
32+
if (commandService != null) {
33+
commandService.refreshElements(commandId, null);
34+
}
35+
36+
return null;
37+
}
38+
39+
@Override
40+
public void updateElement(UIElement element, @SuppressWarnings("rawtypes") Map map) {
41+
boolean condition = true;
42+
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+
// }
50+
}
51+
}

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
package io.snyk.eclipse.plugin.views.snyktoolview.providers;
1+
package io.snyk.eclipse.plugin.views.snyktoolview.handlers;
22

33
import org.eclipse.core.commands.AbstractHandler;
44
import org.eclipse.core.commands.ExecutionEvent;
55
import org.eclipse.core.commands.ExecutionException;
66
import org.eclipse.swt.widgets.Shell;
77
import org.eclipse.ui.PlatformUI;
8-
import org.eclipse.ui.dialogs.PreferencesUtil;
98

109
import io.snyk.eclipse.plugin.utils.SnykMessageDialog;
1110

@@ -29,10 +28,13 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
2928
// Implement behavior for command3
3029
break;
3130
case "io.snyk.eclipse.plugin.commands.snykFilterLow":
32-
// Implement behavior for command3
31+
// Implement behavior for command4
32+
break;
33+
case "io.snyk.eclipse.plugin.commands.snykFilterDelta":
34+
// Implement behavior for command5
3335
break;
3436
case "io.snyk.eclipse.plugin.commands.filter":
35-
// Implement behavior for command3
37+
// Implement behavior for command6
3638
break;
3739
}
3840

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package io.snyk.eclipse.plugin.views.snyktoolview.handlers;
2+
3+
import org.eclipse.core.commands.AbstractHandler;
4+
import org.eclipse.core.commands.ExecutionEvent;
5+
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.ICommandService;
9+
10+
import io.snyk.eclipse.plugin.utils.SnykMessageDialog;
11+
12+
public class HideIgnoredHandler extends AbstractHandler {
13+
14+
@Override
15+
public Object execute(ExecutionEvent event) throws ExecutionException {
16+
// TODO Auto-generated method stub
17+
String commandId = event.getCommand().getId();
18+
19+
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
20+
SnykMessageDialog.showOkDialog(shell, commandId);
21+
22+
return null;
23+
}
24+
25+
}

plugin/src/main/java/io/snyk/eclipse/plugin/views/snyktoolview/providers/OpenSnykPreferencesHandler.java renamed to plugin/src/main/java/io/snyk/eclipse/plugin/views/snyktoolview/handlers/OpenSnykPreferencesHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package io.snyk.eclipse.plugin.views.snyktoolview.providers;
1+
package io.snyk.eclipse.plugin.views.snyktoolview.handlers;
22

33
import org.eclipse.core.commands.AbstractHandler;
44
import org.eclipse.core.commands.ExecutionEvent;

0 commit comments

Comments
 (0)