|
9 | 9 | import com.intellij.openapi.project.Project;
|
10 | 10 | import com.intellij.psi.PsiDirectory;
|
11 | 11 | import com.intellij.psi.PsiFile;
|
| 12 | +import com.intellij.ui.DocumentAdapter; |
12 | 13 | import com.intellij.util.indexing.FileBasedIndex;
|
13 | 14 | import com.magento.idea.magento2plugin.actions.generation.NewEntityAction;
|
14 | 15 | import com.magento.idea.magento2plugin.actions.generation.OverrideClassByAPreferenceAction;
|
|
94 | 95 | import com.magento.idea.magento2plugin.stubs.indexes.xml.MenuIndex;
|
95 | 96 | import com.magento.idea.magento2plugin.ui.FilteredComboBox;
|
96 | 97 | import com.magento.idea.magento2plugin.ui.table.TableGroupWrapper;
|
| 98 | +import com.magento.idea.magento2plugin.util.CamelCaseToSnakeCase; |
97 | 99 | import com.magento.idea.magento2plugin.util.FirstLetterToLowercaseUtil;
|
98 | 100 | import com.magento.idea.magento2plugin.util.GetPhpClassByFQN;
|
99 | 101 | import com.magento.idea.magento2plugin.util.magento.GetAclResourcesListUtil;
|
|
109 | 111 | import java.util.HashMap;
|
110 | 112 | import java.util.LinkedList;
|
111 | 113 | import java.util.List;
|
| 114 | +import java.util.Locale; |
112 | 115 | import java.util.Map;
|
| 116 | +import java.util.stream.Collectors; |
113 | 117 | import javax.swing.JButton;
|
114 | 118 | import javax.swing.JCheckBox;
|
115 | 119 | import javax.swing.JComboBox;
|
|
121 | 125 | import javax.swing.JTextField;
|
122 | 126 | import javax.swing.JTextPane;
|
123 | 127 | import javax.swing.KeyStroke;
|
| 128 | +import javax.swing.event.DocumentEvent; |
124 | 129 | import javax.swing.table.DefaultTableModel;
|
125 | 130 | import org.apache.commons.lang.StringUtils;
|
126 | 131 | import org.jetbrains.annotations.NotNull;
|
@@ -257,6 +262,13 @@ public void windowClosing(final WindowEvent event) {
|
257 | 262 | KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
|
258 | 263 | JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
|
259 | 264 | );
|
| 265 | + |
| 266 | + entityName.getDocument().addDocumentListener(new DocumentAdapter() { |
| 267 | + @Override |
| 268 | + protected void textChanged(final @NotNull DocumentEvent event) { |
| 269 | + autoCompleteIdentifiers(); |
| 270 | + } |
| 271 | + }); |
260 | 272 | }
|
261 | 273 |
|
262 | 274 | /**
|
@@ -1362,4 +1374,29 @@ private List<String> getMenuReferences() {
|
1362 | 1374 |
|
1363 | 1375 | return menuReferencesList;
|
1364 | 1376 | }
|
| 1377 | + |
| 1378 | + /** |
| 1379 | + * Autocomplete entity name dependent fields. |
| 1380 | + */ |
| 1381 | + private void autoCompleteIdentifiers() { |
| 1382 | + if (getEntityName().isEmpty()) { |
| 1383 | + return; |
| 1384 | + } |
| 1385 | + final String entityName = CamelCaseToSnakeCase.getInstance().convert(getEntityName()); |
| 1386 | + final String entityNameLabel = Arrays.stream(entityName.split("_")).map( |
| 1387 | + string -> string.substring(0, 1).toUpperCase(Locale.getDefault()) |
| 1388 | + + string.substring(1) |
| 1389 | + ).collect(Collectors.joining(" ")); |
| 1390 | + |
| 1391 | + dbTableName.setText(entityName); |
| 1392 | + entityId.setText(entityName.concat("_id")); |
| 1393 | + route.setText(entityName); |
| 1394 | + formLabel.setText(entityNameLabel.concat(" Form")); |
| 1395 | + formName.setText(entityName.concat("_form")); |
| 1396 | + gridName.setText(entityName.concat("_listing")); |
| 1397 | + acl.setText(getModuleName().concat("::management")); |
| 1398 | + aclTitle.setText(entityNameLabel.concat(" Management")); |
| 1399 | + menuIdentifier.setText(getModuleName().concat("::management")); |
| 1400 | + menuTitle.setText(entityNameLabel.concat(" Management")); |
| 1401 | + } |
1365 | 1402 | }
|
0 commit comments