|
22 | 22 | import com.magento.idea.magento2plugin.actions.generation.generator.DataModelInterfaceGenerator; |
23 | 23 | import com.magento.idea.magento2plugin.actions.generation.generator.PreferenceDiXmlGenerator; |
24 | 24 | import com.magento.idea.magento2plugin.actions.generation.generator.util.NamespaceBuilder; |
| 25 | +import com.magento.idea.magento2plugin.bundles.CommonBundle; |
| 26 | +import com.magento.idea.magento2plugin.bundles.ValidatorBundle; |
25 | 27 | import com.magento.idea.magento2plugin.magento.files.DataModel; |
26 | 28 | import com.magento.idea.magento2plugin.magento.files.DataModelInterface; |
27 | 29 | import com.magento.idea.magento2plugin.ui.table.ComboBoxEditor; |
28 | 30 | import com.magento.idea.magento2plugin.ui.table.DeleteRowButton; |
29 | 31 | import com.magento.idea.magento2plugin.ui.table.TableButton; |
30 | 32 | import com.magento.idea.magento2plugin.util.GetPhpClassByFQN; |
| 33 | +import com.magento.idea.magento2plugin.util.RegExUtil; |
31 | 34 | import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; |
32 | 35 | import java.awt.event.ActionEvent; |
33 | 36 | import java.awt.event.KeyEvent; |
|
37 | 40 | import javax.swing.JButton; |
38 | 41 | import javax.swing.JCheckBox; |
39 | 42 | import javax.swing.JComponent; |
| 43 | +import javax.swing.JOptionPane; |
40 | 44 | import javax.swing.JPanel; |
41 | 45 | import javax.swing.JTable; |
42 | 46 | import javax.swing.JTextField; |
|
47 | 51 |
|
48 | 52 | @SuppressWarnings({ |
49 | 53 | "PMD.ExcessiveImports", |
| 54 | + "PMD.TooManyMethods", |
50 | 55 | }) |
51 | 56 | public class NewDataModelDialog extends AbstractDialog { |
52 | 57 | private final Project project; |
53 | 58 | private final String moduleName; |
| 59 | + private final ValidatorBundle validatorBundle; |
| 60 | + private final CommonBundle commonBundle; |
54 | 61 | private NamespaceBuilder interfaceNamespace; |
55 | 62 | private NamespaceBuilder modelNamespace; |
56 | 63 | private String formattedProperties; |
@@ -83,6 +90,8 @@ public NewDataModelDialog(final Project project, final PsiDirectory directory) { |
83 | 90 |
|
84 | 91 | this.project = project; |
85 | 92 | this.moduleName = GetModuleNameByDirectoryUtil.execute(directory, project); |
| 93 | + this.validatorBundle = new ValidatorBundle(); |
| 94 | + this.commonBundle = new CommonBundle(); |
86 | 95 |
|
87 | 96 | setContentPane(contentPanel); |
88 | 97 | setModal(true); |
@@ -132,6 +141,46 @@ private void onOK() { |
132 | 141 | } |
133 | 142 | } |
134 | 143 |
|
| 144 | + @Override |
| 145 | + protected boolean validateFormFields() { |
| 146 | + boolean valid = false; |
| 147 | + if (super.validateFormFields()) { |
| 148 | + valid = true; |
| 149 | + final String errorTitle = commonBundle.message("common.error"); |
| 150 | + final int column = 0; |
| 151 | + for (int row = 0; row < properties.getRowCount(); row++) { |
| 152 | + final String propertyName = ((String) properties.getValueAt(row, column)).trim(); |
| 153 | + if (propertyName.isEmpty()) { |
| 154 | + valid = false; |
| 155 | + final String errorMessage = validatorBundle.message( |
| 156 | + "validator.notEmpty", "name" |
| 157 | + ); |
| 158 | + JOptionPane.showMessageDialog( |
| 159 | + null, |
| 160 | + errorMessage, |
| 161 | + errorTitle, |
| 162 | + JOptionPane.ERROR_MESSAGE |
| 163 | + ); |
| 164 | + break; |
| 165 | + } else if (!propertyName.matches(RegExUtil.LOWER_SNAKE_CASE)) { |
| 166 | + valid = false; |
| 167 | + final String errorMessage = validatorBundle.message( |
| 168 | + "validator.lowerSnakeCase", "name" |
| 169 | + ); |
| 170 | + JOptionPane.showMessageDialog( |
| 171 | + null, |
| 172 | + errorMessage, |
| 173 | + errorTitle, |
| 174 | + JOptionPane.ERROR_MESSAGE |
| 175 | + ); |
| 176 | + break; |
| 177 | + } |
| 178 | + } |
| 179 | + } |
| 180 | + |
| 181 | + return valid; |
| 182 | + } |
| 183 | + |
135 | 184 | @Override |
136 | 185 | public void onCancel() { |
137 | 186 | dispose(); |
|
0 commit comments