Search in sources :

Example 1 with SessionNode

use of edu.cmu.tetrad.session.SessionNode in project tetrad by cmu-phil.

the class RunSimulationAction method executeNode.

private void executeNode() {
    Set<SessionNode> children = sessionEditorNode.getChildren();
    boolean noEmptyChildren = true;
    for (SessionNode child : children) {
        if (child.getModel() == null) {
            noEmptyChildren = false;
            break;
        }
    }
    Component centeringComp = sessionEditorNode;
    // if (!noEmptyChildren) {
    // JOptionPane.showMessageDialog(centeringComp, "Nothing to run.");
    // return;
    // }
    Object[] options = { "Simulate", "Cancel" };
    // int selection = 0;
    int selection = JOptionPane.showOptionDialog(centeringComp, "Executing this node will erase any model for this node, " + "\nerase any models for any descendant nodes, and create " + "\nnew models with new values using the default" + "\nparameters for each node, which you may edit, and " + "\nthe repetition numbers for each node, which you " + "\nmay also edit. Continue?", "Warning", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[1]);
    if (selection == 0) {
        int ret = JOptionPane.showConfirmDialog(centeringComp, "Please confirm once more.", "Confirm", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
        if (ret != JOptionPane.YES_OPTION) {
            return;
        }
    }
    if (selection == 0) {
        executeSessionNode(sessionEditorNode.getSessionNode(), true);
    }
}
Also used : SessionNode(edu.cmu.tetrad.session.SessionNode)

Example 2 with SessionNode

use of edu.cmu.tetrad.session.SessionNode in project tetrad by cmu-phil.

the class ConstructTemplateAction method getNewModelNode.

private static SessionNodeWrapper getNewModelNode(String nextButtonType, String name) {
    if (nextButtonType == null) {
        throw new NullPointerException("Next button type must be a " + "non-null string.");
    }
    Class[] modelClasses = getModelClasses(nextButtonType);
    SessionNode newNode = new SessionNode(nextButtonType, name, modelClasses);
    SessionNodeWrapper nodeWrapper = new SessionNodeWrapper(newNode);
    nodeWrapper.setButtonType(nextButtonType);
    return nodeWrapper;
}
Also used : SessionNodeWrapper(edu.cmu.tetradapp.model.SessionNodeWrapper) SessionNode(edu.cmu.tetrad.session.SessionNode)

Example 3 with SessionNode

use of edu.cmu.tetrad.session.SessionNode in project tetrad by cmu-phil.

the class DefaultModelChooser method setSessionNode.

public void setSessionNode(SessionNode sessionNode) {
    /*(
      The session node for the getModel node.
     */
    SessionNode sessionNode1 = sessionNode;
    this.nodeName = sessionNode.getDisplayName();
}
Also used : SessionNode(edu.cmu.tetrad.session.SessionNode)

Example 4 with SessionNode

use of edu.cmu.tetrad.session.SessionNode in project tetrad by cmu-phil.

the class SessionWrapper method pasteSubsession.

/**
 * Pastes a list of session elements (SessionNodeWrappers and SessionEdges)
 * into the workbench.
 */
public void pasteSubsession(List sessionElements, Point upperLeft) {
    // Extract the SessionNodes from the SessionNodeWrappers
    // and pass the list of them to the Session.  Choose a unique
    // name for each of the session wrappers.
    List<SessionNode> sessionNodes = new ArrayList<>();
    List<SessionNodeWrapper> sessionNodeWrappers = new ArrayList<>();
    List<Edge> sessionEdges = new ArrayList<>();
    Point oldUpperLeft = EditorUtils.getTopLeftPoint(sessionElements);
    int deltaX = upperLeft.x - oldUpperLeft.x;
    int deltaY = upperLeft.y - oldUpperLeft.y;
    for (Object sessionElement : sessionElements) {
        if (sessionElement instanceof SessionNodeWrapper) {
            SessionNodeWrapper wrapper = (SessionNodeWrapper) sessionElement;
            sessionNodeWrappers.add(wrapper);
            adjustNameAndPosition(wrapper, sessionNodeWrappers, deltaX, deltaY);
            SessionNode sessionNode = wrapper.getSessionNode();
            sessionNodes.add(sessionNode);
        } else if (sessionElement instanceof Edge) {
            sessionEdges.add((Edge) sessionElement);
        } else {
            throw new IllegalArgumentException("The list of session " + "elements should contain only SessionNodeWrappers " + "and SessionEdges: " + sessionElement);
        }
    }
    // KEY STEP: Add the session nodes to the session.
    try {
        this.session.addNodeList(sessionNodes);
    } catch (Exception e) {
        throw new RuntimeException("There was an error when trying to " + "add session nodes to the session.", e);
    }
    // If that worked, go ahead and put the session node wrappers and
    // session edges into the main data structures and throw events
    // for everything.
    this.sessionNodeWrappers.addAll(sessionNodeWrappers);
    this.sessionEdges.addAll(sessionEdges);
    for (Object sessionNodeWrapper : sessionNodeWrappers) {
        Node node = (Node) sessionNodeWrapper;
        getPropertyChangeSupport().firePropertyChange("nodeAdded", null, node);
    }
    for (Object sessionEdge : sessionEdges) {
        Edge edge = (Edge) sessionEdge;
        getPropertyChangeSupport().firePropertyChange("edgeAdded", null, edge);
    }
}
Also used : SessionNode(edu.cmu.tetrad.session.SessionNode) SessionNode(edu.cmu.tetrad.session.SessionNode) IOException(java.io.IOException)

Example 5 with SessionNode

use of edu.cmu.tetrad.session.SessionNode in project tetrad by cmu-phil.

the class SessionWrapper method addEdge.

// ==================PUBLIC METHODS IMPLEMENTING Graph===========//
/**
 * Adds an edge to the workbench (cast as indicated) and fires a
 * PropertyChangeEvent, property "edgeAdded," with the new edge as the
 * newValue. The nodes connected by the edge must both be
 * SessionNodeWrappers that already lie in the workbench.
 *
 * @param edge the edge to be added.
 * @return true if the edge was added, false if not.
 */
public boolean addEdge(Edge edge) {
    SessionNodeWrapper from = (SessionNodeWrapper) Edges.getDirectedEdgeTail(edge);
    SessionNodeWrapper to = (SessionNodeWrapper) Edges.getDirectedEdgeHead(edge);
    SessionNode parent = from.getSessionNode();
    SessionNode child = to.getSessionNode();
    boolean added = child.addParent2(parent);
    if (added) {
        this.sessionEdges.add(edge);
        getPropertyChangeSupport().firePropertyChange("edgeAdded", null, edge);
        return true;
    } else {
        return false;
    }
}
Also used : SessionNode(edu.cmu.tetrad.session.SessionNode)

Aggregations

SessionNode (edu.cmu.tetrad.session.SessionNode)20 SessionNodeWrapper (edu.cmu.tetradapp.model.SessionNodeWrapper)9 Component (java.awt.Component)5 JComponent (javax.swing.JComponent)5 Point (java.awt.Point)4 CouldNotCreateModelException (edu.cmu.tetrad.session.CouldNotCreateModelException)3 Parameters (edu.cmu.tetrad.util.Parameters)3 JMenuItem (javax.swing.JMenuItem)3 SessionModel (edu.cmu.tetrad.session.SessionModel)2 EditorWindow (edu.cmu.tetradapp.editor.EditorWindow)2 UnlistedSessionModel (edu.cmu.tetradapp.model.UnlistedSessionModel)2 JPopupMenu (javax.swing.JPopupMenu)2 Edge (edu.cmu.tetrad.graph.Edge)1 SessionAdapter (edu.cmu.tetrad.session.SessionAdapter)1 SessionEvent (edu.cmu.tetrad.session.SessionEvent)1 TetradLoggerConfig (edu.cmu.tetrad.util.TetradLoggerConfig)1 FinalizingParameterEditor (edu.cmu.tetradapp.editor.FinalizingParameterEditor)1 ParameterEditor (edu.cmu.tetradapp.editor.ParameterEditor)1 ComponentAdapter (java.awt.event.ComponentAdapter)1 ComponentEvent (java.awt.event.ComponentEvent)1