17
17
import com .magento .idea .magento2plugin .actions .generation .data .dialog .NewEntityDialogData ;
18
18
import com .magento .idea .magento2plugin .actions .generation .data .ui .ComboBoxItemData ;
19
19
import com .magento .idea .magento2plugin .actions .generation .dialog .util .ClassPropertyFormatterUtil ;
20
+ import com .magento .idea .magento2plugin .actions .generation .dialog .util .ProcessWorker ;
20
21
import com .magento .idea .magento2plugin .actions .generation .dialog .validator .annotation .FieldValidation ;
21
22
import com .magento .idea .magento2plugin .actions .generation .dialog .validator .annotation .RuleRegistry ;
22
23
import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .AclResourceIdRule ;
57
58
import com .magento .idea .magento2plugin .util .FirstLetterToLowercaseUtil ;
58
59
import com .magento .idea .magento2plugin .util .magento .GetAclResourcesListUtil ;
59
60
import com .magento .idea .magento2plugin .util .magento .GetModuleNameByDirectoryUtil ;
61
+ import java .awt .Cursor ;
60
62
import java .awt .event .ActionEvent ;
61
63
import java .awt .event .KeyAdapter ;
62
64
import java .awt .event .KeyEvent ;
@@ -184,6 +186,7 @@ public class NewEntityDialog extends AbstractDialog {
184
186
private JTextPane exampleGridName ;
185
187
private JPanel uiComponentsPanel ;
186
188
private JTextField observerName ;
189
+ private final ProcessWorker .InProgressFlag onOkActionFired ;
187
190
188
191
/**
189
192
* Constructor.
@@ -203,7 +206,8 @@ public NewEntityDialog(final @NotNull Project project, final PsiDirectory direct
203
206
setTitle (NewEntityAction .ACTION_DESCRIPTION );
204
207
getRootPane ().setDefaultButton (buttonOK );
205
208
206
- buttonOK .addActionListener ((final ActionEvent event ) -> onOK ());
209
+ onOkActionFired = new ProcessWorker .InProgressFlag (false );
210
+ buttonOK .addActionListener (this ::generateNewEntityFiles );
207
211
buttonCancel .addActionListener ((final ActionEvent event ) -> onCancel ());
208
212
209
213
// call onCancel() when cross is clicked
@@ -294,13 +298,35 @@ private void initPropertiesTable() {
294
298
entityPropertiesTableGroupWrapper .initTableGroup ();
295
299
}
296
300
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
+
297
320
/**
298
321
* Perform code generation using input data.
299
322
*/
300
323
private void onOK () {
301
324
if (!validateFormFields ()) {
325
+ onOkActionFired .setInProgress (false );
302
326
return ;
303
327
}
328
+ setCursor (new Cursor (Cursor .WAIT_CURSOR ));
329
+
304
330
formatProperties ();
305
331
306
332
final NewEntityDialogData dialogData = getNewEntityDialogData ();
@@ -315,8 +341,20 @@ private void onOK() {
315
341
);
316
342
317
343
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 );
318
354
319
- this .setVisible (false );
355
+ if (onOkActionFired .isFinished ()) {
356
+ this .setVisible (false );
357
+ }
320
358
}
321
359
322
360
/**
0 commit comments