catch(IllegalStateException ex) {
view.showError(Util.getStackTrace(ex));
}
}
else if(type == FileChooserType.SAVE_RESPONSE){
Response response = view.getLastResponse();
if(response == null){
JOptionPane.showMessageDialog(view.getContainer(),
"No last response available.",
"No Response",
JOptionPane.ERROR_MESSAGE);
return;
}
Response uiResponse = view.getResponseFromUI();
if(!response.equals(uiResponse)){
if(!doSaveEvenIfUIChanged(DO_SAVE_UI_RESPONSE)){
return;
}
}
File f = getSaveFile(FileChooserType.SAVE_RESPONSE);
if(f != null){
try{
XMLUtil.writeResponseXML(response, f);
recentFilesHelper.openedFile(f);
}
catch(IOException ex){
view.showError(Util.getStackTrace(ex));
}
catch(XMLException ex){
view.showError(Util.getStackTrace(ex));
}
}
}
else if(type == FileChooserType.SAVE_RESPONSE_BODY){
Response response = view.getLastResponse();
if(response == null){
JOptionPane.showMessageDialog(view.getContainer(),
"No last response available.",
"No Response",
JOptionPane.ERROR_MESSAGE);
return;
}
if(response.getResponseBody() == null) {
JOptionPane.showMessageDialog(view.getContainer(),
"Last response does not have body.",
"No Body in Response",
JOptionPane.ERROR_MESSAGE);
return;
}
File f = getSaveFile(FileChooserType.SAVE_RESPONSE_BODY);
if(f != null){
try{
FileUtil.writeBytes(f, response.getResponseBody());
}
catch(IOException ex){
view.showError(Util.getStackTrace(ex));
}
}
}
else if(type == FileChooserType.SAVE_ARCHIVE){
Request request = view.getLastRequest();
Response response = view.getLastResponse();
if(request == null || response == null){
JOptionPane.showMessageDialog(view.getContainer(),
"No last request/response available.",
"No Request/Response",
JOptionPane.ERROR_MESSAGE);
return;
}
try {
Request uiRequest = view.getRequestFromUI();
Response uiResponse = view.getResponseFromUI();
if((!request.equals(uiRequest)) || (!response.equals(uiResponse))){
if(!doSaveEvenIfUIChanged(DO_SAVE_UI_ARCHIVE)){
return;
}
}