11
11
import com .magento .idea .magento2plugin .actions .generation .data .DbSchemaXmlData ;
12
12
import com .magento .idea .magento2plugin .actions .generation .data .DbSchemaXmlSourceData ;
13
13
import com .magento .idea .magento2plugin .actions .generation .data .ui .ComboBoxItemData ;
14
-
15
- import java .awt .event .ActionEvent ;
16
- import java .awt .event .ActionListener ;
14
+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .annotation .FieldValidation ;
15
+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .annotation .RuleRegistry ;
16
+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .AlphanumericWithUnderscoreRule ;
17
+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .Lowercase ;
18
+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .NotEmptyRule ;
19
+ import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .TableNameLength ;
20
+ import com .magento .idea .magento2plugin .actions .generation .generator .DbSchemaXmlGenerator ;
21
+ import com .magento .idea .magento2plugin .magento .files .ModuleDbSchemaXml ;
22
+ import com .magento .idea .magento2plugin .ui .table .TableGroupWrapper ;
23
+ import com .magento .idea .magento2plugin .util .magento .GetModuleNameByDirectoryUtil ;
17
24
import java .awt .event .KeyEvent ;
18
25
import java .awt .event .WindowAdapter ;
19
26
import java .awt .event .WindowEvent ;
22
29
import java .util .LinkedList ;
23
30
import java .util .List ;
24
31
import java .util .Map ;
25
- import javax .swing .AbstractCellEditor ;
26
32
import javax .swing .JButton ;
27
33
import javax .swing .JComboBox ;
28
34
import javax .swing .JComponent ;
32
38
import javax .swing .JTable ;
33
39
import javax .swing .JTextField ;
34
40
import javax .swing .KeyStroke ;
35
- import javax .swing .DefaultCellEditor ;
36
- import javax .swing .table .TableCellEditor ;
37
- import javax .swing .table .TableColumn ;
38
-
39
- import com .magento .idea .magento2plugin .actions .generation .dialog .validator .annotation .FieldValidation ;
40
- import com .magento .idea .magento2plugin .actions .generation .dialog .validator .annotation .RuleRegistry ;
41
- import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .AlphanumericWithUnderscoreRule ;
42
- import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .Lowercase ;
43
- import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .NotEmptyRule ;
44
- import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .TableNameLength ;
45
- import com .magento .idea .magento2plugin .actions .generation .generator .DbSchemaXmlGenerator ;
46
- import com .magento .idea .magento2plugin .magento .files .ModuleDbSchemaXml ;
47
- import com .magento .idea .magento2plugin .ui .table .ComboBoxCellEditor ;
48
- import com .magento .idea .magento2plugin .ui .table .TableGroupWrapper ;
49
- import com .magento .idea .magento2plugin .util .magento .GetModuleNameByDirectoryUtil ;
50
41
import org .jetbrains .annotations .NotNull ;
51
42
52
43
public class NewDbSchemaDialog extends AbstractDialog {
53
44
private static final String TABLE_NAME = "Table Name" ;
54
45
55
- // Table Columns
56
- private static final String COLUMN_TYPE = "Type" ;
57
- private static final String COLUMN_NAME = "Name" ;
58
- private static final String COLUMN_PADDING = "Padding" ;
59
- private static final String COLUMN_UNSIGNED = "Unsigned" ;
60
- private static final String COLUMN_NULLABLE = "Nullable" ;
61
- private static final String COLUMN_IDENTITY = "Identity" ;
62
- private static final String COLUMN_COMMENT = "Comment" ;
63
- private static final String COLUMN_LENGTH = "Length" ;
64
- private static final String COLUMN_PRECISION = "Precision" ;
65
- private static final String COLUMN_SCALE = "Scale" ;
66
- private static final String COLUMN_DEFAULT = "Default" ;
67
- private static final String COLUMN_ON_CREATE = "On Create" ;
68
- private static final String COLUMN_ON_UPDATE = "On Update" ;
69
-
70
46
private final Project project ;
71
47
private final String moduleName ;
72
48
private final PsiDirectory directory ;
@@ -94,22 +70,17 @@ public class NewDbSchemaDialog extends AbstractDialog {
94
70
private JComboBox <ComboBoxItemData > tableResource ;
95
71
96
72
// Table Columns UI components group
73
+ private TableGroupWrapper columnsTableGroupWrapper ;
97
74
private JTable columnsTable ;
98
75
private JButton addColumnButton ;
99
76
private JScrollPane columnsScrollPanel ;//NOPMD
100
77
101
- // Table Constraints UI components group
102
- private JTable constraintsTable ;
103
- private JButton addConstraintButton ;
104
- private JScrollPane constraintsScrollPanel ;//NOPMD
105
-
106
78
// Labels
107
79
private JLabel tableNameLabel ;//NOPMD
108
80
private JLabel tableEngineLabel ;//NOPMD
109
81
private JLabel tableResourceLabel ;//NOPMD
110
82
private JLabel tableCommentLabel ;//NOPMD
111
83
private JLabel tableColumnsLabel ;//NOPMD
112
- private JLabel tableConstraintsLabel ;//NOPMD
113
84
114
85
/**
115
86
* Constructor.
@@ -186,7 +157,8 @@ private void generateDbSchemaXmlFile() {
186
157
getTableName (),
187
158
getTableResource (),
188
159
getTableEngine (),
189
- getTableComment ()
160
+ getTableComment (),
161
+ getColumns ()
190
162
),
191
163
project ,
192
164
moduleName
@@ -195,79 +167,40 @@ private void generateDbSchemaXmlFile() {
195
167
196
168
private void initializeColumnsUiComponentGroup () {
197
169
final List <String > columns = new LinkedList <>(Arrays .asList (
198
- COLUMN_TYPE ,
199
- COLUMN_NAME ,
200
- COLUMN_PADDING ,
201
- COLUMN_UNSIGNED ,
202
- COLUMN_NULLABLE ,
203
- COLUMN_IDENTITY ,
204
- COLUMN_LENGTH ,
205
- COLUMN_PRECISION ,
206
- COLUMN_SCALE ,
207
- COLUMN_DEFAULT ,
208
- COLUMN_ON_CREATE ,
209
- COLUMN_ON_UPDATE ,
210
- COLUMN_COMMENT
170
+ ModuleDbSchemaXml .XML_ATTR_COLUMN_TYPE ,
171
+ ModuleDbSchemaXml .XML_ATTR_COLUMN_NAME ,
172
+ ModuleDbSchemaXml .XML_ATTR_COLUMN_PADDING ,
173
+ ModuleDbSchemaXml .XML_ATTR_COLUMN_UNSIGNED ,
174
+ ModuleDbSchemaXml .XML_ATTR_COLUMN_NULLABLE ,
175
+ ModuleDbSchemaXml .XML_ATTR_COLUMN_IDENTITY ,
176
+ ModuleDbSchemaXml .XML_ATTR_COLUMN_LENGTH ,
177
+ ModuleDbSchemaXml .XML_ATTR_COLUMN_PRECISION ,
178
+ ModuleDbSchemaXml .XML_ATTR_COLUMN_SCALE ,
179
+ ModuleDbSchemaXml .XML_ATTR_COLUMN_ON_UPDATE ,
180
+ ModuleDbSchemaXml .XML_ATTR_COLUMN_DEFAULT ,
181
+ ModuleDbSchemaXml .XML_ATTR_COLUMN_COMMENT
211
182
));
212
183
// Set default values for columns
213
184
final Map <String , String > defaultValues = new HashMap <>();
214
- defaultValues .put (COLUMN_NULLABLE , "false" );
185
+ defaultValues .put (ModuleDbSchemaXml .XML_ATTR_COLUMN_NULLABLE , "false" );
186
+ defaultValues .put (ModuleDbSchemaXml .XML_ATTR_COLUMN_IDENTITY , "false" );
215
187
// Set sources for columns
216
188
final Map <String , List <String >> sources = new HashMap <>();
217
189
final List <String > booleanSource = Arrays .asList ("true" , "false" );
218
- sources .put (COLUMN_TYPE , DbSchemaXmlSourceData .getColumnTypes ());
219
- sources .put (COLUMN_UNSIGNED , booleanSource );
220
- sources .put (COLUMN_NULLABLE , booleanSource );
221
- sources .put (COLUMN_IDENTITY , booleanSource );
222
- sources .put (COLUMN_ON_CREATE , booleanSource );
223
- sources .put (COLUMN_ON_UPDATE , booleanSource );
224
- // Set action listeners for columns
225
- final Map <String , ActionListener > actionListeners = new HashMap <>();
226
- actionListeners .put (COLUMN_TYPE , event -> {
227
- if (event .getActionCommand ().equals ("comboBoxChanged" )) {
228
- if (event .getSource () instanceof JComboBox ) {
229
- final JComboBox source = (JComboBox ) event .getSource ();
230
- final JTable table = (JTable ) source .getParent ();
231
- final String value = source .getSelectedItem ().toString ();
232
-
233
- if (!value .isEmpty ()) {
234
- final int editingRow = ((JTable ) source .getParent ()).getEditingRow ();
235
- // Index should starts from the `1` to not consider xsi:type attribute
236
- for (int index = 1 ; index < columns .size (); index ++) {
237
- TableCellEditor cellEditor = table .getCellEditor (editingRow , index );
238
- JComponent component = null ;
239
-
240
- if (cellEditor instanceof DefaultCellEditor ) {
241
- component = (JComponent ) ((DefaultCellEditor ) cellEditor )
242
- .getComponent ();
243
- } else if (cellEditor instanceof ComboBoxCellEditor ) {
244
- component = (JComponent ) ((ComboBoxCellEditor ) cellEditor )
245
- .getComponent ();
246
- }
247
-
248
- if (component instanceof JComboBox ) {
249
- component .setEnabled (ModuleDbSchemaXml .getAllowedAttributes (value )
250
- .contains (columns .get (index ).toLowerCase ()));
251
- } else if (component instanceof JTextField ) {
252
- ((JTextField ) component ).setEditable (
253
- ModuleDbSchemaXml .getAllowedAttributes (value )
254
- .contains (columns .get (index ).toLowerCase ())
255
- );
256
- }
257
- }
258
- }
259
- }
260
- }
261
- });
190
+ sources .put (ModuleDbSchemaXml .XML_ATTR_COLUMN_TYPE , DbSchemaXmlSourceData .getColumnTypes ());
191
+ sources .put (ModuleDbSchemaXml .XML_ATTR_COLUMN_UNSIGNED , booleanSource );
192
+ sources .put (ModuleDbSchemaXml .XML_ATTR_COLUMN_NULLABLE , booleanSource );
193
+ sources .put (ModuleDbSchemaXml .XML_ATTR_COLUMN_IDENTITY , booleanSource );
194
+ sources .put (ModuleDbSchemaXml .XML_ATTR_COLUMN_ON_UPDATE , booleanSource );
262
195
// Initialize new Table Group
263
- TableGroupWrapper tableGroupWrapper = new TableGroupWrapper (
196
+ columnsTableGroupWrapper = new TableGroupWrapper (
264
197
columnsTable ,
265
198
addColumnButton ,
266
199
columns ,
267
200
defaultValues ,
268
- sources ,
269
- actionListeners
201
+ sources
270
202
);
203
+ columnsTableGroupWrapper .initTableGroup ();
271
204
}
272
205
273
206
/**
@@ -319,4 +252,13 @@ private String getTableEngine() {
319
252
private String getTableComment () {
320
253
return tableComment .getText ().trim ();
321
254
}
255
+
256
+ /**
257
+ * Get columnsTable values.
258
+ *
259
+ * @return List
260
+ */
261
+ private List <Map <String , String >> getColumns () {
262
+ return columnsTableGroupWrapper .getColumnsData ();
263
+ }
322
264
}
0 commit comments