Skip to content

Commit be386bd

Browse files
committed
2080: Add custom dialogs to generate new Magento 2 classes
This commit adds a new feature to the plugin that allows developers to easily create new Magento 2 classes using predefined templates. The added dialogs provide users with a more convenient and intuitive way to generate new code. The changes include: * New dialog for generating new Web API declarations, which replaces the existing action with a custom dialog. * New dialog for generating new controller classes, which also includes a custom UI for selecting the class directory and enabling/disabling the admin panel
1 parent f0ba6c3 commit be386bd

17 files changed

+17
-138
lines changed

src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/AbstractDialog.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,13 @@
2020
import com.magento.idea.magento2plugin.bundles.CommonBundle;
2121
import com.magento.idea.magento2plugin.bundles.ValidatorBundle;
2222
import java.awt.Container;
23-
import java.awt.Dimension;
24-
import java.awt.Toolkit;
2523
import java.awt.event.ComponentEvent;
2624
import java.awt.event.ComponentListener;
2725
import java.lang.reflect.Field;
2826
import java.util.LinkedList;
2927
import java.util.List;
3028
import javax.swing.JComboBox;
3129
import javax.swing.JComponent;
32-
import javax.swing.JOptionPane;
3330
import javax.swing.JTabbedPane;
3431
import javax.swing.JTextArea;
3532
import javax.swing.JTextField;

src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAnObserverDialog.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,7 @@ public CreateAnObserverDialog(@NotNull final Project project, final String targe
102102
setTitle(CreateAnObserverAction.ACTION_DESCRIPTION);
103103
fillTargetAreaOptions();
104104

105-
buttonOK.addActionListener(e -> onOK());
106-
buttonCancel.addActionListener(e -> onCancel());
107-
108-
contentPane.registerKeyboardAction(
109-
e -> onCancel(),
110-
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
111-
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
112-
);
105+
// DialogWrapper handles button actions and ESC key automatically
113106

114107
init();
115108
}

src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/GatherArrayValuesDialog.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,7 @@ public GatherArrayValuesDialog(
6969

7070
setTitle(InjectConstructorArgumentAction.GATHER_ARRAY_VALUES_ACTION_DESCRIPTION);
7171

72-
buttonOK.addActionListener(event -> onOK());
73-
buttonCancel.addActionListener(event -> onCancel());
74-
75-
// call onCancel() on ESCAPE
76-
contentPane.registerKeyboardAction(
77-
event -> onCancel(),
78-
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
79-
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
80-
);
72+
// DialogWrapper handles button actions and ESC key automatically
8173

8274
initTable();
8375
itemsTableErrorMessage.setVisible(false);

src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/InjectAViewModelDialog.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,7 @@ protected void textChanged(final @NotNull DocumentEvent event) {
105105

106106
setTitle(InjectAViewModelAction.ACTION_DESCRIPTION);
107107

108-
buttonOK.addActionListener((final ActionEvent event) -> onOK());
109-
buttonCancel.addActionListener((final ActionEvent event) -> onCancel());
110-
111-
contentPane.registerKeyboardAction(
112-
(final ActionEvent event) -> onCancel(),
113-
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
114-
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
115-
);
108+
// DialogWrapper handles button actions and ESC key automatically
116109

117110
init();
118111
}

src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewBlockDialog.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,7 @@ public NewBlockDialog(final Project project, final PsiDirectory directory) {
7474
setTitle(NewBlockAction.ACTION_DESCRIPTION);
7575
suggestBlockDirectory();
7676

77-
buttonOK.addActionListener((final ActionEvent event) -> onOK());
78-
buttonCancel.addActionListener((final ActionEvent event) -> onCancel());
79-
80-
// call onCancel() on ESCAPE
81-
contentPanel.registerKeyboardAction(
82-
(final ActionEvent event) -> onCancel(),
83-
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
84-
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
85-
);
77+
// DialogWrapper handles button actions and ESC key automatically
8678

8779
init();
8880
}

src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCLICommandDialog.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,7 @@ public NewCLICommandDialog(
101101

102102
setTitle(NewCLICommandAction.ACTION_DESCRIPTION);
103103

104-
buttonOK.addActionListener(e -> onOK());
105-
buttonCancel.addActionListener(e -> onCancel());
106-
107-
contentPane.registerKeyboardAction(
108-
event -> onCancel(),
109-
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
110-
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
111-
);
104+
// DialogWrapper handles button actions and ESC key automatically
112105

113106
init();
114107
}

src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewControllerDialog.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,7 @@ public NewControllerDialog(final Project project, final PsiDirectory directory)
9292
controllerAreaSelect.addActionListener(e -> suggestControllerDirectory());
9393
controllerAreaSelect.addActionListener(e -> toggleAdminPanel());
9494
inheritClass.addActionListener(e -> toggleAdminPanel());
95-
buttonOK.addActionListener(e -> onOK());
96-
buttonCancel.addActionListener(e -> onCancel());
97-
98-
// call onCancel() on ESCAPE
99-
contentPane.registerKeyboardAction(
100-
(final ActionEvent event) -> onCancel(),
101-
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
102-
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
103-
);
95+
// DialogWrapper handles button actions and ESC key automatically
10496

10597
init();
10698
}

src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCronGroupDialog.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,10 @@ public NewCronGroupDialog(final Project project, final PsiDirectory directory) {
8181

8282
setTitle(NewCronGroupAction.ACTION_DESCRIPTION);
8383

84-
buttonOK.addActionListener(event -> onOK());
85-
buttonCancel.addActionListener(event -> onCancel());
84+
// DialogWrapper handles button actions and ESC key automatically
8685
addToggleListenersForCronGroupOptions();
8786
addDefaultValuesToCronGroupOptions();
8887

89-
// call onCancel() on ESCAPE
90-
contentPanel.registerKeyboardAction(
91-
event -> onCancel(),
92-
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
93-
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
94-
);
95-
9688
init();
9789
}
9890

src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewCronjobDialog.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,7 @@ public NewCronjobDialog(final @NotNull Project project, final @NotNull PsiDirect
138138
setTitle(NewCronjobAction.ACTION_DESCRIPTION);
139139
configPathField.setEditable(false);
140140

141-
buttonOK.addActionListener(e -> onOK());
142-
buttonCancel.addActionListener(e -> onCancel());
141+
// DialogWrapper handles button actions automatically
143142

144143
fixedScheduleRadioButton.addActionListener(e -> {
145144
configurableSchedulePanel.setVisible(false);
@@ -185,12 +184,7 @@ public void focusLost(final FocusEvent event) {
185184
}
186185
});
187186

188-
// call onCancel() on ESCAPE
189-
contentPane.registerKeyboardAction(
190-
(final ActionEvent event) -> onCancel(),
191-
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
192-
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
193-
);
187+
// DialogWrapper handles ESC key automatically
194188

195189
init();
196190
}

src/main/java/com/magento/idea/magento2plugin/actions/generation/dialog/NewGraphQlResolverDialog.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,7 @@ public NewGraphQlResolverDialog(
7777
setTitle(NewGraphQlResolverAction.ACTION_DESCRIPTION);
7878
suggestGraphQlResolverDirectory();
7979

80-
buttonOK.addActionListener((final ActionEvent event) -> onOK());
81-
buttonCancel.addActionListener((final ActionEvent event) -> onCancel());
82-
83-
// call onCancel() on ESCAPE
84-
contentPanel.registerKeyboardAction(
85-
(final ActionEvent event) -> onCancel(),
86-
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
87-
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
88-
);
80+
// DialogWrapper handles button actions and ESC key automatically
8981

9082
init();
9183
}

0 commit comments

Comments
 (0)