1313import com .magento .idea .magento2plugin .actions .generation .data .SourceModelData ;
1414import com .magento .idea .magento2plugin .actions .generation .data .ui .ComboBoxItemData ;
1515import 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 ;
1618import com .magento .idea .magento2plugin .actions .generation .dialog .event .EavAttributeInputItemListener ;
19+ import com .magento .idea .magento2plugin .actions .generation .dialog .event .OptionsPanelVisibilityChangeListener ;
1720import com .magento .idea .magento2plugin .actions .generation .dialog .validator .annotation .FieldValidation ;
1821import com .magento .idea .magento2plugin .actions .generation .dialog .validator .annotation .RuleRegistry ;
1922import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .CommaSeparatedStringRule ;
2023import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .Lowercase ;
2124import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .NotEmptyRule ;
2225import com .magento .idea .magento2plugin .actions .generation .generator .EavAttributeSetupPatchGenerator ;
2326import com .magento .idea .magento2plugin .actions .generation .generator .SourceModelGenerator ;
27+ import com .magento .idea .magento2plugin .actions .generation .generator .util .GetAttributeOptionPropertiesUtil ;
2428import com .magento .idea .magento2plugin .magento .files .SourceModelFile ;
2529import com .magento .idea .magento2plugin .magento .packages .eav .AttributeInput ;
2630import com .magento .idea .magento2plugin .magento .packages .eav .AttributeScope ;
2731import com .magento .idea .magento2plugin .magento .packages .eav .AttributeSourceModel ;
2832import com .magento .idea .magento2plugin .magento .packages .eav .AttributeType ;
2933import com .magento .idea .magento2plugin .magento .packages .eav .EavEntity ;
34+ import com .magento .idea .magento2plugin .ui .table .TableGroupWrapper ;
3035import com .magento .idea .magento2plugin .util .magento .GetModuleNameByDirectoryUtil ;
3136import com .magento .idea .magento2plugin .util .magento .GetProductTypesListUtil ;
32- import java .awt .event .ItemEvent ;
33- import java .awt .event .ItemListener ;
3437import java .awt .event .KeyEvent ;
3538import java .awt .event .WindowAdapter ;
3639import java .awt .event .WindowEvent ;
40+ import java .util .Arrays ;
41+ import java .util .HashMap ;
42+ import java .util .LinkedList ;
3743import java .util .List ;
3844import javax .swing .DefaultListModel ;
3945import javax .swing .JButton ;
4248import javax .swing .JComponent ;
4349import javax .swing .JList ;
4450import javax .swing .JPanel ;
51+ import javax .swing .JTable ;
4552import javax .swing .JTextField ;
4653import javax .swing .KeyStroke ;
4754import javax .swing .event .DocumentEvent ;
@@ -98,14 +105,17 @@ public class NewEavAttributeDialog extends AbstractDialog {
98105 @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
99106 message = {NotEmptyRule .MESSAGE , "Source Model Name" })
100107 private JTextField sourceModelNameTexField ;
108+ private JTable optionTable ;
109+ private JButton addOptionButton ;
110+ private JPanel optionsPanel ;
101111 @ FieldValidation (rule = RuleRegistry .COMMA_SEPARATED_STRING ,
102112 message = {CommaSeparatedStringRule .MESSAGE , "Apply To" })
103- private JTextField applyToTextField ;
104113 private JCheckBox applyToAllProductsCheckBox ;
105114 private JPanel applyToPanel ;
106115 private JList productsTypesList ;
107116 private final Project project ;
108117 private final SourceModelData sourceModelData ;
118+ private TableGroupWrapper entityPropertiesTableGroupWrapper ;
109119
110120 /**
111121 * Constructor.
@@ -120,18 +130,37 @@ public NewEavAttributeDialog(final Project project, final PsiDirectory directory
120130 this .moduleName = GetModuleNameByDirectoryUtil .execute (directory , project );
121131 this .sourceModelData = new SourceModelData ();
122132
133+ fillEntityComboBoxes ();
134+ initPropertiesTable ();
123135 setPanelConfiguration ();
124136 addActionListenersForButtons ();
125137 addCancelActionForWindow ();
126138 addCancelActionForEsc ();
127139 addApplyToVisibilityAction ();
128- setAutocompleteListenerForAttributeCodeField ();
129140 fillEntityComboBoxes ();
130141 fillProductsTypesList ();
131142 addDependBetweenInputAndSourceModel ();
143+ addOptionPanelListener ();
144+ setAutocompleteListenerForAttributeCodeField ();
132145 setDefaultSources ();
133146 }
134147
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+
135164 private void fillProductsTypesList () {
136165 final List <String > productTypes = GetProductTypesListUtil .execute (project );
137166
@@ -151,25 +180,23 @@ private void addDependBetweenInputAndSourceModel() {
151180 new EavAttributeInputItemListener (sourceComboBox )
152181 );
153182
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+ );
171186
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+ );
173200 }
174201
175202 private void setDefaultSources () {
@@ -362,6 +389,10 @@ private ProductEntityData populateProductEntityData(final ProductEntityData prod
362389 productEntityData .setInput (getAttributeInput ());
363390 productEntityData .setScope (getAttributeScope ());
364391 productEntityData .setSource (getAttributeSource ());
392+ productEntityData .setOptions (GetAttributeOptionPropertiesUtil .getValues (
393+ entityPropertiesTableGroupWrapper .getColumnsData ()));
394+ productEntityData .setOptionsSortOrder (GetAttributeOptionPropertiesUtil .getSortOrders (
395+ entityPropertiesTableGroupWrapper .getColumnsData ()));
365396
366397 if (!applyToAllProductsCheckBox .isSelected ()) {
367398 productEntityData .setApplyTo (
0 commit comments