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
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
import com.magento.idea.magento2plugin.actions.generation.CreateAnObserverAction;
import com.magento.idea.magento2plugin.actions.generation.data.ObserverEventsXmlData;
import com.magento.idea.magento2plugin.actions.generation.data.ObserverFileData;
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.CreateAnObserverDialogValidator;
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.AlphanumericWithUnderscoreRule;
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.ObserverClassGenerator;
import com.magento.idea.magento2plugin.actions.generation.generator.ObserverEventsXmlGenerator;
import com.magento.idea.magento2plugin.indexes.ModuleIndex;
Expand All @@ -36,26 +41,47 @@
"PMD.MissingSerialVersionUID",
"PMD.DataClass",
"PMD.UnusedPrivateField",
"PMD.ExcessiveImports",
})
public class CreateAnObserverDialog extends AbstractDialog {
@NotNull
private final Project project;
@NotNull
private final CreateAnObserverDialogValidator validator;
private final String targetEvent;
private JPanel contentPane;
private JButton buttonOK;
private JButton buttonCancel;
private JTextField observerClassName;
private JTextField observerDirectory;
private FilteredComboBox observerModule;
private JComboBox observerArea;
private JTextField observerName;
private JLabel observerClassNameLabel;
private JLabel observerDirectoryName;
private JLabel selectObserverModule;
private JLabel observerAreaLabel;
private JLabel observerNameLabel;
private static final String OBSERVER_MODULE = "target module";
private static final String OBSERVER_CLASS = "class name";
private static final String OBSERVER_DIRECTORY = "directory";
private static final String OBSERVER_NAME = "name";

@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
message = {NotEmptyRule.MESSAGE, OBSERVER_MODULE})
private FilteredComboBox observerModule;

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

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

@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
message = {NotEmptyRule.MESSAGE, OBSERVER_NAME})
@FieldValidation(rule = RuleRegistry.ALPHANUMERIC_WITH_UNDERSCORE,
message = {AlphanumericWithUnderscoreRule.MESSAGE, OBSERVER_NAME})
private JTextField observerName;

/**
* Constructor.
Expand All @@ -68,7 +94,6 @@ public CreateAnObserverDialog(@NotNull final Project project, final String targe

this.project = project;
this.targetEvent = targetEvent;
this.validator = CreateAnObserverDialogValidator.getInstance(this);

setContentPane(contentPane);
setModal(true);
Expand Down Expand Up @@ -119,7 +144,7 @@ private void fillTargetAreaOptions() {
* Perform code generation using input data.
*/
private void onOK() {
if (!validator.validate(project)) {
if (!validateFormFields()) {
return;
}
new ObserverClassGenerator(new ObserverFileData(
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

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

import com.jetbrains.php.refactoring.PhpNameUtil;
import com.magento.idea.magento2plugin.util.RegExUtil;

public class PhpClassRule implements ValidationRule {
Expand All @@ -13,7 +14,7 @@ public class PhpClassRule implements ValidationRule {

@Override
public boolean check(final String value) {
return value.matches(RegExUtil.Magento.PHP_CLASS);
return value.matches(RegExUtil.Magento.PHP_CLASS) && PhpNameUtil.isValidClassName(value);
}

public static ValidationRule getInstance() {
Expand Down