/**
   * Returns the link target location entered by the user.
   *
   * @return the link target location entered by the user. null if the user chose not to create a
   *     link.
   */
  public URI getLinkTargetURI() {
    if (!createLink) {
      return null;
    }
    // resolve path variable if we have a relative path
    if (!linkTarget.startsWith("/")) { // $NON-NLS-1$
      IPathVariableManager pathVariableManager =
          RemoteResourcesPlugin.getWorkspace().getPathVariableManager();
      try {

        URI path = new URI(linkTarget.replace(java.io.File.separatorChar, '/'));
        URI resolved = pathVariableManager.resolveURI(path);
        if (path != resolved) {
          // we know this is a path variable, but return unresolved
          // path so resource will be created with variable intact
          return path;
        }
      } catch (URISyntaxException e) {
        // link target is not a valid URI. Fall through to handle this
        // below
      }
    }

    FileSystemConfiguration configuration = getSelectedConfiguration();
    if (configuration == null) {
      return URIUtil.toURI(linkTarget);
    }
    // validate non-local file system location
    return configuration.getContributor().getURI(linkTarget);
  }
  /**
   * Validates this page's controls.
   *
   * @param linkHandle The target to check
   * @return IStatus indicating the validation result. IStatus.OK if the specified link target is
   *     valid given the linkHandle.
   */
  public IStatus validateLinkLocation(IResource linkHandle) {
    if ((linkTargetField == null) || linkTargetField.isDisposed() || !createLink) {
      return Status.OK_STATUS;
    }
    IWorkspace workspace = IDEWorkbenchPlugin.getPluginWorkspace();
    FileSystemConfiguration configuration = getSelectedConfiguration();
    if ((configuration == null) || EFS.SCHEME_FILE.equals(configuration.getScheme())) {
      // Special handling for UNC paths. See bug 90825
      IPath location = new Path(linkTarget);
      if (location.isUNC()) {
        return createStatus(
            IStatus.WARNING,
            IDEWorkbenchMessages.CreateLinkedResourceGroup_unableToValidateLinkTarget);
      }
    }
    URI locationURI = getLinkTargetURI();
    if (locationURI == null) {
      return createStatus(
          IStatus.WARNING,
          IDEWorkbenchMessages.CreateLinkedResourceGroup_unableToValidateLinkTarget);
    }
    IStatus locationStatus = workspace.validateLinkLocationURI(linkHandle, locationURI);
    if ((locationStatus.getSeverity() == IStatus.ERROR) || linkTarget.trim().equals(EMPTY_STRING)) {
      return locationStatus;
    }

    // use the resolved link target name
    URI resolved = workspace.getPathVariableManager().resolveURI(locationURI);
    IFileInfo linkTargetFile = IDEResourceInfoUtils.getFileInfo(resolved);
    if ((linkTargetFile != null) && linkTargetFile.exists()) {
      IStatus fileTypeStatus = validateFileType(linkTargetFile);
      if (!fileTypeStatus.isOK()) {
        return fileTypeStatus;
      }
    } else if (locationStatus.isOK()) {
      // locationStatus takes precedence over missing location warning.
      return createStatus(
          IStatus.WARNING, IDEWorkbenchMessages.CreateLinkedResourceGroup_linkTargetNonExistent);
    }
    return locationStatus;
  }
  /** Opens a file or directory browser depending on the link type. */
  private void handleLinkTargetBrowseButtonPressed() {
    IFileStore store = null;
    String selection = null;
    FileSystemConfiguration config = getSelectedConfiguration();
    @SuppressWarnings("unused")
    boolean isDefault =
        (config == null)
            || (FileSystemSupportRegistry.getInstance().getDefaultConfiguration()).equals(config);

    if (linkTarget.length() > 0) {
      store = IDEResourceInfoUtils.getFileStore(linkTarget);
      if (!store.fetchInfo().exists()) {
        store = null;
      }
    }
    if (type == IResource.FILE) {
      // if (isDefault) {
      // FileDialog dialog = new FileDialog(linkTargetField.getShell());
      // dialog.setText(IDEWorkbenchMessages.CreateLinkedResourceGroup_targetSelectionTitle);
      // if (store != null) {
      // if (store.fetchInfo().isDirectory()) {
      // dialog.setFilterPath(linkTarget);
      // } else {
      // dialog.setFileName(linkTarget);
      // }
      // }
      // selection = dialog.open();
      // } else {
      @SuppressWarnings("null")
      URI uri = config.getContributor().browseFileSystem(linkTarget, linkTargetField.getShell());
      if (uri != null) {
        selection = uri.toString();
        // }
      }
    } else {
      String filterPath = null;
      if (store != null) {
        IFileStore path = store;
        if (!store.fetchInfo().isDirectory()) {
          path = store.getParent();
        }
        if (path != null) {
          filterPath = store.toString();
        }
      }

      // if (isDefault) {
      // DirectoryDialog dialog = new DirectoryDialog(linkTargetField
      // .getShell());
      // dialog
      // .setMessage(IDEWorkbenchMessages.CreateLinkedResourceGroup_targetSelectionLabel);
      // if (filterPath != null)
      // dialog.setFilterPath(filterPath);
      // selection = dialog.open();
      // } else {
      String initialPath = IDEResourceInfoUtils.EMPTY_STRING;
      if (filterPath != null) {
        initialPath = filterPath;
      }
      if (config != null) {
        URI uri = config.getContributor().browseFileSystem(initialPath, linkTargetField.getShell());
        if (uri != null) {
          selection = uri.toString();
        }
      }
      // }
    }
    if (selection != null) {
      linkTargetField.setText(selection);
    }
  }