@@ -183,6 +183,8 @@ public class CheckmarxView extends ViewPart implements EventHandler {
183183 private String latestScanId = PluginConstants .EMPTY_STRING ;
184184 private static String currentScanIdFormmated = PluginConstants .EMPTY_STRING ;
185185 private List <String > currentBranches = new ArrayList <>();
186+ private List <Project > currentProjects = new ArrayList <>();
187+
186188
187189 private boolean scansCleanedByProject = false ;
188190 private boolean firstTimeTriggered = false ;
@@ -375,10 +377,10 @@ private void loadComboboxes() {
375377
376378 @ Override
377379 protected IStatus run (IProgressMonitor arg0 ) {
378- List < Project > projectList = getProjects ();
380+ currentProjects = getProjects ();
379381 sync .asyncExec (() -> {
380- projectComboViewer .setInput (projectList );
381- if (currentProjectId .isEmpty () || projectList .isEmpty ()) {
382+ projectComboViewer .setInput (currentProjects );
383+ if (currentProjectId .isEmpty () || currentProjects .isEmpty ()) {
382384 PluginUtils .setTextForComboViewer (projectComboViewer , PROJECT_COMBO_VIEWER_TEXT );
383385 PluginUtils .setTextForComboViewer (branchComboViewer , BRANCH_COMBO_VIEWER_TEXT );
384386 PluginUtils .setTextForComboViewer (scanIdComboViewer , PluginConstants .COMBOBOX_SCAND_ID_PLACEHOLDER );
@@ -389,7 +391,7 @@ protected IStatus run(IProgressMonitor arg0) {
389391 });
390392
391393 // set project ID
392- String currentProjectName = getProjectFromId (projectList , currentProjectId );
394+ String currentProjectName = getProjectFromId (currentProjects , currentProjectId );
393395 sync .asyncExec (() -> {
394396 PluginUtils .setTextForComboViewer (projectComboViewer , currentProjectName );
395397 });
@@ -760,20 +762,25 @@ public void selectionChanged(SelectionChangedEvent event) {
760762 IStructuredSelection selection = (IStructuredSelection ) event .getSelection ();
761763
762764 if (selection .size () > 0 ) {
763-
764765 Project selectedProject = ((Project ) selection .getFirstElement ());
765766
767+ // Check if selected project exists in currentProjects
768+ if (!currentProjects .contains (selectedProject )) {
769+ // Invalid project - reset to default text and disable scan button
770+ PluginUtils .setTextForComboViewer (projectComboViewer , PROJECT_COMBO_VIEWER_TEXT );
771+ updateStartScanButton (false );
772+ return ;
773+ }
774+
766775 // Avoid non-sense trigger changed when opening the combo
767776 if (selectedProject .getId ().equals (currentProjectId )) {
768777 CxLogger .info (PluginConstants .INFO_CHANGE_PROJECT_EVENT_NOT_TRIGGERED );
769-
770778 return ;
771779 }
772780
773781 onProjectChangePluginLoading (selectedProject .getId ());
774782
775783 Job job = new Job ("Checkmarx: Loading branches..." ) {
776-
777784 @ Override
778785 protected IStatus run (IProgressMonitor arg0 ) {
779786 currentBranches = DataProvider .getInstance ().getBranchesForProject (selectedProject .getId ());
@@ -790,15 +797,29 @@ protected IStatus run(IProgressMonitor arg0) {
790797 });
791798 return Status .OK_STATUS ;
792799 }
793-
794800 };
795801 job .schedule ();
796-
797802 }
798803 }
799804 });
800- }
801805
806+ // Add ModifyListener to handle manual text input for projects
807+ projectComboViewer .getCombo ().addModifyListener (e -> {
808+ String enteredProject = projectComboViewer .getCombo ().getText ();
809+
810+ // Check if text was modified and project doesn't exist
811+ boolean projectExists = currentProjects .stream ()
812+ .anyMatch (p -> p .getName ().equals (enteredProject ));
813+
814+ if (!projectExists ) {
815+ updateStartScanButton (false ); // Disable scan button
816+ } else {
817+ // Only enable if we also have a valid branch
818+ boolean validBranch = !currentBranch .isEmpty () && currentBranches .contains (currentBranch );
819+ updateStartScanButton (validBranch );
820+ }
821+ });
822+ }
802823 /**
803824 * Update state variables and make plugin fields loading when project changes
804825 *
@@ -869,38 +890,57 @@ public void selectionChanged(SelectionChangedEvent event) {
869890 if (selection .size () > 0 ) {
870891 String selectedBranch = ((String ) selection .getFirstElement ());
871892
893+ // Check if selected branch exists in currentBranches
894+ if (!currentBranches .contains (selectedBranch )) {
895+ // Invalid branch - reset to default text and disable scan button
896+ PluginUtils .setTextForComboViewer (branchComboViewer , BRANCH_COMBO_VIEWER_TEXT );
897+ updateStartScanButton (false );
898+ return ;
899+ }
900+
872901 // Avoid non-sense trigger changed when opening the combo
873902 if (selectedBranch .equals (currentBranch ) && !scansCleanedByProject ) {
874903 CxLogger .info (PluginConstants .INFO_CHANGE_BRANCH_EVENT_NOT_TRIGGERED );
875-
876904 return ;
877905 }
878906
879907 onBranchChangePluginLoading (selectedBranch );
880908
881909 List <Scan > scanList = DataProvider .getInstance ().getScansForProject (selectedBranch );
882- if (!scanList .isEmpty ()) {
910+ if (!scanList .isEmpty ()) {
883911 latestScanId = getLatestScanFromScanList (scanList ).getId ();
884912 }
885- scanIdComboViewer .setInput (scanList );
913+ scanIdComboViewer .setInput (scanList );
886914 loadLatestScanByDefault (scanList );
887-
915+
888916 sync .asyncExec (new Runnable () {
889917 public void run () {
890918 PluginUtils .enableComboViewer (projectComboViewer , true );
891919 PluginUtils .enableComboViewer (scanIdComboViewer , true );
892920 PluginUtils .updateFiltersEnabledAndCheckedState (toolBarActions .getFilterActions ());
893921 toolBarActions .getStateFilterAction ().setEnabled (true );
894922 updateStartScanButton (true );
895- }
923+ }
896924 });
897-
925+
898926 PluginUtils .updateFiltersEnabledAndCheckedState (toolBarActions .getFilterActions ());
899927 }
900928 }
901929 });
930+
931+ // Add ModifyListener to handle manual text input
932+ branchComboViewer .getCombo ().addModifyListener (e -> {
933+ String enteredBranch = branchComboViewer .getCombo ().getText ();
934+
935+ // If text was modified and branch doesn't exist
936+ if (!currentBranches .contains (enteredBranch )) {
937+ updateStartScanButton (false ); // Disable scan button
938+ } else {
939+ updateStartScanButton (true ); // Enable scan button if branch is valid
940+ }
941+ });
902942 }
903-
943+
904944 private void loadLatestScanByDefault (List <Scan > scanList ) {
905945 if (scanList .isEmpty ()) {
906946 PluginUtils .setTextForComboViewer (scanIdComboViewer , PluginConstants .COMBOBOX_SCAND_ID_NO_SCANS_AVAILABLE );
0 commit comments