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