Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -12,7 +12,11 @@
import com.magento.idea.magento2plugin.actions.generation.data.ModuleComposerJsonData;
import com.magento.idea.magento2plugin.actions.generation.data.ModuleRegistrationPhpData;
import com.magento.idea.magento2plugin.actions.generation.data.ModuleXmlData;
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.NewModuleDialogValidator;
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.NotEmptyRule;
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.StartWithNumberOrCapitalLetterRule;
import com.magento.idea.magento2plugin.actions.generation.generator.ModuleComposerJsonGenerator;
import com.magento.idea.magento2plugin.actions.generation.generator.ModuleRegistrationPhpGenerator;
import com.magento.idea.magento2plugin.actions.generation.generator.ModuleXmlGenerator;
Expand All @@ -24,7 +28,6 @@
import com.magento.idea.magento2plugin.util.CamelCaseToHyphen;
import com.magento.idea.magento2plugin.util.magento.MagentoVersionUtil;
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 @@ -46,33 +49,63 @@

@SuppressWarnings({"PMD.TooManyFields", "PMD.DataClass", "PMD.UnusedPrivateMethod"})
public class NewModuleDialog extends AbstractDialog implements ListSelectionListener { //NOPMD
@NotNull
private final Project project;
@NotNull
private final PsiDirectory initialBaseDir;
private final NewModuleDialogValidator validator;
private final CamelCaseToHyphen camelCaseToHyphen;
private JPanel contentPane;
private JButton buttonOK;
private JButton buttonCancel;
private static final String MODULE_DESCRIPTION = "module description";
private static final String MODULE_VERSION = "module version";
private static final String MODULE_NAME = "module name";
private static final String PACKAGE_NAME = "package name";

@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
message = {NotEmptyRule.MESSAGE, PACKAGE_NAME})
@FieldValidation(rule = RuleRegistry.START_WITH_NUMBER_OR_CAPITAL_LETTER,
message = {StartWithNumberOrCapitalLetterRule.MESSAGE, PACKAGE_NAME})
@FieldValidation(rule = RuleRegistry.ALPHANUMERIC,
message = {AlphanumericRule.MESSAGE, PACKAGE_NAME})
private JTextField packageName;
private JLabel packageNameLabel;

/* TODO: module name !== package name */
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
message = {NotEmptyRule.MESSAGE, MODULE_NAME})
@FieldValidation(rule = RuleRegistry.START_WITH_NUMBER_OR_CAPITAL_LETTER,
message = {StartWithNumberOrCapitalLetterRule.MESSAGE, MODULE_NAME})
@FieldValidation(rule = RuleRegistry.ALPHANUMERIC,
message = {AlphanumericRule.MESSAGE, MODULE_NAME})
private JTextField moduleName;

@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
message = {NotEmptyRule.MESSAGE, MODULE_DESCRIPTION})
private JTextArea moduleDescription;
private final ModuleIndex moduleIndex;

@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
message = {NotEmptyRule.MESSAGE, MODULE_VERSION})
private JTextField moduleVersion;
private String detectedPackageName;

private JTextField moduleLicenseCustom;

private JList moduleDependencies;
private JList moduleLicense;
private JTextField moduleLicenseCustom;
private JLabel moduleLicenseLabel;//NOPMD

private JScrollPane moduleLicenseScrollPanel;//NOPMD
private JScrollPane moduleDependenciesScrollPanel;//NOPMD

private JLabel moduleLicenseLabel;//NOPMD
private JLabel moduleVersionLabel;//NOPMD
private JLabel moduleDependenciesLabel;//NOPMD
private JScrollPane moduleDependenciesScrollPanel;//NOPMD
private JLabel moduleDescriptionLabel;//NOPMD
private JLabel moduleNameLabel;//NOPMD
private JLabel packageNameLabel;

private JPanel contentPane;

private JButton buttonOK;
private JButton buttonCancel;

@NotNull
private final Project project;
@NotNull
private final PsiDirectory initialBaseDir;
private String detectedPackageName;
private final ModuleIndex moduleIndex;
private final CamelCaseToHyphen camelCaseToHyphen;
private static final String MAGENTO_BEFORE_DECLARATIVE_SCHEMA_VERSION = "2.2.11";

/**
Expand All @@ -90,7 +123,6 @@ public NewModuleDialog(
this.project = project;
this.initialBaseDir = initialBaseDir;
this.camelCaseToHyphen = CamelCaseToHyphen.getInstance();
this.validator = NewModuleDialogValidator.getInstance(this);
this.moduleIndex = ModuleIndex.getInstance(project);
detectPackageName(initialBaseDir);
setContentPane(contentPane);
Expand All @@ -102,19 +134,8 @@ public NewModuleDialog(
moduleLicenseCustom.setToolTipText("Custom License Name");
moduleLicenseCustom.setText(Settings.getDefaultLicenseName(project));

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 @@ -124,13 +145,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
);
}

private void detectPackageName(final @NotNull PsiDirectory initialBaseDir) {
Expand All @@ -143,7 +162,7 @@ private void detectPackageName(final @NotNull PsiDirectory initialBaseDir) {
}

protected void onOK() {
if (!validator.validate()) {
if (!validateFormFields()) {
return;
}
generateFiles();
Expand Down

This file was deleted.