13
13
import com .magento .idea .magento2plugin .actions .generation .data .SourceModelData ;
14
14
import com .magento .idea .magento2plugin .actions .generation .data .ui .ComboBoxItemData ;
15
15
import com .magento .idea .magento2plugin .actions .generation .dialog .event .ApplyToVisibleListener ;
16
+ import com .magento .idea .magento2plugin .actions .generation .dialog .event .AttributeSourcePanelComponentListener ;
17
+ import com .magento .idea .magento2plugin .actions .generation .dialog .event .AttributeSourceRelationsItemListener ;
16
18
import com .magento .idea .magento2plugin .actions .generation .dialog .event .EavAttributeInputItemListener ;
19
+ import com .magento .idea .magento2plugin .actions .generation .dialog .event .OptionsPanelVisibilityChangeListener ;
17
20
import com .magento .idea .magento2plugin .actions .generation .dialog .validator .annotation .FieldValidation ;
18
21
import com .magento .idea .magento2plugin .actions .generation .dialog .validator .annotation .RuleRegistry ;
19
22
import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .CommaSeparatedStringRule ;
20
23
import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .Lowercase ;
21
24
import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .NotEmptyRule ;
22
25
import com .magento .idea .magento2plugin .actions .generation .generator .EavAttributeSetupPatchGenerator ;
23
26
import com .magento .idea .magento2plugin .actions .generation .generator .SourceModelGenerator ;
27
+ import com .magento .idea .magento2plugin .actions .generation .generator .util .GetAttributeOptionPropertiesUtil ;
24
28
import com .magento .idea .magento2plugin .magento .files .SourceModelFile ;
25
29
import com .magento .idea .magento2plugin .magento .packages .eav .AttributeInput ;
26
30
import com .magento .idea .magento2plugin .magento .packages .eav .AttributeScope ;
27
31
import com .magento .idea .magento2plugin .magento .packages .eav .AttributeSourceModel ;
28
32
import com .magento .idea .magento2plugin .magento .packages .eav .AttributeType ;
29
33
import com .magento .idea .magento2plugin .magento .packages .eav .EavEntity ;
34
+ import com .magento .idea .magento2plugin .ui .table .TableGroupWrapper ;
30
35
import com .magento .idea .magento2plugin .util .magento .GetModuleNameByDirectoryUtil ;
31
36
import com .magento .idea .magento2plugin .util .magento .GetProductTypesListUtil ;
32
- import java .awt .event .ItemEvent ;
33
- import java .awt .event .ItemListener ;
34
37
import java .awt .event .KeyEvent ;
35
38
import java .awt .event .WindowAdapter ;
36
39
import java .awt .event .WindowEvent ;
40
+ import java .util .Arrays ;
41
+ import java .util .HashMap ;
42
+ import java .util .LinkedList ;
37
43
import java .util .List ;
38
44
import javax .swing .DefaultListModel ;
39
45
import javax .swing .JButton ;
42
48
import javax .swing .JComponent ;
43
49
import javax .swing .JList ;
44
50
import javax .swing .JPanel ;
51
+ import javax .swing .JTable ;
45
52
import javax .swing .JTextField ;
46
53
import javax .swing .KeyStroke ;
47
54
import javax .swing .event .DocumentEvent ;
@@ -98,14 +105,17 @@ public class NewEavAttributeDialog extends AbstractDialog {
98
105
@ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
99
106
message = {NotEmptyRule .MESSAGE , "Source Model Name" })
100
107
private JTextField sourceModelNameTexField ;
108
+ private JTable optionTable ;
109
+ private JButton addOptionButton ;
110
+ private JPanel optionsPanel ;
101
111
@ FieldValidation (rule = RuleRegistry .COMMA_SEPARATED_STRING ,
102
112
message = {CommaSeparatedStringRule .MESSAGE , "Apply To" })
103
- private JTextField applyToTextField ;
104
113
private JCheckBox applyToAllProductsCheckBox ;
105
114
private JPanel applyToPanel ;
106
115
private JList productsTypesList ;
107
116
private final Project project ;
108
117
private final SourceModelData sourceModelData ;
118
+ private TableGroupWrapper entityPropertiesTableGroupWrapper ;
109
119
110
120
/**
111
121
* Constructor.
@@ -120,18 +130,37 @@ public NewEavAttributeDialog(final Project project, final PsiDirectory directory
120
130
this .moduleName = GetModuleNameByDirectoryUtil .execute (directory , project );
121
131
this .sourceModelData = new SourceModelData ();
122
132
133
+ fillEntityComboBoxes ();
134
+ initPropertiesTable ();
123
135
setPanelConfiguration ();
124
136
addActionListenersForButtons ();
125
137
addCancelActionForWindow ();
126
138
addCancelActionForEsc ();
127
139
addApplyToVisibilityAction ();
128
- setAutocompleteListenerForAttributeCodeField ();
129
140
fillEntityComboBoxes ();
130
141
fillProductsTypesList ();
131
142
addDependBetweenInputAndSourceModel ();
143
+ addOptionPanelListener ();
144
+ setAutocompleteListenerForAttributeCodeField ();
132
145
setDefaultSources ();
133
146
}
134
147
148
+ private void initPropertiesTable () {
149
+ final List <String > columns = new LinkedList <>(Arrays .asList (
150
+ "Value" ,
151
+ "Sort Order"
152
+ ));
153
+ // Initialize entity properties Table Group
154
+ entityPropertiesTableGroupWrapper = new TableGroupWrapper (
155
+ optionTable ,
156
+ addOptionButton ,
157
+ columns ,
158
+ new HashMap <>(),
159
+ new HashMap <>()
160
+ );
161
+ entityPropertiesTableGroupWrapper .initTableGroup ();
162
+ }
163
+
135
164
private void fillProductsTypesList () {
136
165
final List <String > productTypes = GetProductTypesListUtil .execute (project );
137
166
@@ -151,25 +180,23 @@ private void addDependBetweenInputAndSourceModel() {
151
180
new EavAttributeInputItemListener (sourceComboBox )
152
181
);
153
182
154
- sourceComboBox .addItemListener (new ItemListener () {
155
- @ Override
156
- public void itemStateChanged (final ItemEvent itemEvent ) {
157
- final String selectedSource = itemEvent .getItem ().toString ();
158
-
159
- if (selectedSource .equals (AttributeSourceModel .GENERATE_SOURCE .getSource ())) {
160
- customSourceModelPanel .setVisible (true );
161
- sourceModelData .setModuleName (moduleName );
162
-
163
- if (sourceModelDirectoryTexField .getText ().trim ().isEmpty ()) {
164
- sourceModelDirectoryTexField .setText (sourceModelData .getDirectory ());
165
- }
166
- } else {
167
- customSourceModelPanel .setVisible (false );
168
- }
169
- }
170
- });
183
+ sourceComboBox .addItemListener (
184
+ new AttributeSourceRelationsItemListener (customSourceModelPanel )
185
+ );
171
186
172
- sourceModelDirectoryTexField .setText (sourceModelData .getDirectory ());
187
+ customSourceModelPanel .addComponentListener (
188
+ new AttributeSourcePanelComponentListener (sourceModelDirectoryTexField )
189
+ );
190
+ }
191
+
192
+ @ SuppressWarnings ("PMD.AccessorMethodGeneration" )
193
+ private void addOptionPanelListener () {
194
+ sourceComboBox .addItemListener (
195
+ new OptionsPanelVisibilityChangeListener (
196
+ optionsPanel ,
197
+ inputComboBox
198
+ )
199
+ );
173
200
}
174
201
175
202
private void setDefaultSources () {
@@ -362,6 +389,10 @@ private ProductEntityData populateProductEntityData(final ProductEntityData prod
362
389
productEntityData .setInput (getAttributeInput ());
363
390
productEntityData .setScope (getAttributeScope ());
364
391
productEntityData .setSource (getAttributeSource ());
392
+ productEntityData .setOptions (GetAttributeOptionPropertiesUtil .getValues (
393
+ entityPropertiesTableGroupWrapper .getColumnsData ()));
394
+ productEntityData .setOptionsSortOrder (GetAttributeOptionPropertiesUtil .getSortOrders (
395
+ entityPropertiesTableGroupWrapper .getColumnsData ()));
365
396
366
397
if (!applyToAllProductsCheckBox .isSelected ()) {
367
398
productEntityData .setApplyTo (
0 commit comments