Search in sources :

Example 11 with SessionNode

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

the class SessionEditorNode method getAcronym.

/**
 * @return the acronym for the contained model class.
 */
private String getAcronym() {
    SessionNodeWrapper modelNode = (SessionNodeWrapper) getModelNode();
    SessionNode sessionNode = modelNode.getSessionNode();
    Object model = sessionNode.getModel();
    if (model == null) {
        return "No model";
    } else {
        Class<?> modelClass = model.getClass();
        SessionNodeModelConfig modelConfig = this.config.getModelConfig(modelClass);
        if (modelConfig == null) {
            System.out.println("Tried to load model config for " + modelClass);
            return modelClass.getSimpleName();
        }
        return modelConfig.getAcronym();
    }
}
Also used : SessionNodeWrapper(edu.cmu.tetradapp.model.SessionNodeWrapper) SessionNode(edu.cmu.tetrad.session.SessionNode)

Example 12 with SessionNode

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

the class SessionEditorNode method finishedEditingDialog.

/**
 * After editing a session node, either run changes or break edges.
 */
private void finishedEditingDialog() {
    if (!ModificationRegistery.modelHasChanged(getSessionNode())) {
        return;
    }
    // dialog.
    for (SessionNode child : getChildren()) {
        if (child.getModel() != null) {
            continue;
        }
        return;
    }
    Object[] options = { "Execute", "Break Edges" };
    Component centeringComp = SessionEditorNode.this;
    int selection = JOptionPane.showOptionDialog(centeringComp, "Changing this node will affect its children.\n" + "Click on \"Execute\" to percolate changes down.\n" + "Click on \"Break Edges\" to leave the children the same.", "Warning", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]);
    if (selection == 0) {
        for (SessionNode child : getChildren()) {
            executeSessionNode(child, true);
        }
    } else if (selection == 1) {
        for (Edge edge : sessionWrapper.getEdges(getModelNode())) {
            // only break edges to children.
            if (edge.getNode2() == getModelNode()) {
                SessionNodeWrapper otherWrapper = (SessionNodeWrapper) edge.getNode1();
                SessionNode other = otherWrapper.getSessionNode();
                if (getChildren().contains(other)) {
                    sessionWrapper.removeEdge(edge);
                }
            } else {
                SessionNodeWrapper otherWrapper = (SessionNodeWrapper) edge.getNode2();
                SessionNode other = otherWrapper.getSessionNode();
                if (getChildren().contains(other)) {
                    sessionWrapper.removeEdge(edge);
                }
            }
        }
    }
}
Also used : SessionNodeWrapper(edu.cmu.tetradapp.model.SessionNodeWrapper) SessionNode(edu.cmu.tetrad.session.SessionNode) Component(java.awt.Component) JComponent(javax.swing.JComponent) Edge(edu.cmu.tetrad.graph.Edge) Point(java.awt.Point)

Example 13 with SessionNode

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

the class SessionWrappers 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 14 with SessionNode

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

the class SessionWrapper method addNode.

/**
 * Adds a node to the workbench and fires a PropertyChangeEvent for property
 * "nodeAdded" with the new node as the new value.
 *
 * @param node the node to be added.
 * @return true if nodes were added, false if not.
 */
public boolean addNode(Node node) {
    SessionNodeWrapper wrapper = (SessionNodeWrapper) node;
    SessionNode sessionNode = wrapper.getSessionNode();
    try {
        this.session.addNode(sessionNode);
        this.sessionNodeWrappers.add(node);
        getPropertyChangeSupport().firePropertyChange("nodeAdded", null, node);
        return true;
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
        return false;
    }
}
Also used : SessionNode(edu.cmu.tetrad.session.SessionNode)

Example 15 with SessionNode

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

the class SessionEditorNode method createModel.

/**
 * Creates a model in the wrapped SessionNode, given the SessionNode's
 * parent models.
 *
 * @throws IllegalStateException if the model cannot be created. The reason
 * why the model cannot be created is in the message of the exception.
 */
public boolean createModel(boolean simulation) throws Exception {
    if (getSessionNode().getModel() != null) {
        return true;
    }
    SessionNode sessionNode = getSessionNode();
    Class modelClass = determineTheModelClass(sessionNode);
    if (modelClass == null && !simulation) {
        JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), config.getNodeSpecificMessage());
        return false;
    }
    // constructor of the model.)
    if (sessionNode.existsParameterizedConstructor(modelClass)) {
        Parameters params = sessionNode.getParam(modelClass);
        Object[] arguments = sessionNode.getModelConstructorArguments(modelClass);
        if (params != null) {
            boolean edited = editParameters(modelClass, params, arguments);
            if (!edited) {
                return false;
            }
        }
    }
    // Finally, create the model. Don't worry, if anything goes wrong
    // in the process, an exception will be thrown with an
    // appropriate message.
    sessionNode.createModel(modelClass, simulation);
    return true;
}
Also used : Parameters(edu.cmu.tetrad.util.Parameters) 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