Search in sources :

Example 1 with FinalizingParameterEditor

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());
}
Also used : SessionNodeWrapper(edu.cmu.tetradapp.model.SessionNodeWrapper) JComponent(javax.swing.JComponent) FinalizingParameterEditor(edu.cmu.tetradapp.editor.FinalizingParameterEditor) ParameterEditor(edu.cmu.tetradapp.editor.ParameterEditor) FinalizingParameterEditor(edu.cmu.tetradapp.editor.FinalizingParameterEditor) Component(java.awt.Component) JComponent(javax.swing.JComponent) JDialog(javax.swing.JDialog) Point(java.awt.Point)

Aggregations

FinalizingParameterEditor (edu.cmu.tetradapp.editor.FinalizingParameterEditor)1 ParameterEditor (edu.cmu.tetradapp.editor.ParameterEditor)1 SessionNodeWrapper (edu.cmu.tetradapp.model.SessionNodeWrapper)1 Component (java.awt.Component)1 Point (java.awt.Point)1 JComponent (javax.swing.JComponent)1 JDialog (javax.swing.JDialog)1