use of edu.cmu.tetradapp.model.SessionNodeWrapper 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.tetradapp.model.SessionNodeWrapper in project tetrad by cmu-phil.
the class SessionEditorNode method addEditLoggerSettings.
// private void addConsistentChildBoxMenus(JPopupMenu menu, List<String> consistentChildBoxes) {
// for (String _type : consistentChildBoxes) {
// final JMenuItem menuItem = new JMenuItem(_type);
//
// menuItem.addActionListener(new ActionListener() {
// @Override
// public void actionPerformed(ActionEvent e) {
// String text = menuItem.getText();
// String[] tokens = text.split(" ");
// String type = tokens[1];
// new ConstructTemplateAction("Test").addChild(SessionEditorNode.this, type);
// }
// });
//
// menu.add(menuItem);
// }
// }
// private JMenu addConsistentChildBoxMenus(List<String> consistentChildBoxes) {
// JMenu newChildren = new JMenu("New Child Box");
//
// for (String _type : consistentChildBoxes) {
// final JMenuItem menuItem = new JMenuItem(_type);
//
// menuItem.addActionListener(new ActionListener() {
// @Override
// public void actionPerformed(ActionEvent e) {
// new ConstructTemplateAction("Test").addChild(SessionEditorNode.this, menuItem.getText());
// }
// });
//
//
//
// newChildren.add(menuItem);
// }
// return newChildren;
// }
// private JMenu addConsistentParentMenuItems(JPopupMenu menu, List<SessionNode> consistentParentNodes) {
// final JMenu newParents = new JMenu("New Parent Box");
//
// for (final SessionNode node : consistentParentNodes) {
// final JMenuItem menuItem = new JMenuItem("Add Links: " + node.getDisplayName());
//
// menuItem.addActionListener(new ActionListener() {
// @Override
// public void actionPerformed(ActionEvent e) {
// String displayName1 = node.getDisplayName();
// String displayName2 = SessionEditorNode.this.getSessionNode().getDisplayName();
// new ConstructTemplateAction("Test").addEdge(displayName1, displayName2);
// }
// });
//
// menu.add(menuItem);
// }
//
// return newParents;
// }
// private List<String> getConsistentChildBoxTypes(SessionNode thisNode, SessionModel model) {
// List<String> consistentChildBoxes = new ArrayList<>();
//
// List<Node> nodes = sessionWorkbench.getSessionWrapper().getNodes();
// List<SessionNode> sessionNodes = new ArrayList<>();
// for (Node node : nodes) sessionNodes.add(((SessionNodeWrapper) node).getSessionNode());
//
// Set<String> strings = TetradApplicationConfig.getInstance().getConfigs().keySet();
//
// for (String type : strings) {
// SessionNodeConfig config = TetradApplicationConfig.getInstance().getSessionNodeConfig(type);
// Class[] modelClasses = config.getModels();
//
// SessionNode newNode = new SessionNode(modelClasses);
//
// if (newNode.isConsistentParent(thisNode, sessionNodes)) {
// consistentChildBoxes.add("Add " + type);
// }
// }
//
// return consistentChildBoxes;
// }
// private List<SessionNode> getConsistentParentBoxTypes(SessionNode thisNode) {
// List<SessionNode> consistentParentBoxes = new ArrayList<>();
//
// for (Node _node : getSessionWorkbench().getSessionWrapper().getNodes()) {
// SessionNode node = ((SessionNodeWrapper) _node).getSessionNode();
//
// if (sessionWorkbench.getSessionWrapper().isAncestorOf(thisNode, node)) {
// continue;
// }
//
// if (!thisNode.getParents().contains(node) && thisNode.isConsistentParent(node)) {
// consistentParentBoxes.add(node);
// }
// }
//
// return consistentParentBoxes;
// }
/**
* Adds the "Edit logger" option if applicable.
*/
private void addEditLoggerSettings(JPopupMenu menu) {
SessionNodeWrapper modelNode = (SessionNodeWrapper) getModelNode();
SessionNode sessionNode = modelNode.getSessionNode();
final TetradLoggerConfig config = sessionNode.getLoggerConfig();
if (config != null) {
JMenuItem item = new JMenuItem("Edit Logger Settings ...");
item.addActionListener((e) -> {
showLogConfig(config);
});
menu.add(item);
}
}
use of edu.cmu.tetradapp.model.SessionNodeWrapper in project tetrad by cmu-phil.
the class SessionEditorNode method getNotePopup.
/**
* Creates a popup for a note node.
*
* @return - popup
*/
private JPopupMenu getNotePopup() {
JPopupMenu popup = new JPopupMenu();
JMenuItem renameBox = new JMenuItem("Rename note");
renameBox.setToolTipText("<html>Renames this note.</html>");
renameBox.addActionListener((e) -> {
Component centeringComp = SessionEditorNode.this;
String name = JOptionPane.showInputDialog(centeringComp, "New name:");
if (!NamingProtocol.isLegalName(name)) {
JOptionPane.showMessageDialog(centeringComp, NamingProtocol.getProtocolDescription());
return;
}
SessionNodeWrapper wrapper = (SessionNodeWrapper) getModelNode();
wrapper.setSessionName(name);
getSessionDisplayComp().setName(name);
adjustToModel();
});
JMenuItem cloneBox = new JMenuItem("Clone Note");
cloneBox.setToolTipText("<html>" + "Makes a copy of this session note and its contents. To clone<br>" + "a whole subgraph, or to paste into a different sessions, select<br>" + "the subgraph and use the Copy/Paste gadgets in the Edit menu." + "</html>");
cloneBox.addActionListener((e) -> {
firePropertyChange("cloneMe", null, SessionEditorNode.this);
});
JMenuItem deleteBox = new JMenuItem("Delete Note");
deleteBox.setToolTipText("<html>Deletes this note from the workbench</html>");
deleteBox.addActionListener((e) -> {
if (getSessionNode().getModel() == null) {
Component centeringComp = SessionEditorNode.this;
int ret = JOptionPane.showConfirmDialog(centeringComp, "Really delete note?");
if (ret != JOptionPane.YES_OPTION) {
return;
}
} else {
Component centeringComp = SessionEditorNode.this;
int ret = JOptionPane.showConfirmDialog(centeringComp, "<html>" + "Really delete note? Any information it contains will<br>" + "be destroyed." + "</html>");
if (ret != JOptionPane.YES_OPTION) {
return;
}
}
firePropertyChange("deleteNode", null, null);
});
JMenuItem help = new JMenuItem("Help");
deleteBox.setToolTipText("<html>Shows help for this box.</html>");
help.addActionListener((e) -> {
SessionNodeWrapper sessionNodeWrapper = (SessionNodeWrapper) getModelNode();
SessionNode sessionNode = sessionNodeWrapper.getSessionNode();
showInfoBoxForModel(sessionNode, sessionNode.getModelClasses());
});
popup.add(renameBox);
popup.add(cloneBox);
popup.add(deleteBox);
popup.addSeparator();
popup.add(help);
return popup;
}
use of edu.cmu.tetradapp.model.SessionNodeWrapper 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.tetradapp.model.SessionNodeWrapper 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);
}
}
}
}
}
Aggregations