/*
     * (non-Javadoc)
     *
     * @see
     * org.eclipse.jdt.internal.ui.wizards.dialogfields.IStringButtonAdapter
     * #changeControlPressed(org.eclipse.jdt
     * .internal.ui.wizards.dialogfields.DialogField)
     */
    public void changeControlPressed(DialogField field) {
      final DirectoryDialog dialog = new DirectoryDialog(getShell());
      dialog.setMessage(NewWizardMessages.NewJavaProjectWizardPageOne_directory_message);
      String directoryName = fLocation.getText().trim();
      if (directoryName.length() == 0) {
        String prevLocation =
            JavaPlugin.getDefault().getDialogSettings().get(DIALOGSTORE_LAST_EXTERNAL_LOC);
        if (prevLocation != null) {
          directoryName = prevLocation;
        }
      }

      if (directoryName.length() > 0) {
        final File path = new File(directoryName);
        if (path.exists()) dialog.setFilterPath(directoryName);
      }
      final String selectedDirectory = dialog.open();
      if (selectedDirectory != null) {
        String oldDirectory = new Path(fLocation.getText().trim()).lastSegment();
        fLocation.setText(selectedDirectory);
        String lastSegment = new Path(selectedDirectory).lastSegment();
        if (lastSegment != null
            && (fNameGroup.getName().length() == 0 || fNameGroup.getName().equals(oldDirectory))) {
          fNameGroup.setName(lastSegment);
        }
        JavaPlugin.getDefault()
            .getDialogSettings()
            .put(DIALOGSTORE_LAST_EXTERNAL_LOC, selectedDirectory);
      }
    }
  /** Open an appropriate directory browser */
  private void handleLocationBrowseButtonPressed() {
    DirectoryDialog dialog = new DirectoryDialog(locationPathField.getShell(), SWT.SHEET);
    dialog.setMessage(DataTransferMessages.WizardExternalProjectImportPage_directoryLabel);

    String dirName = getProjectLocationFieldValue();
    if (dirName.length() == 0) {
      dirName = previouslyBrowsedDirectory;
    }

    if (dirName.length() == 0) {
      dialog.setFilterPath(getWorkspace().getRoot().getLocation().toOSString());
    } else {
      File path = new File(dirName);
      if (path.exists()) {
        dialog.setFilterPath(new Path(dirName).toOSString());
      }
    }

    String selectedDirectory = dialog.open();
    if (selectedDirectory != null) {
      previouslyBrowsedDirectory = selectedDirectory;
      locationPathField.setText(previouslyBrowsedDirectory);
      setProjectName(projectFile(previouslyBrowsedDirectory));
    }
  }
Esempio n. 3
0
  public void cmdIedeaExportsSelected() {
    DirectoryDialog dlg = new DirectoryDialog(getShell());
    dlg.setText("Select a folder to save the export files in");
    dlg.setMessage("Select a directory");
    final String dir = dlg.open();
    if (dir == null) {
      return;
    }

    final IedeaExporter iedeaExporter = new IedeaExporter();
    try {
      new ProgressMonitorDialog(null)
          .run(
              true,
              true,
              new IRunnableWithProgress() {
                @Override
                public void run(IProgressMonitor monitor)
                    throws InvocationTargetException, InterruptedException {
                  try {
                    iedeaExporter.setMonitor(monitor);
                    iedeaExporter.generate(dir);
                  } catch (TaskException e) {
                    throw new InvocationTargetException(e);
                  }
                }
              });
      MessageDialog.openInformation(null, "Completed", "Tier.net export successful");
    } catch (InvocationTargetException e) {
      MessageUtil.showError(e, "Error running export", e.getMessage());
    } catch (InterruptedException e) {
      MessageDialog.openInformation(null, "Cancelled", e.getMessage());
    }
  }
  private void handleBrowseButtonPressed() {
    final DirectoryDialog dialog = new DirectoryDialog(directoryPathField.getShell(), SWT.SHEET);
    dialog.setMessage("Select search directory");

    String dirName = directoryPathField.getText().trim();
    if (dirName.isEmpty()) {
      dirName = previouslyBrowsedDirectory;
    }

    if (dirName.isEmpty()) {
      dialog.setFilterPath(ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString());
    } else {
      File path = new File(dirName);
      if (path.exists()) {
        dialog.setFilterPath(new Path(dirName).toOSString());
      }
    }

    String selectedDirectory = dialog.open();
    if (selectedDirectory != null) {
      previouslyBrowsedDirectory = selectedDirectory;
      directoryPathField.setText(previouslyBrowsedDirectory);
      updateProjectsList(selectedDirectory);
    }
  }
 /** Listener for Browse Button. */
 protected void browseBtnListener() {
   DirectoryDialog dialog = new DirectoryDialog(this.getShell());
   dialog.setText(Messages.wizPageSelFolder);
   dialog.setMessage(Messages.wizPageChooseDir);
   String directory = dialog.open();
   if (directory != null) {
     textLocation.setText(directory);
   }
 }
Esempio n. 6
0
  /**
   * ************************************************************************* The command has been
   * executed, so extract extract the needed information from the application context.
   * ************************************************************************
   */
  public CommandResult execute(ExecutionEvent event) throws ExecutionException {
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    IRuntimeSettings runtime = (IRuntimeSettings) ServiceManager.get(IRuntimeSettings.class);
    String instanceId = (String) runtime.getRuntimeProperty(RuntimeProperty.ID_PROCEDURE_SELECTION);

    try {
      IProcedureManager mgr = (IProcedureManager) ServiceManager.get(IProcedureManager.class);
      IProcedure proc = null;
      if (mgr.isLocallyLoaded(instanceId)) {
        proc = mgr.getProcedure(instanceId);
      } else {
        proc = mgr.getRemoteProcedure(instanceId);
      }

      List<AsRunFile> toExport = new LinkedList<AsRunFile>();

      ExportAsRunFileJob job = new ExportAsRunFileJob(proc);
      CommandHelper.executeInProgress(job, true, true);

      if (job.result.equals(CommandResult.SUCCESS)) {
        toExport.add(job.asrunFile);
        if (!job.asrunFile.getChildren().isEmpty()) {
          boolean alsoChildren =
              MessageDialog.openQuestion(
                  window.getShell(),
                  "Export children ASRUN files",
                  "This procedure has executed sub-procedures.\n\nDo you want to export these ASRUN files as well?");
          if (alsoChildren) {
            gatherChildAsRunFiles(job.asrunFile, toExport);
          }
        }
      }

      DirectoryDialog dialog = new DirectoryDialog(window.getShell(), SWT.SAVE);
      dialog.setMessage(
          "Select directory to export ASRUN file(s) for '" + proc.getProcName() + "'");
      dialog.setText("Export ASRUN");
      String destination = dialog.open();
      if (destination != null && !destination.isEmpty()) {
        SaveAsRunFileJob saveJob = new SaveAsRunFileJob(destination, toExport);
        CommandHelper.executeInProgress(saveJob, true, true);
        return saveJob.result;
      } else {
        return CommandResult.NO_EFFECT;
      }
    } catch (Exception ex) {
      ex.printStackTrace();
      return CommandResult.FAILED;
    }
  }
 /*
  * Get the directory path using the given location as default.
  */
 private String getDirectoryPath(String location) {
   DirectoryDialog dialog = new DirectoryDialog(getShell(), SWT.OPEN);
   dialog.setText(getDialogTitle());
   dialog.setMessage("Select local database directory:");
   dialog.setFilterPath(location);
   String path = dialog.open();
   if (path != null) {
     File dir = new File(path);
     if (dir.exists() && dir.isDirectory()) {
       return dir.getAbsolutePath();
     }
   }
   return null;
 }
Esempio n. 8
0
 /** Show a dialog that lets the user select a working directory */
 private void handleWorkingDirBrowseButtonSelected() {
   DirectoryDialog dialog = new DirectoryDialog(getShell());
   dialog.setMessage("Select a working directory for the launch configuration:");
   String currentWorkingDir = getWorkingDirectoryText();
   if (!currentWorkingDir.trim().equals("")) { // $NON-NLS-1$
     File path = new File(currentWorkingDir);
     if (path.exists()) {
       dialog.setFilterPath(currentWorkingDir);
     }
   }
   String selectedDirectory = dialog.open();
   if (selectedDirectory != null) {
     fOtherWorkingText.setText(selectedDirectory);
   }
 }
Esempio n. 9
0
  protected void handleBrowseSelected() {
    DirectoryDialog dialog = new DirectoryDialog(getShell());
    dialog.setMessage(browseDialogMessage);
    String currentWorkingDir = textField.getText();
    if (!currentWorkingDir.trim().equals("")) {
      File path = new File(currentWorkingDir);
      if (path.exists()) {
        dialog.setFilterPath(currentWorkingDir);
      }
    }

    String selectedDirectory = dialog.open();
    if (selectedDirectory != null) {
      textField.setText(selectedDirectory);
    }
  }
Esempio n. 10
0
 public static void loadFile(Shell shell, Text text, String msg, boolean isDirectory) {
   if (isDirectory) {
     DirectoryDialog dialog = new DirectoryDialog(shell, SWT.NONE);
     dialog.setMessage(msg);
     String value = dialog.open();
     if (value != null) {
       text.setText(value);
     }
   } else {
     FileDialog dialog = new FileDialog(shell, SWT.NONE);
     dialog.setText(msg);
     String value = dialog.open();
     if (value != null) {
       text.setText(value);
     }
   }
 }
  public static Object run(ActionContext actionContext) throws OgnlException {
    Thing self = (Thing) actionContext.get("self");

    Shell shell = (Shell) self.doAction("getShell", actionContext);

    DirectoryDialog dialog = new DirectoryDialog(shell, SWT.NONE);
    String filterPath = (String) self.doAction("getFilterPath", actionContext);
    if (filterPath != null && !"".equals(filterPath)) {
      dialog.setFilterPath(UtilString.getString(filterPath, actionContext));
    }
    String message = self.getString("message");
    if (message != null && !"".equals(message)) {
      dialog.setMessage(UtilString.getString(message, actionContext));
    }

    String dir = dialog.open();
    self.doAction("open", actionContext, UtilMap.toMap("fileName", dir));

    return dir;
  }
Esempio n. 12
0
  private File getFile(Object exportItem) {
    File file = null;
    if (exportItem instanceof Class) {
      DirectoryDialog directoryDialog = new DirectoryDialog(getShell());

      directoryDialog.setMessage(Messages.ExportWizardSelectDirectory);

      String dir = directoryDialog.open();
      if (dir != null) file = new File(dir);
    } else {
      String name = null;
      if (exportItem instanceof Account) name = ((Account) exportItem).getName();
      else if (exportItem instanceof Portfolio) name = ((Portfolio) exportItem).getName();
      else if (exportItem instanceof Security) name = ((Security) exportItem).getIsin();
      else if (exportItem instanceof String) name = (String) exportItem;

      FileDialog dialog = new FileDialog(getShell(), SWT.SAVE);
      if (name != null) dialog.setFileName(name + ".csv"); // $NON-NLS-1$
      String fileName = dialog.open();

      if (fileName != null) file = new File(fileName);
    }
    return file;
  }
  @Override
  protected String browse(final SapphireRenderingContext context) {
    final Property property = property();
    final List<Path> roots = getBasePaths();
    String selectedAbsolutePath = null;

    final List<String> extensions;

    if (this.fileExtensionService == null) {
      extensions = this.staticFileExtensionsList;
    } else {
      extensions = this.fileExtensionService.extensions();
    }

    if (enclosed()) {
      final List<IContainer> baseContainers = new ArrayList<IContainer>();

      for (Path path : roots) {
        final IContainer baseContainer = getWorkspaceContainer(path.toFile());

        if (baseContainer != null) {
          baseContainers.add(baseContainer);
        } else {
          break;
        }
      }

      final ITreeContentProvider contentProvider;
      final ILabelProvider labelProvider;
      final ViewerComparator viewerComparator;
      final Object input;

      if (roots.size() == baseContainers.size()) {
        // All paths are in the Eclipse Workspace. Use the available content and label
        // providers.

        contentProvider = new WorkspaceContentProvider(baseContainers);
        labelProvider = new WorkbenchLabelProvider();
        viewerComparator = new ResourceComparator();
        input = ResourcesPlugin.getWorkspace().getRoot();
      } else {
        // At least one of the roots is not in the Eclipse Workspace. Use custom file
        // system content and label providers.

        contentProvider = new FileSystemContentProvider(roots);
        labelProvider = new FileSystemLabelProvider(context);
        viewerComparator = new FileSystemNodeComparator();
        input = new Object();
      }

      final ElementTreeSelectionDialog dialog =
          new ElementTreeSelectionDialog(context.getShell(), labelProvider, contentProvider);

      dialog.setTitle(property.definition().getLabel(false, CapitalizationType.TITLE_STYLE, false));
      dialog.setMessage(
          createBrowseDialogMessage(
              property.definition().getLabel(true, CapitalizationType.NO_CAPS, false)));
      dialog.setAllowMultiple(false);
      dialog.setHelpAvailable(false);
      dialog.setInput(input);
      dialog.setComparator(viewerComparator);

      final Path currentPathAbsolute = convertToAbsolute((Path) ((Value<?>) property).content());

      if (currentPathAbsolute != null) {
        Object initialSelection = null;

        if (contentProvider instanceof WorkspaceContentProvider) {
          final URI uri = currentPathAbsolute.toFile().toURI();
          final IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot();

          final IFile[] files = wsroot.findFilesForLocationURI(uri);

          if (files.length > 0) {
            final IFile file = files[0];

            if (file.exists()) {
              initialSelection = file;
            }
          }

          if (initialSelection == null) {
            final IContainer[] containers = wsroot.findContainersForLocationURI(uri);

            if (containers.length > 0) {
              final IContainer container = containers[0];

              if (container.exists()) {
                initialSelection = container;
              }
            }
          }
        } else {
          initialSelection =
              ((FileSystemContentProvider) contentProvider).find(currentPathAbsolute);
        }

        if (initialSelection != null) {
          dialog.setInitialSelection(initialSelection);
        }
      }

      if (this.type == FileSystemResourceType.FILE) {
        dialog.setValidator(new FileSelectionStatusValidator());
      } else if (this.type == FileSystemResourceType.FOLDER) {
        dialog.addFilter(new ContainersOnlyViewerFilter());
      }

      if (!extensions.isEmpty()) {
        dialog.addFilter(new ExtensionBasedViewerFilter(extensions));
      }

      if (dialog.open() == Window.OK) {
        final Object firstResult = dialog.getFirstResult();

        if (firstResult instanceof IResource) {
          selectedAbsolutePath = ((IResource) firstResult).getLocation().toString();
        } else {
          selectedAbsolutePath = ((FileSystemNode) firstResult).getFile().getPath();
        }
      }
    } else if (this.type == FileSystemResourceType.FOLDER) {
      final DirectoryDialog dialog = new DirectoryDialog(context.getShell());
      dialog.setText(
          property.definition().getLabel(true, CapitalizationType.FIRST_WORD_ONLY, false));
      dialog.setMessage(
          createBrowseDialogMessage(
              property.definition().getLabel(true, CapitalizationType.NO_CAPS, false)));

      final Value<?> value = (Value<?>) property;
      final Path path = (Path) value.content();

      if (path != null) {
        dialog.setFilterPath(path.toOSString());
      } else if (roots.size() > 0) {
        dialog.setFilterPath(roots.get(0).toOSString());
      }

      selectedAbsolutePath = dialog.open();
    } else {
      final FileDialog dialog = new FileDialog(context.getShell());
      dialog.setText(
          property.definition().getLabel(true, CapitalizationType.FIRST_WORD_ONLY, false));

      final Value<?> value = (Value<?>) property;
      final Path path = (Path) value.content();

      if (path != null && path.segmentCount() > 1) {
        dialog.setFilterPath(path.removeLastSegments(1).toOSString());
        dialog.setFileName(path.lastSegment());
      } else if (roots.size() > 0) {
        dialog.setFilterPath(roots.get(0).toOSString());
      }

      if (!extensions.isEmpty()) {
        final StringBuilder buf = new StringBuilder();

        for (String extension : extensions) {
          if (buf.length() > 0) {
            buf.append(';');
          }

          buf.append("*.");
          buf.append(extension);
        }

        dialog.setFilterExtensions(new String[] {buf.toString()});
      }

      selectedAbsolutePath = dialog.open();
    }

    if (selectedAbsolutePath != null) {
      final Path relativePath = convertToRelative(new Path(selectedAbsolutePath));

      if (relativePath != null) {
        String result = relativePath.toPortableString();

        if (this.includeLeadingSlash) {
          result = "/" + result;
        }

        return result;
      }
    }

    return null;
  }
Esempio n. 14
0
  /**
   * Handle the create button selection event.
   *
   * @param event org.eclipse.swt.events.SelectionEvent
   */
  void createButtonSelected(SelectionEvent event) {

    /* Compute the appropriate dialog style */
    int style = getDefaultStyle();
    if (okButton.getEnabled() && okButton.getSelection()) style |= SWT.OK;
    if (cancelButton.getEnabled() && cancelButton.getSelection()) style |= SWT.CANCEL;
    if (yesButton.getEnabled() && yesButton.getSelection()) style |= SWT.YES;
    if (noButton.getEnabled() && noButton.getSelection()) style |= SWT.NO;
    if (retryButton.getEnabled() && retryButton.getSelection()) style |= SWT.RETRY;
    if (abortButton.getEnabled() && abortButton.getSelection()) style |= SWT.ABORT;
    if (ignoreButton.getEnabled() && ignoreButton.getSelection()) style |= SWT.IGNORE;
    if (iconErrorButton.getEnabled() && iconErrorButton.getSelection()) style |= SWT.ICON_ERROR;
    if (iconInformationButton.getEnabled() && iconInformationButton.getSelection())
      style |= SWT.ICON_INFORMATION;
    if (iconQuestionButton.getEnabled() && iconQuestionButton.getSelection())
      style |= SWT.ICON_QUESTION;
    if (iconWarningButton.getEnabled() && iconWarningButton.getSelection())
      style |= SWT.ICON_WARNING;
    if (iconWorkingButton.getEnabled() && iconWorkingButton.getSelection())
      style |= SWT.ICON_WORKING;
    if (primaryModalButton.getEnabled() && primaryModalButton.getSelection())
      style |= SWT.PRIMARY_MODAL;
    if (applicationModalButton.getEnabled() && applicationModalButton.getSelection())
      style |= SWT.APPLICATION_MODAL;
    if (systemModalButton.getEnabled() && systemModalButton.getSelection())
      style |= SWT.SYSTEM_MODAL;
    if (saveButton.getEnabled() && saveButton.getSelection()) style |= SWT.SAVE;
    if (openButton.getEnabled() && openButton.getSelection()) style |= SWT.OPEN;
    if (multiButton.getEnabled() && multiButton.getSelection()) style |= SWT.MULTI;

    /* Open the appropriate dialog type */
    String name = dialogCombo.getText();

    if (name.equals(ControlExample.getResourceString("ColorDialog"))) {
      ColorDialog dialog = new ColorDialog(shell, style);
      dialog.setRGB(new RGB(100, 100, 100));
      dialog.setText(ControlExample.getResourceString("Title"));
      RGB result = dialog.open();
      textWidget.append(ControlExample.getResourceString("ColorDialog") + Text.DELIMITER);
      textWidget.append(
          ControlExample.getResourceString("Result", new String[] {"" + result}) + Text.DELIMITER);
      textWidget.append("getRGB() = " + dialog.getRGB() + Text.DELIMITER + Text.DELIMITER);
      return;
    }

    if (name.equals(ControlExample.getResourceString("DirectoryDialog"))) {
      DirectoryDialog dialog = new DirectoryDialog(shell, style);
      dialog.setMessage(ControlExample.getResourceString("Example_string"));
      dialog.setText(ControlExample.getResourceString("Title"));
      String result = dialog.open();
      textWidget.append(ControlExample.getResourceString("DirectoryDialog") + Text.DELIMITER);
      textWidget.append(
          ControlExample.getResourceString("Result", new String[] {"" + result})
              + Text.DELIMITER
              + Text.DELIMITER);
      return;
    }

    if (name.equals(ControlExample.getResourceString("FileDialog"))) {
      FileDialog dialog = new FileDialog(shell, style);
      dialog.setFileName(ControlExample.getResourceString("readme_txt"));
      dialog.setFilterNames(FilterNames);
      dialog.setFilterExtensions(FilterExtensions);
      dialog.setText(ControlExample.getResourceString("Title"));
      String result = dialog.open();
      textWidget.append(ControlExample.getResourceString("FileDialog") + Text.DELIMITER);
      textWidget.append(
          ControlExample.getResourceString("Result", new String[] {"" + result}) + Text.DELIMITER);
      textWidget.append("getFileNames() =" + Text.DELIMITER);
      if ((dialog.getStyle() & SWT.MULTI) != 0) {
        String[] files = dialog.getFileNames();
        for (int i = 0; i < files.length; i++) {
          textWidget.append("\t" + files[i] + Text.DELIMITER);
        }
      }
      textWidget.append(
          "getFilterIndex() = " + dialog.getFilterIndex() + Text.DELIMITER + Text.DELIMITER);
      return;
    }

    if (name.equals(ControlExample.getResourceString("FontDialog"))) {
      FontDialog dialog = new FontDialog(shell, style);
      dialog.setText(ControlExample.getResourceString("Title"));
      FontData result = dialog.open();
      textWidget.append(ControlExample.getResourceString("FontDialog") + Text.DELIMITER);
      textWidget.append(
          ControlExample.getResourceString("Result", new String[] {"" + result}) + Text.DELIMITER);
      textWidget.append("getFontList() =" + Text.DELIMITER);
      FontData[] fonts = dialog.getFontList();
      if (fonts != null) {
        for (int i = 0; i < fonts.length; i++) {
          textWidget.append("\t" + fonts[i] + Text.DELIMITER);
        }
      }
      textWidget.append("getRGB() = " + dialog.getRGB() + Text.DELIMITER + Text.DELIMITER);
      return;
    }

    if (name.equals(ControlExample.getResourceString("PrintDialog"))) {
      PrintDialog dialog = new PrintDialog(shell, style);
      dialog.setText(ControlExample.getResourceString("Title"));
      PrinterData result = dialog.open();
      textWidget.append(ControlExample.getResourceString("PrintDialog") + Text.DELIMITER);
      textWidget.append(
          ControlExample.getResourceString("Result", new String[] {"" + result}) + Text.DELIMITER);
      textWidget.append("getScope() = " + dialog.getScope() + Text.DELIMITER);
      textWidget.append("getStartPage() = " + dialog.getStartPage() + Text.DELIMITER);
      textWidget.append("getEndPage() = " + dialog.getEndPage() + Text.DELIMITER);
      textWidget.append(
          "getPrintToFile() = " + dialog.getPrintToFile() + Text.DELIMITER + Text.DELIMITER);
      return;
    }

    if (name.equals(ControlExample.getResourceString("MessageBox"))) {
      MessageBox dialog = new MessageBox(shell, style);
      dialog.setMessage(ControlExample.getResourceString("Example_string"));
      dialog.setText(ControlExample.getResourceString("Title"));
      int result = dialog.open();
      textWidget.append(ControlExample.getResourceString("MessageBox") + Text.DELIMITER);
      /*
       * The resulting integer depends on the original
       * dialog style.  Decode the result and display it.
       */
      switch (result) {
        case SWT.OK:
          textWidget.append(ControlExample.getResourceString("Result", new String[] {"SWT.OK"}));
          break;
        case SWT.YES:
          textWidget.append(ControlExample.getResourceString("Result", new String[] {"SWT.YES"}));
          break;
        case SWT.NO:
          textWidget.append(ControlExample.getResourceString("Result", new String[] {"SWT.NO"}));
          break;
        case SWT.CANCEL:
          textWidget.append(
              ControlExample.getResourceString("Result", new String[] {"SWT.CANCEL"}));
          break;
        case SWT.ABORT:
          textWidget.append(ControlExample.getResourceString("Result", new String[] {"SWT.ABORT"}));
          break;
        case SWT.RETRY:
          textWidget.append(ControlExample.getResourceString("Result", new String[] {"SWT.RETRY"}));
          break;
        case SWT.IGNORE:
          textWidget.append(
              ControlExample.getResourceString("Result", new String[] {"SWT.IGNORE"}));
          break;
        default:
          textWidget.append(ControlExample.getResourceString("Result", new String[] {"" + result}));
          break;
      }
      textWidget.append(Text.DELIMITER + Text.DELIMITER);
    }
  }
  /** Search for installed VMs in the file system */
  protected void search() {
    if (Platform.OS_MACOSX.equals(Platform.getOS())) {
      doMacSearch();
      return;
    }
    // choose a root directory for the search
    DirectoryDialog dialog = new DirectoryDialog(getShell());
    dialog.setMessage(JREMessages.InstalledJREsBlock_9);
    dialog.setText(JREMessages.InstalledJREsBlock_10);
    String path = dialog.open();
    if (path == null) {
      return;
    }

    // ignore installed locations
    final Set<File> exstingLocations = new HashSet<File>();
    for (IVMInstall vm : fVMs) {
      exstingLocations.add(vm.getInstallLocation());
    }

    // search
    final File rootDir = new File(path);
    final List<File> locations = new ArrayList<File>();
    final List<IVMInstallType> types = new ArrayList<IVMInstallType>();

    IRunnableWithProgress r =
        new IRunnableWithProgress() {
          @Override
          public void run(IProgressMonitor monitor) {
            monitor.beginTask(JREMessages.InstalledJREsBlock_11, IProgressMonitor.UNKNOWN);
            search(rootDir, locations, types, exstingLocations, monitor);
            monitor.done();
          }
        };

    try {
      ProgressMonitorDialog progress =
          new ProgressMonitorDialog(getShell()) {
            /*
             * Overridden createCancelButton to replace Cancel label with Stop label
             * More accurately reflects action taken when button pressed.
             * Bug [162902]
             */
            @Override
            protected void createCancelButton(Composite parent) {
              cancel =
                  createButton(
                      parent, IDialogConstants.CANCEL_ID, IDialogConstants.STOP_LABEL, true);
              if (arrowCursor == null) {
                arrowCursor = new Cursor(cancel.getDisplay(), SWT.CURSOR_ARROW);
              }
              cancel.setCursor(arrowCursor);
              setOperationCancelButtonEnabled(enableCancelButton);
            }
          };
      progress.run(true, true, r);
    } catch (InvocationTargetException e) {
      JDIDebugUIPlugin.log(e);
    } catch (InterruptedException e) {
      // canceled
      return;
    }

    if (locations.isEmpty()) {
      String messagePath = path.replaceAll("&", "&&"); // @see bug 29855  //$NON-NLS-1$//$NON-NLS-2$
      MessageDialog.openInformation(
          getShell(),
          JREMessages.InstalledJREsBlock_12,
          NLS.bind(JREMessages.InstalledJREsBlock_13, new String[] {messagePath})); //
    } else {
      Iterator<IVMInstallType> iter2 = types.iterator();
      for (File location : locations) {
        IVMInstallType type = iter2.next();
        AbstractVMInstall vm = new VMStandin(type, createUniqueId(type));
        String name = location.getName();
        String nameCopy = new String(name);
        int i = 1;
        while (isDuplicateName(nameCopy)) {
          nameCopy = name + '(' + i++ + ')';
        }
        vm.setName(nameCopy);
        vm.setInstallLocation(location);
        if (type instanceof AbstractVMInstallType) {
          // set default java doc location
          AbstractVMInstallType abs = (AbstractVMInstallType) type;
          vm.setJavadocLocation(abs.getDefaultJavadocLocation(location));
          vm.setVMArgs(abs.getDefaultVMArguments(location));
        }
        vmAdded(vm);
      }
    }
  }