/**
   * Queries the user as to whether they would like to save their sessions.
   *
   * @return true if the transaction was ended successfully, false if not (that is, canceled).
   */
  public boolean closeAllSessions() {
    while (existsSession()) {
      SessionEditor sessionEditor = getFrontmostSessionEditor();
      SessionEditorWorkbench workbench = sessionEditor.getSessionWorkbench();
      SessionWrapper wrapper = workbench.getSessionWrapper();

      if (!wrapper.isSessionChanged()) {
        closeFrontmostSession();
        continue;
      }

      String name = sessionEditor.getName();

      int ret =
          JOptionPane.showConfirmDialog(
              JOptionUtils.centeringComp(),
              "Would you like to save the changes you made to " + name + "?",
              "Advise needed...",
              JOptionPane.YES_NO_CANCEL_OPTION);

      if (ret == JOptionPane.NO_OPTION) {
        closeFrontmostSession();
        continue;
      } else if (ret == JOptionPane.CANCEL_OPTION) {
        return false;
      }

      SaveSessionAsAction action = new SaveSessionAsAction();
      action.actionPerformed(
          new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "Dummy close action"));

      if (!action.isSaved()) {
        int ret2 =
            JOptionPane.showConfirmDialog(
                JOptionUtils.centeringComp(),
                "This session was not saved. Close session and continue anyway?",
                "Advise needed...",
                JOptionPane.OK_CANCEL_OPTION);

        if (ret2 == JOptionPane.CANCEL_OPTION) {
          return false;
        }
      }

      closeFrontmostSession();
    }

    return true;
  }
  /**
   * States whether the log display should be automatically displayed, if there is no value in the
   * user's prefs then it will display a prompt asking the user whether they would like to disable
   * automatic popups.
   */
  private boolean allowAutomaticLogPopup() {
    Boolean allowed = TetradLogger.getInstance().isAutomaticLogDisplayEnabled();
    // ask the user whether they way the feature etc.
    if (allowed == null) {
      String message =
          "<html>Whenever Tetrad's logging features are active any generated log <br>"
              + "output will be automatically display in Tetrad's log display. Would you like Tetrad<br>"
              + "to continue to automatically open the log display window whenever there is logging output?</html>";
      int option =
          JOptionPane.showConfirmDialog(
              this, message, "Automatic Logging", JOptionPane.YES_NO_OPTION);
      if (option == JOptionPane.NO_OPTION) {
        JOptionPane.showMessageDialog(
            this, "This feature can be enabled later by going to Logging>Setup Logging.");
      }
      TetradLogger.getInstance().setAutomaticLogDisplayEnabled(option == JOptionPane.YES_OPTION);
      // return true, so that opens this time, in the future the user's pref will be used.
      return true;
    }

    return allowed;
  }