Skip to content
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 @@ -9,6 +9,7 @@
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiDirectory;
import com.intellij.psi.PsiFile;
import com.intellij.ui.DocumentAdapter;
import com.intellij.util.indexing.FileBasedIndex;
import com.magento.idea.magento2plugin.actions.generation.NewEntityAction;
import com.magento.idea.magento2plugin.actions.generation.OverrideClassByAPreferenceAction;
Expand Down Expand Up @@ -94,6 +95,7 @@
import com.magento.idea.magento2plugin.stubs.indexes.xml.MenuIndex;
import com.magento.idea.magento2plugin.ui.FilteredComboBox;
import com.magento.idea.magento2plugin.ui.table.TableGroupWrapper;
import com.magento.idea.magento2plugin.util.CamelCaseToSnakeCase;
import com.magento.idea.magento2plugin.util.FirstLetterToLowercaseUtil;
import com.magento.idea.magento2plugin.util.GetPhpClassByFQN;
import com.magento.idea.magento2plugin.util.magento.GetAclResourcesListUtil;
Expand All @@ -109,7 +111,9 @@
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.stream.Collectors;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
Expand All @@ -121,6 +125,7 @@
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.KeyStroke;
import javax.swing.event.DocumentEvent;
import javax.swing.table.DefaultTableModel;
import org.apache.commons.lang.StringUtils;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -257,6 +262,13 @@ public void windowClosing(final WindowEvent event) {
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
);

entityName.getDocument().addDocumentListener(new DocumentAdapter() {
@Override
protected void textChanged(final @NotNull DocumentEvent event) {
autoCompleteIdentifiers();
}
});
}

/**
Expand Down Expand Up @@ -1362,4 +1374,29 @@ private List<String> getMenuReferences() {

return menuReferencesList;
}

/**
* Autocomplete entity name dependent fields.
*/
private void autoCompleteIdentifiers() {
if (getEntityName().isEmpty()) {
return;
}
final String entityName = CamelCaseToSnakeCase.getInstance().convert(getEntityName());
final String entityNameLabel = Arrays.stream(entityName.split("_")).map(
string -> string.substring(0, 1).toUpperCase(Locale.getDefault())
+ string.substring(1)
).collect(Collectors.joining(" "));

dbTableName.setText(entityName);
entityId.setText(entityName.concat("_id"));
route.setText(entityName);
formLabel.setText(entityNameLabel.concat(" Form"));
formName.setText(entityName.concat("_form"));
gridName.setText(entityName.concat("_listing"));
Comment on lines +1394 to +1396
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm currently checking this, and my question is: What if you don't check the Create Admin Ui Components checkbox? Per my understanding, we should completely hide the Admin Ui Components tab if we have it unchecked and no other action should be done in scope of Ui Components tab.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you don't check the Create Admin Ui Components checkbox you won't get generated any files related to UI components.

We cannot depend on it during inputs autocompletion. What if we will fill all inputs on the first tab and only then check the Create Admin Ui Components checkbox? That is why better to leave this in this way - it is more clear for the user.

What about hiding the Admin Ui Components tab, it is a good idea. I'll implement it. Thank you!

After it will be implemented, I'll leave a comment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hiding that tab would be more logical, and it won't confuse the end-user, since he unchecked the checkbox, but still sees the Tab.

acl.setText(getModuleName().concat("::management"));
aclTitle.setText(entityNameLabel.concat(" Management"));
menuIdentifier.setText(getModuleName().concat("::management"));
menuTitle.setText(entityNameLabel.concat(" Management"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ public void windowClosing(final WindowEvent event) {
this.topicName.getDocument().addDocumentListener(new DocumentAdapter() {
@Override
protected void textChanged(final @NotNull DocumentEvent event) {
updateIndefiersTextes();
updateIdentifiersTexts();
}
});
this.handlerClass.getDocument().addDocumentListener(new DocumentAdapter() {
Expand Down Expand Up @@ -386,7 +386,7 @@ public String getModuleName() {
/**
* Update identifier texts.
*/
public void updateIndefiersTextes() {
public void updateIdentifiersTexts() {
final String topicNameText = this.topicName.getText();
this.handlerName.setText(topicNameText.concat(".handler"));
this.consumerName.setText(topicNameText);
Expand Down