/**
   * 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 createParticipantsGroup
   *
   * @param aToolkit
   * @param aComposite
   */
  private void createParticipantsGroup(FormToolkit aToolkit, Composite aComposite) {
    // Users to Add
    final Group usersToAddGroup = new Group(aComposite, SWT.NONE);
    usersToAddGroup.setText(PARTICIPANTS_GROUP_LABEL);
    usersToAddGroup.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_WHITE));
    usersToAddGroup.setLayout(new GridLayout(4, false));
    final GridData groupGridData = new GridData(GridData.FILL, GridData.FILL, true, true);
    usersToAddGroup.setLayoutData(groupGridData);

    // Participants data composite
    final Composite dataComposite = aToolkit.createComposite(usersToAddGroup);
    dataComposite.setLayout(new GridLayout());
    final GridData dataCompositeData = new GridData(GridData.FILL, GridData.FILL, true, true);
    dataCompositeData.horizontalSpan = 3;
    dataComposite.setLayoutData(dataCompositeData);

    // Participants button composite
    final Composite buttonsComposite = aToolkit.createComposite(usersToAddGroup);
    buttonsComposite.setLayout(new GridLayout());
    final GridData buttonsCompositeData = new GridData(GridData.END, GridData.FILL, false, true);
    buttonsComposite.setLayoutData(buttonsCompositeData);

    final String[] participantsLists = R4EPreferencePage.getParticipantsLists();
    if (participantsLists.length > 0) {
      fUserToAddCombo = new CCombo(dataComposite, SWT.SINGLE | SWT.BORDER);
      ((CCombo) fUserToAddCombo).setItems(participantsLists);
      ((CCombo) fUserToAddCombo).setEditable(true);
    } else {
      fUserToAddCombo = aToolkit.createText(dataComposite, "", SWT.SINGLE | SWT.BORDER);
      ((Text) fUserToAddCombo).setEditable(true);
    }
    final GridData textGridData = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
    fUserToAddCombo.setToolTipText(R4EUIConstants.PARTICIPANT_ADD_USER_TOOLTIP);
    fUserToAddCombo.setLayoutData(textGridData);
    fUserToAddCombo.addListener(
        SWT.Modify,
        new Listener() {
          public void handleEvent(Event event) {
            String widgetStr = null;
            if (fUserToAddCombo instanceof CCombo) {
              widgetStr = ((CCombo) fUserToAddCombo).getText();
            } else {
              widgetStr = ((Text) fUserToAddCombo).getText().trim();
            }
            if (widgetStr.trim().length() > 0) {
              fAddUserButton.setEnabled(true);
            } else {
              fAddUserButton.setEnabled(false);
            }
          }
        });
    // Trap \R key (Return)
    fUserToAddCombo.addListener(
        SWT.KeyDown,
        new Listener() {
          public void handleEvent(Event event) {
            if (event.character == SWT.CR) {
              getShell().setCursor(getShell().getDisplay().getSystemCursor(SWT.CURSOR_WAIT));

              String widgetStr = null;
              if (fUserToAddCombo instanceof CCombo) {
                widgetStr = ((CCombo) fUserToAddCombo).getText();
              } else {
                widgetStr = ((Text) fUserToAddCombo).getText();
              }

              // Tokenize the users list
              final String[] users = widgetStr.split(R4EUIConstants.LIST_SEPARATOR);
              for (String user : users) {
                addUsersToParticipantList(user);
              }
              if (fUserToAddCombo instanceof CCombo) {
                ((CCombo) fUserToAddCombo).setText("");
              } else {
                ((Text) fUserToAddCombo).setText("");
              }
              getShell().setCursor(getShell().getDisplay().getSystemCursor(SWT.CURSOR_ARROW));
            }
          }
        });

    // Participants table
    final Composite tableComposite = aToolkit.createComposite(dataComposite);
    final GridData tableCompositeData = new GridData(GridData.FILL, GridData.FILL, true, true);
    fAddedParticipantsTable = aToolkit.createTable(tableComposite, SWT.FULL_SELECTION | SWT.BORDER);
    fAddedParticipantsTable.setHeaderVisible(true);
    fAddedParticipantsTable.setLinesVisible(true);
    fAddedParticipantsTable.setToolTipText(R4EUIConstants.PARTICIPANTS_ADD_TOOLTIP);
    fAddedParticipantsTable.setLinesVisible(true);
    fAddedParticipantsTable.setItemCount(0);
    final GridData tableGridData = new GridData(GridData.FILL, GridData.FILL, true, true);
    fAddedParticipantsTable.setLayoutData(tableGridData);

    final TableColumnLayout tableColumnLayout = new TableColumnLayout();
    final TableColumn idColumn = new TableColumn(fAddedParticipantsTable, SWT.NONE, 0);
    idColumn.setText(R4EUIConstants.ID_LABEL);
    final TableColumn emailColumn = new TableColumn(fAddedParticipantsTable, SWT.NONE, 1);
    emailColumn.setText(R4EUIConstants.EMAIL_LABEL);

    tableColumnLayout.setColumnData(
        idColumn, new ColumnWeightData(30, idColumn.getWidth() * 2, true));
    tableColumnLayout.setColumnData(
        emailColumn, new ColumnWeightData(70, emailColumn.getWidth(), true));

    tableComposite.setLayout(tableColumnLayout);
    tableComposite.setLayoutData(tableCompositeData);

    fAddedParticipantsTable.addListener(
        SWT.Selection,
        new Listener() {
          public void handleEvent(Event event) {
            fSelectedParticipantIndex = fAddedParticipantsTable.getSelectionIndex();
            if (fSelectedParticipantIndex >= 0) {
              final R4EParticipant participant = fParticipants.get(fSelectedParticipantIndex);
              if (null != participant) {
                fParticipantIdInputTextField.setText(participant.getId());
                if (null != participant.getEmail()) {
                  fParticipantEmailInputTextField.setText(participant.getEmail());
                } else {
                  fParticipantEmailInputTextField.setText("");
                }
                if (fSelectedParticipantIndex < fParticipantsDetailsValues.size()) {
                  fParticipantDetailsInputTextField.setText(
                      fParticipantsDetailsValues.get(fSelectedParticipantIndex));
                } else {
                  fParticipantDetailsInputTextField.setText("");
                }
              }

              // Make sure fields are enabled
              fParticipantIdInputTextField.setEnabled(true);
              fParticipantEmailInputTextField.setEnabled(true);
              fParticipantDetailsInputTextField.setEnabled(true);
            }
          }
        });

    // Add user button
    fAddUserButton = aToolkit.createButton(buttonsComposite, ADD_BUTTON_LABEL, SWT.NONE);
    final GridData addButtonGridData =
        new GridData(GridData.BEGINNING, GridData.BEGINNING, false, false);
    fAddUserButton.setEnabled(false);
    fAddUserButton.setToolTipText(R4EUIConstants.PARTICIPANT_ADD_USER_TOOLTIP);
    fAddUserButton.setLayoutData(addButtonGridData);
    fAddUserButton.addListener(
        SWT.Selection,
        new Listener() {
          public void handleEvent(Event event) {
            getShell().setCursor(getShell().getDisplay().getSystemCursor(SWT.CURSOR_WAIT));

            String widgetStr = null;
            if (fUserToAddCombo instanceof CCombo) {
              widgetStr = ((CCombo) fUserToAddCombo).getText();
            } else {
              widgetStr = ((Text) fUserToAddCombo).getText();
            }

            // Tokenize the users list
            final String[] users = widgetStr.split(R4EUIConstants.LIST_SEPARATOR);
            for (String user : users) {
              addUsersToParticipantList(user);
            }
            getShell().setCursor(getShell().getDisplay().getSystemCursor(SWT.CURSOR_ARROW));
          }
        });

    fFindUserButton = aToolkit.createButton(buttonsComposite, FIND_BUTTON_LABEL, SWT.NONE);
    final GridData findButtonGridData =
        new GridData(GridData.BEGINNING, GridData.BEGINNING, false, false);
    fFindUserButton.setToolTipText(R4EUIConstants.PARTICIPANT_FIND_USER_TOOLTIP);
    fFindUserButton.setLayoutData(findButtonGridData);
    fFindUserButton.addListener(
        SWT.Selection,
        new Listener() {
          public void handleEvent(Event event) {
            if (R4EUIModelController.isUserQueryAvailable()) {
              final IFindUserDialog dialog = R4EUIDialogFactory.getInstance().getFindUserDialog();
              dialog.create();
              dialog.setDialogsDefaults();
              final int result = dialog.open();
              if (result == Window.OK) {
                final List<IUserInfo> usersInfos = dialog.getUserInfos();
                for (IUserInfo user : usersInfos) {
                  addUserToParticipantList(user);
                }
              }
            } else {
              R4EUIPlugin.Ftracer.traceWarning(LDAP_NOT_CONFIGURED);
              final ErrorDialog dialog =
                  new ErrorDialog(
                      null,
                      R4EUIConstants.DIALOG_TITLE_WARNING,
                      LDAP_NOT_CONFIGURED,
                      new Status(
                          IStatus.WARNING,
                          R4EUIPlugin.PLUGIN_ID,
                          0,
                          LDAP_NOT_CONFIGURED_DETAILED,
                          null),
                      IStatus.WARNING);
              Display.getDefault()
                  .syncExec(
                      new Runnable() {
                        public void run() {
                          dialog.open();
                        }
                      });
            }
          }
        });

    fRemoveUserButton = aToolkit.createButton(buttonsComposite, REMOVE_BUTTON_LABEL, SWT.NONE);
    final GridData removeButtonGridData =
        new GridData(GridData.BEGINNING, GridData.BEGINNING, false, false);
    fRemoveUserButton.setEnabled(false);
    fRemoveUserButton.setToolTipText(R4EUIConstants.PARTICIPANT_REMOVE_TOOLTIP);
    fRemoveUserButton.setLayoutData(removeButtonGridData);
    if (!R4EUIModelController.isUserQueryAvailable()) {
      fRemoveUserButton.setEnabled(false);
    }
    fRemoveUserButton.addListener(
        SWT.Selection,
        new Listener() {
          public void handleEvent(Event event) {
            if (fSelectedParticipantIndex >= 0
                && fSelectedParticipantIndex < fAddedParticipantsTable.getItemCount()) {
              fAddedParticipantsTable.remove(fSelectedParticipantIndex);
              fParticipants.remove(fSelectedParticipantIndex);
              fParticipantsDetailsValues.remove(fSelectedParticipantIndex);
              clearParametersFields();
            }
          }
        });

    // Clear participants list button
    fClearParticipantsButton =
        aToolkit.createButton(buttonsComposite, CLEAR_BUTTON_LABEL, SWT.NONE);
    final GridData clearButtonGridData =
        new GridData(GridData.BEGINNING, GridData.BEGINNING, false, false);
    fClearParticipantsButton.setEnabled(false);
    fClearParticipantsButton.setToolTipText(R4EUIConstants.PARTICIPANTS_CLEAR_TOOLTIP);
    fClearParticipantsButton.setLayoutData(clearButtonGridData);
    fClearParticipantsButton.addListener(
        SWT.Selection,
        new Listener() {
          public void handleEvent(Event event) {
            fParticipants.clear();
            fParticipantsDetailsValues.clear();
            fAddedParticipantsTable.removeAll();
            fSelectedParticipantIndex = R4EUIConstants.INVALID_VALUE;
            clearParametersFields();
          }
        });
  }