if (cc instanceof Experiment) { experiment = (Experiment)cc;  Experiment experimentCopy = organizer.copyExperiment(experiment, false); if (experimentCopy == null) return;  SocietyComponent sc = experimentCopy.getSocietyComponent(); if (sc != null) experimentCopy.removeComponent(sc); RecipeComponent[] recipes = experimentCopy.getRecipeComponents(); for (int i = 0; i < recipes.length; i++) experimentCopy.removeRecipeComponent(recipes[i]);  organizer.removeChildren(experimentCopy);   ComponentData cdata = experiment.getSocietyComponentData(); cdata.setName(cdata.getName() + " Society"); cc = new SocietyCDataComponent(cdata, ((SocietyComponent)experiment.getSocietyComponent()).getAssemblyId()); cc.initProperties();   String name = ((SocietyComponent)cc).getSocietyName(); String newName = organizer.getUniqueSocietyName(name, true); if (newName == null) return; else if (!newName.equals(name)) cc.setName(newName);  ((SocietyComponent)cc).saveToDatabase();  experimentCopy.addSocietyComponent((SocietyComponent)cc);  organizer.addSociety((SocietyComponent)cc);  organizer.addChildren(experimentCopy);  experiment = experimentCopy; } else {  DefaultMutableTreeNode selectedNode = organizer.getSelectedNode(); if (selectedNode.getUserObject() != null && selectedNode.getUserObject().equals(cc)) { DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode)selectedNode.getParent(); if (parentNode.getUserObject() != null && parentNode.getUserObject() instanceof Experiment) { experiment = (Experiment)parentNode.getUserObject();  if (cc instanceof SocietyComponent) { SocietyComponent society = (SocietyComponent)cc; String newName = organizer.generateSocietyName(society.getSocietyName(), false); SocietyComponent societyCopy = (SocietyComponent)society.copy(newName); originalComponent = cc; cc = societyCopy; } else if (cc instanceof RecipeComponent) { RecipeComponent recipe = (RecipeComponent)cc; String newName = organizer.generateRecipeName(recipe.getRecipeName(), false); if (newName == null) return; RecipeComponent recipeCopy = (RecipeComponent)recipe.copy(newName); originalComponent = cc; cc = recipeCopy; }
DefaultMutableTreeNode selectedNode = organizer.getSelectedNode(); if (selectedNode.getUserObject() != null && selectedNode.getUserObject().equals(cc)) { DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode)selectedNode.getParent(); if (parentNode.getUserObject() != null && parentNode.getUserObject() instanceof Experiment) { experiment = (Experiment)parentNode.getUserObject();  if (cc instanceof SocietyComponent) { SocietyComponent society = (SocietyComponent)cc; String newName = organizer.generateSocietyName(society.getSocietyName(), false); if (newName == null) return; SocietyComponent societyCopy = (SocietyComponent)society.copy(newName); originalComponent = cc; cc = societyCopy; } else if (cc instanceof RecipeComponent) { RecipeComponent recipe = (RecipeComponent)cc; String newName = organizer.generateRecipeName(recipe.getRecipeName(), false); if (newName == null) return; RecipeComponent recipeCopy = (RecipeComponent)recipe.copy(newName); originalComponent = cc; cc = recipeCopy;
  protected void runBuilder(ModifiableComponent cc,                          boolean alwaysNew) {    // note that cc is guaranteed non-null when this is called    ModifiableComponent originalComponent = null;    Experiment experiment = null;    if (cc instanceof Experiment) {      experiment = (Experiment)cc;      // copy the original experiment and put the copy in the workspace      Experiment experimentCopy = organizer.copyExperiment(experiment, false);      if (experimentCopy == null)        return;      // remove all the components from the copy      SocietyComponent sc = experimentCopy.getSocietyComponent();      if (sc != null)        experimentCopy.removeComponent(sc);      RecipeComponent[] recipes = experimentCopy.getRecipeComponents();      for (int i = 0; i < recipes.length; i++)        experimentCopy.removeRecipeComponent(recipes[i]);      // remove components from the workspace      organizer.removeChildren(experimentCopy);      // create a new society based on the society component data      // in the original experiment      ComponentData cdata = experiment.getSocietyComponentData();      cdata.setName(cdata.getName() + " Society");      cc = new SocietyCDataComponent(cdata,         ((SocietyComponent)experiment.getSocietyComponent()).getAssemblyId());      cc.initProperties();      // get an unique name for the society and if the      // user cancels out, then cancel this operation      String name = ((SocietyComponent)cc).getSocietyName();      String newName =         organizer.getUniqueSocietyName(name, true);      if (newName == null)        return;      else if (!newName.equals(name))        cc.setName(newName);      // Save this new society:      ((SocietyComponent)cc).saveToDatabase();      // put the new society in the copy of the experiment      experimentCopy.addSocietyComponent((SocietyComponent)cc);      // also put the new society in the workspace      organizer.addSociety((SocietyComponent)cc);      // and add the society to the workspace as a child of the experiment      organizer.addChildren(experimentCopy);      // edit the society within the newly created experiment      experiment = experimentCopy;    } else {      // if configuring a component in an experiment, get the experiment      DefaultMutableTreeNode selectedNode = organizer.getSelectedNode();      if (selectedNode.getUserObject() != null &&          selectedNode.getUserObject().equals(cc)) {        DefaultMutableTreeNode parentNode =           (DefaultMutableTreeNode)selectedNode.getParent();        if (parentNode.getUserObject() != null &&            parentNode.getUserObject() instanceof Experiment) {          experiment = (Experiment)parentNode.getUserObject();          // copy the component, so it's modified only in the experiment          if (cc instanceof SocietyComponent) {            SocietyComponent society = (SocietyComponent)cc;            String newName =              organizer.generateSocietyName(society.getSocietyName(),                                             false);            SocietyComponent societyCopy = (SocietyComponent)society.copy(newName);            originalComponent = cc;            cc = societyCopy;          } else if (cc instanceof RecipeComponent) {            RecipeComponent recipe = (RecipeComponent)cc;            String newName =              organizer.generateRecipeName(recipe.getRecipeName(), false);            if (newName == null)              return;            RecipeComponent recipeCopy = (RecipeComponent)recipe.copy(newName);            originalComponent = cc;            cc = recipeCopy;          }        }      }    }    JFrame tool =       (JFrame)new PropertyBuilder(this, cc, originalComponent, experiment);    addTool(CONFIGURATION_BUILDER, cc.getShortName(), tool);  }