/*
   * Refreshes the external folders referenced on the buildpath of the given
   * source project
   */
  public void refreshReferences(IProject source, IProgressMonitor monitor) {
    IProject externalProject = getExternalFoldersProject();
    if (source.equals(externalProject)) return;
    if (!ScriptProject.hasScriptNature(source)) return;
    try {
      HashSet externalFolders =
          getExternalFolders(((ScriptProject) DLTKCore.create(source)).getResolvedBuildpath());
      if (externalFolders == null) return;
      final Iterator iterator = externalFolders.iterator();
      Job refreshJob =
          new Job(Messages.refreshing_external_folders) {
            public boolean belongsTo(Object family) {
              return family == ResourcesPlugin.FAMILY_MANUAL_REFRESH;
            }

            protected IStatus run(IProgressMonitor pm) {
              try {
                while (iterator.hasNext()) {
                  IPath externalPath = (IPath) iterator.next();
                  IFolder folder = getFolder(externalPath);
                  if (folder != null) folder.refreshLocal(IResource.DEPTH_INFINITE, pm);
                }
              } catch (CoreException e) {
                return e.getStatus();
              }
              return Status.OK_STATUS;
            }
          };
      refreshJob.schedule();
    } catch (CoreException e) {
      Util.log(e, "Exception while refreshing external project"); // $NON-NLS-1$
    }
    return;
  }
 private HashMap getFolders() {
   if (this.folders == null) {
     this.folders = new HashMap();
     IProject project = getExternalFoldersProject();
     if (project.isAccessible()) {
       try {
         IResource[] members = project.members();
         for (int i = 0, length = members.length; i < length; i++) {
           IResource member = members[i];
           if (member.getType() == IResource.FOLDER
               && member.isLinked()
               && member.getName().startsWith(LINKED_FOLDER_NAME)) {
             IPath externalFolderPath = member.getLocation();
             this.folders.put(externalFolderPath, member);
           }
         }
       } catch (CoreException e) {
         Util.log(e, "Exception while initializing external folders"); // $NON-NLS-1$
       }
     }
   }
   return this.folders;
 }
 private IProject createExternalFoldersProject(IProgressMonitor monitor) {
   IProject project = getExternalFoldersProject();
   if (!project.isAccessible()) {
     try {
       if (!project.exists()) {
         IProjectDescription desc =
             project.getWorkspace().newProjectDescription(project.getName());
         IPath stateLocation = DLTKCore.getPlugin().getStateLocation();
         desc.setLocation(stateLocation.append(EXTERNAL_PROJECT_NAME));
         project.create(desc, IResource.HIDDEN, monitor);
       }
       try {
         project.open(monitor);
       } catch (CoreException e1) {
         // .project or folder on disk have been deleted, recreate
         // them
         IPath stateLocation = DLTKCore.getPlugin().getStateLocation();
         IPath projectPath = stateLocation.append(EXTERNAL_PROJECT_NAME);
         projectPath.toFile().mkdirs();
         FileOutputStream output =
             new FileOutputStream(
                 projectPath.append(IScriptProjectFilenames.PROJECT_FILENAME).toOSString());
         try {
           output.write(
               ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
                       + //$NON-NLS-1$
                       "<projectDescription>\n" //$NON-NLS-1$
                       + "	<name>" //$NON-NLS-1$
                       + EXTERNAL_PROJECT_NAME
                       + "</name>\n"
                       + //$NON-NLS-1$
                       "	<comment></comment>\n"
                       + //$NON-NLS-1$
                       "	<projects>\n"
                       + //$NON-NLS-1$
                       "	</projects>\n"
                       + //$NON-NLS-1$
                       "	<buildSpec>\n"
                       + //$NON-NLS-1$
                       "	</buildSpec>\n"
                       + //$NON-NLS-1$
                       "	<natures>\n"
                       + //$NON-NLS-1$
                       "	</natures>\n"
                       + //$NON-NLS-1$
                       "</projectDescription>")
                   .getBytes()); //$NON-NLS-1$
         } finally {
           output.close();
         }
         project.open(null);
       }
     } catch (CoreException e) {
       Util.log(e, "Problem creating hidden project for external folders"); // $NON-NLS-1$
       return project;
     } catch (IOException e) {
       Util.log(e, "Problem creating hidden project for external folders"); // $NON-NLS-1$
       return project;
     }
   }
   return project;
 }