Skip to content

Commit 40192fb

Browse files
Merge pull request #893 from Iamwade/857-fixed-error-when-class-already-exists
857: fixed error when class already exists
2 parents dc4b87d + ee07294 commit 40192fb

File tree

1 file changed

+27
-24
lines changed

1 file changed

+27
-24
lines changed

src/com/magento/idea/magento2plugin/actions/generation/generator/ModuleControllerClassGenerator.java

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.util.Arrays;
3232
import java.util.List;
3333
import java.util.Properties;
34+
import java.util.concurrent.atomic.AtomicBoolean;
3435
import javax.swing.JOptionPane;
3536

3637
public class ModuleControllerClassGenerator extends FileGenerator {
@@ -73,47 +74,49 @@ public ModuleControllerClassGenerator(
7374
@Override
7475
public PsiFile generate(final String actionName) {
7576
final PsiFile[] controllerFiles = new PsiFile[1];
77+
final AtomicBoolean isControllerExists = new AtomicBoolean(false);
78+
final AtomicBoolean isControllerCanNotBeCreated = new AtomicBoolean(false);
7679

7780
WriteCommandAction.runWriteCommandAction(project, () -> {
7881
PhpClass controller = GetPhpClassByFQN.getInstance(project).execute(
7982
getControllerFqn()
8083
);
8184

8285
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);
9487
return;
9588
}
96-
9789
controller = createControllerClass(actionName);
9890

9991
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);
11193
return;
11294
}
113-
11495
controllerFiles[0] = controller.getContainingFile();
11596
});
11697

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+
117120
return controllerFiles[0];
118121
}
119122

0 commit comments

Comments
 (0)