Skip to content

Commit dc4b87d

Browse files
authored
Merge pull request #892 from bohdan-harniuk/879-enhance-new-ui-form-dialog-ux
879 enhance new UI form dialog ux
2 parents 6304129 + 7c43b7f commit dc4b87d

22 files changed

+733
-264
lines changed

resources/magento2/validation.properties

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
validator.notEmpty=The {0} field must not be empty
22
validator.box.notEmpty=The {0} field must contain a valid selection from the dropdown
33
validator.package.validPath=Please specify a valid Magento 2 installation path
4+
validator.properties.notEmpty=The properties must not be empty
45
validator.alphaNumericCharacters=The {0} field must contain letters and numbers only
56
validator.alphaNumericAndUnderscoreCharacters={0} must contain letters, numbers and underscores only
67
validator.alphaAndPeriodCharacters=The {0} field must contain alphabets and periods only

src/com/magento/idea/magento2plugin/actions/generation/NewDataModelAction.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.jetbrains.annotations.NotNull;
1919

2020
public class NewDataModelAction extends AnAction {
21+
2122
public static final String ACTION_NAME = "Magento 2 Data Model";
2223
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 Data Model";
2324

@@ -29,24 +30,23 @@ public NewDataModelAction() {
2930
}
3031

3132
@Override
32-
public void actionPerformed(@NotNull final AnActionEvent event) {
33+
public void actionPerformed(final @NotNull AnActionEvent event) {
3334
final DataContext dataContext = event.getDataContext();
34-
3535
final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
36+
3637
if (view == null) {
3738
return;
3839
}
39-
4040
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
41+
4142
if (project == null) {
4243
return;
4344
}
44-
4545
final PsiDirectory directory = view.getOrChooseDirectory();
46+
4647
if (directory == null) {
4748
return;
4849
}
49-
5050
NewDataModelDialog.open(project, directory);
5151
}
5252

src/com/magento/idea/magento2plugin/actions/generation/NewDbSchemaAction.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.jetbrains.annotations.NotNull;
1919

2020
public class NewDbSchemaAction extends AnAction {
21+
2122
public static final String ACTION_NAME = "Magento 2 Declarative Schema XML";
2223
public static final String ACTION_DESCRIPTION = "Create a new declarative schema XML";
2324

@@ -32,16 +33,17 @@ public NewDbSchemaAction() {
3233
public void actionPerformed(final @NotNull AnActionEvent event) {
3334
final DataContext dataContext = event.getDataContext();
3435
final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
36+
3537
if (view == null) {
3638
return;
3739
}
38-
3940
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
41+
4042
if (project == null) {
4143
return;
4244
}
43-
4445
final PsiDirectory directory = view.getOrChooseDirectory();
46+
4547
if (directory == null) {
4648
return;
4749
}

src/com/magento/idea/magento2plugin/actions/generation/NewEmailTemplateAction.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
import com.magento.idea.magento2plugin.MagentoIcons;
1717
import com.magento.idea.magento2plugin.actions.generation.dialog.NewEmailTemplateDialog;
1818

19-
@SuppressWarnings({"PMD.OnlyOneReturn", "PMD.FieldNamingConventions"})
2019
public class NewEmailTemplateAction extends AnAction {
20+
2121
public static final String ACTION_NAME = "Magento 2 Email Template";
2222
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 email template";
2323

@@ -36,17 +36,16 @@ public void actionPerformed(final AnActionEvent event) {
3636
if (view == null) {
3737
return;
3838
}
39-
4039
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
40+
4141
if (project == null) {
4242
return;
4343
}
44-
4544
final PsiDirectory directory = view.getOrChooseDirectory();
45+
4646
if (directory == null) {
4747
return;
4848
}
49-
5049
NewEmailTemplateDialog.open(project, directory);
5150
}
5251

src/com/magento/idea/magento2plugin/actions/generation/NewMessageQueueAction.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.jetbrains.annotations.NotNull;
1919

2020
public class NewMessageQueueAction extends AnAction {
21+
2122
public static final String ACTION_NAME = "Magento 2 Message Queue";
2223
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 Message Queue";
2324

@@ -29,24 +30,23 @@ public NewMessageQueueAction() {
2930
}
3031

3132
@Override
32-
public void actionPerformed(@NotNull final AnActionEvent event) {
33+
public void actionPerformed(final @NotNull AnActionEvent event) {
3334
final DataContext dataContext = event.getDataContext();
34-
3535
final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
36+
3637
if (view == null) {
3738
return;
3839
}
39-
4040
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
41+
4142
if (project == null) {
4243
return;
4344
}
44-
4545
final PsiDirectory directory = view.getOrChooseDirectory();
46+
4647
if (directory == null) {
4748
return;
4849
}
49-
5050
NewMessageQueueDialog.open(project, directory);
5151
}
5252

src/com/magento/idea/magento2plugin/actions/generation/NewModelsAction.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.magento.idea.magento2plugin.actions.generation.dialog.NewModelsDialog;
1818

1919
public class NewModelsAction extends AnAction {
20+
2021
public static final String ACTION_NAME = "Magento 2 Models";
2122
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 models";
2223

@@ -35,17 +36,16 @@ public void actionPerformed(final AnActionEvent event) {
3536
if (view == null) {
3637
return;
3738
}
38-
3939
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
40+
4041
if (project == null) {
4142
return;
4243
}
43-
4444
final PsiDirectory directory = view.getOrChooseDirectory();
45+
4546
if (directory == null) {
4647
return;
4748
}
48-
4949
NewModelsDialog.open(project, directory);
5050
}
5151

src/com/magento/idea/magento2plugin/actions/generation/NewUiComponentFormAction.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.magento.idea.magento2plugin.actions.generation.dialog.NewUiComponentFormDialog;
1818

1919
public class NewUiComponentFormAction extends AnAction {
20+
2021
public static final String ACTION_NAME = "Magento 2 UI Component Form";
2122
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 UI Component Form";
2223

@@ -35,17 +36,16 @@ public void actionPerformed(final AnActionEvent event) {
3536
if (view == null) {
3637
return;
3738
}
38-
3939
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
40+
4041
if (project == null) {
4142
return;
4243
}
43-
4444
final PsiDirectory directory = view.getOrChooseDirectory();
45+
4546
if (directory == null) {
4647
return;
4748
}
48-
4949
NewUiComponentFormDialog.open(project, directory);
5050
}
5151

src/com/magento/idea/magento2plugin/actions/generation/NewUiComponentGridAction.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
import com.magento.idea.magento2plugin.MagentoIcons;
1717
import com.magento.idea.magento2plugin.actions.generation.dialog.NewUiComponentGridDialog;
1818

19-
@SuppressWarnings({"PMD.OnlyOneReturn"})
2019
public class NewUiComponentGridAction extends AnAction {
20+
2121
public static final String ACTION_NAME = "Magento 2 UI Component Grid";
2222
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 UI Component Grid";
2323

@@ -41,18 +41,16 @@ public void actionPerformed(final AnActionEvent event) {
4141
if (view == null) {
4242
return;
4343
}
44-
4544
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
45+
4646
if (project == null) {
4747
return;
4848
}
49-
5049
final PsiDirectory directory = view.getOrChooseDirectory();
5150

5251
if (directory == null) {
5352
return;
5453
}
55-
5654
NewUiComponentGridDialog.open(project, directory);
5755
}
5856

src/com/magento/idea/magento2plugin/actions/generation/dialog/NewDataModelDialog.form

+9-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</properties>
1111
<border type="none"/>
1212
<children>
13-
<grid id="e3588" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
13+
<grid id="e3588" layout-manager="GridLayoutManager" row-count="4" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
1414
<margin top="0" left="0" bottom="0" right="0"/>
1515
<constraints>
1616
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@@ -36,6 +36,14 @@
3636
<text value=""/>
3737
</properties>
3838
</component>
39+
<component id="8fecc" class="javax.swing.JLabel" binding="modelNameErrorMessage">
40+
<constraints>
41+
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
42+
</constraints>
43+
<properties>
44+
<text value=""/>
45+
</properties>
46+
</component>
3947
</children>
4048
</grid>
4149
<grid id="ebe15" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">

src/com/magento/idea/magento2plugin/actions/generation/dialog/NewDataModelDialog.java

+32-18
Original file line numberDiff line numberDiff line change
@@ -40,48 +40,53 @@
4040
import javax.swing.JButton;
4141
import javax.swing.JCheckBox;
4242
import javax.swing.JComponent;
43+
import javax.swing.JLabel;
4344
import javax.swing.JOptionPane;
4445
import javax.swing.JPanel;
4546
import javax.swing.JTable;
4647
import javax.swing.JTextField;
4748
import javax.swing.KeyStroke;
4849
import javax.swing.table.DefaultTableModel;
4950
import javax.swing.table.TableColumn;
51+
import org.jetbrains.annotations.NotNull;
5052

5153
@SuppressWarnings({
5254
"PMD.ExcessiveImports"
5355
})
5456
public class NewDataModelDialog extends AbstractDialog {
5557

56-
private final Project project;
57-
private final String moduleName;
58-
private final ValidatorBundle validatorBundle;
59-
private final CommonBundle commonBundle;
60-
private final List<String> properties;
61-
6258
private static final String MODEL_NAME = "Model Name";
6359
private static final String PROPERTY_NAME = "Name";
6460
private static final String PROPERTY_TYPE = "Type";
6561
private static final String PROPERTY_ACTION = "Action";
6662
private static final String PROPERTY_DELETE = "Delete";
6763

64+
private final Project project;
65+
private final String moduleName;
66+
private final ValidatorBundle validatorBundle;
67+
private final CommonBundle commonBundle;
68+
private final List<String> properties;
69+
6870
private JPanel contentPanel;
6971
private JButton buttonOK;
7072
private JButton buttonCancel;
7173
private JTable propertyTable;
7274
private JButton addProperty;
7375
private JCheckBox createInterface;
7476

75-
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
76-
message = {NotEmptyRule.MESSAGE, MODEL_NAME})
77-
@FieldValidation(rule = RuleRegistry.PHP_CLASS,
78-
message = {PhpClassRule.MESSAGE, MODEL_NAME})
77+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, MODEL_NAME})
78+
@FieldValidation(rule = RuleRegistry.PHP_CLASS, message = {PhpClassRule.MESSAGE, MODEL_NAME})
7979
private JTextField modelName;
8080

81+
private JLabel modelNameErrorMessage;//NOPMD
82+
8183
/**
8284
* Constructor.
8385
*/
84-
public NewDataModelDialog(final Project project, final PsiDirectory directory) {
86+
public NewDataModelDialog(
87+
final @NotNull Project project,
88+
final @NotNull PsiDirectory directory
89+
) {
8590
super();
8691

8792
this.project = project;
@@ -122,7 +127,10 @@ public void windowClosing(final WindowEvent event) {
122127
/**
123128
* Opens the dialog window.
124129
*/
125-
public static void open(final Project project, final PsiDirectory directory) {
130+
public static void open(
131+
final @NotNull Project project,
132+
final @NotNull PsiDirectory directory
133+
) {
126134
final NewDataModelDialog dialog = new NewDataModelDialog(project, directory);
127135
dialog.pack();
128136
dialog.centerDialog(dialog);
@@ -145,8 +153,8 @@ private void onOK() {
145153
generateDataModelInterfaceFile();
146154
generatePreferenceForInterface();
147155
}
156+
exit();
148157
}
149-
exit();
150158
}
151159

152160
@Override
@@ -157,6 +165,17 @@ protected boolean validateFormFields() {
157165
valid = true;
158166
final String errorTitle = commonBundle.message("common.error");
159167
final int column = 0;
168+
169+
if (propertyTable.getRowCount() == 0) {
170+
valid = false;
171+
JOptionPane.showMessageDialog(
172+
null,
173+
validatorBundle.message("validator.properties.notEmpty"),
174+
errorTitle,
175+
JOptionPane.ERROR_MESSAGE
176+
);
177+
}
178+
160179
for (int row = 0; row < propertyTable.getRowCount(); row++) {
161180
final String propertyName = ((String) propertyTable.getValueAt(row, column)).trim();
162181
if (propertyName.isEmpty()) {
@@ -190,11 +209,6 @@ protected boolean validateFormFields() {
190209
return valid;
191210
}
192211

193-
@Override
194-
public void onCancel() {
195-
dispose();
196-
}
197-
198212
/**
199213
* Generate DTO interface file.
200214
*/

0 commit comments

Comments
 (0)