8888import com .checkmarx .eclipse .Activator ;
8989import com .checkmarx .eclipse .enums .ActionName ;
9090import com .checkmarx .eclipse .enums .Severity ;
91+ import com .checkmarx .eclipse .properties .Preferences ;
9192import com .checkmarx .eclipse .utils .CxLogger ;
9293import com .checkmarx .eclipse .utils .NotificationPopUpUI ;
9394import com .checkmarx .eclipse .utils .PluginConstants ;
@@ -160,6 +161,7 @@ public class CheckmarxView extends ViewPart implements EventHandler {
160161 private Button triageButton ;
161162 private SelectionAdapter triageButtonAdapter , codeBashingAdapter ;
162163 private Shell shell = PlatformUI .getWorkbench ().getActiveWorkbenchWindow ().getShell ();
164+ private String lastApiKey ;
163165
164166 private boolean alreadyRunning = false ;
165167 private static List <LearnMore > learnMoreData ;
@@ -207,6 +209,7 @@ public class CheckmarxView extends ViewPart implements EventHandler {
207209 public CheckmarxView () {
208210 super ();
209211 sync = new UISynchronizeImpl (PlatformUI .getWorkbench ().getDisplay ());
212+ lastApiKey = Preferences .STORE .getString (Preferences .API_KEY );
210213 rootModel = new DisplayModel .DisplayModelBuilder (PluginConstants .EMPTY_STRING ).build ();
211214 globalSettings .loadSettings ();
212215 currentProjectId = globalSettings .getProjectId ();
@@ -714,9 +717,17 @@ private void drawAttackVectorSeparator(Composite parent) {
714717 * Draw panel when Checkmarx credentials are not defined
715718 */
716719 private void drawMissingCredentialsPanel () {
720+
721+ // Dispose all children to remove any previous panels
722+ for (Control child : parent .getChildren ()) {
723+ child .dispose ();
724+ }
717725 openSettingsComposite = new Composite (parent , SWT .NONE );
718726
719727 openSettingsComposite .setLayout (new GridLayout (1 , true ));
728+
729+ // This is the key line: center horizontally and vertically, and expand to fill
730+ openSettingsComposite .setLayoutData (new GridData (SWT .CENTER , SWT .CENTER , true , true ));
720731
721732 final Label hidden = new Label (openSettingsComposite , SWT .NONE );
722733 hidden .setLayoutData (new GridData (SWT .CENTER , SWT .CENTER , true , false ));
@@ -742,6 +753,7 @@ public void handleEvent(Event arg0) {
742753 }
743754 }
744755 });
756+ parent .layout (true , true );
745757 }
746758
747759 private void createProjectListComboBox (Composite parent ) {
@@ -779,7 +791,6 @@ public void selectionChanged(SelectionChangedEvent event) {
779791 updateStartScanButton (false );
780792 return ;
781793 }
782-
783794 // Avoid non-sense trigger changed when opening the combo
784795 if (selectedProject .getId ().equals (currentProjectId )) {
785796 CxLogger .info (PluginConstants .INFO_CHANGE_PROJECT_EVENT_NOT_TRIGGERED );
@@ -1153,6 +1164,7 @@ private String formatScanLabel(Scan scan) {
11531164 */
11541165
11551166 private Scan getLatestScanFromScanList (List <Scan > scanList ) {
1167+
11561168 return scanList .get (0 );
11571169 }
11581170
@@ -1425,7 +1437,7 @@ public void widgetSelected(SelectionEvent event) {
14251437
14261438 Job job = new Job ("Checkmarx: Updating triage information..." ) {
14271439 String comment = commentText .getText () != null
1428- && !commentText .getText ().equalsIgnoreCase ("Notes" ) ? commentText .getText ()
1440+ && !commentText .getText ().equalsIgnoreCase ("Notes (Optional or required based on tenant configuration) " ) ? commentText .getText ()
14291441 : "" ;
14301442
14311443 @ Override
@@ -2686,16 +2698,32 @@ private void enablePluginFields(boolean enableBranchCombobox) {
26862698 */
26872699 @ Override
26882700 public void handleEvent (org .osgi .service .event .Event arg0 ) {
2689- if (!isPluginDraw ) {
2701+ String currentApiKey = Preferences .STORE .getString (Preferences .API_KEY );
2702+ if (!currentApiKey .isEmpty () && !isPluginDraw ) {
26902703 drawPluginPanel ();
26912704 } else {
2692- // If authenticated successfully and the projects are empty try to get them again
2693- if (projectComboViewer .getCombo ().getItemCount () == 0 ) {
2694- clearAndRefreshPlugin ();
2705+ // If credentials changed reload projects, branches and scans from new tenant
2706+ if (currentApiKey .isEmpty ()) {
2707+ updateStartScanButton (false );
2708+ drawMissingCredentialsPanel ();
2709+ //Dispose toolbar
2710+ if (toolBarActions != null ) {
2711+ toolBarActions .disposeToolbar ();
2712+ toolBarActions = null ;
2713+ }
2714+ isPluginDraw = false ;
2715+ } else if (lastApiKey .equalsIgnoreCase (currentApiKey )) {
2716+ return ;
2717+ } else {
2718+ // clear result section
2719+ PluginUtils .clearMessage (rootModel , resultsTree );
2720+ // Reset state variables
2721+ currentProjectId = PluginConstants .EMPTY_STRING ;
2722+ currentBranch = PluginConstants .EMPTY_STRING ;
2723+ currentScanId = PluginConstants .EMPTY_STRING ;
2724+ loadComboboxes ();
26952725 }
2696-
2697- toolBarActions .refreshToolbar ();
2698- updateStartScanButton (true );
2726+ lastApiKey =currentApiKey ;
26992727 }
27002728 }
27012729
0 commit comments