Skip to content

Commit

Permalink
#72 confirming with the user to load the content
Browse files Browse the repository at this point in the history
  • Loading branch information
subwiz committed Aug 27, 2018
1 parent ca15f71 commit 5becc75
Showing 1 changed file with 28 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,23 @@ protected void init() {

jb_body_params.setToolTipText("Insert parameters");
jb_body_params.addActionListener((ActionEvent ae) -> {
if(canSetReqBodyText()) {
checkAndSetParameterContentType();
jd_req_paramDialog.setData(HttpUtil.getXWwwFormUrlEncoded2Map(se_req_body.getText()));
jd_req_paramDialog.setLocationRelativeTo(rest_ui.getFrame());
jd_req_paramDialog.setVisible(true);
FormEnc openFrmEncDialg = openFrmEncDialg();
switch(openFrmEncDialg) {
case OPEN_EMPTY:
case ERASE:
case LOAD:
checkAndSetParameterContentType();
break;
case CANCEL:
return;
}
switch(openFrmEncDialg) {
case LOAD:
jd_req_paramDialog.setData(HttpUtil.getXWwwFormUrlEncoded2Map(se_req_body.getText()));
break;
}
jd_req_paramDialog.setLocationRelativeTo(rest_ui.getFrame());
jd_req_paramDialog.setVisible(true);
});
jp_north.add(jb_body_params);

Expand Down Expand Up @@ -165,20 +176,26 @@ private void loadFile(File f) {
}
}

private boolean canSetReqBodyText(){
private enum FormEnc {
ERASE, LOAD, OPEN_EMPTY, CANCEL
}
private FormEnc openFrmEncDialg() {
if(StringUtil.isEmpty(se_req_body.getText())){
return true;
return FormEnc.OPEN_EMPTY;
}
else{
int response = JOptionPane.showConfirmDialog(rest_ui.getFrame(),
"Body text exists. Erase?",
"Body text exists. Erase?\n1. Yes - erase!\n2. No - load existing body for editing (silent on failures).\n3. Cancel - to cancel.",
"Erase?",
JOptionPane.YES_NO_OPTION);
JOptionPane.YES_NO_CANCEL_OPTION);
if(response == JOptionPane.YES_OPTION){
return true;
return FormEnc.ERASE;
}
if(response == JOptionPane.NO_OPTION){
return FormEnc.LOAD;
}
}
return false;
return FormEnc.CANCEL;
}

private void checkAndSetParameterContentType(){
Expand Down

0 comments on commit 5becc75

Please sign in to comment.