diff --git a/CHANGELOG.md b/CHANGELOG.md index 69232b6ca..6c52e6490 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0). - Throwable: Stub index points to a file without PSI [#1232](https://github.com/magento/magento2-phpstorm-plugin/pull/1232) - Create an entity - delete button is displayed in a new entity form [#1268](https://github.com/magento/magento2-phpstorm-plugin/pull/1268) - Covered possible NullPointerException in InjectAViewModelDialog.java [#1213](https://github.com/magento/magento2-phpstorm-plugin/pull/1213) +- AWT events are not allowed inside write action [#1271](https://github.com/magento/magento2-phpstorm-plugin/pull/1271) ## 5.0.0 diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/ModuleGraphQlResolverClassGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/ModuleGraphQlResolverClassGenerator.java index c9e734284..ce7f43848 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/ModuleGraphQlResolverClassGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/ModuleGraphQlResolverClassGenerator.java @@ -64,35 +64,38 @@ public ModuleGraphQlResolverClassGenerator( @Override public PsiFile generate(final String actionName) { - final PsiFile[] graphQlFile = {null}; - WriteCommandAction.runWriteCommandAction(project, () -> { - PhpClass graphQlResolverClass = GetPhpClassByFQN.getInstance(project) - .execute(graphQlResolverFileData.getGraphQlResolverClassFqn()); - if (graphQlResolverClass == null) { - graphQlResolverClass = createGraphQlResolverClass(actionName); - } + final PhpClass[] graphQlResolverClass = {GetPhpClassByFQN.getInstance(project) + .execute(graphQlResolverFileData.getGraphQlResolverClassFqn())}; - if (graphQlResolverClass == null) { - final String errorMessage = validatorBundle.message( - "validator.file.cantBeCreated", - "GraphQL Resolver Class" - ); - JOptionPane.showMessageDialog( - null, - errorMessage, - commonBundle.message("common.error"), - JOptionPane.ERROR_MESSAGE - ); - - return; - } + if (graphQlResolverClass[0] == null) { + WriteCommandAction.runWriteCommandAction(project, () -> { + graphQlResolverClass[0] = createGraphQlResolverClass(actionName); + }); + } + + if (graphQlResolverClass[0] == null) { + final String errorMessage = validatorBundle.message( + "validator.file.cantBeCreated", + "GraphQL Resolver Class" + ); + JOptionPane.showMessageDialog( + null, + errorMessage, + commonBundle.message("common.error"), + JOptionPane.ERROR_MESSAGE + ); + + return null; + } + final PsiFile[] graphQlFile = {null}; + WriteCommandAction.runWriteCommandAction(project, () -> { final Properties attributes = new Properties(); final String methodTemplate = PhpCodeUtil.getCodeTemplate( GraphQlResolverPhp.GRAPHQL_RESOLVER_TEMPLATE_NAME, attributes, project); - graphQlFile[0] = graphQlResolverClass.getContainingFile(); + graphQlFile[0] = graphQlResolverClass[0].getContainingFile(); final CodeStyleSettings codeStyleSettings = new CodeStyleSettings( (PhpFile) graphQlFile[0] ); @@ -100,13 +103,14 @@ public PsiFile generate(final String actionName) { final PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(project); final Document document = psiDocumentManager.getDocument(graphQlFile[0]); - final int insertPos = getInsertPos(graphQlResolverClass); + final int insertPos = getInsertPos(graphQlResolverClass[0]); document.insertString(insertPos, methodTemplate); final int endPos = insertPos + methodTemplate.length() + 1; CodeStyleManager.getInstance(project).reformatText(graphQlFile[0], insertPos, endPos); psiDocumentManager.commitDocument(document); codeStyleSettings.restore(); }); + return graphQlFile[0]; } @@ -116,7 +120,7 @@ private int getInsertPos(final PhpClass graphQlResolverClass) { graphQlResolverClass, LeafPsiElement.class ); - for (final LeafPsiElement leafPsiElement: leafElements) { + for (final LeafPsiElement leafPsiElement : leafElements) { if (!MagentoPhpClass.CLOSING_TAG.equals(leafPsiElement.getText())) { continue; }