Skip to content

Commit d150ec8

Browse files
authored
Merge pull request #483 from bohdan-harniuk/entity-manager-form-ux-improvements
Improved UX by adding autocompletion for entity name dependent fields
2 parents d1c65f3 + f57f07b commit d150ec8

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

src/com/magento/idea/magento2plugin/actions/generation/dialog/NewEntityDialog.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.intellij.openapi.project.Project;
1010
import com.intellij.psi.PsiDirectory;
1111
import com.intellij.psi.PsiFile;
12+
import com.intellij.ui.DocumentAdapter;
1213
import com.intellij.util.indexing.FileBasedIndex;
1314
import com.magento.idea.magento2plugin.actions.generation.NewEntityAction;
1415
import com.magento.idea.magento2plugin.actions.generation.OverrideClassByAPreferenceAction;
@@ -94,6 +95,7 @@
9495
import com.magento.idea.magento2plugin.stubs.indexes.xml.MenuIndex;
9596
import com.magento.idea.magento2plugin.ui.FilteredComboBox;
9697
import com.magento.idea.magento2plugin.ui.table.TableGroupWrapper;
98+
import com.magento.idea.magento2plugin.util.CamelCaseToSnakeCase;
9799
import com.magento.idea.magento2plugin.util.FirstLetterToLowercaseUtil;
98100
import com.magento.idea.magento2plugin.util.GetPhpClassByFQN;
99101
import com.magento.idea.magento2plugin.util.magento.GetAclResourcesListUtil;
@@ -109,7 +111,9 @@
109111
import java.util.HashMap;
110112
import java.util.LinkedList;
111113
import java.util.List;
114+
import java.util.Locale;
112115
import java.util.Map;
116+
import java.util.stream.Collectors;
113117
import javax.swing.JButton;
114118
import javax.swing.JCheckBox;
115119
import javax.swing.JComboBox;
@@ -121,6 +125,7 @@
121125
import javax.swing.JTextField;
122126
import javax.swing.JTextPane;
123127
import javax.swing.KeyStroke;
128+
import javax.swing.event.DocumentEvent;
124129
import javax.swing.table.DefaultTableModel;
125130
import org.apache.commons.lang.StringUtils;
126131
import org.jetbrains.annotations.NotNull;
@@ -257,6 +262,13 @@ public void windowClosing(final WindowEvent event) {
257262
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
258263
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
259264
);
265+
266+
entityName.getDocument().addDocumentListener(new DocumentAdapter() {
267+
@Override
268+
protected void textChanged(final @NotNull DocumentEvent event) {
269+
autoCompleteIdentifiers();
270+
}
271+
});
260272
}
261273

262274
/**
@@ -1362,4 +1374,29 @@ private List<String> getMenuReferences() {
13621374

13631375
return menuReferencesList;
13641376
}
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+
}
13651402
}

src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public void windowClosing(final WindowEvent event) {
189189
this.topicName.getDocument().addDocumentListener(new DocumentAdapter() {
190190
@Override
191191
protected void textChanged(final @NotNull DocumentEvent event) {
192-
updateIndefiersTextes();
192+
updateIdentifiersTexts();
193193
}
194194
});
195195
this.handlerClass.getDocument().addDocumentListener(new DocumentAdapter() {
@@ -386,7 +386,7 @@ public String getModuleName() {
386386
/**
387387
* Update identifier texts.
388388
*/
389-
public void updateIndefiersTextes() {
389+
public void updateIdentifiersTexts() {
390390
final String topicNameText = this.topicName.getText();
391391
this.handlerName.setText(topicNameText.concat(".handler"));
392392
this.consumerName.setText(topicNameText);

0 commit comments

Comments
 (0)