Skip to content

877 enhance new db schema dialog ux #890

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

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 @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<properties/>
<border type="none"/>
<children>
<grid id="40126" layout-manager="GridLayoutManager" row-count="2" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="40126" layout-manager="GridLayoutManager" row-count="3" column-count="4" 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 Down Expand Up @@ -92,7 +92,7 @@
</component>
<component id="a42c4" class="javax.swing.JLabel" binding="tableEngineLabel">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="21a4a"/>
Expand All @@ -101,7 +101,7 @@
</component>
<component id="d636e" class="javax.swing.JLabel" binding="tableCommentLabel">
<constraints>
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelFor value="dd0b9"/>
Expand All @@ -110,15 +110,15 @@
</component>
<component id="dd0b9" class="javax.swing.JTextField" binding="tableComment">
<constraints>
<grid row="1" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<grid row="2" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="21a4a" class="javax.swing.JComboBox" binding="tableEngine">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
Expand All @@ -128,6 +128,14 @@
</constraints>
<properties/>
</component>
<component id="e5139" class="javax.swing.JLabel" binding="tableNameErrorMessage">
<constraints>
<grid row="1" 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>
<component id="4443e" class="javax.swing.JLabel" binding="tableColumnsLabel">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

@SuppressWarnings({"PMD.TooManyFields", "PMD.ExcessiveImports"})
public class NewDbSchemaDialog extends AbstractDialog {

private static final String TABLE_NAME = "Table Name";

private final Project project;
Expand Down Expand Up @@ -85,6 +86,7 @@ public class NewDbSchemaDialog extends AbstractDialog {
private JLabel tableResourceLabel;//NOPMD
private JLabel tableCommentLabel;//NOPMD
private JLabel tableColumnsLabel;//NOPMD
private JLabel tableNameErrorMessage;//NOPMD

/**
* Constructor.
Expand Down Expand Up @@ -150,8 +152,8 @@ private void onOK() {
return;
}
generateWhitelistJsonFile(dbSchemaXmlData);
exit();
}
exit();
}

/**
Expand Down
Loading