Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

879 enhance new UI form dialog ux #892

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions resources/magento2/validation.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
validator.notEmpty=The {0} field must not be empty
validator.box.notEmpty=The {0} field must contain a valid selection from the dropdown
validator.package.validPath=Please specify a valid Magento 2 installation path
validator.properties.notEmpty=The properties must not be empty
validator.alphaNumericCharacters=The {0} field must contain letters and numbers only
validator.alphaNumericAndUnderscoreCharacters={0} must contain letters, numbers and underscores only
validator.alphaAndPeriodCharacters=The {0} field must contain alphabets and periods only
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.jetbrains.annotations.NotNull;

public class NewDataModelAction extends AnAction {

public static final String ACTION_NAME = "Magento 2 Data Model";
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 Data Model";

Expand All @@ -29,24 +30,23 @@ public NewDataModelAction() {
}

@Override
public void actionPerformed(@NotNull final AnActionEvent event) {
public void actionPerformed(final @NotNull AnActionEvent event) {
final DataContext dataContext = event.getDataContext();

final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);

if (view == null) {
return;
}

final Project project = CommonDataKeys.PROJECT.getData(dataContext);

if (project == null) {
return;
}

final PsiDirectory directory = view.getOrChooseDirectory();

if (directory == null) {
return;
}

NewDataModelDialog.open(project, directory);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.jetbrains.annotations.NotNull;

public class NewDbSchemaAction extends AnAction {

public static final String ACTION_NAME = "Magento 2 Declarative Schema XML";
public static final String ACTION_DESCRIPTION = "Create a new declarative schema XML";

Expand All @@ -32,16 +33,17 @@ public NewDbSchemaAction() {
public void actionPerformed(final @NotNull AnActionEvent event) {
final DataContext dataContext = event.getDataContext();
final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);

if (view == null) {
return;
}

final Project project = CommonDataKeys.PROJECT.getData(dataContext);

if (project == null) {
return;
}

final PsiDirectory directory = view.getOrChooseDirectory();

if (directory == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import com.magento.idea.magento2plugin.MagentoIcons;
import com.magento.idea.magento2plugin.actions.generation.dialog.NewEmailTemplateDialog;

@SuppressWarnings({"PMD.OnlyOneReturn", "PMD.FieldNamingConventions"})
public class NewEmailTemplateAction extends AnAction {

public static final String ACTION_NAME = "Magento 2 Email Template";
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 email template";

Expand All @@ -36,17 +36,16 @@ public void actionPerformed(final AnActionEvent event) {
if (view == null) {
return;
}

final Project project = CommonDataKeys.PROJECT.getData(dataContext);

if (project == null) {
return;
}

final PsiDirectory directory = view.getOrChooseDirectory();

if (directory == null) {
return;
}

NewEmailTemplateDialog.open(project, directory);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.jetbrains.annotations.NotNull;

public class NewMessageQueueAction extends AnAction {

public static final String ACTION_NAME = "Magento 2 Message Queue";
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 Message Queue";

Expand All @@ -29,24 +30,23 @@ public NewMessageQueueAction() {
}

@Override
public void actionPerformed(@NotNull final AnActionEvent event) {
public void actionPerformed(final @NotNull AnActionEvent event) {
final DataContext dataContext = event.getDataContext();

final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);

if (view == null) {
return;
}

final Project project = CommonDataKeys.PROJECT.getData(dataContext);

if (project == null) {
return;
}

final PsiDirectory directory = view.getOrChooseDirectory();

if (directory == null) {
return;
}

NewMessageQueueDialog.open(project, directory);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.magento.idea.magento2plugin.actions.generation.dialog.NewModelsDialog;

public class NewModelsAction extends AnAction {

public static final String ACTION_NAME = "Magento 2 Models";
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 models";

Expand All @@ -35,17 +36,16 @@ public void actionPerformed(final AnActionEvent event) {
if (view == null) {
return;
}

final Project project = CommonDataKeys.PROJECT.getData(dataContext);

if (project == null) {
return;
}

final PsiDirectory directory = view.getOrChooseDirectory();

if (directory == null) {
return;
}

NewModelsDialog.open(project, directory);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.magento.idea.magento2plugin.actions.generation.dialog.NewUiComponentFormDialog;

public class NewUiComponentFormAction extends AnAction {

public static final String ACTION_NAME = "Magento 2 UI Component Form";
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 UI Component Form";

Expand All @@ -35,17 +36,16 @@ public void actionPerformed(final AnActionEvent event) {
if (view == null) {
return;
}

final Project project = CommonDataKeys.PROJECT.getData(dataContext);

if (project == null) {
return;
}

final PsiDirectory directory = view.getOrChooseDirectory();

if (directory == null) {
return;
}

NewUiComponentFormDialog.open(project, directory);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import com.magento.idea.magento2plugin.MagentoIcons;
import com.magento.idea.magento2plugin.actions.generation.dialog.NewUiComponentGridDialog;

@SuppressWarnings({"PMD.OnlyOneReturn"})
public class NewUiComponentGridAction extends AnAction {

public static final String ACTION_NAME = "Magento 2 UI Component Grid";
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 UI Component Grid";

Expand All @@ -41,18 +41,16 @@ public void actionPerformed(final AnActionEvent event) {
if (view == null) {
return;
}

final Project project = CommonDataKeys.PROJECT.getData(dataContext);

if (project == null) {
return;
}

final PsiDirectory directory = view.getOrChooseDirectory();

if (directory == null) {
return;
}

NewUiComponentGridDialog.open(project, directory);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</properties>
<border type="none"/>
<children>
<grid id="e3588" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="e3588" layout-manager="GridLayoutManager" row-count="4" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<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"/>
Expand All @@ -36,6 +36,14 @@
<text value=""/>
</properties>
</component>
<component id="8fecc" class="javax.swing.JLabel" binding="modelNameErrorMessage">
<constraints>
<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"/>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
</children>
</grid>
<grid id="ebe15" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,48 +40,53 @@
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import org.jetbrains.annotations.NotNull;

@SuppressWarnings({
"PMD.ExcessiveImports"
})
public class NewDataModelDialog extends AbstractDialog {

private final Project project;
private final String moduleName;
private final ValidatorBundle validatorBundle;
private final CommonBundle commonBundle;
private final List<String> properties;

private static final String MODEL_NAME = "Model Name";
private static final String PROPERTY_NAME = "Name";
private static final String PROPERTY_TYPE = "Type";
private static final String PROPERTY_ACTION = "Action";
private static final String PROPERTY_DELETE = "Delete";

private final Project project;
private final String moduleName;
private final ValidatorBundle validatorBundle;
private final CommonBundle commonBundle;
private final List<String> properties;

private JPanel contentPanel;
private JButton buttonOK;
private JButton buttonCancel;
private JTable propertyTable;
private JButton addProperty;
private JCheckBox createInterface;

@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
message = {NotEmptyRule.MESSAGE, MODEL_NAME})
@FieldValidation(rule = RuleRegistry.PHP_CLASS,
message = {PhpClassRule.MESSAGE, MODEL_NAME})
@FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, MODEL_NAME})
@FieldValidation(rule = RuleRegistry.PHP_CLASS, message = {PhpClassRule.MESSAGE, MODEL_NAME})
private JTextField modelName;

private JLabel modelNameErrorMessage;//NOPMD

/**
* Constructor.
*/
public NewDataModelDialog(final Project project, final PsiDirectory directory) {
public NewDataModelDialog(
final @NotNull Project project,
final @NotNull PsiDirectory directory
) {
super();

this.project = project;
Expand Down Expand Up @@ -122,7 +127,10 @@ public void windowClosing(final WindowEvent event) {
/**
* Opens the dialog window.
*/
public static void open(final Project project, final PsiDirectory directory) {
public static void open(
final @NotNull Project project,
final @NotNull PsiDirectory directory
) {
final NewDataModelDialog dialog = new NewDataModelDialog(project, directory);
dialog.pack();
dialog.centerDialog(dialog);
Expand All @@ -145,8 +153,8 @@ private void onOK() {
generateDataModelInterfaceFile();
generatePreferenceForInterface();
}
exit();
}
exit();
}

@Override
Expand All @@ -157,6 +165,17 @@ protected boolean validateFormFields() {
valid = true;
final String errorTitle = commonBundle.message("common.error");
final int column = 0;

if (propertyTable.getRowCount() == 0) {
valid = false;
JOptionPane.showMessageDialog(
null,
validatorBundle.message("validator.properties.notEmpty"),
errorTitle,
JOptionPane.ERROR_MESSAGE
);
}

for (int row = 0; row < propertyTable.getRowCount(); row++) {
final String propertyName = ((String) propertyTable.getValueAt(row, column)).trim();
if (propertyName.isEmpty()) {
Expand Down Expand Up @@ -190,11 +209,6 @@ protected boolean validateFormFields() {
return valid;
}

@Override
public void onCancel() {
dispose();
}

/**
* Generate DTO interface file.
*/
Expand Down
Loading