/**
   * 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 useWorkspaceResource.
  *
  * @param aVersion R4EFileVersion
  * @return boolean
  */
 public static boolean useWorkspaceResource(R4EFileVersion aVersion) {
   // Get handle to local storage repository
   try {
     if (null != R4EUIModelController.getActiveReview()) {
       final IRFSRegistry localRepository =
           RFSRegistryFactory.getRegistry(R4EUIModelController.getActiveReview().getReview());
       if (null != localRepository) {
         // If resource is available in the workspace, use it.  Otherwise use the local repo
         // version
         if ((null != aVersion) && (null != aVersion.getResource())) {
           final String workspaceFileId =
               localRepository.blobIdFor(((IFile) aVersion.getResource()).getContents());
           final String repoFileId = aVersion.getLocalVersionID();
           if ((null != workspaceFileId) && workspaceFileId.equals((repoFileId))) {
             return true;
           }
         }
       }
     }
   } catch (ReviewsFileStorageException e) {
     R4EUIPlugin.Ftracer.traceWarning("Exception: " + e.toString() + " (" + e.getMessage() + ")");
   } catch (CoreException e) {
     R4EUIPlugin.Ftracer.traceWarning("Exception: " + e.toString() + " (" + e.getMessage() + ")");
   }
   return false;
 }
  /** Method setViewTreeTable. */
  public void setViewTreeTable() {
    final Object[] expandedElements = getExpandedElements();

    // Create Columns
    createPathColumn();
    createAssignmentColumn();
    createNumChangesColumn();
    createNumAnomaliesColumn();
    getTree().setHeaderVisible(true);

    // Reset Layout to adjust Columns widths
    fTreeColumnLayout.setColumnData(
        fElementColumn.getColumn(), new ColumnWeightData(fElementColumnWeight, true));
    fTreeColumnLayout.setColumnData(
        fPathColumn.getColumn(), new ColumnWeightData(fPathColumnWeight, true));
    fTreeColumnLayout.setColumnData(
        fAssignColumn.getColumn(), new ColumnWeightData(fAssignColumnWeight, true));
    fTreeColumnLayout.setColumnData(
        fNumChangesColumn.getColumn(), new ColumnWeightData(fNumChangesColumnWeight, true));
    fTreeColumnLayout.setColumnData(
        fNumAnomaliesColumn.getColumn(), new ColumnWeightData(fNumAnomaliesColumnWeight, true));

    final R4EUIReviewBasic activeReview = R4EUIModelController.getActiveReview();
    if (null != activeReview) {
      fElementColumn.getColumn().setText(activeReview.getReview().getName());
      fElementColumn
          .getColumn()
          .setToolTipText(
              REVIEW_GROUP_COLUMN_TOOLTIP
                  + activeReview.getParent().getName()
                  + R4EUIConstants.LINE_FEED
                  + REVIEW_COLUMN_LABEL
                  + activeReview.getName());
    }

    // Set Tree Table Filters (shows only Review Items and Files for current review
    final TreeTableFilter filter =
        ((ReviewNavigatorActionGroup) R4EUIModelController.getNavigatorView().getActionSet())
            .getTreeTableFilter();
    fIsDefaultDisplay = false;

    // Save Default Tree input and adjust Tree Table input
    fDefaultInput = this.getInput();
    if (fDefaultInput instanceof R4EUIRootElement || fDefaultInput instanceof R4EUIReviewGroup) {
      this.setInput(R4EUIModelController.getActiveReview());
    }
    this.addFilter(filter);

    // Set Default sorter
    fTreeComparator = getComparator();
    setComparator(fTreeTableComparator);

    // Refresh Display
    this.getTree().getParent().layout();
    setExpandedElements(expandedElements);
  }
 /**
  * Method decorateFont.
  *
  * @param aElement Object
  * @return Font
  * @see org.eclipse.jface.viewers.IFontDecorator#decorateFont(Object)
  */
 public Font decorateFont(Object aElement) { // $codepro.audit.disable
   if (null != R4EUIModelController.getActiveReview()
       && R4EUIModelController.getActiveReview().equals(aElement)) {
     return JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT);
   }
   if (isMyReview((IR4EUIModelElement) aElement)) {
     return JFaceResources.getFontRegistry().getItalic(JFaceResources.DEFAULT_FONT);
   }
   return null;
 }
  /**
   * 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 setUp - Sets up the fixture, for example, open a network connection. This method is
  * called before a test is executed.
  *
  * @throws java.lang.Exception
  */
 @Override
 @Before
 public void setUp() throws Exception {
   fProxy = R4EUITestMain.getInstance();
   createReviewGroups();
   if (((ReviewNavigatorActionGroup) R4EUIModelController.getNavigatorView().getActionSet())
       .isHideDeltasFilterSet()) {
     fProxy.getCommandProxy().toggleHideDeltasFilter();
   }
 }
  /**
   * Verifies whether this element in a Review element and, if so, if we are part of it
   *
   * @param aElement - the model element
   * @return - true if this is a review and we are part of it, false otherwise
   */
  private boolean isMyReview(IR4EUIModelElement aElement) {

    IR4EUIModelElement currentElement = aElement;
    while (null != currentElement) {
      if (currentElement instanceof R4EUIReviewBasic) {
        if (((R4EUIReviewBasic) currentElement).isParticipant(R4EUIModelController.getReviewer())) {
          return true;
        }
      }
      currentElement = currentElement.getParent();
    }
    return false;
  }
  /** Method createReviewGroups */
  private void createReviewGroups() {

    fGroup = null;

    // Create Review Group
    for (R4EUIReviewGroup group : R4EUIModelController.getRootElement().getGroups()) {
      if (group.getReviewGroup().getName().equals(TestConstants.REVIEW_GROUP_TEST_NAME)) {
        fGroup = group;
        fGroupName = group.getName();
        break;
      }
    }
    if (null == fGroup) {
      fGroup =
          fProxy
              .getReviewGroupProxy()
              .createReviewGroup(
                  TestUtils.FSharedFolder + File.separator + TestConstants.REVIEW_GROUP_TEST_NAME,
                  TestConstants.REVIEW_GROUP_TEST_NAME,
                  TestConstants.REVIEW_GROUP_TEST_DESCRIPTION,
                  TestConstants.REVIEW_GROUP_TEST_ENTRY_CRITERIA,
                  TestConstants.REVIEW_GROUP_TEST_AVAILABLE_PROJECTS,
                  TestConstants.REVIEW_GROUP_TEST_AVAILABLE_COMPONENTS,
                  new String[0]);
      Assert.assertNotNull(fGroup);
      Assert.assertEquals(TestConstants.REVIEW_GROUP_TEST_NAME, fGroup.getReviewGroup().getName());
      Assert.assertEquals(
          new Path(TestUtils.FSharedFolder).toPortableString()
              + "/"
              + TestConstants.REVIEW_GROUP_TEST_NAME,
          fGroup.getReviewGroup().getFolder());
      Assert.assertEquals(
          TestConstants.REVIEW_GROUP_TEST_DESCRIPTION, fGroup.getReviewGroup().getDescription());
      Assert.assertEquals(
          TestConstants.REVIEW_GROUP_TEST_ENTRY_CRITERIA,
          fGroup.getReviewGroup().getDefaultEntryCriteria());
      for (int i = 0; i < TestConstants.REVIEW_GROUP_TEST_AVAILABLE_PROJECTS.length; i++) {
        Assert.assertEquals(
            TestConstants.REVIEW_GROUP_TEST_AVAILABLE_PROJECTS[i],
            fGroup.getReviewGroup().getAvailableProjects().get(i));
      }
      for (int i = 0; i < TestConstants.REVIEW_GROUP_TEST_AVAILABLE_COMPONENTS.length; i++) {
        Assert.assertEquals(
            TestConstants.REVIEW_GROUP_TEST_AVAILABLE_COMPONENTS[i],
            fGroup.getReviewGroup().getAvailableComponents().get(i));
      }
      fGroupName = fGroup.getName();
    }
  }
 /** Method setEnabledFields. */
 @Override
 protected void setEnabledFields() {
   if (R4EUIModelController.isJobInProgress()
       || fProperties.getElement().isReadOnly()
       || !fProperties.getElement().isEnabled()
       || null == R4EUIModelController.getActiveReview()
       || ((R4EReviewState) R4EUIModelController.getActiveReview().getReview().getState())
           .getState()
           .equals(R4EReviewPhase.R4E_REVIEW_PHASE_COMPLETED)) {
     fPositionText.setForeground(UIUtils.DISABLED_FONT_COLOR);
     fAssignedToText.setForeground(UIUtils.DISABLED_FONT_COLOR);
     fAssignedToButton.setEnabled(false);
     fUnassignedFromButton.setEnabled(false);
   } else {
     fPositionText.setForeground(UIUtils.ENABLED_FONT_COLOR);
     fAssignedToText.setForeground(UIUtils.ENABLED_FONT_COLOR);
     fAssignedToButton.setEnabled(true);
     if (fAssignedToText.getText().length() > 0) {
       fUnassignedFromButton.setEnabled(true);
     } else {
       fUnassignedFromButton.setEnabled(false);
     }
   }
 }
  /**
   * Method updateTargetFile.
   *
   * @param aFile IFile
   * @return IFile
   * @throws CoreException
   * @throws ReviewsFileStorageException
   */
  public static R4EFileVersion updateTargetFile(IFile aFile)
      throws CoreException, ReviewsFileStorageException {

    if (null == aFile) {
      return null; // should never happen
    }

    String remoteID = null;
    String localID = null;

    // Get handle to local storage repository
    final IRFSRegistry localRepository =
        RFSRegistryFactory.getRegistry(R4EUIModelController.getActiveReview().getReview());
    if (null == localRepository) {
      return null;
    }
    // Get Remote repository file info
    final ScmConnector connector = ScmCore.getConnector(aFile.getProject());
    if (null != connector) {
      final ScmArtifact artifact = connector.getArtifact(aFile);
      if ((null != artifact) && (null != artifact.getPath())) {
        // File found in remote repo.

        // Here we check if the file in the remote repository is different than the input file.
        // We cannot use the artifact ID directly and we need to fetch and calculate that SHA of the
        // remote file
        // because we do not know which version control system is used.
        // We need to do this comparison because the versions always return the latest file stored.

        final IFileRevision fileRev = artifact.getFileRevision(null);
        if (null != fileRev) {
          final IStorage fileStore = fileRev.getStorage(null);
          if (null != fileStore) {
            remoteID = localRepository.blobIdFor(fileStore.getContents());
            localID = localRepository.blobIdFor(aFile.getContents());
            if ((null != remoteID) && remoteID.equals(localID)) {
              // The files are the same. Copy from the remote repo
              return copyRemoteFileToLocalRepository(localRepository, artifact);
            }
          }
        }
        // The files are different.  This means the current user modified the file in his workspace
        return copyWorkspaceFileToLocalRepository(localRepository, aFile);
      }
    }
    // Else we copy the file that is in the current workspace
    return copyWorkspaceFileToLocalRepository(localRepository, aFile);
  }
  /** Method createReviews */
  private void createReviews() {
    // Update Review Group handle
    for (IR4EUIModelElement elem : R4EUIModelController.getRootElement().getChildren()) {
      if (fGroupName.equals(elem.getName())) {
        fGroup = (R4EUIReviewGroup) elem;
      }
    }
    if (!fGroup.isOpen()) {
      fProxy.getCommandProxy().openElement(fGroup);
    }
    Assert.assertTrue(fGroup.isOpen());

    fReview =
        fProxy
            .getReviewProxy()
            .createReview(
                fGroup,
                TestConstants.REVIEW_TEST_TYPE_INFORMAL,
                TestConstants.REVIEW_TEST_NAME_INF,
                TestConstants.REVIEW_TEST_DESCRIPTION,
                TestConstants.REVIEW_TEST_DUE_DATE,
                TestConstants.REVIEW_TEST_PROJECT,
                TestConstants.REVIEW_TEST_COMPONENTS,
                TestConstants.REVIEW_TEST_ENTRY_CRITERIA,
                TestConstants.REVIEW_TEST_OBJECTIVES,
                TestConstants.REVIEW_TEST_REFERENCE_MATERIALS);
    Assert.assertNotNull(fReview);
    Assert.assertNotNull(fReview.getParticipantContainer());
    Assert.assertNotNull(fReview.getAnomalyContainer());
    Assert.assertEquals(TestConstants.REVIEW_TEST_TYPE_INFORMAL, fReview.getReview().getType());
    Assert.assertEquals(TestConstants.REVIEW_TEST_NAME_INF, fReview.getReview().getName());
    Assert.assertEquals(TestConstants.REVIEW_TEST_DESCRIPTION, fReview.getReview().getExtraNotes());
    Assert.assertEquals(TestConstants.REVIEW_TEST_DUE_DATE, fReview.getReview().getDueDate());
    Assert.assertEquals(TestConstants.REVIEW_TEST_PROJECT, fReview.getReview().getProject());
    for (int i = 0; i < TestConstants.REVIEW_TEST_COMPONENTS.length; i++) {
      Assert.assertEquals(
          TestConstants.REVIEW_TEST_COMPONENTS[i], fReview.getReview().getComponents().get(i));
    }
    Assert.assertEquals(
        TestConstants.REVIEW_TEST_ENTRY_CRITERIA, fReview.getReview().getEntryCriteria());
    Assert.assertEquals(TestConstants.REVIEW_TEST_OBJECTIVES, fReview.getReview().getObjectives());
    Assert.assertEquals(
        TestConstants.REVIEW_TEST_REFERENCE_MATERIALS, fReview.getReview().getReferenceMaterial());
    Assert.assertTrue(fReview.isOpen());
  }
  /**
   * Method copyAnomalyData.
   *
   * @param aTargetAnomaly R4EAnomaly
   * @param aSourceAnomaly R4EAnomaly
   * @throws ResourceHandlingException
   * @throws OutOfSyncException
   */
  public static void copyAnomalyData(R4EAnomaly aTargetAnomaly, R4EAnomaly aSourceAnomaly)
      throws ResourceHandlingException, OutOfSyncException {
    if ((null != aTargetAnomaly) && (null != aSourceAnomaly)) {
      final Long bookNum =
          R4EUIModelController.FResourceUpdater.checkOut(
              aTargetAnomaly, R4EUIModelController.getReviewer());

      // Data copied unconditionally
      aTargetAnomaly.setCreatedOn(aSourceAnomaly.getCreatedOn());
      aTargetAnomaly.setDecidedByID(aSourceAnomaly.getDecidedByID());
      aTargetAnomaly.setFixedByID(aSourceAnomaly.getFixedByID());
      aTargetAnomaly.setFollowUpByID(aSourceAnomaly.getFollowUpByID());
      aTargetAnomaly.setState(aSourceAnomaly.getState());
      aTargetAnomaly.setFixedInVersion(aSourceAnomaly.getFixedInVersion());
      aTargetAnomaly.setNotAcceptedReason(aSourceAnomaly.getNotAcceptedReason());

      // Data copied only if not set previously
      if (null == aTargetAnomaly.getTitle() || ("").equals(aTargetAnomaly.getTitle())) {
        aTargetAnomaly.setTitle(aSourceAnomaly.getTitle());
      }
      if (null == aTargetAnomaly.getDescription() || ("").equals(aTargetAnomaly.getDescription())) {
        aTargetAnomaly.setDescription(aSourceAnomaly.getDescription());
      }
      if (null == aTargetAnomaly.getRank()) {
        aTargetAnomaly.setRank(aSourceAnomaly.getRank());
      }
      if (null == aTargetAnomaly.getRuleID() && null != aSourceAnomaly.getRuleID()) {
        aTargetAnomaly.setRuleID(aSourceAnomaly.getRuleID());
      }
      if (null != aSourceAnomaly.getType()) {
        final R4ECommentType oldCommentType = (R4ECommentType) aSourceAnomaly.getType();
        R4ECommentType commentType = (R4ECommentType) aTargetAnomaly.getType();
        if (null != oldCommentType) {
          if (null == commentType) {
            commentType = RModelFactory.eINSTANCE.createR4ECommentType();
            if (null != commentType) {
              commentType.setType(oldCommentType.getType());
            }
            aTargetAnomaly.setType(commentType);
          }
        }
      }
      R4EUIModelController.FResourceUpdater.checkIn(bookNum);
    }
  }
  /**
   * Method updateBaseFile.
   *
   * @param aFile IFile
   * @return IFile
   * @throws CoreException
   * @throws ReviewsFileStorageException
   */
  public static R4EFileVersion updateBaseFile(IFile aFile)
      throws CoreException, ReviewsFileStorageException {
    if (null == aFile) {
      return null; // should never happen
    }

    // Get Remote repository file info
    final ScmConnector connector = ScmCore.getConnector(aFile.getProject());
    if (null != connector) {
      final ScmArtifact artifact = connector.getArtifact(aFile);
      if ((null != artifact) && (null != artifact.getId())) {
        // File was modified, so we need to fetch the base file from the versions repository and
        // copy it to our own local repository
        final IRFSRegistry localRepository =
            RFSRegistryFactory.getRegistry(R4EUIModelController.getActiveReview().getReview());
        return copyRemoteFileToLocalRepository(localRepository, artifact);
      }
    } // else file not in source control

    // File was not modified, or No Version Control System or Remote File detected, so there is no
    // base
    return null;
  }
  /** Method setViewTree. */
  public void setViewTree() {
    final Object[] expandedElements = getExpandedElements();

    double elementColumnWidth = R4EUIConstants.INVALID_VALUE;
    double pathColumnWidth = R4EUIConstants.INVALID_VALUE;
    double assignColumnWidth = R4EUIConstants.INVALID_VALUE;
    double numChangesColumnWidth = R4EUIConstants.INVALID_VALUE;
    double numAnomaliesColumnWidth = R4EUIConstants.INVALID_VALUE;

    if (null != fElementColumn) {
      elementColumnWidth = fElementColumn.getColumn().getWidth();
    }
    createElementsColumn();
    getTree().setHeaderVisible(false);
    if (null != fPathColumn) {
      pathColumnWidth = fPathColumn.getColumn().getWidth();
      fPathColumn.getColumn().dispose();
      fPathColumn = null;
    }
    if (null != fAssignColumn) {
      assignColumnWidth = fAssignColumn.getColumn().getWidth();
      fAssignColumn.getColumn().dispose();
      fAssignColumn = null;
    }
    if (null != fNumChangesColumn) {
      numChangesColumnWidth = fNumChangesColumn.getColumn().getWidth();
      fNumChangesColumn.getColumn().dispose();
      fNumChangesColumn = null;
    }
    if (null != fNumAnomaliesColumn) {
      numAnomaliesColumnWidth = fNumAnomaliesColumn.getColumn().getWidth();
      fNumAnomaliesColumn.getColumn().dispose();
      fNumAnomaliesColumn = null;
    }
    fTreeColumnLayout.setColumnData(fElementColumn.getColumn(), new ColumnWeightData(100, true));

    // Calculate column weights to preserve (if any)
    if (elementColumnWidth != R4EUIConstants.INVALID_VALUE
        && pathColumnWidth != R4EUIConstants.INVALID_VALUE
        && assignColumnWidth != R4EUIConstants.INVALID_VALUE
        && numChangesColumnWidth != R4EUIConstants.INVALID_VALUE
        && numAnomaliesColumnWidth != R4EUIConstants.INVALID_VALUE) {
      final double totalWidth =
          elementColumnWidth
              + pathColumnWidth
              + assignColumnWidth
              + numChangesColumnWidth
              + numAnomaliesColumnWidth;
      fElementColumnWeight = (int) ((elementColumnWidth / totalWidth) * 100);
      fPathColumnWeight = (int) ((pathColumnWidth / totalWidth) * 100);
      fAssignColumnWeight = (int) ((assignColumnWidth / totalWidth) * 100);
      fNumChangesColumnWeight = (int) ((numChangesColumnWidth / totalWidth) * 100);
      fNumAnomaliesColumnWeight = (int) ((numAnomaliesColumnWidth / totalWidth) * 100);
      fElementColumn
          .getColumn()
          .setWidth((int) totalWidth); // make sure width is reset to full treeViewer width
    }
    fIsDefaultDisplay = true;

    // Remove Tree Table filters
    final TreeTableFilter filter =
        ((ReviewNavigatorActionGroup) R4EUIModelController.getNavigatorView().getActionSet())
            .getTreeTableFilter();
    this.removeFilter(filter);

    // Restore Tree sorters (if any)
    setComparator(fTreeComparator);

    // Restore Default Tree input
    this.setInput(fDefaultInput);

    // Set Expanded states correctly
    final List<Object> updatedExpandedElements = new ArrayList<Object>();
    if (expandedElements.length > 0) {
      if (null != expandedElements[0]
          && null != ((IR4EUIModelElement) expandedElements[0]).getParent()) {
        updatedExpandedElements.add(((IR4EUIModelElement) expandedElements[0]).getParent());
        if (null != ((IR4EUIModelElement) expandedElements[0]).getParent().getParent()) {
          updatedExpandedElements.add(
              ((IR4EUIModelElement) expandedElements[0]).getParent().getParent());
        }
      }
      for (Object expandedElement : expandedElements) {
        if (null != expandedElement) {
          updatedExpandedElements.add(expandedElement);
        }
      }
    } else {
      final R4EUIReviewBasic activeReview = R4EUIModelController.getActiveReview();
      if (null != activeReview) {
        updatedExpandedElements.add(activeReview);
        if (null != activeReview.getParent()) {
          updatedExpandedElements.add(activeReview.getParent());
        }
      }
    }
    Object[] elementsToExpand =
        updatedExpandedElements.toArray(new Object[updatedExpandedElements.size()]);
    setExpandedElements(elementsToExpand);
  }
  /**
   * Method createRuleSetSetup
   *
   * @throws ExecutionException
   * @throws NotDefinedException
   * @throws NotEnabledException
   * @throws NotHandledException
   * @throws ResourceHandlingException
   * @throws OutOfSyncException
   */
  public void createRuleSetSetup() {

    // Create a Rule Set
    R4EUIRuleSet newRuleSet =
        fProxy
            .getRuleSetProxy()
            .createRuleSet(
                TestUtils.FSharedFolder,
                TestConstants.RULE_SET_TEST_NAME,
                TestConstants.RULE_SET_TEST_VERSION);
    Assert.assertNotNull(newRuleSet);
    Assert.assertEquals(TestConstants.RULE_SET_TEST_VERSION, newRuleSet.getRuleSet().getVersion());
    Assert.assertEquals(
        new Path(TestUtils.FSharedFolder).toPortableString(), newRuleSet.getRuleSet().getFolder());
    Assert.assertEquals(TestConstants.RULE_SET_TEST_NAME, newRuleSet.getRuleSet().getName());

    // Create a second Rule Set
    R4EUIRuleSet newRuleSet2 =
        fProxy
            .getRuleSetProxy()
            .createRuleSet(
                TestUtils.FSharedFolder,
                TestConstants.RULE_SET_TEST_NAME2,
                TestConstants.RULE_SET_TEST_VERSION);
    String newRuleSet2Name = newRuleSet2.getName();
    Assert.assertNotNull(newRuleSet2);
    Assert.assertEquals(TestConstants.RULE_SET_TEST_VERSION, newRuleSet2.getRuleSet().getVersion());
    Assert.assertEquals(
        new Path(TestUtils.FSharedFolder).toPortableString(), newRuleSet2.getRuleSet().getFolder());
    Assert.assertEquals(TestConstants.RULE_SET_TEST_NAME2, newRuleSet2.getRuleSet().getName());

    // Create Rule Area
    R4EUIRuleArea newRuleArea =
        fProxy.getRuleAreaProxy().createRuleArea(newRuleSet, TestConstants.RULE_AREA_TEST_NAME);
    Assert.assertNotNull(newRuleArea);
    Assert.assertEquals(TestConstants.RULE_AREA_TEST_NAME, newRuleArea.getArea().getName());

    // Create Rule Violation
    R4EUIRuleViolation newRuleViolation =
        fProxy
            .getRuleViolationProxy()
            .createRuleViolation(newRuleArea, TestConstants.RULE_VIOLATION_TEST_NAME);
    Assert.assertNotNull(newRuleViolation);
    Assert.assertEquals(
        TestConstants.RULE_VIOLATION_TEST_NAME, newRuleViolation.getViolation().getName());

    // Create Rule
    R4EUIRule newRule =
        fProxy
            .getRuleProxy()
            .createRule(
                newRuleViolation,
                TestConstants.RULE_TEST_ID,
                TestConstants.RULE_TEST_TITLE,
                TestConstants.RULE_TEST_DESCRIPTION,
                UIUtils.getClassFromString(TestConstants.RULE_TEST_CLASS),
                UIUtils.getRankFromString(TestConstants.RULE_TEST_RANK));
    Assert.assertNotNull(newRule);
    Assert.assertEquals(TestConstants.RULE_TEST_ID, newRule.getRule().getId());
    Assert.assertEquals(TestConstants.RULE_TEST_TITLE, newRule.getRule().getTitle());
    Assert.assertEquals(TestConstants.RULE_TEST_DESCRIPTION, newRule.getRule().getDescription());
    Assert.assertEquals(
        UIUtils.getClassFromString(TestConstants.RULE_TEST_CLASS), newRule.getRule().getClass_());
    Assert.assertEquals(
        UIUtils.getRankFromString(TestConstants.RULE_TEST_RANK), newRule.getRule().getRank());

    // Close a Rule Set
    fProxy.getCommandProxy().closeElement(newRuleSet);
    Assert.assertFalse(newRuleSet.isOpen());

    // Open the closed Rule Set
    fProxy.getCommandProxy().openElement(newRuleSet);
    Assert.assertTrue(newRuleSet.isOpen());
    Assert.assertEquals(
        TestConstants.RULE_TEST_ID,
        ((R4EUIRule) newRuleSet.getChildren()[0].getChildren()[0].getChildren()[0])
            .getRule()
            .getId());

    // Remove Rule Set from preferences
    String prefsRuleSet = newRuleSet2.getRuleSet().eResource().getURI().toFileString();
    fProxy.getPreferencesProxy().removeRuleSetFromPreferences(prefsRuleSet);
    for (R4EUIRuleSet ruleSet : R4EUIModelController.getRootElement().getRuleSets()) {
      if (ruleSet.getRuleSet().getName().equals(newRuleSet2.getRuleSet().getName())) {
        fail(
            "RuleSet "
                + prefsRuleSet
                + " should not be present since it was removed from preferences");
      }
    }

    // Add back Rule Set to preferences
    boolean ruleSetFound = false;
    fProxy.getPreferencesProxy().addRuleSetToPreferences(prefsRuleSet);
    for (R4EUIRuleSet ruleSet : R4EUIModelController.getRootElement().getRuleSets()) {
      if (ruleSet.getRuleSet().getName().equals(newRuleSet2.getRuleSet().getName())) {
        ruleSetFound = true;
        break;
      }
    }
    Assert.assertTrue(ruleSetFound);

    for (IR4EUIModelElement elem : R4EUIModelController.getRootElement().getChildren()) {
      if (newRuleSet2Name.equals(elem.getName())) {
        newRuleSet2 = (R4EUIRuleSet) elem;
      }
    }
    fProxy.getCommandProxy().openElement(newRuleSet2);
    Assert.assertTrue(newRuleSet2.isOpen());
  }
  /**
   * Method createReviewGroupSetup
   *
   * @throws ExecutionException
   * @throws NotDefinedException
   * @throws NotEnabledException
   * @throws NotHandledException
   * @throws ResourceHandlingException
   * @throws OutOfSyncException
   */
  public void createReviewGroupSetup() {

    // Create Review Group
    R4EUIReviewGroup newGroup =
        fProxy
            .getReviewGroupProxy()
            .createReviewGroup(
                TestUtils.FSharedFolder + File.separator + TestConstants.REVIEW_GROUP_TEST_NAME,
                TestConstants.REVIEW_GROUP_TEST_NAME,
                TestConstants.REVIEW_GROUP_TEST_DESCRIPTION,
                TestConstants.REVIEW_GROUP_TEST_ENTRY_CRITERIA,
                TestConstants.REVIEW_GROUP_TEST_AVAILABLE_PROJECTS,
                TestConstants.REVIEW_GROUP_TEST_AVAILABLE_COMPONENTS,
                new String[0]);
    Assert.assertNotNull(newGroup);
    Assert.assertEquals(TestConstants.REVIEW_GROUP_TEST_NAME, newGroup.getReviewGroup().getName());
    Assert.assertEquals(
        new Path(TestUtils.FSharedFolder).toPortableString()
            + "/"
            + TestConstants.REVIEW_GROUP_TEST_NAME,
        newGroup.getReviewGroup().getFolder());
    Assert.assertEquals(
        TestConstants.REVIEW_GROUP_TEST_DESCRIPTION, newGroup.getReviewGroup().getDescription());
    Assert.assertEquals(
        TestConstants.REVIEW_GROUP_TEST_ENTRY_CRITERIA,
        newGroup.getReviewGroup().getDefaultEntryCriteria());
    for (int i = 0; i < TestConstants.REVIEW_GROUP_TEST_AVAILABLE_PROJECTS.length; i++) {
      Assert.assertEquals(
          TestConstants.REVIEW_GROUP_TEST_AVAILABLE_PROJECTS[i],
          newGroup.getReviewGroup().getAvailableProjects().get(i));
    }
    for (int i = 0; i < TestConstants.REVIEW_GROUP_TEST_AVAILABLE_COMPONENTS.length; i++) {
      Assert.assertEquals(
          TestConstants.REVIEW_GROUP_TEST_AVAILABLE_COMPONENTS[i],
          newGroup.getReviewGroup().getAvailableComponents().get(i));
    }
    String newGroupName = newGroup.getName();

    // Create a second Review Group
    R4EUIReviewGroup newGroup2 =
        fProxy
            .getReviewGroupProxy()
            .createReviewGroup(
                TestUtils.FSharedFolder + File.separator + TestConstants.REVIEW_GROUP_TEST_NAME2,
                TestConstants.REVIEW_GROUP_TEST_NAME2,
                TestConstants.REVIEW_GROUP_TEST_DESCRIPTION,
                TestConstants.REVIEW_GROUP_TEST_ENTRY_CRITERIA,
                TestConstants.REVIEW_GROUP_TEST_AVAILABLE_PROJECTS,
                TestConstants.REVIEW_GROUP_TEST_AVAILABLE_COMPONENTS,
                new String[0]);
    Assert.assertNotNull(newGroup2);
    Assert.assertEquals(
        TestConstants.REVIEW_GROUP_TEST_NAME2, newGroup2.getReviewGroup().getName());
    Assert.assertEquals(
        new Path(TestUtils.FSharedFolder).toPortableString()
            + "/"
            + TestConstants.REVIEW_GROUP_TEST_NAME2,
        newGroup2.getReviewGroup().getFolder());
    Assert.assertEquals(
        TestConstants.REVIEW_GROUP_TEST_DESCRIPTION, newGroup2.getReviewGroup().getDescription());
    Assert.assertEquals(
        TestConstants.REVIEW_GROUP_TEST_ENTRY_CRITERIA,
        newGroup2.getReviewGroup().getDefaultEntryCriteria());
    for (int i = 0; i < TestConstants.REVIEW_GROUP_TEST_AVAILABLE_PROJECTS.length; i++) {
      Assert.assertEquals(
          TestConstants.REVIEW_GROUP_TEST_AVAILABLE_PROJECTS[i],
          newGroup2.getReviewGroup().getAvailableProjects().get(i));
    }
    for (int i = 0; i < TestConstants.REVIEW_GROUP_TEST_AVAILABLE_COMPONENTS.length; i++) {
      Assert.assertEquals(
          TestConstants.REVIEW_GROUP_TEST_AVAILABLE_COMPONENTS[i],
          newGroup2.getReviewGroup().getAvailableComponents().get(i));
    }

    // Close a Review Group
    fProxy.getCommandProxy().closeElement(newGroup);
    Assert.assertFalse(newGroup.isOpen());

    // Open the closed Review Group
    fProxy.getCommandProxy().openElement(newGroup);
    Assert.assertTrue(newGroup.isOpen());

    // Remove Review Group from preferences
    String prefsGroup = newGroup2.getReviewGroup().eResource().getURI().toFileString();
    fProxy.getPreferencesProxy().removeGroupFromPreferences(prefsGroup);
    for (R4EUIReviewGroup group : R4EUIModelController.getRootElement().getGroups()) {
      if (group.getReviewGroup().getName().equals(newGroup2.getReviewGroup().getName())) {
        fail(
            "Group " + prefsGroup + " should not be present since it was removed from preferences");
      }
    }

    // Add back Review Group to preferences
    boolean groupFound = false;
    fProxy.getPreferencesProxy().addGroupToPreferences(prefsGroup);
    for (R4EUIReviewGroup group : R4EUIModelController.getRootElement().getGroups()) {
      if (group.getReviewGroup().getName().equals(newGroup2.getReviewGroup().getName())) {
        groupFound = true;
        break;
      }
    }
    Assert.assertTrue(groupFound);

    // Get back handle to Review Group since view is refreshed
    for (IR4EUIModelElement elem : R4EUIModelController.getRootElement().getChildren()) {
      if (newGroupName.equals(elem.getName())) {
        newGroup = (R4EUIReviewGroup) elem;
      }
    }
    fProxy.getCommandProxy().openElement(newGroup);
    Assert.assertTrue(newGroup.isOpen());

    // Update Review Group properties
    fProxy
        .getReviewGroupProxy()
        .changeReviewGroupDescription(newGroup, TestConstants.REVIEW_GROUP_TEST_DESCRIPTION2);
    Assert.assertEquals(
        TestConstants.REVIEW_GROUP_TEST_DESCRIPTION2, newGroup.getReviewGroup().getDescription());
    fProxy
        .getReviewGroupProxy()
        .changeReviewGroupDefaultEntryCriteria(
            newGroup, TestConstants.REVIEW_GROUP_TEST_ENTRY_CRITERIA2);
    Assert.assertEquals(
        TestConstants.REVIEW_GROUP_TEST_ENTRY_CRITERIA2,
        newGroup.getReviewGroup().getDefaultEntryCriteria());
    fProxy
        .getReviewGroupProxy()
        .removeReviewGroupAvailableProject(
            newGroup, TestConstants.REVIEW_GROUP_TEST_REM_AVAILABLE_PROJECT);
    fProxy
        .getReviewGroupProxy()
        .addReviewGroupAvailableProject(
            newGroup, TestConstants.REVIEW_GROUP_TEST_ADD_AVAILABLE_PROJECT);
    for (int i = 0; i < TestConstants.REVIEW_GROUP_TEST_AVAILABLE_PROJECTS2.length; i++) {
      Assert.assertEquals(
          TestConstants.REVIEW_GROUP_TEST_AVAILABLE_PROJECTS2[i],
          newGroup.getReviewGroup().getAvailableProjects().get(i));
    }
    fProxy
        .getReviewGroupProxy()
        .removeReviewGroupAvailableComponent(
            newGroup, TestConstants.REVIEW_GROUP_TEST_REM_AVAILABLE_COMPONENT);
    fProxy
        .getReviewGroupProxy()
        .addReviewGroupAvailableComponent(
            newGroup, TestConstants.REVIEW_GROUP_TEST_ADD_AVAILABLE_COMPONENT);
    for (int i = 0; i < TestConstants.REVIEW_GROUP_TEST_AVAILABLE_COMPONENTS2.length; i++) {
      Assert.assertEquals(
          TestConstants.REVIEW_GROUP_TEST_AVAILABLE_COMPONENTS2[i],
          newGroup.getReviewGroup().getAvailableComponents().get(i));
    }

    for (R4EUIRuleSet ruleSet : R4EUIModelController.getRootElement().getRuleSets()) {
      if (ruleSet.getName().equals(TestConstants.RULE_SET_TEST_NAME2)) {
        fProxy
            .getReviewGroupProxy()
            .addReviewGroupRuleSet(newGroup, ruleSet.getRuleSet().getName());
        Assert.assertEquals(
            ruleSet.getRuleSet().getName(),
            newGroup.getReviewGroup().getDesignRuleLocations().get(0));
        break;
      }
    }

    for (R4EUIRuleSet ruleSet : R4EUIModelController.getRootElement().getRuleSets()) {
      if (ruleSet.getName().equals(TestConstants.RULE_SET_TEST_NAME)) {
        fProxy
            .getReviewGroupProxy()
            .addReviewGroupRuleSet(newGroup, ruleSet.getRuleSet().getName());
      } else if (ruleSet.getName().equals(TestConstants.RULE_SET_TEST_NAME2)) {
        fProxy
            .getReviewGroupProxy()
            .removeReviewGroupRuleSet(newGroup, ruleSet.getRuleSet().getName());
      }
    }

    for (R4EUIRuleSet ruleSet : R4EUIModelController.getRootElement().getRuleSets()) {
      if (ruleSet.getName().equals(TestConstants.RULE_SET_TEST_NAME)) {
        Assert.assertEquals(
            ruleSet.getRuleSet().getName(),
            newGroup.getReviewGroup().getDesignRuleLocations().get(0));
        break;
      }
    }
  }
  /**
   * 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();
          }
        });
  }
  /** Method createReviewItems */
  private void createReviewItems() throws CoreException {
    fItem = fProxy.getItemProxy().createCommitItem(TestUtils.FJavaIProject, 0);
    // close and re-open, so the validation takes de-serialized information
    String itemName = fItem.getName();
    fProxy.getCommandProxy().closeElement(fReview);
    fProxy.getCommandProxy().openElement(fReview);
    for (IR4EUIModelElement elem : fReview.getChildren()) {
      if (elem.getName().equals(itemName)) {
        fItem = (R4EUIReviewItem) elem;
      }
    }

    // Now validate
    Assert.assertNotNull(fItem);
    Assert.assertEquals(R4EUIModelController.getReviewer(), fItem.getItem().getAddedById());
    Assert.assertEquals("*****@*****.**", fItem.getItem().getAuthorRep());
    Assert.assertEquals("second Java Commit", fItem.getItem().getDescription());
    Assert.assertEquals(4, fItem.getChildren().length);
    for (int i = 0; i < fItem.getChildren().length; i++) {
      if (((R4EUIFileContext) fItem.getChildren()[i])
          .getName()
          .equals(TestUtils.JAVA_FILE1_PROJ_NAME)) {
        fAnomalyFileIndex = i; // Used later to add anomalies
        Assert.assertEquals(
            TestUtils.JAVA_FILE1_PROJ_NAME,
            fItem.getItem().getFileContextList().get(i).getBase().getName());
        Assert.assertEquals(
            TestUtils.JAVA_FILE1_PROJ_NAME,
            fItem.getItem().getFileContextList().get(i).getTarget().getName());
        Assert.assertEquals(
            606,
            ((R4ETextPosition)
                    fItem
                        .getItem()
                        .getFileContextList()
                        .get(i)
                        .getDeltas()
                        .get(0)
                        .getTarget()
                        .getLocation())
                .getStartPosition());
        Assert.assertEquals(
            25,
            ((R4ETextPosition)
                    fItem
                        .getItem()
                        .getFileContextList()
                        .get(i)
                        .getDeltas()
                        .get(0)
                        .getTarget()
                        .getLocation())
                .getLength());
        Assert.assertEquals(
            665,
            ((R4ETextPosition)
                    fItem
                        .getItem()
                        .getFileContextList()
                        .get(i)
                        .getDeltas()
                        .get(1)
                        .getTarget()
                        .getLocation())
                .getStartPosition());
        Assert.assertEquals(
            63,
            ((R4ETextPosition)
                    fItem
                        .getItem()
                        .getFileContextList()
                        .get(i)
                        .getDeltas()
                        .get(1)
                        .getTarget()
                        .getLocation())
                .getLength());
        Assert.assertEquals(
            733,
            ((R4ETextPosition)
                    fItem
                        .getItem()
                        .getFileContextList()
                        .get(i)
                        .getDeltas()
                        .get(2)
                        .getTarget()
                        .getLocation())
                .getStartPosition());
        Assert.assertEquals(
            61,
            ((R4ETextPosition)
                    fItem
                        .getItem()
                        .getFileContextList()
                        .get(i)
                        .getDeltas()
                        .get(2)
                        .getTarget()
                        .getLocation())
                .getLength());
        Assert.assertTrue(
            fProxy
                .getCommandProxy()
                .verifyAnnotations(
                    ((R4EUIFileContext) fItem.getChildren()[i])
                        .getContentsContainerElement()
                        .getChildren(),
                    true,
                    R4EUIConstants.DELTA_ANNOTATION_ID));
      } else if (((R4EUIFileContext) fItem.getChildren()[i])
          .getName()
          .equals(TestUtils.JAVA_FILE4_PROJ_NAME)) {
        Assert.assertNull(fItem.getItem().getFileContextList().get(i).getBase());
        Assert.assertEquals(
            TestUtils.JAVA_FILE4_PROJ_NAME,
            fItem.getItem().getFileContextList().get(i).getTarget().getName());
      } else if (((R4EUIFileContext) fItem.getChildren()[i])
          .getName()
          .equals(TestUtils.JAVA_FILE3_PROJ_NAME)) {
        Assert.assertNull(fItem.getItem().getFileContextList().get(i).getBase());
        Assert.assertEquals(
            TestUtils.JAVA_FILE3_PROJ_NAME,
            fItem.getItem().getFileContextList().get(i).getTarget().getName());
      } else if (((R4EUIFileContext) fItem.getChildren()[i])
          .getName()
          .equals(TestUtils.JAVA_FILE2_PROJ_NAME)) {
        Assert.assertEquals(
            TestUtils.JAVA_FILE2_PROJ_NAME,
            fItem.getItem().getFileContextList().get(i).getBase().getName());
        Assert.assertNull(fItem.getItem().getFileContextList().get(i).getTarget());
      }
    }

    fItem2 = fProxy.getItemProxy().createManualTreeItem(TestUtils.FJavaFile3);
    Assert.assertNotNull(fItem2);
    Assert.assertEquals(R4EUIModelController.getReviewer(), fItem2.getItem().getAddedById());
    Assert.assertEquals(
        TestUtils.JAVA_FILE3_PROJ_NAME,
        fItem2.getItem().getFileContextList().get(0).getBase().getName());
    Assert.assertEquals(
        TestUtils.JAVA_FILE3_PROJ_NAME,
        fItem2.getItem().getFileContextList().get(0).getTarget().getName());
    Assert.assertEquals(
        0,
        ((R4ETextPosition)
                fItem2
                    .getItem()
                    .getFileContextList()
                    .get(0)
                    .getDeltas()
                    .get(0)
                    .getTarget()
                    .getLocation())
            .getStartPosition());
    Assert.assertEquals(
        755,
        ((R4ETextPosition)
                fItem2
                    .getItem()
                    .getFileContextList()
                    .get(0)
                    .getDeltas()
                    .get(0)
                    .getTarget()
                    .getLocation())
            .getLength());
    Assert.assertTrue(
        fProxy
            .getCommandProxy()
            .verifyAnnotations(
                ((R4EUIFileContext) fItem2.getChildren()[0])
                    .getContentsContainerElement()
                    .getChildren(),
                false,
                R4EUIConstants.SELECTION_ANNOTATION_ID));

    fItem3 = fProxy.getItemProxy().createManualTextItem(TestUtils.FJavaFile4, 50, 20);
    Assert.assertNotNull(fItem3);
    Assert.assertEquals(R4EUIModelController.getReviewer(), fItem3.getItem().getAddedById());
    Assert.assertEquals(
        TestUtils.JAVA_FILE4_PROJ_NAME,
        fItem3.getItem().getFileContextList().get(0).getBase().getName());
    Assert.assertEquals(
        TestUtils.JAVA_FILE4_PROJ_NAME,
        fItem3.getItem().getFileContextList().get(0).getTarget().getName());
    Assert.assertEquals(
        50,
        ((R4ETextPosition)
                fItem3
                    .getItem()
                    .getFileContextList()
                    .get(0)
                    .getDeltas()
                    .get(0)
                    .getTarget()
                    .getLocation())
            .getStartPosition());
    Assert.assertEquals(
        20,
        ((R4ETextPosition)
                fItem3
                    .getItem()
                    .getFileContextList()
                    .get(0)
                    .getDeltas()
                    .get(0)
                    .getTarget()
                    .getLocation())
            .getLength());
    Assert.assertTrue(
        fProxy
            .getCommandProxy()
            .verifyAnnotations(
                ((R4EUIFileContext) fItem3.getChildren()[0])
                    .getContentsContainerElement()
                    .getChildren(),
                true,
                R4EUIConstants.SELECTION_ANNOTATION_ID));
  }
  /**
   * 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);
  }