Search in sources :

Example 1 with SessionWrapper

use of edu.cmu.tetradapp.model.SessionWrapper in project tetrad by cmu-phil.

the class SaveSessionAsAction method actionPerformed.

/**
 * Performs the action of saving a session to 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();
    // Select the file to save this to.
    String sessionSaveLocation = Preferences.userRoot().get("sessionSaveLocation", "");
    File file = EditorUtils.getSaveFileWithPath(sessionEditor.getName(), "tet", JOptionUtils.centeringComp(), true, "Save Session As...", sessionSaveLocation);
    if (file == null) {
        this.saved = false;
        return;
    }
    if ((DesktopController.getInstance().existsSessionByName(file.getName()) && !(sessionWrapper.getName().equals(file.getName())))) {
        this.saved = false;
        JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), "Another session by that name is currently open. Please " + "\nclose that session first.");
        return;
    }
    sessionWrapper.setName(file.getName());
    sessionEditor.setName(file.getName());
    // Save it.
    try {
        FileOutputStream out = new FileOutputStream(file);
        ObjectOutputStream objOut = new ObjectOutputStream(out);
        objOut.writeObject(metadata);
        objOut.writeObject(sessionWrapper);
        out.close();
        FileInputStream in = new FileInputStream(file);
        ObjectInputStream objIn = new ObjectInputStream(in);
        objIn.readObject();
        sessionWrapper.setSessionChanged(false);
        sessionWrapper.setNewSession(false);
        this.saved = true;
    } catch (Exception e2) {
        this.saved = false;
        e2.printStackTrace();
        JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), "An error occurred while attempting to save the session.");
    }
    DesktopController.getInstance().putMetadata(sessionWrapper, metadata);
    sessionEditor.firePropertyChange("name", null, file.getName());
}
Also used : TetradMetadata(edu.cmu.tetradapp.model.TetradMetadata) SessionEditorIndirectRef(edu.cmu.tetradapp.util.SessionEditorIndirectRef) SessionWrapper(edu.cmu.tetradapp.model.SessionWrapper)

Example 2 with SessionWrapper

use of edu.cmu.tetradapp.model.SessionWrapper in project tetrad by cmu-phil.

the class TetradDesktop method putMetadata.

public void putMetadata(SessionWrapperIndirectRef sessionWrapperRef, TetradMetadataIndirectRef metadataRef) {
    SessionWrapper sessionWrapper = (SessionWrapper) sessionWrapperRef;
    TetradMetadata metadata = (TetradMetadata) metadataRef;
    this.metadataMap.put(sessionWrapper, metadata);
}
Also used : TetradMetadata(edu.cmu.tetradapp.model.TetradMetadata) SessionWrapper(edu.cmu.tetradapp.model.SessionWrapper)

Example 3 with SessionWrapper

use of edu.cmu.tetradapp.model.SessionWrapper in project tetrad by cmu-phil.

the class SessionEditorWorkbench method pasteSubsession.

/**
 * Pastes list of session elements into the workbench.
 */
public void pasteSubsession(List sessionElements, Point point) {
    SessionWrapper sessionWrapper = (SessionWrapper) getGraph();
    sessionWrapper.pasteSubsession(sessionElements, point);
    deselectAll();
    for (Object sessionElement : sessionElements) {
        if (sessionElement instanceof GraphNode) {
            Node modelNode = (Node) sessionElement;
            selectNode(modelNode);
        }
    }
    selectConnectingEdges();
}
Also used : DisplayNode(edu.cmu.tetradapp.workbench.DisplayNode) MarshalledObject(java.rmi.MarshalledObject) SessionWrapper(edu.cmu.tetradapp.model.SessionWrapper)

Example 4 with SessionWrapper

use of edu.cmu.tetradapp.model.SessionWrapper in project tetrad by cmu-phil.

the class SessionVersionAction 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();
    TetradMetadataIndirectRef metadataRef = DesktopController.getInstance().getTetradMetadata(sessionWrapper);
    TetradMetadata metadata = (TetradMetadata) metadataRef;
    StringBuilder buf = new StringBuilder();
    if (metadata == null) {
        buf.append("This session has not yet been saved or loaded. The model\n");
        buf.append("version you are working in is ");
        buf.append(Version.currentViewableVersion());
        buf.append(".");
        JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), buf.toString());
        return;
    }
    SimpleDateFormat df = new SimpleDateFormat("MMM dd, yyyy");
    buf.append("Version information for \"");
    buf.append(sessionWrapper.getName());
    buf.append("\":\n\n");
    buf.append("Last saved using Tetrad ");
    buf.append(metadata.getVersion());
    buf.append(" (");
    buf.append(df.format(metadata.getDate()));
    buf.append(").\n");
    buf.append("You are running Tetrad ");
    buf.append(Version.currentViewableVersion());
    buf.append(".");
    JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), buf.toString());
}
Also used : TetradMetadataIndirectRef(edu.cmu.tetradapp.util.TetradMetadataIndirectRef) TetradMetadata(edu.cmu.tetradapp.model.TetradMetadata) SessionEditorIndirectRef(edu.cmu.tetradapp.util.SessionEditorIndirectRef) SimpleDateFormat(java.text.SimpleDateFormat) SessionWrapper(edu.cmu.tetradapp.model.SessionWrapper)

Example 5 with SessionWrapper

use of edu.cmu.tetradapp.model.SessionWrapper in project tetrad by cmu-phil.

the class TestSessionEditorWorkbench method setUp.

public final void setUp() {
    Session session = new Session("Test");
    SessionWrapper sessionWrapper = new SessionWrapper(session);
    this.workbench = new SessionEditorWorkbench(sessionWrapper);
}
Also used : Session(edu.cmu.tetrad.session.Session) SessionWrapper(edu.cmu.tetradapp.model.SessionWrapper)

Aggregations

SessionWrapper (edu.cmu.tetradapp.model.SessionWrapper)13 TetradMetadata (edu.cmu.tetradapp.model.TetradMetadata)6 SessionEditorIndirectRef (edu.cmu.tetradapp.util.SessionEditorIndirectRef)5 Session (edu.cmu.tetrad.session.Session)3 SimpleDateFormat (java.text.SimpleDateFormat)3 Node (edu.cmu.tetrad.graph.Node)2 Version (edu.cmu.tetrad.util.Version)2 Point (java.awt.Point)2 Date (java.util.Date)2 Edge (edu.cmu.tetrad.graph.Edge)1 EdgeListGraph (edu.cmu.tetrad.graph.EdgeListGraph)1 Endpoint (edu.cmu.tetrad.graph.Endpoint)1 GraphNode (edu.cmu.tetrad.graph.GraphNode)1 SessionNode (edu.cmu.tetrad.session.SessionNode)1 DecompressibleInputStream (edu.cmu.tetradapp.app.DecompressibleInputStream)1 SessionEditor (edu.cmu.tetradapp.app.SessionEditor)1 SessionEditorWorkbench (edu.cmu.tetradapp.app.SessionEditorWorkbench)1 TetradMetadataIndirectRef (edu.cmu.tetradapp.util.TetradMetadataIndirectRef)1 WatchedProcess (edu.cmu.tetradapp.util.WatchedProcess)1 DisplayNode (edu.cmu.tetradapp.workbench.DisplayNode)1