/**
  * Updates the test target package name
  *
  * <p>When using the "self-test" option, the packageName argument is ignored and the current value
  * from the project package is used.
  *
  * <p>Otherwise the packageName is used if it is not null.
  */
 private void updateTestTargetPackageField(String packageName) {
   if (mValues.testingSelf) {
     mValues.testTargetPackageName = mValues.packageName;
   } else if (packageName != null) {
     mValues.testTargetPackageName = packageName;
   }
 }
  @Override
  public void widgetSelected(SelectionEvent e) {
    if (mIgnore) {
      return;
    }

    Object source = e.getSource();
    if (source == mExistingRadioButton) {
      mProjectList.setEnabled(true);
      mValues.testingSelf = false;
      setExistingProject(getSelectedProject());
      mProjectList.setFocus();
    } else if (source == mCurrentRadioButton) {
      mProjectList.setEnabled(false);
      mValues.testingSelf = true;
      mValues.testedProject = null;
    } else {
      // The event must be from the project list, which unfortunately doesn't
      // pass itself as the selection event, it passes a reference to some internal
      // table widget that it uses, so we check for this case last
      IProject project = getSelectedProject();
      if (project != mValues.testedProject) {
        setExistingProject(project);
      }
    }

    validatePage();
  }
  @Override
  public void setVisible(boolean visible) {
    super.setVisible(visible);
    mPageShown = true;

    if (visible) {
      try {
        mIgnore = true;
        mCurrentRadioButton.setSelection(mValues.testingSelf);
        mExistingRadioButton.setSelection(!mValues.testingSelf);
        mProjectList.setEnabled(!mValues.testingSelf);

        if (mProjectList.isEmpty()) {
          initializeList();
        }
        if (!mValues.testingSelf) {
          mProjectList.setFocus();
          IProject project = getSelectedProject();
          if (project != null) {
            // The FilteredList seems to -insist- on selecting the first item
            // in the list, even when the selection is explicitly set to an empty
            // array. This means the user is looking at a selection, so we need
            // to also go ahead and select this item in the model such that the
            // two agree, even if we would have preferred to have no initial
            // selection.
            mValues.testedProject = project;
          }
        }
      } finally {
        mIgnore = false;
      }
    }

    validatePage();
  }
  private void setExistingProject(IProject project) {
    mValues.testedProject = project;

    // Try to update the application, package, sdk target and minSdkVersion accordingly
    if (project != null
        && (!mValues.applicationNameModifiedByUser
            || !mValues.packageNameModifiedByUser
            || !mValues.targetModifiedByUser
            || !mValues.minSdkModifiedByUser)) {
      ManifestData manifestData = AndroidManifestHelper.parseForData(project);
      if (manifestData != null) {
        String appName = String.format("%1$sTest", project.getName());
        String packageName = manifestData.getPackage();
        String minSdkVersion = manifestData.getMinSdkVersionString();
        IAndroidTarget sdkTarget = null;
        if (Sdk.getCurrent() != null) {
          sdkTarget = Sdk.getCurrent().getTarget(project);
        }

        if (packageName == null) {
          packageName = ""; // $NON-NLS-1$
        }
        mLastExistingPackageName = packageName;

        if (!mValues.projectNameModifiedByUser) {
          mValues.projectName = appName;
        }

        if (!mValues.applicationNameModifiedByUser) {
          mValues.applicationName = appName;
        }

        if (!mValues.packageNameModifiedByUser) {
          packageName += ".test"; // $NON-NLS-1$
          mValues.packageName = packageName;
        }

        if (!mValues.targetModifiedByUser && sdkTarget != null) {
          mValues.target = sdkTarget;
        }

        if (!mValues.minSdkModifiedByUser) {
          if (minSdkVersion != null || sdkTarget != null) {
            mValues.minSdk = minSdkVersion;
          }
          if (sdkTarget == null) {
            mValues.updateSdkTargetToMatchMinSdkVersion();
          }
        }
      }
    }

    updateTestTargetPackageField(mLastExistingPackageName);
  }