/**
   * Method updateComponents.
   *
   * @param aParticipant - R4EParticipant
   */
  private void updateComponents(R4EParticipant aParticipant) {
    // Add item to the participants table
    final TableItem item = new TableItem(fAddedParticipantsTable, SWT.NONE);
    item.setText(0, aParticipant.getId());
    if (null != aParticipant.getEmail() && !("".equals(aParticipant.getEmail()))) {
      item.setFont(JFaceResources.getFontRegistry().get(JFaceResources.DEFAULT_FONT));
      item.setText(1, aParticipant.getEmail());
    } else {
      // Mark table item as not complete
      item.setFont(JFaceResources.getFontRegistry().getItalic(JFaceResources.DEFAULT_FONT));
    }
    fAddedParticipantsTable.showItem(item);

    if (fParticipants.size() > 0) {
      fClearParticipantsButton.setEnabled(true);
      fRemoveUserButton.setEnabled(true);
      if (fUserToAddCombo instanceof CCombo) {
        ((CCombo) fUserToAddCombo).setText("");
      } else {
        ((Text) fUserToAddCombo).setText("");
      }
      getButton(IDialogConstants.OK_ID).setEnabled(true);
      getButton(IDialogConstants.OK_ID).setSelection(false);
    } else {
      if (fReviewSource) {
        getButton(IDialogConstants.OK_ID).setEnabled(false);
      }
    }
  }
 /**
  * Method itemsUpdated.
  *
  * @param aItems Item[]
  * @param aInstanceId int
  * @see org.eclipse.mylyn.reviews.r4e.ui.internal.utils.IEditableListListener#itemsUpdated(Item[],
  *     int)
  */
 public void itemsUpdated(Item[] aItems, int aInstanceId) {
   if (fSelectedParticipantIndex >= 0) {
     final R4EParticipant participant = fParticipants.get(fSelectedParticipantIndex);
     if (0 == aInstanceId) {
       // Update roles
       participant.getRoles().clear();
       for (Item item : aItems) {
         R4EUserRole role = R4EUIParticipant.mapStringToRole(item.getText());
         if (null != role) {
           participant.getRoles().add(role);
         }
       }
     }
   }
 }
 /** Method createParticipants */
 private void createParticipants() {
   List<R4EParticipant> participants = new ArrayList<R4EParticipant>(1);
   R4EParticipant participant = RModelFactory.eINSTANCE.createR4EParticipant();
   participant.setId(TestConstants.PARTICIPANT_TEST_ID);
   participant.setEmail(TestConstants.PARTICIPANT_TEST_EMAIL);
   participants.add(participant);
   fParticipant =
       fProxy
           .getParticipantProxy()
           .createParticipant(fReview.getParticipantContainer(), participants);
   Assert.assertNotNull(fParticipant);
   Assert.assertEquals(TestConstants.PARTICIPANT_TEST_ID, fParticipant.getParticipant().getId());
   Assert.assertEquals(
       TestConstants.PARTICIPANT_TEST_EMAIL, fParticipant.getParticipant().getEmail());
   Assert.assertEquals(R4EUserRole.REVIEWER, fParticipant.getParticipant().getRoles().get(0));
 }
  /**
   * Method addUserToParticipantList.
   *
   * @param aUserInfo - IUserInfo
   */
  private void addUserToParticipantList(IUserInfo aUserInfo) {

    // First check if the participant already exist in the participant list
    for (R4EParticipant tmpPart : fParticipants) {
      if (aUserInfo.getUserId().equalsIgnoreCase(tmpPart.getId())) {
        return;
      }
    }

    // Add User to List
    final R4EParticipant participant = RModelFactory.eINSTANCE.createR4EParticipant();
    participant.setId(aUserInfo.getUserId());
    participant.setEmail(aUserInfo.getEmail());
    fParticipantsDetailsValues.add(UIUtils.buildUserDetailsString(aUserInfo));
    fParticipants.add(participant);

    updateComponents(participant);
  }
  /**
   * Method getParticipant.
   *
   * @param aId - String
   * @return R4EParticipant
   */
  protected R4EParticipant getParticipant(String aId) {
    // First check if the participant already exist in the participant list
    for (R4EParticipant tmpPart : fParticipants) {
      if (aId.equalsIgnoreCase(tmpPart.getId())) {
        return null;
      }
    }
    final R4EParticipant participant = RModelFactory.eINSTANCE.createR4EParticipant();
    if (R4EUIModelController.isUserQueryAvailable()) {
      final IQueryUser query = new QueryUserFactory().getInstance();
      try {
        final List<IUserInfo> users = query.searchByUserId(aId);

        // Fill info with first user returned
        for (IUserInfo user : users) {
          if (user.getUserId().toLowerCase().equals(aId)) {
            participant.setId(user.getUserId().toLowerCase());
            participant.setEmail(user.getEmail());
            fParticipantsDetailsValues.add(UIUtils.buildUserDetailsString(user));
            return participant;
          }
        }
      } catch (NamingException e) {
        R4EUIPlugin.Ftracer.traceError("Exception: " + e.toString() + " (" + e.getMessage() + ")");
        R4EUIPlugin.getDefault().logError("Exception: " + e.toString(), e);
      } catch (IOException e) {
        R4EUIPlugin.getDefault().logWarning("Exception: " + e.toString(), e);
      }
    }
    participant.setId(aId);
    fParticipantsDetailsValues.add("");
    return participant;
  }
  /**
   * Method addUserToParticipantList.
   *
   * @param aUser - String
   */
  private void addUsersToParticipantList(String aUser) {
    // Here we first need to resolve any group aliases to multiple users
    final List<String> resolvedUsers = R4EPreferencePage.getParticipantsFromList(aUser.trim());

    for (String user : resolvedUsers) {
      String[] userTokens = user.split(R4EUIConstants.LIST_SEPARATOR);

      // Resolve user in database (if possible)
      R4EParticipant participant = getParticipant(userTokens[0].toLowerCase());
      if (null == participant) {
        return; // Participant already in list
      }

      // Override email with address defined in users group (if any)
      if (2 == userTokens.length && !(userTokens[1].trim().equals(""))) {
        participant.setEmail(userTokens[1]);
      }

      // Override email with address defined in current review (if any)
      if (null != R4EUIModelController.getActiveReview()) {
        R4EParticipant reviewParticipant;
        try {
          reviewParticipant =
              R4EUIModelController.getActiveReview().getParticipant(participant.getId(), false);
          if (null != reviewParticipant) {
            participant.setEmail(reviewParticipant.getEmail());
          }
        } catch (ResourceHandlingException e) {
          UIUtils.displayResourceErrorDialog(e);
        }
      }
      fParticipants.add(participant);
      updateComponents(participant);
    }
  }
  /**
   * Method buttonPressed.
   *
   * @param buttonId int
   * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int)
   */
  @Override
  protected void buttonPressed(int buttonId) {
    if (buttonId == IDialogConstants.OK_ID) {
      final List<R4EParticipant> validatedParticipants = new ArrayList<R4EParticipant>();

      for (R4EParticipant newParticipant : fParticipants) {
        // Validate Participant Id
        String validateResult = validateEmptyInput(newParticipant.getId());
        if (null != validateResult) {
          // Validation of input failed
          final ErrorDialog dialog =
              new ErrorDialog(
                  null,
                  R4EUIConstants.DIALOG_TITLE_ERROR,
                  "No input given for Participant Id",
                  new Status(IStatus.ERROR, R4EUIPlugin.PLUGIN_ID, 0, validateResult, null),
                  IStatus.ERROR);
          dialog.open();
          return;
        }

        // Validate Participant Email
        validateResult = validateEmptyInput(newParticipant.getEmail());
        if (null != validateResult) {
          // Validation of input failed
          final ErrorDialog dialog =
              new ErrorDialog(
                  null,
                  R4EUIConstants.DIALOG_TITLE_ERROR,
                  "No Email given for Participant " + newParticipant.getId(),
                  new Status(IStatus.ERROR, R4EUIPlugin.PLUGIN_ID, 0, validateResult, null),
                  IStatus.ERROR);
          dialog.open();
          return;
        }
        if (!CommandUtils.isEmailValid(newParticipant.getEmail())) {
          return;
        }

        // Check if participant already exists (if so ignore but continue)
        R4EParticipant currentParticipant = null;
        if (null
            != R4EUIModelController.getActiveReview()) { // do not do this for participants lists
          try {
            currentParticipant =
                R4EUIModelController.getActiveReview()
                    .getParticipant(newParticipant.getId(), false);
          } catch (ResourceHandlingException e) {
            // ignore
          }
          if (fReviewSource
              && R4EUIModelController.getActiveReview().isParticipant(newParticipant.getId())
              && null != currentParticipant
              && currentParticipant.isEnabled()) {
            final ErrorDialog dialog =
                new ErrorDialog(
                    null,
                    R4EUIConstants.DIALOG_TITLE_ERROR,
                    "Cannot Add Participant " + newParticipant.getId(),
                    new Status(
                        IStatus.ERROR,
                        R4EUIPlugin.PLUGIN_ID,
                        0,
                        "Participant already part of this Review",
                        null),
                    IStatus.ERROR);
            dialog.open();
            continue;
          }

          // Validate Roles (optional)
          if (0 == newParticipant.getRoles().size()) {
            // If there is no roles defined, put one as default depending on the review type
            if (R4EUIModelController.getActiveReview()
                .getReview()
                .getType()
                .equals(R4EReviewType.BASIC)) {
              newParticipant.getRoles().add(R4EUserRole.LEAD);
            } else {
              newParticipant.getRoles().add(R4EUserRole.REVIEWER);
            }
          }
        }
        validatedParticipants.add(newParticipant);
      }
      // Set the participant list to include only the validated participants
      fParticipants = validatedParticipants;
    }
    super.buttonPressed(buttonId);
  }