|
1 | 1 | package io.snyk.eclipse.plugin.wizards; |
2 | 2 |
|
| 3 | +import java.util.Arrays; |
| 4 | + |
| 5 | +import org.eclipse.core.resources.IProject; |
| 6 | +import org.eclipse.core.resources.ResourcesPlugin; |
3 | 7 | import org.eclipse.jface.viewers.IStructuredSelection; |
4 | 8 | import org.eclipse.jface.wizard.Wizard; |
5 | 9 | import org.eclipse.ui.INewWizard; |
|
9 | 13 | import io.snyk.languageserver.protocolextension.SnykExtendedLanguageClient; |
10 | 14 |
|
11 | 15 | public class SnykWizard extends Wizard implements INewWizard { |
12 | | - protected SnykWizardConfigureAPIPage configureAPIPage; |
13 | | - protected SnykWizardAuthenticatePage authenticatePage; |
14 | | - |
15 | | - protected SnykWizardModel model; |
16 | | - |
17 | | - protected IWorkbench workbench; |
18 | | - protected IStructuredSelection selection; |
19 | | - |
20 | | - public SnykWizard() { |
21 | | - super(); |
22 | | - model = new SnykWizardModel(); |
23 | | - setNeedsProgressMonitor(true); |
24 | | - } |
25 | | - |
26 | | - @Override |
27 | | - public String getWindowTitle() { |
28 | | - return "Snyk Wizard"; |
29 | | - } |
30 | | - |
31 | | - @Override |
32 | | - public void addPages() { |
33 | | - configureAPIPage = new SnykWizardConfigureAPIPage(); |
34 | | - addPage(configureAPIPage); |
35 | | - |
36 | | - authenticatePage = new SnykWizardAuthenticatePage(); |
37 | | - addPage(authenticatePage); |
38 | | - } |
39 | | - |
40 | | - public void init(IWorkbench workbench, IStructuredSelection selection) { |
41 | | - this.workbench = workbench; |
42 | | - this.selection = selection; |
43 | | - } |
44 | | - |
45 | | - public boolean canFinish() { |
46 | | - if (this.getContainer().getCurrentPage() == authenticatePage) { |
47 | | - return true; |
48 | | - } |
49 | | - return false; |
50 | | - } |
51 | | - |
52 | | - public boolean performCancel() { |
53 | | - model.resetPreferences(); |
54 | | - return true; |
55 | | - } |
56 | | - |
57 | | - public boolean performFinish() { |
58 | | - new LsConfigurationUpdater().configurationChanged(); |
59 | | - SnykExtendedLanguageClient.getInstance().triggerAuthentication(); |
60 | | - SnykExtendedLanguageClient.getInstance().trustWorkspaceFolders(); |
61 | | - return true; |
62 | | - } |
| 16 | + protected SnykWizardConfigureAPIPage configureAPIPage; |
| 17 | + protected SnykWizardAuthenticatePage authenticatePage; |
| 18 | + |
| 19 | + protected SnykWizardModel model; |
| 20 | + |
| 21 | + protected IWorkbench workbench; |
| 22 | + protected IStructuredSelection selection; |
| 23 | + |
| 24 | + public SnykWizard() { |
| 25 | + super(); |
| 26 | + model = new SnykWizardModel(); |
| 27 | + setNeedsProgressMonitor(true); |
| 28 | + } |
| 29 | + |
| 30 | + @Override |
| 31 | + public String getWindowTitle() { |
| 32 | + return "Snyk Wizard"; |
| 33 | + } |
| 34 | + |
| 35 | + @Override |
| 36 | + public void addPages() { |
| 37 | + configureAPIPage = new SnykWizardConfigureAPIPage(); |
| 38 | + addPage(configureAPIPage); |
| 39 | + |
| 40 | + authenticatePage = new SnykWizardAuthenticatePage(); |
| 41 | + addPage(authenticatePage); |
| 42 | + } |
| 43 | + |
| 44 | + public void init(IWorkbench workbench, IStructuredSelection selection) { |
| 45 | + this.workbench = workbench; |
| 46 | + this.selection = selection; |
| 47 | + } |
| 48 | + |
| 49 | + public boolean canFinish() { |
| 50 | + if (this.getContainer().getCurrentPage() == authenticatePage) { |
| 51 | + return true; |
| 52 | + } |
| 53 | + return false; |
| 54 | + } |
| 55 | + |
| 56 | + public boolean performCancel() { |
| 57 | + model.resetPreferences(); |
| 58 | + return true; |
| 59 | + } |
| 60 | + |
| 61 | + public boolean performFinish() { |
| 62 | + new LsConfigurationUpdater().configurationChanged(); |
| 63 | + var projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); |
| 64 | + if (projects != null && projects.length > 0 |
| 65 | + && Arrays.stream(projects).filter(p -> p.isAccessible()).count() > 0) { |
| 66 | + SnykExtendedLanguageClient.getInstance().triggerAuthentication(); |
| 67 | + SnykExtendedLanguageClient.getInstance().trustWorkspaceFolders(); |
| 68 | + } |
| 69 | + return true; |
| 70 | + } |
63 | 71 | } |
0 commit comments