/** Validates the options of the fields inputted. */
  private void validateFields() {
    errorDisplay.removeAllErrors();
    Calendar cal = new GregorianCalendar();
    cal.setTime(Calendar.getInstance().getTime());
    cal.add(Calendar.DAY_OF_YEAR, -1);
    Iteration forName = IterationModel.getInstance().getIteration(boxName.getText().trim());
    if (boxName.getText().trim().length() == 0) {
      errorDisplay.displayError(EMPTY_NAME_ERROR);
    } else if (forName != null && forName != displayIteration) {
      errorDisplay.displayError(INVALID_NAME_ERROR);
    }

    if (endDateBox.getText().trim().length() == 0 || endDateBox.getText().trim().length() == 0) {
      errorDisplay.displayError(DATES_REQ);
    } else if (((Date) startDateBox.getValue()).after((Date) endDateBox.getValue())) {
      errorDisplay.displayError(START_AFTER_END_ERROR);
    } else if (((Date) startDateBox.getValue()).before(cal.getTime())) {
      errorDisplay.displayError(PAST_ERROR);
    } else {
      Iteration conflicting =
          IterationModel.getInstance()
              .getConflictingIteration(
                  (Date) startDateBox.getValue(), (Date) endDateBox.getValue());
      if (conflicting != null && conflicting != displayIteration) {
        errorDisplay.displayError(
            OVERLAPPING_ERROR + " Overlaps with " + conflicting.getName() + ".");
      }
    }

    buttonAdd.setEnabled(!errorDisplay.hasErrors());
  }
  /** Updates the display iteration */
  private void updateIteration() {
    String name = boxName.getText();
    displayIteration.setName(name);
    displayIteration.setDateInterval((Date) startDateBox.getValue(), (Date) endDateBox.getValue());

    if (vm == ViewMode.CREATING) {
      int id = IterationModel.getInstance().getNextID();
      displayIteration.setId(id);
      IterationModel.getInstance().addIteration(displayIteration);

    } else {
      UpdateIterationController.getInstance().updateIteration(displayIteration);
    }

    forceRemove = true;

    ViewEventController.getInstance().removeTab(IterationPanel.this);
  }