boolean actionAllowed = false; while (nodes.hasMoreElements()) { DefaultMutableTreeNode nextNode = (DefaultMutableTreeNode)nodes.nextElement(); Object o = nextNode.getUserObject(); if (o instanceof String) actionAllowed = isActionAllowedOnFolder(action, organizer, nextNode); else if (o instanceof Experiment) actionAllowed = isActionAllowedOnExperiment(action, organizer, (Experiment)o); else if (o instanceof SocietyComponent) actionAllowed = isActionAllowedOnSociety(action, organizer, (SocietyComponent)o); else if (o instanceof RecipeComponent) actionAllowed = isActionAllowedOnRecipe(action, organizer, (RecipeComponent)o); if (actionAllowed) return true; }
  private static boolean isActionAllowedOnFolder(String action,                                                 Organizer organizer,                                                 DefaultMutableTreeNode node) {    if (action.equals(NEW_EXPERIMENT_ACTION) ||        action.equals(NEW_RECIPE_ACTION) ||        action.equals(NEW_FOLDER_ACTION) ||        action.equals(RENAME_ACTION))       return true;    Enumeration nodes = node.breadthFirstEnumeration();    nodes.nextElement(); // advance over first element which is the folder    // can delete empty folder, but not root    if (!nodes.hasMoreElements() && !node.isRoot())       return action.equals(DELETE_ACTION);    boolean actionAllowed = false;    while (nodes.hasMoreElements()) {      DefaultMutableTreeNode nextNode =         (DefaultMutableTreeNode)nodes.nextElement();      Object o = nextNode.getUserObject();      if (o instanceof String)         actionAllowed =           isActionAllowedOnFolder(action, organizer, nextNode);      else if (o instanceof Experiment)        actionAllowed =          isActionAllowedOnExperiment(action, organizer, (Experiment)o);      else if (o instanceof SocietyComponent)        actionAllowed =          isActionAllowedOnSociety(action, organizer, (SocietyComponent)o);      else if (o instanceof RecipeComponent)        actionAllowed =          isActionAllowedOnRecipe(action, organizer, (RecipeComponent)o);      if (actionAllowed)        return true;    }    return false;  }