Skip to content
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 @@ -17,10 +17,10 @@
import com.magento.idea.magento2plugin.actions.generation.dialog.NewCronjobDialog;
import org.jetbrains.annotations.NotNull;

@SuppressWarnings({"PMD.FieldNamingConventions", "PMD.OnlyOneReturn"})
public class NewCronjobAction extends AnAction {
public static String ACTION_NAME = "Magento 2 Cron Job";
public static String ACTION_DESCRIPTION = "Create a new Magento 2 Cron Job";

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

public NewCronjobAction() {
super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE);
Expand All @@ -34,17 +34,16 @@ public void actionPerformed(final @NotNull 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;
}

NewCronjobDialog.open(project, directory);
}

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="false"/>
<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="false"/>
<toolTipText value=""/>
</properties>
<clientProperties>
Expand Down
Loading