use of edu.cmu.tetrad.session.CouldNotCreateModelException in project tetrad by cmu-phil.
the class SessionEditorNode method launchEditorVisit.
private void launchEditorVisit() {
try {
// If there is already an editor open, don't launch another one.
if (spawnedEditor() != null) {
return;
}
boolean created = createModel(false);
if (!created) {
return;
}
final SessionNode sessionNode = getSessionNode();
boolean cloned = sessionNode.useClonedModel();
SessionModel model = sessionNode.getModel();
Class<?> modelClass = model.getClass();
SessionNodeModelConfig modelConfig = this.config.getModelConfig(modelClass);
Object[] arguments = new Object[] { model };
JPanel editor = modelConfig.getEditorInstance(arguments);
addEditorListener(editor);
ModificationRegistery.registerEditor(sessionNode, editor);
String descrip = modelConfig.getName();
editor.setName(getName() + " (" + descrip + ")");
EditorWindow editorWindow = new EditorWindow(editor, editor.getName(), "Done", cloned, this);
editorWindow.addInternalFrameListener(new InternalFrameAdapter() {
@Override
public void internalFrameClosing(InternalFrameEvent e) {
if (getChildren().iterator().hasNext()) {
finishedEditingDialog();
}
ModificationRegistery.unregisterSessionNode(sessionNode);
setSpawnedEditor(null);
EditorWindow window = (EditorWindow) e.getSource();
if (window.isCanceled()) {
sessionNode.restoreOriginalModel();
}
sessionNode.forgetSavedModel();
}
});
DesktopController.getInstance().addEditorWindow(editorWindow, JLayeredPane.PALETTE_LAYER);
editorWindow.pack();
editorWindow.setVisible(true);
spawnedEditor = editorWindow;
if (sessionWrapper != null) {
sessionWrapper.setSessionChanged(true);
}
// for (SessionNode child : getChildren()) {
//
// // 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);
// }
// }
// }
// Class[] consistentModelClasses = child.getConsistentModelClasses(false);
// if (consistentModelClasses.length == 0) {
// child.removeParent(sessionNode);
// SessionEditorWorkbench sessionWorkbench = getSessionWorkbench();
// SessionWrapper sessionWrapper = sessionWorkbench.getSessionWrapper();
// Node node1 = sessionWrapper.getNode(sessionNode.getDisplayName());
// Node node2 = sessionWrapper.getNode(child.getDisplayName());
// Edge edge = sessionWrapper.getEdge(node1, node2);
// sessionWrapper.removeEdge(edge);
// }
} catch (CouldNotCreateModelException e) {
SessionUtils.showPermissibleParentsDialog(e.getModelClass(), SessionEditorNode.this, true, true);
e.printStackTrace();
} catch (ClassCastException e) {
e.printStackTrace();
} catch (Exception e) {
Throwable cause = e;
while (cause.getCause() != null) {
cause = cause.getCause();
}
Component centeringComp = SessionEditorNode.this;
String s = cause.getMessage();
if (!"".equals(s)) {
JOptionPane.showMessageDialog(centeringComp, s, null, JOptionPane.WARNING_MESSAGE);
}
e.printStackTrace();
}
}
Aggregations