1212import com .magento .idea .magento2plugin .actions .generation .data .ProductEntityData ;
1313import com .magento .idea .magento2plugin .actions .generation .data .SourceModelData ;
1414import 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 ;
1517import com .magento .idea .magento2plugin .actions .generation .dialog .event .EavAttributeInputItemListener ;
18+ import com .magento .idea .magento2plugin .actions .generation .dialog .event .OptionsPanelVisibilityChangeListener ;
1619import com .magento .idea .magento2plugin .actions .generation .dialog .validator .annotation .FieldValidation ;
1720import com .magento .idea .magento2plugin .actions .generation .dialog .validator .annotation .RuleRegistry ;
1821import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .Lowercase ;
1922import com .magento .idea .magento2plugin .actions .generation .dialog .validator .rule .NotEmptyRule ;
2023import com .magento .idea .magento2plugin .actions .generation .generator .EavAttributeSetupPatchGenerator ;
2124import com .magento .idea .magento2plugin .actions .generation .generator .SourceModelGenerator ;
25+ import com .magento .idea .magento2plugin .actions .generation .generator .util .GetAttributeOptionPropertiesUtil ;
2226import com .magento .idea .magento2plugin .magento .files .SourceModelFile ;
2327import com .magento .idea .magento2plugin .magento .packages .eav .AttributeInput ;
2428import com .magento .idea .magento2plugin .magento .packages .eav .AttributeScope ;
2529import com .magento .idea .magento2plugin .magento .packages .eav .AttributeSourceModel ;
2630import com .magento .idea .magento2plugin .magento .packages .eav .AttributeType ;
2731import com .magento .idea .magento2plugin .magento .packages .eav .EavEntity ;
32+ import com .magento .idea .magento2plugin .ui .table .TableGroupWrapper ;
2833import com .magento .idea .magento2plugin .util .magento .GetModuleNameByDirectoryUtil ;
29- import java .awt .event .ItemEvent ;
30- import java .awt .event .ItemListener ;
3134import java .awt .event .KeyEvent ;
3235import java .awt .event .WindowAdapter ;
3336import java .awt .event .WindowEvent ;
37+ import java .util .Arrays ;
38+ import java .util .HashMap ;
39+ import java .util .LinkedList ;
40+ import java .util .List ;
3441import javax .swing .JButton ;
3542import javax .swing .JCheckBox ;
3643import javax .swing .JComboBox ;
3744import javax .swing .JComponent ;
3845import javax .swing .JPanel ;
46+ import javax .swing .JTable ;
3947import javax .swing .JTextField ;
4048import javax .swing .KeyStroke ;
4149import javax .swing .event .DocumentEvent ;
@@ -92,8 +100,12 @@ public class NewEavAttributeDialog extends AbstractDialog {
92100 @ FieldValidation (rule = RuleRegistry .NOT_EMPTY ,
93101 message = {NotEmptyRule .MESSAGE , "Source Model Name" })
94102 private JTextField sourceModelNameTexField ;
103+ private JTable optionTable ;
104+ private JButton addOptionButton ;
105+ private JPanel optionsPanel ;
95106 private final Project project ;
96107 private final SourceModelData sourceModelData ;
108+ private TableGroupWrapper entityPropertiesTableGroupWrapper ;
97109
98110 /**
99111 * Constructor.
@@ -108,41 +120,57 @@ public NewEavAttributeDialog(final Project project, final PsiDirectory directory
108120 this .moduleName = GetModuleNameByDirectoryUtil .execute (directory , project );
109121 this .sourceModelData = new SourceModelData ();
110122
123+ fillEntityComboBoxes ();
124+ initPropertiesTable ();
111125 setPanelConfiguration ();
112126 addActionListenersForButtons ();
113127 addCancelActionForWindow ();
114128 addCancelActionForEsc ();
115- setAutocompleteListenerForAttributeCodeField ();
116- fillEntityComboBoxes ();
117129 addDependBetweenInputAndSourceModel ();
130+ addOptionPanelListener ();
131+ setAutocompleteListenerForAttributeCodeField ();
118132 setDefaultSources ();
119133 }
120134
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+
121151 @ SuppressWarnings ("PMD.AccessorMethodGeneration" )
122152 private void addDependBetweenInputAndSourceModel () {
123153 inputComboBox .addItemListener (
124154 new EavAttributeInputItemListener (sourceComboBox )
125155 );
126156
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+ );
144160
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+ );
146174 }
147175
148176 private void setDefaultSources () {
@@ -295,7 +323,7 @@ private void generateSourceModelFile() {
295323
296324 if (selectedSource == null
297325 || !selectedSource .getText ().equals (
298- AttributeSourceModel .GENERATE_SOURCE .getSource ()
326+ AttributeSourceModel .GENERATE_SOURCE .getSource ()
299327 )) {
300328 return ;
301329 }
@@ -335,6 +363,10 @@ private ProductEntityData populateProductEntityData(final ProductEntityData prod
335363 productEntityData .setInput (getAttributeInput ());
336364 productEntityData .setScope (getAttributeScope ());
337365 productEntityData .setSource (getAttributeSource ());
366+ productEntityData .setOptions (GetAttributeOptionPropertiesUtil .getValues (
367+ entityPropertiesTableGroupWrapper .getColumnsData ()));
368+ productEntityData .setOptionsSortOrder (GetAttributeOptionPropertiesUtil .getSortOrders (
369+ entityPropertiesTableGroupWrapper .getColumnsData ()));
338370
339371 return productEntityData ;
340372 }
@@ -344,7 +376,7 @@ private String getAttributeSource() {
344376
345377 if (selectedItem == null
346378 || selectedItem .getText ().equals (
347- AttributeSourceModel .NULLABLE_SOURCE .getSource ()
379+ AttributeSourceModel .NULLABLE_SOURCE .getSource ()
348380 )) {
349381 return null ;
350382 }
0 commit comments