/**
  * Given an experiment, we see for each condition if a new growth medium is associated to the cell
  * line, and if new media are found, these are added to the medium binding list.
  *
  * @param experiment
  */
 public void addNewMedia(Experiment experiment) {
   for (PlateCondition plateCondition : experiment.getPlateConditionList()) {
     CellLine cellLine = plateCondition.getCellLine();
     String medium = cellLine.getGrowthMedium();
     if (!mediumBindingList.contains(medium)) {
       mediumBindingList.add(medium);
     }
   }
 }
 /**
  * Given an experiment, we see for each condition if a new serum is associated to the cell line,
  * and if new sera are found, these are added to the serum binding list.
  *
  * @param experiment
  */
 public void addNewSera(Experiment experiment) {
   for (PlateCondition plateCondition : experiment.getPlateConditionList()) {
     CellLine cellLine = plateCondition.getCellLine();
     String serum = cellLine.getSerum();
     if (!serumBindingList.contains(serum)) {
       serumBindingList.add(serum);
     }
   }
 }
 /**
  * validate a Plate Condition
  *
  * @param plateCondition
  * @return a list of strings to be concatenated in order to show message to the user
  */
 public List<String> validateCondition(PlateCondition plateCondition) {
   List<String> messages = new ArrayList<>();
   // validate cell line
   if (!validateCellLine(plateCondition.getCellLine()).isEmpty()) {
     messages.addAll(validateCellLine(plateCondition.getCellLine()));
   }
   // validate ECM (2D and 3D) input
   if (!assayEcmController.validate2DEcm().isEmpty()) {
     messages.addAll(assayEcmController.validate2DEcm());
   }
   if (!assayEcmController.validate3DEcm().isEmpty()) {
     messages.addAll(assayEcmController.validate3DEcm());
   }
   // if validation was OK, validate the condition: check for wells collection
   if (messages.isEmpty()) {
     if (plateCondition.getWellList().isEmpty()) {
       String message = "Conditions must have at least one well";
       messages.add(message);
     }
   }
   return messages;
 }
 /**
  * this method assigns default fields to the first Condition created and added to the List
  *
  * @param firstCondition
  */
 private void initFirstCondition(PlateCondition firstCondition) {
   // set the name
   firstCondition.setName("Condition " + ++conditionIndex);
   // set the cell line
   CellLine cellLine = new CellLine();
   cellLine.setCellLineType(cellLineTypeBindingList.get(0));
   cellLine.setSeedingDensity(50000);
   cellLine.setSeedingTime("day -1");
   cellLine.setGrowthMedium(mediumBindingList.get(0));
   cellLine.setSerum(serumBindingList.get(0));
   cellLine.setSerumConcentration(10.0);
   firstCondition.setCellLine(cellLine);
   cellLine.setPlateCondition(firstCondition);
   // set the migration assay: Oris platform; matrix dimension: 2D
   firstCondition.setAssay(assayEcmController.getAssay2DBindingList().get(0));
   // create a new AssayMedium object and set its class members
   AssayMedium assayMedium = new AssayMedium();
   assayMedium.setMedium(
       treatmentsController.getTreatmentsPanel().getAssayMediumComboBox().getItemAt(0).toString());
   assayMedium.setSerum(serumBindingList.get(0));
   assayMedium.setSerumConcentration(1.0);
   assayMedium.setVolume(10.0);
   firstCondition.setAssayMedium(assayMedium);
   assayMedium.setPlateCondition(firstCondition);
   // create a new ECM object and set its class members
   Ecm ecm = new Ecm();
   ecm.setEcmComposition(assayEcmController.getEcm2DCompositionBindingList().get(0));
   ecm.setCoatingTemperature("RT");
   ecm.setCoatingTime("60");
   ecm.setConcentration(0.04);
   ecm.setVolume(100.0);
   ecm.setVolumeUnit("\u00B5" + "l");
   ecm.setConcentrationUnit("mg/ml");
   firstCondition.setEcm(ecm);
   // set an empty collection of treatments
   List<Treatment> treatmentList = new ArrayList<>();
   firstCondition.setTreatmentList(treatmentList);
   // set an empty collection of wells
   List<Well> wellList = new ArrayList<>();
   firstCondition.setWellList(wellList);
 }
 /**
  * this method assigns values for each new condition, from the previously created 8and set-up) one
  *
  * @param newCondition
  */
 private void initNewCondition(PlateCondition newCondition) {
   PlateCondition previousCondition = plateConditionBindingList.get(previousConditionIndex);
   // set the name
   newCondition.setName("Condition " + ++conditionIndex);
   // set the cell line (the same as the previous condition)
   CellLine cellLine = previousCondition.getCellLine();
   CellLine newCellLine =
       new CellLine(
           cellLine.getSeedingTime(),
           cellLine.getSeedingDensity(),
           cellLine.getGrowthMedium(),
           cellLine.getSerumConcentration(),
           cellLine.getCellLineType(),
           cellLine.getSerum());
   newCondition.setCellLine(newCellLine);
   newCellLine.setPlateCondition(newCondition);
   // set assay medium (another object, but with the same parameters as previous condition)
   String medium =
       mediumBindingList.get(
           treatmentsController.getTreatmentsPanel().getAssayMediumComboBox().getSelectedIndex());
   String serum =
       serumBindingList.get(
           treatmentsController.getTreatmentsPanel().getSerumComboBox().getSelectedIndex());
   Double serumConcentration =
       Double.parseDouble(
           treatmentsController.getTreatmentsPanel().getSerumConcentrationTextField().getText());
   Double volume =
       Double.parseDouble(
           treatmentsController.getTreatmentsPanel().getMediumVolumeTextField().getText());
   AssayMedium assayMedium = new AssayMedium(medium, serum, serumConcentration, volume);
   newCondition.setAssayMedium(assayMedium);
   assayMedium.setPlateCondition(newCondition);
   // set assay and ecm (get the values according to the last selected ones)
   Ecm ecm = new Ecm();
   Assay assay = null;
   BottomMatrix bottomMatrix = null;
   // need to set different values according to matrix dimension: 2D or 3D or 2.5D
   switch (assayEcmController
       .getMatrixDimensionBindingList()
       .get(setupConditionsPanel.getEcmDimensionComboBox().getSelectedIndex())
       .getDimension()) {
     case "2D":
       // set assay
       assay =
           assayEcmController
               .getAssay2DBindingList()
               .get(assayEcmController.getAssayEcm2DPanel().getAssayComboBox().getSelectedIndex());
       // 2D matrix: set ecm 2D fields
       ecm.setEcmComposition(
           assayEcmController
               .getEcm2DCompositionBindingList()
               .get(
                   assayEcmController
                       .getAssayEcm2DPanel()
                       .getCompositionComboBox()
                       .getSelectedIndex()));
       ecm.setConcentration(
           Double.parseDouble(
               assayEcmController.getAssayEcm2DPanel().getConcentrationTextField().getText()));
       ecm.setVolume(
           Double.parseDouble(
               assayEcmController.getAssayEcm2DPanel().getVolumeTextField().getText()));
       ecm.setCoatingTime(
           assayEcmController.getAssayEcm2DPanel().getCoatingTimeTextField().getText());
       ecm.setCoatingTemperature(
           assayEcmController.getAssayEcm2DPanel().getCoatingTemperatureTextField().getText());
       ecm.setVolumeUnit(assayEcmController.getAssayEcm2DPanel().getVolumeUnitLabel().getText());
       ecm.setConcentrationUnit(
           assayEcmController
               .getAssayEcm2DPanel()
               .getConcentrationUnitOfMeasure()
               .getSelectedItem()
               .toString());
       break;
     case "3D":
       // set assay
       assay =
           assayEcmController
               .getAssay3DBindingList()
               .get(assayEcmController.getAssayEcm3DPanel().getAssayComboBox().getSelectedIndex());
       // 3D matrix: set ecm 3D fields
       ecm.setEcmComposition(
           assayEcmController
               .getEcm3DCompositionBindingList()
               .get(
                   assayEcmController
                       .getAssayEcm3DPanel()
                       .getCompositionComboBox()
                       .getSelectedIndex()));
       ecm.setEcmDensity(
           assayEcmController
               .getEcmDensityBindingList()
               .get(
                   assayEcmController
                       .getAssayEcm3DPanel()
                       .getDensityComboBox()
                       .getSelectedIndex()));
       // bottom matrix
       bottomMatrix =
           assayEcmController
               .getBottomMatrixBindingList()
               .get(
                   assayEcmController
                       .getAssayEcm3DPanel()
                       .getBottomMatrixTypeComboBox()
                       .getSelectedIndex());
       ecm.setBottomMatrix(bottomMatrix);
       switch (bottomMatrix.getType()) {
         case "gel":
           // both top and bottom matrix volumes
           String text =
               assayEcmController.getAssayEcm3DPanel().getTopMatrixVolumeTextField().getText();
           if (!text.isEmpty()) {
             ecm.setTopMatrixVolume(Double.parseDouble(text));
           } else {
             ecm.setTopMatrixVolume(40.0);
           }
           ecm.setBottomMatrixVolume(
               Double.parseDouble(
                   assayEcmController
                       .getAssayEcm3DPanel()
                       .getBottomMatrixVolumeTextField()
                       .getText()));
           break;
         case "thin gel coating":
           // top matrix but no bottom matrix volume
           ecm.setTopMatrixVolume(
               Double.parseDouble(
                   assayEcmController
                       .getAssayEcm3DPanel()
                       .getTopMatrixVolumeTextField()
                       .getText()));
           break;
       }
       ecm.setPolymerisationTime(
           assayEcmController.getAssayEcm3DPanel().getPolymerizationTimeTextField().getText());
       ecm.setPolymerisationTemperature(
           assayEcmController
               .getAssayEcm3DPanel()
               .getPolymerizationTemperatureTextField()
               .getText());
       ecm.setPolymerisationPh(
           assayEcmController
               .getPolymerisationPhBindingList()
               .get(
                   assayEcmController
                       .getAssayEcm3DPanel()
                       .getPolymerizationPhComboBox()
                       .getSelectedIndex()));
       break;
     case "2.5D":
       // set assay
       assay =
           assayEcmController
               .getAssay25DBindingList()
               .get(
                   assayEcmController.getAssayEcm25DPanel().getAssayComboBox().getSelectedIndex());
       // 3D matrix: set ecm 2.5D fields
       ecm.setEcmComposition(
           assayEcmController
               .getEcm25DCompositionBindingList()
               .get(
                   assayEcmController
                       .getAssayEcm25DPanel()
                       .getCompositionComboBox()
                       .getSelectedIndex()));
       ecm.setEcmDensity(
           assayEcmController
               .getEcmDensityBindingList()
               .get(
                   assayEcmController
                       .getAssayEcm25DPanel()
                       .getDensityComboBox()
                       .getSelectedIndex()));
       // bottom matrix
       bottomMatrix =
           assayEcmController
               .getBottomMatrixBindingList()
               .get(
                   assayEcmController
                       .getAssayEcm25DPanel()
                       .getBottomMatrixTypeComboBox()
                       .getSelectedIndex());
       ecm.setBottomMatrix(bottomMatrix);
       switch (bottomMatrix.getType()) {
         case "gel":
           // bottom matrix volume
           ecm.setBottomMatrixVolume(
               Double.parseDouble(
                   assayEcmController
                       .getAssayEcm25DPanel()
                       .getBottomMatrixVolumeTextField()
                       .getText()));
           break;
       }
       ecm.setPolymerisationTime(
           assayEcmController.getAssayEcm25DPanel().getPolymerizationTimeTextField().getText());
       ecm.setPolymerisationTemperature(
           assayEcmController
               .getAssayEcm25DPanel()
               .getPolymerizationTemperatureTextField()
               .getText());
       ecm.setPolymerisationPh(
           assayEcmController
               .getPolymerisationPhBindingList()
               .get(
                   assayEcmController
                       .getAssayEcm25DPanel()
                       .getPolymerizationPhComboBox()
                       .getSelectedIndex()));
       break;
   }
   newCondition.setAssay(assay);
   newCondition.setEcm(ecm);
   // create new treatment with same parameters as ones from previous condition
   List<Treatment> treatmentList = new ArrayList<>();
   ObservableList<Treatment> treatmentBindingList = treatmentsController.getTreatmentBindingList();
   for (Treatment treatment : treatmentBindingList) {
     Double concentration = treatment.getConcentration();
     String concentrationUnit = treatment.getConcentrationUnit();
     String timing = treatment.getTiming();
     String drugSolvent = treatment.getDrugSolvent();
     Double drugSolventConcentration = treatment.getDrugSolventConcentration();
     TreatmentType treatmentType = treatment.getTreatmentType();
     Treatment newTreatment =
         new Treatment(
             concentration,
             concentrationUnit,
             timing,
             drugSolvent,
             drugSolventConcentration,
             treatmentType);
     newTreatment.setPlateCondition(newCondition);
     treatmentList.add(newTreatment);
   }
   newCondition.setTreatmentList(treatmentList);
   // set an empty collection of wells (wells are not recalled from previous condition)
   List<Well> wellList = new ArrayList<>();
   newCondition.setWellList(wellList);
 }