/**
   * Add the given catalog to the catalog list if it is not already there. If a separate catalog
   * with the same name is in the list, the user is asked if it should be removed.
   */
  public void addCatalog(int index, Catalog cat) {
    // check for duplicates
    int i = _catalogs.indexOf(cat);
    if (i != -1) {
      return;
    }

    // check if it is a catalog with the same name (maybe from a different config file)
    String name = cat.getName();
    Catalog oldCat = getCatalog(name);
    int size = _catalogs.size();
    if (oldCat != null) {
      int ans = DialogUtil.confirm(name + " already exists. Do you want to replace it?");
      if (ans != JOptionPane.YES_OPTION) return;
      removeCatalog(oldCat);
      size--;
    }

    if (index < 0 || index >= size) _catalogs.add(cat);
    else _catalogs.add(index, cat);

    cat.setParent(this);
    CatalogFactory.registerCatalog(cat, isLocal());
    _fireTreeNodesInserted(_getTreeModelEvent(cat));
  }
 /** Return the named catalog, if found in this directory */
 public Catalog getCatalog(String catalogName) {
   int n = getNumCatalogs();
   for (int i = 0; i < n; i++) {
     Catalog cat = getCatalog(i);
     if (catalogName.equals(cat.getName()) || catalogName.equals(cat.getId())) return cat;
   }
   return null;
 }