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);
}
}
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;
}
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();
}
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);
}
}
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;
}
}
Aggregations