Search in sources :

Example 1 with CouldNotCreateModelException

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();
    }
}
Also used : JPanel(javax.swing.JPanel) SessionNode(edu.cmu.tetrad.session.SessionNode) InternalFrameEvent(javax.swing.event.InternalFrameEvent) CouldNotCreateModelException(edu.cmu.tetrad.session.CouldNotCreateModelException) EditorWindow(edu.cmu.tetradapp.editor.EditorWindow) CouldNotCreateModelException(edu.cmu.tetrad.session.CouldNotCreateModelException) UnlistedSessionModel(edu.cmu.tetradapp.model.UnlistedSessionModel) SessionModel(edu.cmu.tetrad.session.SessionModel) InternalFrameAdapter(javax.swing.event.InternalFrameAdapter) Component(java.awt.Component) JComponent(javax.swing.JComponent)

Aggregations

CouldNotCreateModelException (edu.cmu.tetrad.session.CouldNotCreateModelException)1 SessionModel (edu.cmu.tetrad.session.SessionModel)1 SessionNode (edu.cmu.tetrad.session.SessionNode)1 EditorWindow (edu.cmu.tetradapp.editor.EditorWindow)1 UnlistedSessionModel (edu.cmu.tetradapp.model.UnlistedSessionModel)1 Component (java.awt.Component)1 JComponent (javax.swing.JComponent)1 JPanel (javax.swing.JPanel)1 InternalFrameAdapter (javax.swing.event.InternalFrameAdapter)1 InternalFrameEvent (javax.swing.event.InternalFrameEvent)1