1515
1616import javax .swing .*;
1717import java .awt .*;
18+ import java .awt .event .ActionEvent ;
19+ import java .awt .event .ActionListener ;
1820
1921public 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