12
12
import com .magento .idea .magento2plugin .actions .generation .data .ProductEntityData ;
13
13
import com .magento .idea .magento2plugin .actions .generation .data .SourceModelData ;
14
14
import com .magento .idea .magento2plugin .actions .generation .data .ui .ComboBoxItemData ;
15
+ import com .magento .idea .magento2plugin .actions .generation .dialog .event .AttributeSourcePanelComponentListener ;
16
+ import com .magento .idea .magento2plugin .actions .generation .dialog .event .AttributeSourceRelationsItemListener ;
15
17
import com .magento .idea .magento2plugin .actions .generation .dialog .event .EavAttributeInputItemListener ;
18
+ import com .magento .idea .magento2plugin .actions .generation .dialog .event .OptionsPanelVisibilityChangeListener ;
16
19
import com .magento .idea .magento2plugin .actions .generation .dialog .validator .annotation .FieldValidation ;
17
20
import com .magento .idea .magento2plugin .actions .generation .dialog .validator .annotation .RuleRegistry ;
18
21
import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .Lowercase ;
19
22
import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .NotEmptyRule ;
20
23
import com .magento .idea .magento2plugin .actions .generation .generator .EavAttributeSetupPatchGenerator ;
21
24
import com .magento .idea .magento2plugin .actions .generation .generator .SourceModelGenerator ;
25
+ import com .magento .idea .magento2plugin .actions .generation .generator .util .GetAttributeOptionPropertiesUtil ;
22
26
import com .magento .idea .magento2plugin .magento .files .SourceModelFile ;
23
27
import com .magento .idea .magento2plugin .magento .packages .eav .AttributeInput ;
24
28
import com .magento .idea .magento2plugin .magento .packages .eav .AttributeScope ;
25
29
import com .magento .idea .magento2plugin .magento .packages .eav .AttributeSourceModel ;
26
30
import com .magento .idea .magento2plugin .magento .packages .eav .AttributeType ;
27
31
import com .magento .idea .magento2plugin .magento .packages .eav .EavEntity ;
32
+ import com .magento .idea .magento2plugin .ui .table .TableGroupWrapper ;
28
33
import com .magento .idea .magento2plugin .util .magento .GetModuleNameByDirectoryUtil ;
29
- import java .awt .event .ItemEvent ;
30
- import java .awt .event .ItemListener ;
31
34
import java .awt .event .KeyEvent ;
32
35
import java .awt .event .WindowAdapter ;
33
36
import java .awt .event .WindowEvent ;
37
+ import java .util .Arrays ;
38
+ import java .util .HashMap ;
39
+ import java .util .LinkedList ;
40
+ import java .util .List ;
34
41
import javax .swing .JButton ;
35
42
import javax .swing .JCheckBox ;
36
43
import javax .swing .JComboBox ;
37
44
import javax .swing .JComponent ;
38
45
import javax .swing .JPanel ;
46
+ import javax .swing .JTable ;
39
47
import javax .swing .JTextField ;
40
48
import javax .swing .KeyStroke ;
41
49
import javax .swing .event .DocumentEvent ;
@@ -92,8 +100,12 @@ public class NewEavAttributeDialog extends AbstractDialog {
92
100
@ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
93
101
message = {NotEmptyRule .MESSAGE , "Source Model Name" })
94
102
private JTextField sourceModelNameTexField ;
103
+ private JTable optionTable ;
104
+ private JButton addOptionButton ;
105
+ private JPanel optionsPanel ;
95
106
private final Project project ;
96
107
private final SourceModelData sourceModelData ;
108
+ private TableGroupWrapper entityPropertiesTableGroupWrapper ;
97
109
98
110
/**
99
111
* Constructor.
@@ -108,41 +120,57 @@ public NewEavAttributeDialog(final Project project, final PsiDirectory directory
108
120
this .moduleName = GetModuleNameByDirectoryUtil .execute (directory , project );
109
121
this .sourceModelData = new SourceModelData ();
110
122
123
+ fillEntityComboBoxes ();
124
+ initPropertiesTable ();
111
125
setPanelConfiguration ();
112
126
addActionListenersForButtons ();
113
127
addCancelActionForWindow ();
114
128
addCancelActionForEsc ();
115
- setAutocompleteListenerForAttributeCodeField ();
116
- fillEntityComboBoxes ();
117
129
addDependBetweenInputAndSourceModel ();
130
+ addOptionPanelListener ();
131
+ setAutocompleteListenerForAttributeCodeField ();
118
132
setDefaultSources ();
119
133
}
120
134
135
+ private void initPropertiesTable () {
136
+ final List <String > columns = new LinkedList <>(Arrays .asList (
137
+ "Value" ,
138
+ "Sort Order"
139
+ ));
140
+ // Initialize entity properties Table Group
141
+ entityPropertiesTableGroupWrapper = new TableGroupWrapper (
142
+ optionTable ,
143
+ addOptionButton ,
144
+ columns ,
145
+ new HashMap <>(),
146
+ new HashMap <>()
147
+ );
148
+ entityPropertiesTableGroupWrapper .initTableGroup ();
149
+ }
150
+
121
151
@ SuppressWarnings ("PMD.AccessorMethodGeneration" )
122
152
private void addDependBetweenInputAndSourceModel () {
123
153
inputComboBox .addItemListener (
124
154
new EavAttributeInputItemListener (sourceComboBox )
125
155
);
126
156
127
- sourceComboBox .addItemListener (new ItemListener () {
128
- @ Override
129
- public void itemStateChanged (final ItemEvent itemEvent ) {
130
- final String selectedSource = itemEvent .getItem ().toString ();
131
-
132
- if (selectedSource .equals (AttributeSourceModel .GENERATE_SOURCE .getSource ())) {
133
- customSourceModelPanel .setVisible (true );
134
- sourceModelData .setModuleName (moduleName );
135
-
136
- if (sourceModelDirectoryTexField .getText ().trim ().isEmpty ()) {
137
- sourceModelDirectoryTexField .setText (sourceModelData .getDirectory ());
138
- }
139
- } else {
140
- customSourceModelPanel .setVisible (false );
141
- }
142
- }
143
- });
157
+ sourceComboBox .addItemListener (
158
+ new AttributeSourceRelationsItemListener (customSourceModelPanel )
159
+ );
144
160
145
- sourceModelDirectoryTexField .setText (sourceModelData .getDirectory ());
161
+ customSourceModelPanel .addComponentListener (
162
+ new AttributeSourcePanelComponentListener (sourceModelDirectoryTexField )
163
+ );
164
+ }
165
+
166
+ @ SuppressWarnings ("PMD.AccessorMethodGeneration" )
167
+ private void addOptionPanelListener () {
168
+ sourceComboBox .addItemListener (
169
+ new OptionsPanelVisibilityChangeListener (
170
+ optionsPanel ,
171
+ inputComboBox
172
+ )
173
+ );
146
174
}
147
175
148
176
private void setDefaultSources () {
@@ -295,7 +323,7 @@ private void generateSourceModelFile() {
295
323
296
324
if (selectedSource == null
297
325
|| !selectedSource .getText ().equals (
298
- AttributeSourceModel .GENERATE_SOURCE .getSource ()
326
+ AttributeSourceModel .GENERATE_SOURCE .getSource ()
299
327
)) {
300
328
return ;
301
329
}
@@ -335,6 +363,10 @@ private ProductEntityData populateProductEntityData(final ProductEntityData prod
335
363
productEntityData .setInput (getAttributeInput ());
336
364
productEntityData .setScope (getAttributeScope ());
337
365
productEntityData .setSource (getAttributeSource ());
366
+ productEntityData .setOptions (GetAttributeOptionPropertiesUtil .getValues (
367
+ entityPropertiesTableGroupWrapper .getColumnsData ()));
368
+ productEntityData .setOptionsSortOrder (GetAttributeOptionPropertiesUtil .getSortOrders (
369
+ entityPropertiesTableGroupWrapper .getColumnsData ()));
338
370
339
371
return productEntityData ;
340
372
}
@@ -344,7 +376,7 @@ private String getAttributeSource() {
344
376
345
377
if (selectedItem == null
346
378
|| selectedItem .getText ().equals (
347
- AttributeSourceModel .NULLABLE_SOURCE .getSource ()
379
+ AttributeSourceModel .NULLABLE_SOURCE .getSource ()
348
380
)) {
349
381
return null ;
350
382
}
0 commit comments