6464 */
6565public class NvsCsvEditorPage
6666{
67-
67+ private static final String DEFAULT_PARTITION_SIZE = "0x3000" ; //$NON-NLS-1$
6868 private Composite mainControl ;
6969 private IFile csvFile ;
7070 private Consumer <Boolean > dirtyStateListener ;
@@ -127,8 +127,34 @@ public void createControl()
127127 // Initial setup
128128 setMessage (Messages .NvsEditorDialog_DefaultMessage , IMessageProvider .INFORMATION );
129129 encryptAction .notifyListeners (SWT .Selection , null );
130- generateButton .setEnabled (false );
131- setErrorMessage (null );
130+ validateGenerationState (); // Set initial button state
131+ }
132+
133+ /**
134+ * Runs all validation checks for the "Generate Partition" action, updates the error map, and sets the button and
135+ * error message status.
136+ */
137+ private void validateGenerationState ()
138+ {
139+ // 1. Start with a clean slate
140+ validationErrors .clear ();
141+
142+ // 2. Run all individual validation checks
143+ String sizeError = validateSize ();
144+ if (!sizeError .isBlank ())
145+ {
146+ validationErrors .put (GeneratePartitionValidationError .SIZE_ERROR , sizeError );
147+ }
148+
149+ String encKeyError = validateEncKeyPath ();
150+ if (!encKeyError .isBlank ())
151+ {
152+ validationErrors .put (GeneratePartitionValidationError .ENCRYPTION_PATH_ERROR , encKeyError );
153+ }
154+
155+ // 3. Update all dependent UI from one single place
156+ setGenerationButtonStatus ();
157+ updateErrorMessage ();
132158 }
133159
134160 /**
@@ -188,9 +214,7 @@ else if (mainControl != null && !mainControl.isDisposed())
188214 }
189215
190216 /**
191- * Called by NvsEditor's doSave() to perform the save logic.
192- *
193- * @return true if save was successful, false otherwise.
217+ * Called by NvsEditor's doSave() to perform the save logic. * @return true if save was successful, false otherwise.
194218 */
195219 public boolean getSaveAction ()
196220 {
@@ -205,7 +229,16 @@ public boolean getSaveAction()
205229 }
206230
207231 new NvsTableDataService ().saveCsv (csvFile , beansToSave );
208- setMessage (Messages .NvsTableEditorDialog_SaveInfoMsg , IMessageProvider .INFORMATION );
232+
233+ String baseMessage = Messages .NvsTableEditorDialog_SaveInfoMsg ;
234+ String status = statusText .getText ();
235+
236+ if (status != null && !status .isBlank ())
237+ {
238+ baseMessage = baseMessage + StringUtil .LINE_SEPARATOR + status ;
239+ }
240+
241+ setMessage (baseMessage , IMessageProvider .INFORMATION );
209242 Logger .log (Messages .NvsTableEditorDialog_SaveInfoMsg );
210243 try
211244 {
@@ -244,8 +277,9 @@ public void updateErrorMessage()
244277 }
245278 if (!validationErrors .isEmpty ())
246279 {
247- newErrorMessage = newErrorMessage .isBlank () ? newErrorMessage
248- : newErrorMessage .concat (StringUtil .LINE_SEPARATOR ).concat (" " ); //$NON-NLS-1$
280+ if (newErrorMessage != null && !newErrorMessage .isBlank ())
281+ newErrorMessage = newErrorMessage .concat (StringUtil .LINE_SEPARATOR ).concat (" " ); //$NON-NLS-1$
282+
249283 List <String > valuesArr = new ArrayList <>();
250284 for (Entry <GeneratePartitionValidationError , String > errorEntry : validationErrors .entrySet ())
251285 {
@@ -256,7 +290,6 @@ public void updateErrorMessage()
256290
257291 }
258292
259- newErrorMessage = newErrorMessage .isBlank () ? null : newErrorMessage ;
260293 setErrorMessage (newErrorMessage );
261294 }
262295
@@ -284,11 +317,8 @@ public void widgetSelected(SelectionEvent e)
284317 {
285318 generateEncryptionKeyCheckBox .notifyListeners (SWT .Selection , null );
286319 }
287- else
288- {
289- validationErrors .remove (GeneratePartitionValidationError .ENCRYPTION_PATH_ERROR );
290- }
291320 markDirty ();
321+ validateGenerationState ();
292322 }
293323
294324 });
@@ -370,6 +400,7 @@ private void createEnctyptionLable(Composite parent)
370400 errorIconLabel .setToolTipText (errMsg );
371401 }
372402 markDirty ();
403+ validateGenerationState ();
373404 });
374405
375406 encyptionKeyBrowseButton .addSelectionListener (new SelectionAdapter ()
@@ -403,7 +434,6 @@ public void widgetSelected(SelectionEvent e)
403434 if (generateEncryptionKeyCheckBox .getSelection ())
404435 {
405436 canBeDisposedList .forEach (t -> t .setEnabled (false ));
406- validationErrors .remove (GeneratePartitionValidationError .ENCRYPTION_PATH_ERROR );
407437 errorIconLabel .setImage (null ); // Hide error when disabled
408438 errorIconLabel .setToolTipText (null );
409439 }
@@ -413,6 +443,7 @@ public void widgetSelected(SelectionEvent e)
413443 encryptionKeyText .notifyListeners (SWT .Modify , null );
414444 }
415445 markDirty ();
446+ validateGenerationState ();
416447 }
417448 });
418449 generateEncryptionKeyCheckBox .setSelection (true );
@@ -429,10 +460,11 @@ private void createSizeOfPartitionLable(Composite parent)
429460
430461 Label sizeOfPartitionLbl = new Label (sizeComposite , SWT .NONE );
431462 sizeOfPartitionLbl .setText (Messages .NvsTableEditorSizeOfPartitionLblMsg );
432- sizeOfPartitionLbl .setLayoutData (new GridData (GridData . FILL_BOTH ));
463+ sizeOfPartitionLbl .setLayoutData (new GridData (SWT . BEGINNING , SWT . CENTER , false , false ));
433464 sizeText = new Text (sizeComposite , SWT .BORDER );
434- sizeText .setLayoutData (new GridData (GridData . FILL_BOTH ));
465+ sizeText .setLayoutData (new GridData (SWT . FILL , SWT . CENTER , true , false ));
435466 sizeText .setMessage (Messages .NvsEditorDialog_DefaultSizeMsg );
467+
436468 ControlDecoration deco = new ControlDecoration (sizeText , SWT .RIGHT );
437469 Image image = FieldDecorationRegistry .getDefault ().getFieldDecoration (FieldDecorationRegistry .DEC_ERROR )
438470 .getImage ();
@@ -449,6 +481,7 @@ private void createSizeOfPartitionLable(Composite parent)
449481 deco .setDescriptionText (errMsg );
450482 }
451483 markDirty ();
484+ validateGenerationState ();
452485 });
453486
454487 }
@@ -723,20 +756,25 @@ private void createTable(Composite parent)
723756
724757 private void getGeneratePartitionAction ()
725758 {
726- String errorMsg = validateSize ();
727- errorMsg = errorMsg .isBlank () ? validateEncKeyPath () : errorMsg ;
759+ validateGenerationState ();
728760
729- if (errorMsg .isEmpty ())
761+ if (validationErrors .isEmpty ())
730762 {
731763 String infoMsg = NvsPartitionGenerator .generateNvsPartititon (encryptAction .getSelection (), getEncKeyPath (),
732764 sizeText .getText (), csvFile );
765+
766+ String status = statusText != null ? statusText .getText () : null ;
767+ if (status != null && !status .isBlank ())
768+ {
769+ infoMsg = infoMsg + StringUtil .LINE_SEPARATOR + status .trim ();
770+ }
771+
733772 setMessage (infoMsg , IMessageProvider .INFORMATION );
734773 Logger .log (infoMsg );
735774 }
736775 else
737776 {
738- setMessage (errorMsg , IMessageProvider .ERROR );
739- Logger .log (errorMsg );
777+ Logger .log ("NVS Partition Generation failed validation." ); //$NON-NLS-1$
740778 }
741779
742780 try
@@ -762,35 +800,27 @@ private String validateEncKeyPath()
762800 if (encryptAction .getSelection () && !generateEncryptionKeyCheckBox .getSelection ()
763801 && !new File (encKeyPath ).canRead ())
764802 {
765- validationErrors .put (GeneratePartitionValidationError .ENCRYPTION_PATH_ERROR ,
766- Messages .NvsEditorDialog_EncKeyCantBeReadErrMsg );
767803 return Messages .NvsEditorDialog_EncKeyCantBeReadErrMsg ;
768804 }
769- validationErrors .remove (GeneratePartitionValidationError .ENCRYPTION_PATH_ERROR );
770805
771806 return StringUtil .EMPTY ;
772807 }
773808
774809 private String validateSize ()
775810 {
776- Long decodedSize = 0l ;
811+ Long decodedSize = 0L ;
777812 try
778813 {
779814 decodedSize = Long .decode (sizeText .getText ());
780815 }
781816 catch (NumberFormatException e )
782817 {
783- validationErrors .put (GeneratePartitionValidationError .SIZE_ERROR ,
784- Messages .NvsEditorDialog_SizeValidationDecodedErr + e .getMessage ());
785818 return Messages .NvsEditorDialog_SizeValidationDecodedErr + e .getMessage ();
786819 }
787820 if (decodedSize < 4096 || decodedSize % 4096 != 0 )
788821 {
789- validationErrors .put (GeneratePartitionValidationError .SIZE_ERROR ,
790- Messages .NvsEditorDialog_WrongSizeFormatErrMsg );
791822 return Messages .NvsEditorDialog_WrongSizeFormatErrMsg ;
792823 }
793- validationErrors .remove (GeneratePartitionValidationError .SIZE_ERROR );
794824 return StringUtil .EMPTY ;
795825 }
796826
0 commit comments