1717import com .magento .idea .magento2plugin .actions .generation .data .dialog .NewEntityDialogData ;
1818import com .magento .idea .magento2plugin .actions .generation .data .ui .ComboBoxItemData ;
1919import com .magento .idea .magento2plugin .actions .generation .dialog .util .ClassPropertyFormatterUtil ;
20+ import com .magento .idea .magento2plugin .actions .generation .dialog .util .ProcessWorker ;
2021import com .magento .idea .magento2plugin .actions .generation .dialog .validator .annotation .FieldValidation ;
2122import com .magento .idea .magento2plugin .actions .generation .dialog .validator .annotation .RuleRegistry ;
2223import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .AclResourceIdRule ;
5758import com .magento .idea .magento2plugin .util .FirstLetterToLowercaseUtil ;
5859import com .magento .idea .magento2plugin .util .magento .GetAclResourcesListUtil ;
5960import com .magento .idea .magento2plugin .util .magento .GetModuleNameByDirectoryUtil ;
61+ import java .awt .Cursor ;
6062import java .awt .event .ActionEvent ;
6163import java .awt .event .KeyAdapter ;
6264import java .awt .event .KeyEvent ;
@@ -184,6 +186,7 @@ public class NewEntityDialog extends AbstractDialog {
184186 private JTextPane exampleGridName ;
185187 private JPanel uiComponentsPanel ;
186188 private JTextField observerName ;
189+ private final ProcessWorker .InProgressFlag onOkActionFired ;
187190
188191 /**
189192 * Constructor.
@@ -203,7 +206,8 @@ public NewEntityDialog(final @NotNull Project project, final PsiDirectory direct
203206 setTitle (NewEntityAction .ACTION_DESCRIPTION );
204207 getRootPane ().setDefaultButton (buttonOK );
205208
206- buttonOK .addActionListener ((final ActionEvent event ) -> onOK ());
209+ onOkActionFired = new ProcessWorker .InProgressFlag (false );
210+ buttonOK .addActionListener (this ::generateNewEntityFiles );
207211 buttonCancel .addActionListener ((final ActionEvent event ) -> onCancel ());
208212
209213 // call onCancel() when cross is clicked
@@ -294,13 +298,35 @@ private void initPropertiesTable() {
294298 entityPropertiesTableGroupWrapper .initTableGroup ();
295299 }
296300
301+ /**
302+ * Generate new entity files.
303+ *
304+ * @param event ActionEvent
305+ */
306+ @ SuppressWarnings ("PMD.UnusedFormalParameter" )
307+ private void generateNewEntityFiles (final @ NotNull ActionEvent event ) {
308+ if (!onOkActionFired .isInProgress ()) {
309+ buttonOK .setEnabled (false );
310+ buttonCancel .setEnabled (false );
311+
312+ new ProcessWorker (
313+ this ::onOK ,
314+ this ::releaseDialogAfterGeneration ,
315+ onOkActionFired
316+ ).execute ();
317+ }
318+ }
319+
297320 /**
298321 * Perform code generation using input data.
299322 */
300323 private void onOK () {
301324 if (!validateFormFields ()) {
325+ onOkActionFired .setInProgress (false );
302326 return ;
303327 }
328+ setCursor (new Cursor (Cursor .WAIT_CURSOR ));
329+
304330 formatProperties ();
305331
306332 final NewEntityDialogData dialogData = getNewEntityDialogData ();
@@ -315,8 +341,20 @@ private void onOK() {
315341 );
316342
317343 generatorPoolHandler .run ();
344+ onOkActionFired .setFinished (true );
345+ }
346+
347+ /**
348+ * Release dialog buttons and hide.
349+ */
350+ private void releaseDialogAfterGeneration () {
351+ setCursor (new Cursor (Cursor .DEFAULT_CURSOR ));
352+ buttonCancel .setEnabled (true );
353+ buttonOK .setEnabled (true );
318354
319- this .setVisible (false );
355+ if (onOkActionFired .isFinished ()) {
356+ this .setVisible (false );
357+ }
320358 }
321359
322360 /**
0 commit comments