@Override
  public void handleEvent(Event event) {
    // TODO Auto-generated method stub
    File file =
        new File(
            this.dataType.getPath().toString()
                + File.separator
                + this.dataType.getStudy().toString()
                + ".subject_mapping.tmp");
    File stsmf = ((GeneExpressionData) this.dataType).getStsmf();
    if (stsmf == null) {
      this.setStudyTreeUI.displayMessage("Error: no subject to sample mapping file");
    }
    String category = "";
    TreeNode node = this.setStudyTreeUI.getRoot();
    if (!node.hasChildren()) {
      this.setStudyTreeUI.displayMessage("You have to set a category code");
      return;
    }
    node = node.getChildren().get(0);
    while (node != null) {
      if (category.compareTo("") == 0) {
        category += node.toString().replace(' ', '_');
      } else {
        category += "+" + node.toString().replace(' ', '_');
      }
      if (node.hasChildren()) {
        node = node.getChildren().get(0);
      } else {
        node = null;
      }
    }
    try {
      FileWriter fw = new FileWriter(file);
      BufferedWriter out = new BufferedWriter(fw);
      out.write(
          "study_id\tsite_id\tsubject_id\tSAMPLE_ID\tPLATFORM\tTISSUETYPE\tATTR1\tATTR2\tcategory_cd\n");

      try {
        BufferedReader br = new BufferedReader(new FileReader(stsmf));
        String line = br.readLine();
        while ((line = br.readLine()) != null) {
          String[] fields = line.split("\t", -1);
          out.write(
              fields[0] + "\t" + fields[1] + "\t" + fields[2] + "\t" + fields[3] + "\t" + fields[4]
                  + "\t" + fields[5] + "\t" + fields[6] + "\t" + fields[7] + "\t" + category
                  + "\n");
        }
        br.close();
      } catch (Exception e) {
        this.setStudyTreeUI.displayMessage("File error: " + e.getLocalizedMessage());
        out.close();
        e.printStackTrace();
      }
      out.close();
      try {
        File fileDest;
        if (stsmf != null) {
          String fileName = stsmf.getName();
          stsmf.delete();
          fileDest = new File(this.dataType.getPath() + File.separator + fileName);
        } else {
          fileDest =
              new File(
                  this.dataType.getPath()
                      + File.separator
                      + this.dataType.getStudy().toString()
                      + ".subject_mapping");
        }
        FileUtils.moveFile(file, fileDest);
        ((GeneExpressionData) this.dataType).setSTSMF(fileDest);
      } catch (IOException ioe) {
        this.setStudyTreeUI.displayMessage("File error: " + ioe.getLocalizedMessage());
        return;
      }
    } catch (Exception e) {
      this.setStudyTreeUI.displayMessage("Eerror: " + e.getLocalizedMessage());
      e.printStackTrace();
    }
    this.setStudyTreeUI.displayMessage("Subject to sample mapping file updated");
    WorkPart.updateSteps();
    WorkPart.updateFiles();
  }
  @Override
  public void handleEvent(Event event) {
    // TODO Auto-generated method stub
    Vector<String> values = this.setPlatformsUI.getValues();
    Vector<String> samples = this.setPlatformsUI.getSamples();
    File file =
        new File(
            this.dataType.getPath().toString()
                + File.separator
                + this.dataType.getStudy().toString()
                + ".subject_mapping.tmp");
    File stsmf = ((GeneExpressionData) this.dataType).getStsmf();
    if (stsmf == null) {
      this.setPlatformsUI.displayMessage("Error: no subject to sample mapping file");
    }
    try {
      FileWriter fw = new FileWriter(file);
      BufferedWriter out = new BufferedWriter(fw);
      out.write(
          "study_id\tsite_id\tsubject_id\tSAMPLE_ID\tPLATFORM\tTISSUETYPE\tATTR1\tATTR2\tcategory_cd\n");

      try {
        BufferedReader br = new BufferedReader(new FileReader(stsmf));
        String line = br.readLine();
        while ((line = br.readLine()) != null) {
          String[] fields = line.split("\t", -1);
          String sample = fields[3];
          String platform;
          if (samples.contains(sample)) {
            platform = values.get(samples.indexOf(sample));
          } else {
            br.close();
            return;
          }
          out.write(
              fields[0] + "\t" + fields[1] + "\t" + fields[2] + "\t" + sample + "\t" + platform
                  + "\t" + fields[5] + "\t" + fields[6] + "\t" + fields[7] + "\t" + fields[8]
                  + "\n");
        }
        br.close();
      } catch (Exception e) {
        this.setPlatformsUI.displayMessage("Error: " + e.getLocalizedMessage());
        out.close();
        e.printStackTrace();
      }
      out.close();
      try {
        File fileDest;
        if (stsmf != null) {
          String fileName = stsmf.getName();
          stsmf.delete();
          fileDest = new File(this.dataType.getPath() + File.separator + fileName);
        } else {
          fileDest =
              new File(
                  this.dataType.getPath()
                      + File.separator
                      + this.dataType.getStudy().toString()
                      + ".subject_mapping");
        }
        FileUtils.moveFile(file, fileDest);
        ((GeneExpressionData) this.dataType).setSTSMF(fileDest);
      } catch (IOException ioe) {
        this.setPlatformsUI.displayMessage("File error: " + ioe.getLocalizedMessage());
        return;
      }
    } catch (Exception e) {
      this.setPlatformsUI.displayMessage("Error: " + e.getLocalizedMessage());
      e.printStackTrace();
    }
    this.setPlatformsUI.displayMessage("Subject to sample mapping file updated");
    WorkPart.updateSteps();
    WorkPart.updateFiles();
  }
  @Override
  public void handleEvent(Event event) {
    Vector<File> rawFiles = ((ClinicalData) this.dataType).getRawFiles();
    Vector<String> siteIds = this.setOtherIdsUI.getSiteIds();
    Vector<String> visitNames = this.setOtherIdsUI.getVisitNames();

    // write in a new file
    File file =
        new File(
            this.dataType.getPath().toString()
                + File.separator
                + this.dataType.getStudy().toString()
                + ".columns.tmp");
    try {
      FileWriter fw = new FileWriter(file);
      BufferedWriter out = new BufferedWriter(fw);
      out.write(
          "Filename\tCategory Code\tColumn Number\tData Label\tData Label Source\tControlled Vocab Code\n");

      for (int i = 0; i < rawFiles.size(); i++) {

        // site identifier
        if (siteIds.elementAt(i).compareTo("") != 0) {
          int columnNumber =
              FileHandler.getHeaderNumber(rawFiles.elementAt(i), siteIds.elementAt(i));
          if (columnNumber != -1) {
            out.write(rawFiles.elementAt(i).getName() + "\t\t" + columnNumber + "\tSITE_ID\t\t\n");
          }
        }

        // visit name
        if (visitNames.elementAt(i).compareTo("") != 0) {
          int columnNumber =
              FileHandler.getHeaderNumber(rawFiles.elementAt(i), visitNames.elementAt(i));
          if (columnNumber != -1) {
            out.write(
                rawFiles.elementAt(i).getName() + "\t\t" + columnNumber + "\tVISIT_NAME\t\t\n");
          }
        }
      }
      // add lines from existing CMF
      try {
        BufferedReader br =
            new BufferedReader(new FileReader(((ClinicalData) this.dataType).getCMF()));
        String line = br.readLine();
        while ((line = br.readLine()) != null) {
          String[] s = line.split("\t", -1);
          if (s[3].compareTo("SITE_ID") != 0 && s[3].compareTo("VISIT_NAME") != 0) {
            out.write(line + "\n");
          }
        }
        br.close();
      } catch (Exception e) {
        this.setOtherIdsUI.displayMessage("Error: " + e.getLocalizedMessage());
        e.printStackTrace();
        out.close();
      }
      out.close();
      try {
        String fileName = ((ClinicalData) this.dataType).getCMF().getName();
        ((ClinicalData) this.dataType).getCMF().delete();
        File fileDest = new File(this.dataType.getPath() + File.separator + fileName);
        FileUtils.moveFile(file, fileDest);
        ((ClinicalData) this.dataType).setCMF(fileDest);
      } catch (IOException ioe) {
        this.setOtherIdsUI.displayMessage("File error: " + ioe.getLocalizedMessage());
        return;
      }

    } catch (Exception e) {
      this.setOtherIdsUI.displayMessage("Error: " + e.getLocalizedMessage());
      e.printStackTrace();
    }
    this.setOtherIdsUI.displayMessage("Column mapping file updated");
    WorkPart.updateSteps();
    WorkPart.updateFiles();
    UsedFilesPart.sendFilesChanged(dataType);
  }