11package io .snyk .eclipse .plugin .views .snyktoolview ;
22
33import java .nio .file .Paths ;
4- import java .util .Arrays ;
54import java .util .HashMap ;
65import java .util .Map ;
76
1817import org .eclipse .swt .SWT ;
1918import org .eclipse .swt .browser .Browser ;
2019import org .eclipse .swt .custom .SashForm ;
21- import org .eclipse .swt .events .SelectionAdapter ;
22- import org .eclipse .swt .events .SelectionEvent ;
2320import org .eclipse .swt .layout .FillLayout ;
2421import org .eclipse .swt .layout .GridData ;
2522import org .eclipse .swt .layout .GridLayout ;
26- import org .eclipse .swt .widgets .Button ;
27- import org .eclipse .swt .widgets .Combo ;
2823import org .eclipse .swt .widgets .Composite ;
2924import org .eclipse .swt .widgets .Display ;
3025import org .eclipse .swt .widgets .Event ;
31- import org .eclipse .swt .widgets .Label ;
3226import org .eclipse .swt .widgets .Listener ;
3327import org .eclipse .swt .widgets .Menu ;
3428import org .eclipse .swt .widgets .Tree ;
4135import io .snyk .eclipse .plugin .properties .preferences .EclipsePreferenceState ;
4236import io .snyk .eclipse .plugin .properties .preferences .Preferences ;
4337import io .snyk .eclipse .plugin .utils .ResourceUtils ;
44- import io .snyk .eclipse .plugin .utils .SnykLogger ;
4538import io .snyk .eclipse .plugin .views .snyktoolview .providers .TreeContentProvider ;
4639import io .snyk .eclipse .plugin .views .snyktoolview .providers .TreeLabelProvider ;
4740import io .snyk .languageserver .protocolextension .SnykExtendedLanguageClient ;
@@ -290,18 +283,19 @@ public void enableDelta() {
290283 ContentRootNode node = (ContentRootNode ) item .getData ();
291284 String projectName = node .getText ().toString ();
292285 String projectPath = node .getPath ().toString ();
293- String baseBranch = preferenceState .getBaseBranch (projectPath );
294286 IProject project = ResourcesPlugin .getWorkspace ().getRoot ().getProject (projectName );
287+ String baseBranch = preferenceState .getBaseBranch (projectPath );
295288 String [] localBranches = preferenceState .getLocalBranches (projectPath ).toArray (String []::new );
296289
297- item .setText (
298- String . format ( "%s - Click here choose base branch [ current: %s ]" , projectName , baseBranch ));
290+ item .setText (String . format ( "%s - Click here choose base branch [ current: %s ]" , projectName ,
291+ baseBranch ));
299292
300293 Listener selectionListener = new Listener () {
301294 @ Override
302295 public void handleEvent (Event event ) {
303296 if (event .item == item ) {
304- baseBranchDialog (event .display , projectPath , project , localBranches );
297+ new BaseBranchDialog ().baseBranchDialog (event .display , projectPath , project ,
298+ localBranches );
305299 }
306300 }
307301 };
@@ -316,48 +310,6 @@ public void handleEvent(Event event) {
316310 });
317311 }
318312
319- private void baseBranchDialog (Display display , String projectPath , IProject project , String [] localBranches ) {
320- Shell shell = new Shell (display , SWT .APPLICATION_MODAL | SWT .DIALOG_TRIM );
321- shell .setText ("Choose base branch for net-new issues scanning" );
322- shell .setLayout (new GridLayout (1 , false ));
323- Label label = new Label (shell , SWT .NONE );
324- label .setText ("Base Branch for: " + projectPath );
325- label .setLayoutData (new GridData (SWT .FILL , SWT .CENTER , true , false ));
326-
327- Combo dropdown = new Combo (shell , SWT .DROP_DOWN );
328- dropdown .setItems (localBranches );
329- dropdown .setLayoutData (new GridData (SWT .FILL , SWT .CENTER , true , false ));
330- dropdown .setText (preferenceState .getBaseBranch (projectPath ));
331-
332- Button okButton = new Button (shell , SWT .PUSH );
333- okButton .setText ("OK" );
334- okButton .setLayoutData (new GridData (SWT .END , SWT .CENTER , false , false ));
335- okButton .addSelectionListener (new SelectionAdapter () {
336- @ Override
337- public void widgetSelected (SelectionEvent e ) {
338- // Handle OK button press
339- String selectedBranch = dropdown .getText ();
340- if (Arrays .asList (localBranches ).contains (selectedBranch )) {
341- preferenceState .setBaseBranch (projectPath , selectedBranch );
342- shell .close ();
343- SnykExtendedLanguageClient .getInstance ().triggerScan (project );
344- } else {
345- SnykLogger .logInfo ("Branch is not a valid local branch for repository: " + projectPath );
346- }
347-
348- }
349- });
350-
351- shell .pack ();
352- shell .open ();
353-
354- while (!shell .isDisposed ()) {
355- if (!display .readAndDispatch ()) {
356- display .sleep ();
357- }
358- }
359- }
360-
361313 /*
362314 * Disables Net New Issues scan, and starts a regular scan.
363315 */
0 commit comments