private void selectFirstElement() {
   //  select all  if list is not empty
   if (root.getChildCount() > 0) {
     DefaultMutableTreeNode typeNode = (DefaultMutableTreeNode) root.getFirstChild();
     TreePath tp = new TreePath(((DefaultMutableTreeNode) typeNode.getFirstChild()).getPath());
     setSelectionPath(tp); // select																												
   }
 }
 void deleteNodeParent(DefaultMutableTreeNode parent) throws Exception {
   while (parent.getChildCount() != 0) {
     DefaultMutableTreeNode node = (DefaultMutableTreeNode) parent.getFirstChild();
     deleteNodeParent(node);
   }
   deleteNode(parent);
 }
 protected void addNewGroup() {
   final DefaultMutableTreeNode root =
       (DefaultMutableTreeNode)
           ((DefaultMutableTreeNode) (tree.getModel().getRoot())).getFirstChild();
   DefaultMutableTreeNode node = root;
   if (node.getChildCount() > 0) {
     node = (DefaultMutableTreeNode) node.getFirstChild();
   }
   if (tree.getSelectionPath() != null) {
     node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
   }
   if (node != root) {
     DefaultMutableTreeNode newNode =
         new ActivableMutableTreeNode(new Group("group" + node.getParent().getChildCount() + 1));
     final DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent();
     parent.insert(newNode, parent.getIndex(node));
     newModel.reload();
     tree.setSelectionPath(new TreePath(newModel.getPathToRoot(newNode)));
   }
 }
  /**
   * Obtiene los nodos seleccionados de un jtree creando una hash de Capas/Atributos
   *
   * @param jtreeAtributes
   * @return
   */
  private Map<String, List<String>> getLayersAtributesList(JTree jtreeAtributes) {
    Map<String, List<String>> tablaCapasAtributos = new HashMap<String, List<String>>();
    List<String> listaAtr = null;
    String nombreCapa = null;
    String nombreAtributo = null;
    DefaultTreeModel model = (DefaultTreeModel) jtreeAtributes.getModel();
    DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
    DefaultMutableTreeNode chosen = (DefaultMutableTreeNode) root.getFirstChild();
    DefaultMutableTreeNode leaf = null;
    CheckBoxNode checkNode = null;
    for (int i = 0; i < root.getChildCount(); i++) {
      nombreCapa = chosen.toString();
      leaf = chosen.getFirstLeaf();
      for (int j = 0; j < chosen.getLeafCount(); j++) {
        checkNode = (CheckBoxNode) leaf.getUserObject();
        nombreAtributo = checkNode.getText();
        // testeamos si el atributo está seleccionado
        if (checkNode.isSelected()) {
          if (tablaCapasAtributos.containsKey(nombreCapa)) {
            listaAtr = tablaCapasAtributos.get(nombreCapa);
          } else {
            listaAtr = new ArrayList<String>();
          }
          listaAtr.add(nombreAtributo);
          tablaCapasAtributos.put(nombreCapa, listaAtr);
        }
        leaf = leaf.getNextLeaf();
      }
      // si no hay ningun atributo seleccionado guardamos unicamente la capa
      if (!tablaCapasAtributos.containsKey(nombreCapa)) {
        tablaCapasAtributos.put(nombreCapa, null);
      }
      chosen = chosen.getNextSibling();
    }

    return tablaCapasAtributos;
  }
  /** This will select the intial ligand in the tree and trigger an update */
  public void selectInitialLigand() {
    String initialLigand = LigandExplorer.sgetModel().getInitialLigand();
    DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) ligandJList.getModel().getRoot();
    TreePath paths[] = null;

    // select initial BIRD molecules
    for (int ix = 0; ix < rootNode.getChildCount(); ix++) {
      DefaultMutableTreeNode chainNode = (DefaultMutableTreeNode) rootNode.getChildAt(ix);
      if (initialLigand != null) {
        for (int lx = 0; lx < chainNode.getChildCount(); lx++) {
          DefaultMutableTreeNode subNode = (DefaultMutableTreeNode) chainNode.getChildAt(lx);
          if (subNode.getUserObject() instanceof Chain) {
            Chain chain = (Chain) subNode.getUserObject();
            if (isInitialBirdChain(chain, initialLigand)) {
              if (paths == null) {
                paths = new TreePath[1];
                paths[0] = new TreePath(subNode.getPath());
              } else {
                break;
              }
            }
          }
        }
      }
    }

    // select initial chemical components
    for (int ix = 0; ix < rootNode.getChildCount(); ix++) {
      DefaultMutableTreeNode chainNode = (DefaultMutableTreeNode) rootNode.getChildAt(ix);
      if (initialLigand != null) {
        for (int lx = 0; lx < chainNode.getChildCount(); lx++) {
          DefaultMutableTreeNode residueNode = (DefaultMutableTreeNode) chainNode.getChildAt(lx);
          if (residueNode.getUserObject() instanceof Residue) {
            Residue residue = (Residue) residueNode.getUserObject();

            if (isInitialLigandResidue(residue, initialLigand)) {
              Residue[] ligs = new Residue[1];
              ligs[0] = residue;
              LigandExplorer.sgetSceneController().setLigandResidues(ligs);

              // The following code generates an exception in the swing libs
              // (see bug PDBWW-1917 PDB ID 1OLN, ligand XBB), most likely because
              // the path has null entries, i.e. for the case above.
              //						if (paths == null) {
              //							paths = new TreePath[chainNode.getChildCount()];
              //						}
              //						paths[lx] = new TreePath(residueNode.getPath());

              // Since we are only selecting a single entry, there is no need to pass in an array
              // with
              // null entries.
              if (paths == null) {
                paths = new TreePath[1];
                paths[0] = new TreePath(residueNode.getPath());
              } else {
                break;
              }
            }
          }
        }
      }
    }

    TreePath rootPath = new TreePath(rootNode);
    for (int ix = 0; ix < rootNode.getChildCount(); ix++)
      ligandJList.expandPath(rootPath.pathByAddingChild(rootNode.getChildAt(ix)));

    if (paths != null) ligandJList.setSelectionPaths(paths);
    // set the discovered intial ligand path(s) as selected
    else {
      DefaultMutableTreeNode firstChainNode = (DefaultMutableTreeNode) rootNode.getFirstChild();
      TreePath selectedPath = rootPath.pathByAddingChild(firstChainNode);
      selectedPath = selectedPath.pathByAddingChild(firstChainNode.getFirstChild());
      ligandJList.setSelectionPath(selectedPath);
      // set the first residue in the first chain as selected
      // (jeez, this is a lot of work to do something this simple, I might add...)
    }
  }