40
40
import javax .swing .JButton ;
41
41
import javax .swing .JCheckBox ;
42
42
import javax .swing .JComponent ;
43
+ import javax .swing .JLabel ;
43
44
import javax .swing .JOptionPane ;
44
45
import javax .swing .JPanel ;
45
46
import javax .swing .JTable ;
46
47
import javax .swing .JTextField ;
47
48
import javax .swing .KeyStroke ;
48
49
import javax .swing .table .DefaultTableModel ;
49
50
import javax .swing .table .TableColumn ;
51
+ import org .jetbrains .annotations .NotNull ;
50
52
51
53
@ SuppressWarnings ({
52
54
"PMD.ExcessiveImports"
53
55
})
54
56
public class NewDataModelDialog extends AbstractDialog {
55
57
56
- private final Project project ;
57
- private final String moduleName ;
58
- private final ValidatorBundle validatorBundle ;
59
- private final CommonBundle commonBundle ;
60
- private final List <String > properties ;
61
-
62
58
private static final String MODEL_NAME = "Model Name" ;
63
59
private static final String PROPERTY_NAME = "Name" ;
64
60
private static final String PROPERTY_TYPE = "Type" ;
65
61
private static final String PROPERTY_ACTION = "Action" ;
66
62
private static final String PROPERTY_DELETE = "Delete" ;
67
63
64
+ private final Project project ;
65
+ private final String moduleName ;
66
+ private final ValidatorBundle validatorBundle ;
67
+ private final CommonBundle commonBundle ;
68
+ private final List <String > properties ;
69
+
68
70
private JPanel contentPanel ;
69
71
private JButton buttonOK ;
70
72
private JButton buttonCancel ;
71
73
private JTable propertyTable ;
72
74
private JButton addProperty ;
73
75
private JCheckBox createInterface ;
74
76
75
- @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
76
- message = {NotEmptyRule .MESSAGE , MODEL_NAME })
77
- @ FieldValidation (rule = RuleRegistry .PHP_CLASS ,
78
- message = {PhpClassRule .MESSAGE , MODEL_NAME })
77
+ @ FieldValidation (rule = RuleRegistry .NOT_EMPTY , message = {NotEmptyRule .MESSAGE , MODEL_NAME })
78
+ @ FieldValidation (rule = RuleRegistry .PHP_CLASS , message = {PhpClassRule .MESSAGE , MODEL_NAME })
79
79
private JTextField modelName ;
80
80
81
+ private JLabel modelNameErrorMessage ;//NOPMD
82
+
81
83
/**
82
84
* Constructor.
83
85
*/
84
- public NewDataModelDialog (final Project project , final PsiDirectory directory ) {
86
+ public NewDataModelDialog (
87
+ final @ NotNull Project project ,
88
+ final @ NotNull PsiDirectory directory
89
+ ) {
85
90
super ();
86
91
87
92
this .project = project ;
@@ -122,7 +127,10 @@ public void windowClosing(final WindowEvent event) {
122
127
/**
123
128
* Opens the dialog window.
124
129
*/
125
- public static void open (final Project project , final PsiDirectory directory ) {
130
+ public static void open (
131
+ final @ NotNull Project project ,
132
+ final @ NotNull PsiDirectory directory
133
+ ) {
126
134
final NewDataModelDialog dialog = new NewDataModelDialog (project , directory );
127
135
dialog .pack ();
128
136
dialog .centerDialog (dialog );
@@ -145,8 +153,8 @@ private void onOK() {
145
153
generateDataModelInterfaceFile ();
146
154
generatePreferenceForInterface ();
147
155
}
156
+ exit ();
148
157
}
149
- exit ();
150
158
}
151
159
152
160
@ Override
@@ -157,6 +165,17 @@ protected boolean validateFormFields() {
157
165
valid = true ;
158
166
final String errorTitle = commonBundle .message ("common.error" );
159
167
final int column = 0 ;
168
+
169
+ if (propertyTable .getRowCount () == 0 ) {
170
+ valid = false ;
171
+ JOptionPane .showMessageDialog (
172
+ null ,
173
+ validatorBundle .message ("validator.properties.notEmpty" ),
174
+ errorTitle ,
175
+ JOptionPane .ERROR_MESSAGE
176
+ );
177
+ }
178
+
160
179
for (int row = 0 ; row < propertyTable .getRowCount (); row ++) {
161
180
final String propertyName = ((String ) propertyTable .getValueAt (row , column )).trim ();
162
181
if (propertyName .isEmpty ()) {
@@ -190,11 +209,6 @@ protected boolean validateFormFields() {
190
209
return valid ;
191
210
}
192
211
193
- @ Override
194
- public void onCancel () {
195
- dispose ();
196
- }
197
-
198
212
/**
199
213
* Generate DTO interface file.
200
214
*/
0 commit comments