Skip to content

1269: fixed AWT events are not allowed inside write action #1271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,49 +64,53 @@ 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]
);
codeStyleSettings.adjustBeforeWrite();

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];
}

Expand All @@ -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;
}
Expand Down