@@ -120,6 +120,7 @@ public class CheckmarxView extends ViewPart implements EventHandler {
120120 private static final String FORMATTED_SCAN_LABEL = "%s %s" ;
121121 private static final String FORMATTED_SCAN_LABEL_LATEST = "%s %s (%s)" ;
122122 private boolean isUpdatingCombo = false ;
123+ private boolean resetStoredProjects = false ;
123124
124125 private Timer debounceTimer = new Timer ("ProjectSearchDebounce" , true );
125126 private TimerTask pendingSearchTask ;
@@ -199,6 +200,7 @@ public class CheckmarxView extends ViewPart implements EventHandler {
199200 private static String currentScanIdFormmated = PluginConstants .EMPTY_STRING ;
200201 private List <String > currentBranches = new ArrayList <>();
201202 private List <Project > currentProjects = new ArrayList <>();
203+ private List <Project > storeCurrentProjects = new ArrayList <>();
202204
203205
204206 private boolean scansCleanedByProject = false ;
@@ -394,6 +396,7 @@ private void loadComboboxes() {
394396 @ Override
395397 protected IStatus run (IProgressMonitor arg0 ) {
396398 currentProjects = getProjects ();
399+ storeCurrentProjects = currentProjects ;
397400 sync .asyncExec (() -> {
398401 projectComboViewer .setInput (currentProjects );
399402 if (currentProjectId .isEmpty () || currentProjects .isEmpty ()) {
@@ -780,7 +783,8 @@ public String getText(Object element) {
780783 return super .getText (element );
781784 }
782785 });
783-
786+
787+
784788 projectComboViewer .addSelectionChangedListener (new ISelectionChangedListener () {
785789 @ Override
786790 public void selectionChanged (SelectionChangedEvent event ) {
@@ -799,6 +803,8 @@ public void selectionChanged(SelectionChangedEvent event) {
799803 // Avoid non-sense trigger changed when opening the combo
800804 if (selectedProject .getId ().equals (currentProjectId )) {
801805 CxLogger .info (PluginConstants .INFO_CHANGE_PROJECT_EVENT_NOT_TRIGGERED );
806+ preservCaretposition (storeCurrentProjects , selectedProject .getName ());
807+ currentProjects = storeCurrentProjects ;
802808 return ;
803809 }
804810
@@ -811,7 +817,6 @@ protected IStatus run(IProgressMonitor arg0) {
811817 sync .asyncExec (() -> {
812818 branchComboViewer .setInput (currentBranches );
813819 PluginUtils .setTextForComboViewer (branchComboViewer , currentBranches .isEmpty () ? NO_BRANCHES_AVAILABLE : BRANCH_COMBO_VIEWER_TEXT );
814-
815820 PluginUtils .enableComboViewer (branchComboViewer , true );
816821 PluginUtils .enableComboViewer (scanIdComboViewer , true );
817822 PluginUtils .updateFiltersEnabledAndCheckedState (toolBarActions .getFilterActions ());
@@ -823,6 +828,13 @@ protected IStatus run(IProgressMonitor arg0) {
823828 }
824829 };
825830 job .schedule ();
831+ //After project selected and branches loaded reset the project list
832+ if (resetStoredProjects ) {
833+ storeCurrentProjects .add (selectedProject );
834+ preservCaretposition (storeCurrentProjects , selectedProject .getName ());
835+ currentProjects = storeCurrentProjects ;
836+ resetStoredProjects =false ;
837+ }
826838 }
827839 }
828840 });
@@ -831,6 +843,7 @@ protected IStatus run(IProgressMonitor arg0) {
831843 projectComboViewer .getCombo ().addModifyListener (e -> {
832844 if (isUpdatingCombo ) return ;
833845 String enteredProject = projectComboViewer .getCombo ().getText ().trim ();
846+
834847 // Skip search if the text is the default instruction
835848 if (enteredProject .equals (PROJECT_COMBO_VIEWER_TEXT ) || enteredProject .equals (LOADING_PROJECTS )) {
836849 updateStartScanButton (false ); // Disable scan button
@@ -839,10 +852,7 @@ protected IStatus run(IProgressMonitor arg0) {
839852 // If user starts typing again and list is empty, restore currentProjects
840853 if (projectComboViewer .getCombo ().getItemCount () == 0 && !currentProjects .isEmpty () && enteredProject .length ()>0 ) {
841854 isUpdatingCombo = true ;
842- int caretPos = projectComboViewer .getCombo ().getCaretPosition ();
843- projectComboViewer .setInput (currentProjects );
844- PluginUtils .setTextForComboViewer (projectComboViewer , enteredProject );
845- projectComboViewer .getCombo ().setSelection (new Point (caretPos , caretPos ));
855+ preservCaretposition (currentProjects ,enteredProject );
846856 isUpdatingCombo = false ;
847857 }
848858
@@ -874,13 +884,11 @@ protected IStatus run(IProgressMonitor monitor) {
874884 isUpdatingCombo = true ;
875885 // Update UI in UI thread
876886 if (searchedProjects != null && !searchedProjects .isEmpty ()) {
877- projectComboViewer . setInput (searchedProjects );
887+ preservCaretposition (searchedProjects , searchTerm );
878888 currentProjects = searchedProjects ;
889+ resetStoredProjects =true ;
879890 } else {
880- int caretPos = projectComboViewer .getCombo ().getCaretPosition ();
881- projectComboViewer .setInput (Collections .emptyList ());
882- PluginUtils .setTextForComboViewer (projectComboViewer , searchTerm );
883- projectComboViewer .getCombo ().setSelection (new Point (caretPos , caretPos ));
891+ preservCaretposition (Collections .emptyList (),searchTerm );
884892 updateStartScanButton (false ); // Disable scan button
885893 isUpdatingCombo = false ;
886894 return ;
@@ -898,6 +906,7 @@ protected IStatus run(IProgressMonitor monitor) {
898906 }
899907 };
900908 debounceTimer .schedule (pendingSearchTask , DEBOUNCE_DELAY_MS );
909+
901910 }
902911 });
903912
@@ -2595,6 +2604,7 @@ private void clearAndRefreshPlugin() {
25952604 @ Override
25962605 protected IStatus run (IProgressMonitor arg0 ) {
25972606 currentProjects = getProjects ();
2607+ storeCurrentProjects = currentProjects ;
25982608 sync .asyncExec (() -> {
25992609 projectComboViewer .setInput (currentProjects );
26002610 projectComboViewer .refresh ();
@@ -2787,4 +2797,17 @@ private void updateStartScanButton(boolean enabled) {
27872797 toolBarActions .getStartScanAction ().setEnabled (false );
27882798 }
27892799 }
2800+
2801+ /**
2802+ * Store the user entered value and the caret position
2803+ *
2804+ * @param projectList
2805+ * @param searchText
2806+ */
2807+ private void preservCaretposition ( List <Project > projectList , String searchText ) {
2808+ int caretPos = projectComboViewer .getCombo ().getCaretPosition ();
2809+ projectComboViewer .setInput (projectList );
2810+ PluginUtils .setTextForComboViewer (projectComboViewer , searchText );
2811+ projectComboViewer .getCombo ().setSelection (new Point (caretPos , caretPos ));
2812+ }
27902813}
0 commit comments