Search in sources :

Example 16 with SessionNodeWrapper

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());
}
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)

Example 17 with SessionNodeWrapper

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();
    }
}
Also used : SessionNodeWrapper(edu.cmu.tetradapp.model.SessionNodeWrapper) SessionNode(edu.cmu.tetrad.session.SessionNode) Component(java.awt.Component) JComponent(javax.swing.JComponent) LinkedList(java.util.LinkedList) Point(java.awt.Point)

Aggregations

SessionNodeWrapper (edu.cmu.tetradapp.model.SessionNodeWrapper)17 SessionNode (edu.cmu.tetrad.session.SessionNode)11 Component (java.awt.Component)5 Point (java.awt.Point)5 JComponent (javax.swing.JComponent)5 Edge (edu.cmu.tetrad.graph.Edge)3 JMenuItem (javax.swing.JMenuItem)3 Node (edu.cmu.tetrad.graph.Node)2 FinalizingParameterEditor (edu.cmu.tetradapp.editor.FinalizingParameterEditor)2 ParameterEditor (edu.cmu.tetradapp.editor.ParameterEditor)2 JPopupMenu (javax.swing.JPopupMenu)2 CouldNotCreateModelException (edu.cmu.tetrad.session.CouldNotCreateModelException)1 SessionModel (edu.cmu.tetrad.session.SessionModel)1 Parameters (edu.cmu.tetrad.util.Parameters)1 TetradLoggerConfig (edu.cmu.tetrad.util.TetradLoggerConfig)1 UnlistedSessionModel (edu.cmu.tetradapp.model.UnlistedSessionModel)1 LinkedList (java.util.LinkedList)1 JDialog (javax.swing.JDialog)1