private boolean validateGeneratedName() {

    // if Generate button never pressed
    if (nextNumberInSequence == null) {
      MessageNotifier.showError(
          getWindow(),
          "Error with Cross Code",
          MessageFormat.format(
              messageSource.getMessage(Message.ERROR_NEXT_NAME_MUST_BE_GENERATED_FIRST), ""),
          Notification.POSITION_CENTERED);
      return false;

      // if prefix specifications were changed and next name in sequence not generated first
    } else {
      String currentPrefixString = buildPrefixString();
      if (!currentPrefixString.equals(lastPrefixUsed)) {
        MessageNotifier.showError(
            getWindow(),
            "Error with Cross Code",
            MessageFormat.format(
                messageSource.getMessage(Message.ERROR_NEXT_NAME_MUST_BE_GENERATED_FIRST),
                " (" + currentPrefixString + ")"),
            Notification.POSITION_CENTERED);
        return false;
      }
    }

    return true;
  }
 @Override
 public void updateLabels() {
   messageSource.setCaption(specifyPrefixLabel, Message.SPECIFY_PREFIX_REQUIRED);
   messageSource.setCaption(specifySuffixLabel, Message.SPECIFY_SUFFIX_OPTIONAL);
   messageSource.setCaption(
       sequenceNumCheckBox, Message.SEQUENCE_NUMBER_SHOULD_HAVE_LEADING_ZEROS);
   messageSource.setCaption(howManyDigitsLabel, Message.HOW_MANY_DIGITS);
   messageSource.setCaption(
       nextNameInSequenceLabel, Message.THE_NEXT_NAME_IN_THE_SEQUENCE_WILL_BE);
   messageSource.setCaption(generateButton, Message.GENERATE);
 }
  private boolean validateCrossNameFields() {
    Window window = getWindow();
    String prefix = ((String) prefixTextField.getValue()).trim();

    if (StringUtils.isEmpty(prefix)) {
      MessageNotifier.showError(
          window,
          "Error with Cross Code",
          messageSource.getMessage(Message.ERROR_ENTER_PREFIX_FIRST),
          Notification.POSITION_CENTERED);
      return false;

    } else if (prefix.contains(" ")) {
      MessageNotifier.showError(
          window,
          "Error with Cross Code",
          messageSource.getMessage(Message.ERROR_PREFIX_HAS_WHITESPACE),
          Notification.POSITION_CENTERED);
      return false;
    }

    return true;
  }
  // Action handler for Generation button
  public void generateNextNameButtonAction() {
    if (validateCrossNameFields()) {
      String suffix = ((String) suffixTextField.getValue()).trim();

      try {
        lastPrefixUsed = buildPrefixString();
        String nextSequenceNumberString =
            this.germplasmManager.getNextSequenceNumberForCrossName(lastPrefixUsed);

        nextNumberInSequence = Integer.parseInt(nextSequenceNumberString);
        generatedNameLabel.setCaption(
            buildNextNameInSequence(lastPrefixUsed, suffix, nextNumberInSequence));

      } catch (MiddlewareQueryException e) {
        LOG.error(e.toString() + "\n" + e.getStackTrace());
        e.printStackTrace();
        MessageNotifier.showError(
            getWindow(),
            messageSource.getMessage(Message.ERROR_DATABASE),
            messageSource.getMessage(Message.ERROR_IN_GETTING_NEXT_NUMBER_IN_CROSS_NAME_SEQUENCE),
            Notification.POSITION_CENTERED);
      }
    }
  }