Skip to content

Commit f14ebf5

Browse files
authoredMar 24, 2025··
Fix/20250323 (#35)
Upgrade plugin version to 2.x Fix bug: java.lang.Throwable: 'virtualFile' is requested on EDT... Add Group and Client check box for grpc generation.
1 parent d963100 commit f14ebf5

File tree

5 files changed

+66
-19
lines changed

5 files changed

+66
-19
lines changed
 

‎src/main/java/cn/xiaoheiban/action/ApiAction.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ public String getExtension() {
2626
@Override
2727
public void performed(@NotNull AnActionEvent e, @NotNull VirtualFile file, @NotNull Project project) {
2828
String parent = file.getParent().getPath();
29-
FileChooseDialog dialog = new FileChooseDialog("API Generate Option", "Cancel", false);
29+
FileChooseDialog dialog = new FileChooseDialog("API Generate Option", "Cancel", false,false);
3030
dialog.setDefaultPath(parent);
3131
dialog.setOnClickListener(new FileChooseDialog.OnClickListener() {
3232
@Override
33-
public void onOk(String goctlHome, String output, String protoPath, String style) {
33+
public void onOk(String goctlHome, String output, String protoPath, String style,boolean group,boolean client) {
3434
ProgressManager.getInstance().run(new Task.Backgroundable(project, "generating api ...") {
3535
@Override
3636
public void run(@NotNull ProgressIndicator indicator) {

‎src/main/java/cn/xiaoheiban/action/ModelAction.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ public String getExtension() {
2727
@Override
2828
public void performed(@NotNull AnActionEvent e, @NotNull VirtualFile file, @NotNull Project project) {
2929
String parent = file.getParent().getPath();
30-
FileChooseDialog dialog = new FileChooseDialog("Model Generate Option", "Cancel", false);
30+
FileChooseDialog dialog = new FileChooseDialog("Model Generate Option", "Cancel", false, false);
3131
dialog.setDefaultPath(parent);
3232
dialog.setOnClickListener(new FileChooseDialog.OnClickListener() {
3333
@Override
34-
public void onOk(String goctlHome, String output, String protoPath, String style) {
34+
public void onOk(String goctlHome, String output, String protoPath, String style, boolean group,boolean client) {
3535
ProgressManager.getInstance().run(new Task.Backgroundable(project, "generating model ...") {
3636
@Override
3737
public void run(@NotNull ProgressIndicator indicator) {

‎src/main/java/cn/xiaoheiban/action/RpcAction.java

+10-4
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ public void performed(@NotNull AnActionEvent e, @NotNull VirtualFile file, @NotN
2626
try {
2727
String parent = file.getParent().getPath();
2828
String content = IO.read(file.getInputStream());
29-
FileChooseDialog dialog = new FileChooseDialog("zRPC Generate Option", "Cancel", content.contains("import"));
29+
FileChooseDialog dialog = new FileChooseDialog("zRPC Generate Option", "Cancel", content.contains("import"), true);
3030
dialog.setDefaultPath(parent);
3131
dialog.setOnClickListener(new FileChooseDialog.OnClickListener() {
3232
@Override
33-
public void onOk(String goctlHome, String output, String protoPath, String style) {
34-
generateRpc(project, goctlHome, protoPath, path, output, style, e);
33+
public void onOk(String goctlHome, String output, String protoPath, String style, boolean group, boolean client) {
34+
generateRpc(project, goctlHome, protoPath, path, output, style, group, client, e);
3535
}
3636

3737
@Override
@@ -44,7 +44,7 @@ public void onJump() {
4444
}
4545
}
4646

47-
private void generateRpc(Project project, String goctlHome, String protoPath, String src, String target, String style, AnActionEvent e) {
47+
private void generateRpc(Project project, String goctlHome, String protoPath, String src, String target, String style, boolean group, boolean client, AnActionEvent e) {
4848
ProgressManager.getInstance().run(new Task.Backgroundable(project, "generating rpc ...") {
4949
@Override
5050
public void run(@NotNull ProgressIndicator indicator) {
@@ -67,6 +67,12 @@ public void run(@NotNull ProgressIndicator indicator) {
6767
}
6868
}
6969
}
70+
if (group) {
71+
command += " --multiple ";
72+
}
73+
if (!client) {
74+
command += " --client=false ";
75+
}
7076
boolean done = Exec.runGoctl(project, command);
7177
if (done) {
7278
FileReload.reloadFromDisk(e);

‎src/main/java/cn/xiaoheiban/action/RpcQuickAction.java

+11-5
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ public void performed(@NotNull AnActionEvent e, @NotNull VirtualFile file, @NotN
3535
String content = IO.read(file.getInputStream());
3636
boolean hasImport = content.contains("import");
3737
if (!hasImport) {
38-
generateRpc(project, "", "", path, parent, "", e);
38+
generateRpc(project, "", "", path, parent, "", false, false, e);
3939
return;
4040
}
41-
FileChooseDialog dialog = new FileChooseDialog("zRPC Generate Option", "Cancel", content.contains("import"));
41+
FileChooseDialog dialog = new FileChooseDialog("zRPC Generate Option", "Cancel", content.contains("import"), true);
4242
dialog.setDefaultPath(parent);
4343
dialog.setOnClickListener(new FileChooseDialog.OnClickListener() {
4444
@Override
45-
public void onOk(String goctlHome, String output, String protoPath, String style) {
46-
generateRpc(project, goctlHome, protoPath, path, output, style, e);
45+
public void onOk(String goctlHome, String output, String protoPath, String style, boolean group, boolean client) {
46+
generateRpc(project, goctlHome, protoPath, path, output, style, group, client, e);
4747
}
4848

4949
@Override
@@ -56,7 +56,7 @@ public void onJump() {
5656
}
5757
}
5858

59-
private void generateRpc(Project project, String goctlHome, String protoPath, String src, String target, String style, AnActionEvent e) {
59+
private void generateRpc(Project project, String goctlHome, String protoPath, String src, String target, String style, boolean group, boolean client, AnActionEvent e) {
6060
ProgressManager.getInstance().run(new Task.Backgroundable(project, "generating rpc ...") {
6161
@Override
6262
public void run(@NotNull ProgressIndicator indicator) {
@@ -82,6 +82,12 @@ public void run(@NotNull ProgressIndicator indicator) {
8282
}
8383
}
8484
}
85+
if (group) {
86+
command += " --multiple ";
87+
}
88+
if (!client) {
89+
command += " --client=false ";
90+
}
8591
boolean done = Exec.runGoctl(project, command);
8692
if (done) {
8793
FileReload.reloadFromDisk(e);

‎src/main/java/cn/xiaoheiban/ui/FileChooseDialog.java

+41-6
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,33 @@
1515

1616
import javax.swing.*;
1717
import java.awt.*;
18+
import java.awt.event.ActionEvent;
19+
import java.awt.event.ActionListener;
1820

1921
public class FileChooseDialog extends DialogWrapper {
2022
private OnClickListener onOkClickListener;
2123
private String title;
24+
private boolean rpc;
2225
private boolean showProtoPath;
2326

2427
public interface OnClickListener {
25-
void onOk(String goctlHome, String output, String protoPath, String style);
28+
void onOk(String goctlHome, String output, String protoPath, String style, boolean group, boolean client);
2629

2730
void onJump();
2831
}
2932

3033
private TextFieldWithBrowseButton textFieldWithBrowseButton;
3134
private TextFieldWithBrowseButton protoPathBrowseButton;
3235
private TextFieldWithBrowseButton templateBrowseButton;
36+
private Checkbox groupCheckBox, clientBox;
3337
private JTextField gozeroTextField;
3438
private final String stylePropertyKey = "cn.xiaoheiban.go-zero" + "_style";
3539

36-
public FileChooseDialog(String title, String cancelText, boolean showProtoPath) {
40+
public FileChooseDialog(String title, String cancelText, boolean showProtoPath, boolean rpc) {
3741
super(true);
3842
this.title = title;
3943
this.showProtoPath = showProtoPath;
44+
this.rpc = rpc;
4045
init();
4146
setTitle(title);
4247
setOKButtonText("Confirm");
@@ -61,7 +66,7 @@ public void setDefaultPath(String path) {
6166
@Override
6267
protected JComponent createCenterPanel() {
6368
final JPanel contentPane = new JPanel();
64-
contentPane.setLayout(new GridLayoutManager(4, 2, new Insets(10, 10, 10, 10), -1, -1));
69+
contentPane.setLayout(new GridLayoutManager(6, 2, new Insets(10, 10, 10, 10), -1, -1));
6570

6671
Dimension labelDimension = new Dimension(100, -1);
6772
Dimension textFieldDimension = new Dimension(500, -1);
@@ -113,6 +118,29 @@ protected JComponent createCenterPanel() {
113118
contentPane.add(stylePanel, new GridConstraints(0, 0, 1, 2, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
114119
contentPane.add(outputPanel, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
115120
contentPane.add(templatePanel, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
121+
if (rpc) {
122+
final JPanel groupPanel = new JPanel();
123+
groupPanel.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1));
124+
final JLabel groupLabel = new JLabel();
125+
groupLabel.setText("Group");
126+
groupPanel.add(groupLabel, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, labelDimension, null, 0, false));
127+
128+
groupCheckBox = new Checkbox();
129+
groupPanel.add(groupCheckBox, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, textFieldDimension, null, 0, false));
130+
contentPane.add(groupPanel, new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
131+
132+
final JPanel clientPanel = new JPanel();
133+
clientPanel.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1));
134+
final JLabel clientLabel = new JLabel();
135+
clientLabel.setText("Client");
136+
clientPanel.add(clientLabel, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, labelDimension, null, 0, false));
137+
138+
clientBox = new Checkbox();
139+
clientBox.setState(true);
140+
clientPanel.add(clientBox, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, textFieldDimension, null, 0, false));
141+
contentPane.add(clientPanel, new GridConstraints(4, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
142+
143+
}
116144
if (showProtoPath) {
117145
final JPanel protoPathPanel = new JPanel();
118146
protoPathPanel.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1));
@@ -126,7 +154,7 @@ protected JComponent createCenterPanel() {
126154
TextBrowseFolderListener protoPathListener = new TextBrowseFolderListener(protoPathChooserDescriptor);
127155
protoPathBrowseButton.addBrowseFolderListener(protoPathListener);
128156
protoPathPanel.add(protoPathBrowseButton, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, textFieldDimension, null, 0, false));
129-
contentPane.add(protoPathPanel, new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
157+
contentPane.add(protoPathPanel, new GridConstraints(5, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
130158
}
131159
return contentPane;
132160
}
@@ -136,7 +164,8 @@ protected JComponent createCenterPanel() {
136164
protected ValidationInfo doValidate() {
137165
String goctlHome = templateBrowseButton.getText();
138166
String outputBrowserPath = textFieldWithBrowseButton.getText();
139-
167+
boolean groupCheck = false;
168+
boolean clientCheck = true;
140169
// store style string
141170
String style = gozeroTextField.getText();
142171
PropertiesComponent.getInstance().setValue(stylePropertyKey, style);
@@ -154,8 +183,14 @@ protected ValidationInfo doValidate() {
154183
protoPath = protoFile.getPath();
155184
}
156185
}
186+
if (groupCheckBox != null) {
187+
groupCheck = groupCheckBox.getState();
188+
}
189+
if (clientBox != null) {
190+
clientCheck = clientBox.getState();
191+
}
157192
if (this.onOkClickListener != null) {
158-
this.onOkClickListener.onOk(goctlHome, output, protoPath, style);
193+
this.onOkClickListener.onOk(goctlHome, output, protoPath, style, groupCheck, clientCheck);
159194
}
160195
return null;
161196
}

0 commit comments

Comments
 (0)
Please sign in to comment.