use of edu.cmu.tetradapp.model.SessionNodeWrapper in project tetrad by cmu-phil.
the class SessionEditorNode method editParameters.
/**
* Tries to edit the parameters, returns true if successfully otherwise
* false is returned
*/
public boolean editParameters(final Class modelClass, Parameters params, Object[] parentModels) {
if (parentModels == null) {
throw new NullPointerException("Parent models array is null.");
}
if (params == null) {
throw new NullPointerException("Parameters cannot be null.");
}
final ParameterEditor paramEditor = getParameterEditor(modelClass);
if (paramEditor == null) {
// if no editor, then consider the params "edited".
return true;
} else {
paramEditor.setParams(params);
paramEditor.setParentModels(parentModels);
}
// If a finalizing editor and a dialog then let it handle things on itself onw.
if (paramEditor instanceof FinalizingParameterEditor && paramEditor instanceof JDialog) {
FinalizingParameterEditor e = (FinalizingParameterEditor) paramEditor;
e.setup();
return e.finalizeEdit();
}
// wrap editor and deal with response.
paramEditor.setup();
JComponent editor = (JComponent) paramEditor;
SessionNodeWrapper nodeWrapper = (SessionNodeWrapper) getModelNode();
String buttonType = nodeWrapper.getButtonType();
editor.setName(buttonType + " Structure Editor");
Component centeringComp = SessionEditorNode.this;
int ret = JOptionPane.showOptionDialog(centeringComp, editor, editor.getName(), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null);
// if finalizing editor, then deal with specially.
return ret == JOptionPane.OK_OPTION && (!(paramEditor instanceof FinalizingParameterEditor) || ((FinalizingParameterEditor) paramEditor).finalizeEdit());
}
use of edu.cmu.tetradapp.model.SessionNodeWrapper in project tetrad by cmu-phil.
the class SessionEditorNode method getModelClassFromUser.
/**
* @return the selected model class, or null if no model class was selected.
*/
private Class getModelClassFromUser(Class[] modelClasses, boolean cancelable) {
// Count the number of model classes that can be listed for the user;
// if there's only one, don't ask the user for input.
List<Class> reducedList = new LinkedList<>();
for (Class modelClass : modelClasses) {
if (!(UnlistedSessionModel.class.isAssignableFrom(modelClass))) {
reducedList.add(modelClass);
}
}
if (reducedList.isEmpty()) {
throw new RuntimeException("There is no model to choose.");
}
SessionNodeWrapper sessionNodeWrapper = (SessionNodeWrapper) getModelNode();
SessionNode sessionNode = sessionNodeWrapper.getSessionNode();
ModelChooser chooser = this.config.getModelChooserInstance(sessionNode);
Component centeringComp = SessionEditorNode.this;
if (cancelable) {
int selection = JOptionPane.showOptionDialog(centeringComp, chooser, chooser.getTitle(), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, new String[] { "OK", "Cancel" }, "OK");
if (selection == 0) {
// this.rememberLastClass = modelTypeChooser.getRemembered();
return chooser.getSelectedModel();
} else {
return null;
}
} else {
JOptionPane.showOptionDialog(centeringComp, chooser, chooser.getTitle(), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] { "OK" }, "OK");
// this.rememberLastClass = modelTypeChooser.getRemembered();
return chooser.getSelectedModel();
}
}
Aggregations