Skip to content

867: enhanced new controller dialog UX #880

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

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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.jetbrains.annotations.NotNull;

public class NewBlockAction extends AnAction {

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

Expand All @@ -26,23 +27,24 @@ public NewBlockAction() {
}

@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;
}

NewBlockDialog.open(project, directory);
}

Expand All @@ -51,4 +53,3 @@ public boolean isDumbAware() {
return false;
}
}

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.NewControllerDialog;

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

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

Expand All @@ -36,13 +36,13 @@ 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
</grid>
</children>
</grid>
<grid id="e3588" layout-manager="GridLayoutManager" row-count="2" 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 Down Expand Up @@ -85,7 +85,7 @@
</component>
<component id="fdc52" class="javax.swing.JTextField" binding="blockParentDir">
<constraints>
<grid row="1" column="1" 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="1" 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>
Expand All @@ -96,7 +96,7 @@
</component>
<component id="be25f" class="javax.swing.JLabel">
<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="fdc52"/>
Expand All @@ -106,6 +106,22 @@
<html.disable class="java.lang.Boolean" value="true"/>
</clientProperties>
</component>
<component id="48e8" class="javax.swing.JLabel" binding="blockNameErrorMessage">
<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>
<component id="340c3" class="javax.swing.JLabel" binding="blockParentDirErrorMessage">
<constraints>
<grid row="3" 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="ddd4f" layout-manager="GridLayoutManager" row-count="2" 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 @@ -7,7 +7,6 @@

import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiDirectory;
import com.intellij.psi.PsiFile;
import com.magento.idea.magento2plugin.actions.generation.NewBlockAction;
import com.magento.idea.magento2plugin.actions.generation.data.BlockFileData;
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.FieldValidation;
Expand All @@ -26,13 +25,15 @@
import java.awt.event.WindowEvent;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.KeyStroke;

public class NewBlockDialog extends AbstractDialog {

private final PsiDirectory baseDir;
private final String moduleName;
private JPanel contentPanel;
Expand All @@ -44,18 +45,18 @@ public class NewBlockDialog extends AbstractDialog {
private static final String NAME = "name";
private static final String DIRECTORY = "directory";

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

@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
message = {NotEmptyRule.MESSAGE, DIRECTORY})
@FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, DIRECTORY})
@FieldValidation(rule = RuleRegistry.PHP_DIRECTORY,
message = {PhpDirectoryRule.MESSAGE, DIRECTORY})
private JTextField blockParentDir;

private JLabel blockNameErrorMessage;//NOPMD
private JLabel blockParentDirErrorMessage;//NOPMD

/**
* Constructor.
*
Expand Down Expand Up @@ -113,12 +114,12 @@ public static void open(final Project project, final PsiDirectory directory) {
protected void onOK() {
if (validateFormFields()) {
generateFile();
exit();
}
exit();
}

private PsiFile generateFile() {
return new ModuleBlockClassGenerator(new BlockFileData(
private void generateFile() {
new ModuleBlockClassGenerator(new BlockFileData(
getBlockDirectory(),
getBlockName(),
getModuleName(),
Expand All @@ -140,13 +141,15 @@ public String getBlockDirectory() {

private void suggestBlockDirectory() {
final String moduleIdentifierPath = getModuleIdentifierPath();

if (moduleIdentifierPath == null) {
blockParentDir.setText(BlockPhp.DEFAULT_DIR);
return;
}
final String path = baseDir.getVirtualFile().getPath();
final String[] pathParts = path.split(moduleIdentifierPath);
final int minimumPathParts = 2;

if (pathParts.length != minimumPathParts) {
blockParentDir.setText(BlockPhp.DEFAULT_DIR);
return;
Expand All @@ -161,27 +164,25 @@ private void suggestBlockDirectory() {

private String getModuleIdentifierPath() {
final String[]parts = moduleName.split(Package.vendorModuleNameSeparator);

if (parts[0] == null || parts[1] == null || parts.length > 2) {
return null;
}

return parts[0] + File.separator + parts[1];
}

private String getNamespace() {
final String[]parts = moduleName.split(Package.vendorModuleNameSeparator);

if (parts[0] == null || parts[1] == null || parts.length > 2) {
return null;
}
final String directoryPart = getBlockDirectory().replace(
File.separator,
Package.fqnSeparator
);
return parts[0] + Package.fqnSeparator + parts[1] + Package.fqnSeparator + directoryPart;
}

@Override
public void onCancel() {
// add your code here if necessary
dispose();
return parts[0] + Package.fqnSeparator + parts[1] + Package.fqnSeparator + directoryPart;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="8" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>
<xy x="48" y="54" width="454" height="423"/>
<xy x="48" y="54" width="454" height="431"/>
</constraints>
<properties>
<preferredSize width="450" height="300"/>
Expand Down Expand Up @@ -51,7 +51,7 @@
</grid>
</children>
</grid>
<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="6" 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="5" 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 @@ -61,15 +61,15 @@
<children>
<component id="5a121" class="javax.swing.JLabel">
<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>
<text resource-bundle="magento2/common" key="common.controller.name"/>
</properties>
</component>
<component id="4e6cb" class="javax.swing.JTextField" binding="controllerName">
<constraints>
<grid row="1" column="1" 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="1" 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>
Expand All @@ -79,15 +79,15 @@
</component>
<component id="d25a" class="javax.swing.JLabel">
<constraints>
<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"/>
<grid row="4" 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>
<text resource-bundle="magento2/common" key="common.parentDirectory"/>
</properties>
</component>
<component id="7df01" class="javax.swing.JTextField" binding="controllerParentDir">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<grid row="4" column="1" 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>
Expand All @@ -111,13 +111,38 @@
</constraints>
<properties/>
</component>
<component id="77374" class="javax.swing.JLabel" binding="actionNameErrorMessage">
<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>
<component id="d71e2" class="javax.swing.JLabel" binding="controllerNameErrorMessage">
<constraints>
<grid row="3" 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>
<component id="f1afe" class="javax.swing.JLabel" binding="controllerParentDirErrorMessage">
<constraints>
<grid row="5" 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="b8894" class="com.magento.idea.magento2plugin.ui.FilteredComboBox" binding="controllerAreaSelect" custom-create="true">
<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"/>
</constraints>
<properties>
<editable value="true"/>
<toolTipText value=""/>
</properties>
<clientProperties>
Expand Down Expand Up @@ -145,6 +170,7 @@
<grid row="3" 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>
<editable value="true"/>
<toolTipText value=""/>
</properties>
<clientProperties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
Expand All @@ -43,14 +44,14 @@
"PMD.ExcessiveImports"
})
public class NewControllerDialog extends AbstractDialog {

private final String moduleName;
private final Project project;
private JPanel contentPane;
private JButton buttonOK;
private JButton buttonCancel;
private FilteredComboBox controllerAreaSelect;
private FilteredComboBox httpMethodSelect;
private JTextField controllerParentDir;
private JCheckBox inheritClass;
private JPanel adminPanel;
private JTextField acl;
Expand All @@ -64,12 +65,16 @@ public class NewControllerDialog extends AbstractDialog {
message = {PhpDirectoryRule.MESSAGE, CONTROLLER_NAME})
private JTextField controllerName;

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

private JTextField controllerParentDir;

private JLabel actionNameErrorMessage;//NOPMD
private JLabel controllerNameErrorMessage;//NOPMD
private JLabel controllerParentDirErrorMessage;//NOPMD

/**
* Open new dialog for adding new controller.
*
Expand Down Expand Up @@ -196,8 +201,8 @@ public static void open(final Project project, final PsiDirectory directory) {
private void onOK() {
if (validateFormFields()) {
generateFile();
exit();
}
exit();
}

/**
Expand Down Expand Up @@ -264,11 +269,6 @@ private Boolean getIsInheritClass() {
return inheritClass.isSelected();
}

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

private List<String> getAreaList() {
return new ArrayList<>(
Arrays.asList(
Expand Down