@Override
public void doAction(ActionEvent e) throws IllegalUserActionException {
HashTree subTree = null;
if (!commands.contains(e.getActionCommand())) {
throw new IllegalUserActionException("Invalid user command:" + e.getActionCommand());
}
if (e.getActionCommand().equals(SAVE_AS)) {
subTree = ReportGuiPackage.getInstance().getCurrentSubTree();
} else {
subTree = ReportGuiPackage.getInstance().getTreeModel().getReportPlan();
}
String updateFile = ReportGuiPackage.getInstance().getReportPlanFile();
if (!SAVE.equals(e.getActionCommand()) || updateFile == null) {
JFileChooser chooser = ReportFileDialoger.promptToSaveFile(ReportGuiPackage.getInstance().getTreeListener()
.getCurrentNode().getName()
+ ".jmr");
if (chooser == null) {
return;
}
updateFile = chooser.getSelectedFile().getAbsolutePath();
if (!e.getActionCommand().equals(SAVE_AS)) {
ReportGuiPackage.getInstance().setReportPlanFile(updateFile);
}
}
// TODO: doesn't putting this here mark the tree as
// saved even though a failure may occur later?
ReportActionRouter.getInstance().doActionNow(new ActionEvent(subTree, e.getID(), ReportCheckDirty.SUB_TREE_SAVED));
try {
convertSubTree(subTree);
} catch (Exception err) {
}
FileOutputStream ostream = null;
try {
ostream = new FileOutputStream(updateFile);
SaveService.saveTree(subTree, ostream);
log.info("saveTree");
} catch (Exception ex) {
ReportGuiPackage.getInstance().setReportPlanFile(null);
log.error("", ex);
throw new IllegalUserActionException("Couldn't save test plan to file: " + updateFile);
} finally {
JOrphanUtils.closeQuietly(ostream);
}
}