use of edu.cmu.tetradapp.model.TetradMetadata in project tetrad by cmu-phil.
the class SaveSessionAction method actionPerformed.
/**
* Performs the action of loading a session from a file.
*/
public void actionPerformed(ActionEvent e) {
// Get the frontmost SessionWrapper.
SessionEditorIndirectRef sessionEditorRef = DesktopController.getInstance().getFrontmostSessionEditor();
SessionEditor sessionEditor = (SessionEditor) sessionEditorRef;
SessionEditorWorkbench workbench = sessionEditor.getSessionWorkbench();
SessionWrapper sessionWrapper = workbench.getSessionWrapper();
TetradMetadata metadata = new TetradMetadata();
File file = new File(Preferences.userRoot().get("sessionSaveLocation", Preferences.userRoot().absolutePath()), sessionWrapper.getName());
if (!file.exists() || sessionWrapper.isNewSession()) {
SaveSessionAsAction saveSessionAsAction = new SaveSessionAsAction();
saveSessionAsAction.actionPerformed(e);
this.saved = saveSessionAsAction.isSaved();
return;
}
if (file.exists()) {
int ret = JOptionPane.showConfirmDialog(JOptionUtils.centeringComp(), "File already exists. Overwrite?", "Save", JOptionPane.YES_NO_OPTION);
if (ret == JOptionPane.NO_OPTION) {
SaveSessionAsAction saveSessionAsAction = new SaveSessionAsAction();
saveSessionAsAction.actionPerformed(e);
this.saved = saveSessionAsAction.isSaved();
return;
}
}
// Save it.
try {
FileOutputStream out = new FileOutputStream(file);
ObjectOutputStream objOut = new ObjectOutputStream(out);
sessionWrapper.setNewSession(false);
objOut.writeObject(metadata);
objOut.writeObject(sessionWrapper);
out.close();
// JOptionPane.showMessageDialog(JOptionUtils.centeringComp(),
// "Session saved.");
FileInputStream in = new FileInputStream(file);
ObjectInputStream objIn = new ObjectInputStream(in);
objIn.readObject();
} catch (Exception e2) {
e2.printStackTrace();
JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), "An error occurred while attempting to save the session as " + file.getAbsolutePath() + ".");
}
sessionWrapper.setSessionChanged(false);
DesktopController.getInstance().putMetadata(sessionWrapper, metadata);
}
Aggregations