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
2 changes: 1 addition & 1 deletion resources/magento2/common.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ common.httpMethod=HTTP Method
common.controller.name=Controller Name
common.controller.inheritAction=Inherit Action Class
common.controller.backend.acl=Admin Resource ACL
common.controller.action=Controller Action
common.controller.action=Action Name
common.ok=OK
common.yes=Yes
common.no=No
Expand Down
6 changes: 3 additions & 3 deletions resources/magento2/validation.properties
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
validator.notEmpty=The {0} field must not be empty
validator.package.validPath=Please specify a valid Magento 2 installation path
validator.alphaNumericCharacters={0} must contain letters and numbers only
validator.alphaNumericCharacters=The {0} must contain letters and numbers only
validator.alphaNumericAndUnderscoreCharacters={0} must contain letters, numbers and underscores only
validator.alreadyDeclared={0} is already declared in the {1} module.
validator.startWithNumberOrCapitalLetter={0} must start from a number or a capital letter
validator.startWithNumberOrCapitalLetter=The {0} must start from a number or a capital letter
validator.onlyNumbers={0} must contain numbers only
validator.mustNotBeNegative={0} must not be negative
validator.identifier={0} must contain letters, numbers, dashes, and underscores only
validator.class.isNotValid=The {0} field does not contain a valid class name
validator.class.shouldBeUnique=Duplicated class {0}
validator.namespace.isNotValid={0} is not valid namespace name
validator.namespace.isNotValid=The {0} is not valid namespace name
validator.directory.isNotValid={0} is not valid
validator.directory.php.isNotValid=The {0} field does not contain a valid PHP directory
validator.module.noSuchModule=No such module {0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
import com.intellij.psi.PsiFile;
import com.magento.idea.magento2plugin.actions.generation.NewControllerAction;
import com.magento.idea.magento2plugin.actions.generation.data.ControllerFileData;
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.NewControllerValidator;
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.NotEmptyRule;
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.PhpClassRule;
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.PhpDirectoryRule;
import com.magento.idea.magento2plugin.actions.generation.generator.ModuleControllerClassGenerator;
import com.magento.idea.magento2plugin.magento.files.ControllerBackendPhp;
import com.magento.idea.magento2plugin.magento.files.ControllerFrontendPhp;
Expand All @@ -21,7 +25,6 @@
import com.magento.idea.magento2plugin.ui.FilteredComboBox;
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 @@ -37,22 +40,35 @@

@SuppressWarnings({
"PMD.TooManyFields",
"PMD.ConstructorCallsOverridableMethod"
"PMD.ConstructorCallsOverridableMethod",
"PMD.ExcessiveImports"
})
public class NewControllerDialog extends AbstractDialog {
private final NewControllerValidator validator;
private final String moduleName;
private final Project project;
private JPanel contentPane;
private JButton buttonOK;
private JButton buttonCancel;
private FilteredComboBox controllerAreaSelect;
private FilteredComboBox httpMethodSelect;
private JTextField controllerName;
private JTextField controllerParentDir;
private JCheckBox inheritClass;
private JPanel adminPanel;
private JTextField acl;

private static final String CONTROLLER_NAME = "controller name";
private static final String ACTION_NAME = "action name";

@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
message = {NotEmptyRule.MESSAGE, CONTROLLER_NAME})
@FieldValidation(rule = RuleRegistry.PHP_DIRECTORY,
message = {PhpDirectoryRule.MESSAGE, CONTROLLER_NAME})
private JTextField controllerName;

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

/**
Expand All @@ -65,7 +81,6 @@ public NewControllerDialog(final Project project, final PsiDirectory directory)
super();
this.project = project;
this.moduleName = GetModuleNameByDirectoryUtil.execute(directory, project);
this.validator = NewControllerValidator.getInstance(this);

setContentPane(contentPane);
setModal(true);
Expand All @@ -87,11 +102,7 @@ public void windowClosing(final WindowEvent event) {

// call onCancel() on ESCAPE
contentPane.registerKeyboardAction(
new ActionListener() {
public void actionPerformed(final ActionEvent event) {
onCancel();
}
},
(final ActionEvent event) -> onCancel(),
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
);
Expand Down Expand Up @@ -178,7 +189,7 @@ public static void open(final Project project, final PsiDirectory directory) {
}

private void onOK() {
if (!validator.validate()) {
if (!validateFormFields()) {
return;
}

Expand Down Expand Up @@ -243,6 +254,7 @@ private Boolean getIsInheritClass() {
return inheritClass.isSelected();
}

@Override
protected void onCancel() {
dispose();
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

package com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule;

import com.magento.idea.magento2plugin.util.RegExUtil;
Expand Down