Search in sources :

Example 1 with SessionEditorIndirectRef

use of edu.cmu.tetradapp.util.SessionEditorIndirectRef 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 SessionEditorIndirectRef

use of edu.cmu.tetradapp.util.SessionEditorIndirectRef in project tetrad by cmu-phil.

the class ConstructTemplateAction method estimateFromSimulatedData.

private void estimateFromSimulatedData(int leftX) {
    SessionEditorIndirectRef sessionEditorRef = DesktopController.getInstance().getFrontmostSessionEditor();
    SessionEditor sessionEditor = (SessionEditor) sessionEditorRef;
    SessionEditorWorkbench sessionWorkbench = sessionEditor.getSessionWorkbench();
    sessionWorkbench.deselectAll();
    List<Node> nodes = new LinkedList<>();
    String data = nextName("Data");
    String search = nextName("Search");
    nodes.add(addNode("Data", data, leftX, 100));
    nodes.add(addNode("Search", search, leftX + 150, 100));
    String graph = nextName("Graph");
    nodes.add(addNode("Graph", graph, leftX + 150, 200));
    String pm = nextName("PM");
    nodes.add(addNode("PM", pm, leftX + 150, 300));
    String estimator = nextName("Estimator");
    nodes.add(addNode("Estimator", estimator, leftX, 300));
    addEdge(data, search);
    addEdge(search, graph);
    addEdge(graph, pm);
    addEdge(data, estimator);
    addEdge(data, pm);
    addEdge(pm, estimator);
    selectSubgraph(nodes);
}
Also used : Node(edu.cmu.tetrad.graph.Node) SessionNode(edu.cmu.tetrad.session.SessionNode) SessionEditorIndirectRef(edu.cmu.tetradapp.util.SessionEditorIndirectRef) LinkedList(java.util.LinkedList)

Example 3 with SessionEditorIndirectRef

use of edu.cmu.tetradapp.util.SessionEditorIndirectRef in project tetrad by cmu-phil.

the class ConstructTemplateAction method updateFromSimulatedData.

private void updateFromSimulatedData(int leftX) {
    SessionEditorIndirectRef sessionEditorRef = DesktopController.getInstance().getFrontmostSessionEditor();
    SessionEditor sessionEditor = (SessionEditor) sessionEditorRef;
    SessionEditorWorkbench sessionWorkbench = sessionEditor.getSessionWorkbench();
    sessionWorkbench.deselectAll();
    List<Node> nodes = new LinkedList<>();
    String data = nextName("Data");
    String search = nextName("Search");
    String estimator = nextName("Estimator");
    String updater = nextName("Updater");
    nodes.add(addNode("Data", data, leftX, 100));
    nodes.add(addNode("Search", search, 150 + leftX, 100));
    nodes.add(addNode("Estimator", estimator, 80 + leftX, 200));
    nodes.add(addNode("Updater", updater, 80 + leftX, 300));
    addEdge(data, search);
    addEdge(data, estimator);
    addEdge(search, estimator);
    addEdge(estimator, updater);
    selectSubgraph(nodes);
}
Also used : Node(edu.cmu.tetrad.graph.Node) SessionNode(edu.cmu.tetrad.session.SessionNode) SessionEditorIndirectRef(edu.cmu.tetradapp.util.SessionEditorIndirectRef) LinkedList(java.util.LinkedList)

Example 4 with SessionEditorIndirectRef

use of edu.cmu.tetradapp.util.SessionEditorIndirectRef 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 SessionEditorIndirectRef

use of edu.cmu.tetradapp.util.SessionEditorIndirectRef in project tetrad by cmu-phil.

the class SessionEditorNode method getSessionWorkbench.

// ===========================PRIVATE METHODS===========================//
private SessionEditorWorkbench getSessionWorkbench() {
    if (sessionWorkbench == null) {
        SessionEditorIndirectRef sessionEditorRef = DesktopController.getInstance().getFrontmostSessionEditor();
        SessionEditor sessionEditor = (SessionEditor) sessionEditorRef;
        if (sessionEditor == null) {
            DesktopController.getInstance().newSessionEditor();
            sessionEditorRef = DesktopController.getInstance().getFrontmostSessionEditor();
            sessionEditor = (SessionEditor) sessionEditorRef;
        }
        this.sessionWorkbench = sessionEditor.getSessionWorkbench();
    }
    return sessionWorkbench;
}
Also used : SessionEditorIndirectRef(edu.cmu.tetradapp.util.SessionEditorIndirectRef)

Aggregations

SessionEditorIndirectRef (edu.cmu.tetradapp.util.SessionEditorIndirectRef)19 Node (edu.cmu.tetrad.graph.Node)7 SessionNode (edu.cmu.tetrad.session.SessionNode)7 SessionWrapper (edu.cmu.tetradapp.model.SessionWrapper)5 LinkedList (java.util.LinkedList)5 TetradMetadata (edu.cmu.tetradapp.model.TetradMetadata)3 List (java.util.List)3 Endpoint (edu.cmu.tetrad.graph.Endpoint)2 Edge (edu.cmu.tetrad.graph.Edge)1 HpcAccountSettingAction (edu.cmu.tetradapp.app.hpc.action.HpcAccountSettingAction)1 TetradMetadataIndirectRef (edu.cmu.tetradapp.util.TetradMetadataIndirectRef)1 DataFlavor (java.awt.datatransfer.DataFlavor)1 Transferable (java.awt.datatransfer.Transferable)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 SimpleDateFormat (java.text.SimpleDateFormat)1