Skip to content
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
3 changes: 2 additions & 1 deletion resources/magento2/common.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ common.module.target=Target Module
common.theme.target=Target Theme
common.area.target=Target Area
common.name=Name
common.className=Class Name
common.className=Class name
common.argument=Argument name
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @VitaliyBoyko, @coderimus. I was just doing some local testing and I noticed that this line (line 26) with the value for common.argument is missing from the current codebase? This PR was merged but this particular file doesn't seem to be 'registered' in the git commit history? I'm very confused, maybe I'm missing something. Could you please check on this? Thanks.

common.directoryPath=Directory Path
common.methodType=Method Type
common.sortOrder=Sort Order
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Argument Name"/>
<text resource-bundle="magento2/common" key="common.argument"/>
</properties>
</component>
<component id="c3a92" class="javax.swing.JTextField" binding="viewModelArgumentName">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@
import com.intellij.ui.DocumentAdapter;
import com.magento.idea.magento2plugin.actions.generation.InjectAViewModelAction;
import com.magento.idea.magento2plugin.actions.generation.data.ViewModelFileData;
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.InjectAViewModelDialogValidator;
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.FieldValidation;
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.RuleRegistry;
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.AlphanumericRule;
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.DirectoryRule;
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NotEmptyRule;
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.PhpClassRule;
import com.magento.idea.magento2plugin.actions.generation.generator.ModuleViewModelClassGenerator;
import com.magento.idea.magento2plugin.actions.generation.generator.code.ClassArgumentInXmlConfigGenerator;
import com.magento.idea.magento2plugin.actions.generation.generator.util.NamespaceBuilder;
Expand All @@ -21,7 +26,6 @@
import com.magento.idea.magento2plugin.util.FirstLetterToLowercaseUtil;
import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
Expand All @@ -35,24 +39,43 @@
import javax.swing.event.DocumentEvent;
import org.jetbrains.annotations.NotNull;

@SuppressWarnings({
"PMD.ExcessiveImports"
})
public class InjectAViewModelDialog extends AbstractDialog {
@NotNull
private final Project project;
@NotNull
private final InjectAViewModelDialogValidator validator;
private final XmlTag targetBlockTag;
private JPanel contentPane;
private JButton buttonOK;
private JButton buttonCancel;
private JTextField viewModelClassName;
private JTextField viewModelDirectory;
private final CommonBundle commonBundle;
private final ValidatorBundle validatorBundle;
private JTextField viewModelArgumentName;
private JLabel inheritClassLabel;//NOPMD
private JLabel viewModelDirectoryLabel;//NOPMD
private JLabel viewModelClassNameLabel;//NOPMD
private JLabel viewModelArgumentNameLabel;//NOPMD
private static final String CLASS_NAME = "class name";
private static final String DIRECTORY = "directory";
private static final String ARGUMENT_NAME = "argument name";

@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
message = {NotEmptyRule.MESSAGE, CLASS_NAME})
@FieldValidation(rule = RuleRegistry.PHP_CLASS,
message = {PhpClassRule.MESSAGE, CLASS_NAME})
private JTextField viewModelClassName;

@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
message = {NotEmptyRule.MESSAGE, DIRECTORY})
@FieldValidation(rule = RuleRegistry.DIRECTORY,
message = {DirectoryRule.MESSAGE, DIRECTORY})
private JTextField viewModelDirectory;

@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
message = {NotEmptyRule.MESSAGE, ARGUMENT_NAME})
@FieldValidation(rule = RuleRegistry.ALPHANUMERIC,
message = {AlphanumericRule.MESSAGE, ARGUMENT_NAME})
private JTextField viewModelArgumentName;

/**
* Constructor.
Expand All @@ -68,7 +91,6 @@ public InjectAViewModelDialog(

this.project = project;
this.targetBlockTag = targetBlockTag;
this.validator = new InjectAViewModelDialogValidator(this);
this.validatorBundle = new ValidatorBundle();
this.commonBundle = new CommonBundle();

Expand All @@ -84,19 +106,8 @@ protected void textChanged(final @NotNull DocumentEvent event) {
setModal(true);
getRootPane().setDefaultButton(buttonOK);

buttonOK.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent event) {
onOK();
}
});

buttonCancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent event) {
onCancel();
}
});
buttonOK.addActionListener((final ActionEvent event) -> onOK());
buttonCancel.addActionListener((final ActionEvent event) -> onCancel());

setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
Expand All @@ -106,13 +117,11 @@ public void windowClosing(final WindowEvent event) {
}
});

contentPane.registerKeyboardAction(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent event) {
onCancel();
}
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
contentPane.registerKeyboardAction(
(final ActionEvent event) -> onCancel(),
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
);
}

protected void updateArgumentText() {
Expand All @@ -123,7 +132,7 @@ protected void updateArgumentText() {
}

protected void onOK() {
if (!validator.validate(project)) {
if (!validateFormFields()) {
return;
}
final String moduleName = GetModuleNameByDirectoryUtil.execute(
Expand Down

This file was deleted.