/* (non-Javadoc)
   * @see pcgen.core.facade.SpellSupportFacade#removeSpellList(java.lang.String)
   */
  @Override
  public void removeSpellList(String spellList) {
    if (spellList.equalsIgnoreCase(Globals.getDefaultSpellBook())) {
      Logging.errorPrint(
          LanguageBundle.getString("InfoSpells.can.not.delete.default.spellbook")); // $NON-NLS-1$

      return;
    }

    if (pc.delSpellBook(spellList)) {
      pc.setDirty(true);
      for (Iterator<SpellNode> iterator = preparedSpellLists.iterator(); iterator.hasNext(); ) {
        SpellNode listNode = iterator.next();
        if (spellList.equals(listNode.getRootNode().getName())) {
          iterator.remove();
        }
      }

      for (Iterator<SpellNode> iterator = preparedSpellNodes.iterator(); iterator.hasNext(); ) {
        SpellNode spell = iterator.next();
        if (spellList.equals(spell.getRootNode().getName())) {
          iterator.remove();
        }
      }
    } else {
      Logging.errorPrint("delBookButton:failed "); // $NON-NLS-1$

      return;
    }
  }
  /* (non-Javadoc)
   * @see pcgen.core.facade.SpellSupportFacade#addSpellList(java.lang.String)
   */
  @Override
  public void addSpellList(String spellList) {
    if (StringUtils.isEmpty(spellList)) {
      return;
    }

    // Prevent spellbooks being given the same name as a class
    for (PCClass current :
        Globals.getContext().getReferenceContext().getConstructedCDOMObjects(PCClass.class)) {
      if ((spellList.equals(current.getKeyName()))) {
        JOptionPane.showMessageDialog(
            null,
            LanguageBundle.getString("in_spellbook_name_error"), // $NON-NLS-1$
            Constants.APPLICATION_NAME,
            JOptionPane.ERROR_MESSAGE);

        return;
      }
    }

    if (pc.addSpellBook(spellList)) {
      pc.setDirty(true);

      DummySpellNodeImpl spellListNode = new DummySpellNodeImpl(getRootNode(spellList));
      preparedSpellLists.add(spellListNode);
      addDummyNodeIfSpellListEmpty(spellList);
    } else {
      JOptionPane.showMessageDialog(
          null,
          LanguageBundle.getFormattedString(
              "InfoPreparedSpells.add.list.fail", spellList), // $NON-NLS-1$
          Constants.APPLICATION_NAME,
          JOptionPane.ERROR_MESSAGE);

      return;
    }
  }