/**
   * Copies a parentally closed selection of session nodes in the frontmost session editor to the
   * clipboard.
   */
  public void actionPerformed(ActionEvent e) {
    Transferable transferable = InternalClipboard.getInstance().getContents(null);

    if (!(transferable instanceof SubgraphSelection)) {
      return;
    }

    SubgraphSelection selection = (SubgraphSelection) transferable;
    DataFlavor flavor = new DataFlavor(SubgraphSelection.class, "Subgraph Selection");

    try {
      List modelList = (List) selection.getTransferData(flavor);
      Point point = EditorUtils.getTopLeftPoint(modelList);
      point.translate(50, 50);
      graphEditor().pasteSubsession(modelList, point);
    } catch (Exception e1) {
      throw new RuntimeException(e1);
    }
  }
  /** Performs the action of saving a session to a file. */
  public void actionPerformed(ActionEvent e) {

    // Get the frontmost SessionWrapper.
    SessionEditorIndirectRef sessionEditorRef =
        DesktopController.getInstance().getFrontmostSessionEditor();
    SessionEditor sessionEditor = (SessionEditor) sessionEditorRef;
    SessionEditorWorkbench workbench = sessionEditor.getSessionWorkbench();
    SessionWrapper sessionWrapper = workbench.getSessionWrapper();
    TetradMetadata metadata = new TetradMetadata();

    // Select the file to save this to.
    File file =
        EditorUtils.getSaveFile(
            sessionEditor.getName(),
            "tet",
            JOptionUtils.centeringComp(),
            true,
            "Save Session As...");

    if (file == null) {
      this.saved = false;
      return;
    }

    if ((DesktopController.getInstance().existsSessionByName(file.getName())
        && !(sessionWrapper.getName().equals(file.getName())))) {
      this.saved = false;
      JOptionPane.showMessageDialog(
          JOptionUtils.centeringComp(),
          "Another session by that name is currently open. Please "
              + "\nclose that session first.");
      return;
    }

    sessionWrapper.setName(file.getName());
    sessionEditor.setName(file.getName());

    // Save it.
    try {
      FileOutputStream out = new FileOutputStream(file);
      ObjectOutputStream objOut = new ObjectOutputStream(out);
      objOut.writeObject(metadata);
      objOut.writeObject(sessionWrapper);
      out.close();

      FileInputStream in = new FileInputStream(file);
      ObjectInputStream objIn = new ObjectInputStream(in);
      objIn.readObject();

      sessionWrapper.setSessionChanged(false);
      sessionWrapper.setNewSession(false);
      this.saved = true;
    } catch (Exception e2) {
      this.saved = false;
      e2.printStackTrace();
      JOptionPane.showMessageDialog(
          JOptionUtils.centeringComp(), "An error occurred while attempting to save the session.");
    }

    DesktopController.getInstance().putMetadata(sessionWrapper, metadata);
    sessionEditor.firePropertyChange("name", null, file.getName());
  }