/**
   * Provides UI for switching compiler between versions
   *
   * @param toVersion
   */
  private static void switchVersion(
      final SpecifiedVersion toVersion, final Composite compilerPage) {
    final BundleDescription toBundle = CompilerUtils.getBundleDescription(toVersion);
    if (toBundle == null) {
      // this version is not installed
      return;
    }

    Button switchTo = new Button(compilerPage, SWT.PUSH);
    switchTo.setText("Switch to " + toBundle.getVersion());
    switchTo.addSelectionListener(
        new SelectionListener() {

          public void widgetSelected(SelectionEvent e) {
            Shell shell = compilerPage.getShell();
            boolean result =
                MessageDialog.openQuestion(
                    shell,
                    "Change compiler and restart?",
                    "Do you want to change the compiler?\n\nIf you select \"Yes\","
                        + " the compiler will be changed and Eclipse will be restarted.\n\n"
                        + "Make sure all your work is saved before clicking \"Yes\".");

            if (result) {
              // change compiler
              SpecifiedVersion activeGroovyVersion = CompilerUtils.getActiveGroovyVersion();
              IStatus status = CompilerUtils.switchVersions(activeGroovyVersion, toVersion);
              if (status == Status.OK_STATUS) {
                restart(shell);
              } else {
                ErrorDialog error =
                    new ErrorDialog(
                        shell,
                        "Error occurred",
                        "Error occurred when trying to enable Groovy " + toBundle.getVersion(),
                        status,
                        IStatus.ERROR);
                error.open();
              }
            }
          }

          public void widgetDefaultSelected(SelectionEvent e) {}
        });
  }