|
31 | 31 | import java.util.Arrays;
|
32 | 32 | import java.util.List;
|
33 | 33 | import java.util.Properties;
|
| 34 | +import java.util.concurrent.atomic.AtomicBoolean; |
34 | 35 | import javax.swing.JOptionPane;
|
35 | 36 |
|
36 | 37 | public class ModuleControllerClassGenerator extends FileGenerator {
|
@@ -73,47 +74,49 @@ public ModuleControllerClassGenerator(
|
73 | 74 | @Override
|
74 | 75 | public PsiFile generate(final String actionName) {
|
75 | 76 | final PsiFile[] controllerFiles = new PsiFile[1];
|
| 77 | + final AtomicBoolean isControllerExists = new AtomicBoolean(false); |
| 78 | + final AtomicBoolean isControllerCanNotBeCreated = new AtomicBoolean(false); |
76 | 79 |
|
77 | 80 | WriteCommandAction.runWriteCommandAction(project, () -> {
|
78 | 81 | PhpClass controller = GetPhpClassByFQN.getInstance(project).execute(
|
79 | 82 | getControllerFqn()
|
80 | 83 | );
|
81 | 84 |
|
82 | 85 | if (controller != null) {
|
83 |
| - final String errorMessage = this.validatorBundle.message( |
84 |
| - "validator.file.alreadyExists", |
85 |
| - "Controller Class" |
86 |
| - ); |
87 |
| - JOptionPane.showMessageDialog( |
88 |
| - null, |
89 |
| - errorMessage, |
90 |
| - commonBundle.message("common.error"), |
91 |
| - JOptionPane.ERROR_MESSAGE |
92 |
| - ); |
93 |
| - |
| 86 | + isControllerExists.set(true); |
94 | 87 | return;
|
95 | 88 | }
|
96 |
| - |
97 | 89 | controller = createControllerClass(actionName);
|
98 | 90 |
|
99 | 91 | if (controller == null) {
|
100 |
| - final String errorMessage = this.validatorBundle.message( |
101 |
| - "validator.file.cantBeCreated", |
102 |
| - "Controller Class" |
103 |
| - ); |
104 |
| - JOptionPane.showMessageDialog( |
105 |
| - null, |
106 |
| - errorMessage, |
107 |
| - commonBundle.message("common.error"), |
108 |
| - JOptionPane.ERROR_MESSAGE |
109 |
| - ); |
110 |
| - |
| 92 | + isControllerCanNotBeCreated.set(true); |
111 | 93 | return;
|
112 | 94 | }
|
113 |
| - |
114 | 95 | controllerFiles[0] = controller.getContainingFile();
|
115 | 96 | });
|
116 | 97 |
|
| 98 | + if (isControllerExists.get()) { |
| 99 | + JOptionPane.showMessageDialog( |
| 100 | + null, |
| 101 | + validatorBundle.message( |
| 102 | + "validator.file.alreadyExists", |
| 103 | + "Controller Class" |
| 104 | + ), |
| 105 | + commonBundle.message("common.error"), |
| 106 | + JOptionPane.ERROR_MESSAGE |
| 107 | + ); |
| 108 | + } else if (isControllerCanNotBeCreated.get()) { |
| 109 | + JOptionPane.showMessageDialog( |
| 110 | + null, |
| 111 | + validatorBundle.message( |
| 112 | + "validator.file.cantBeCreated", |
| 113 | + "Controller Class" |
| 114 | + ), |
| 115 | + commonBundle.message("common.error"), |
| 116 | + JOptionPane.ERROR_MESSAGE |
| 117 | + ); |
| 118 | + } |
| 119 | + |
117 | 120 | return controllerFiles[0];
|
118 | 121 | }
|
119 | 122 |
|
|
0 commit comments