use of edu.cmu.tetradapp.editor.FinalizingParameterEditor 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());
}
Aggregations