Class[] paramClasses = { CSMART.class, ModifiableComponent.class, Experiment.class }; Object[] params = new Object[3]; params[0] = this;
ModifiableComponent originalComponent = null;
  protected void runBuilder(ModifiableComponent cc,                          boolean alwaysNew) {    // note that cc is guaranteed non-null when this is called    Class[] paramClasses =       { CSMART.class, ModifiableComponent.class, Experiment.class };    Object[] params = new Object[3];    params[0] = this;    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);      // 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);      // Copy the old society assembly_id into the new      // so it can copy the OPLAN info, if any      ((SocietyComponent)cc).setAssemblyId(((SocietyComponent)experiment.getSocietyComponent()).getAssemblyId());      cc.initProperties();      // 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());            SocietyComponent societyCopy = (SocietyComponent)society.copy(newName);            experiment.removeSocietyComponent();            experiment.addSocietyComponent(societyCopy);            // remove old society from workspace and add new society            organizer.replaceComponent(experiment, society, societyCopy);            cc = societyCopy;          } else if (cc instanceof RecipeComponent) {            RecipeComponent recipe = (RecipeComponent)cc;            String newName =              organizer.generateRecipeName(recipe.getRecipeName());            RecipeComponent recipeCopy = (RecipeComponent)recipe.copy(newName);            experiment.removeRecipeComponent(recipe);            experiment.addRecipeComponent(recipeCopy);            // remove old recipe from workspace and add new recipe            organizer.replaceComponent(experiment, recipe, recipeCopy);            cc = recipeCopy;          }        }      }    }    params[1] = cc;    params[2] = experiment;    createTool(CONFIGURATION_BUILDER, PropertyBuilder.class, 	       alwaysNew, cc.getShortName(), (ModifiableComponent)cc,	       paramClasses, params);  }