@Override
    @SuppressWarnings("unchecked")
    public Image getImage(Object element) {
      ProjectDependency projectDep = (ProjectDependency) element;
      IdentificationJob job =
          identificationJobs == null ? null : identificationJobs.get(projectDep);
      if (job != null) {
        int jobState = job.getState();
        if (jobState == Job.RUNNING || jobState == Job.WAITING) {
          return loadingImage;
        }
      }

      Dependency d = dependencyMap.get(projectDep);

      if (d == null) {
        return failedImage;
      } else {
        Image img;
        if (isResolved(d)) {
          img = okImage;
        } else {
          img = unresolvedImage;
        }
        return img;
      }
    }
 public boolean hasNoRunningJobs() {
   for (IdentificationJob job : identificationJobs.values()) {
     if (job.getState() == Job.RUNNING || job.getState() == Job.WAITING) {
       return false;
     }
   }
   return true;
 }
 private void resolve(ProjectDependency projectDependency, Dependency d) {
   if (d != null) {
     IdentificationJob job = identificationJobs.get(projectDependency);
     job.setDependency(d);
     job.setRequestedProcess(Task.RESOLUTION_ONLY);
     job.schedule();
   }
 }
 @Override
 @SuppressWarnings("unchecked")
 public String getText(Object element) {
   ProjectDependency projectDep = (ProjectDependency) element;
   IdentificationJob job =
       identificationJobs == null ? null : identificationJobs.get(projectDep);
   if (job != null) {
     int jobState = job.getState();
     if (jobState == Job.RUNNING || jobState == Job.WAITING) {
       return "Identification in progress...";
     }
   }
   Dependency d = dependencyMap.get(projectDep);
   if (d == null) {
     return "Unidentified dependency";
   }
   return IdentifyMavenDependencyPage.getKey(d);
 }
  protected void runIdentificationJobs(IProgressMonitor monitor) {

    initJobs();
    if (monitor == null) {
      monitor = new NullProgressMonitor();
    }
    for (Map.Entry<ProjectDependency, Dependency> entry : dependencyMap.entrySet()) {
      if (entry.getValue() != null) {
        // don't need to run identification
        // continue;
      }
      IdentificationJob job = identificationJobs.get(entry.getKey());
      if (job != null) {
        job.setProgressGroup(monitor, 1);
        int jobState = job.getState();
        if (jobState == Job.NONE) {
          job.setRequestedProcess(Task.ALL);
          job.schedule();
        }
      }
    }
    refresh();
  }
 public void cancel() {
   for (IdentificationJob job : identificationJobs.values()) {
     job.cancel();
   }
 }
  private void initJobs() {
    if (identificationJobs == null) {
      identificationJobs = new HashMap<ProjectDependency, IdentificationJob>(dependencyMap.size());

      Table t = dependenciesViewer.getTable();
      IFileIdentificationManager fileIdentificationManager = new FileIdentificationManager();

      for (final TableItem item : t.getItems()) {
        final ProjectDependency projectDep = (ProjectDependency) item.getData();
        Dependency mavenDep = dependencyMap.get(projectDep);
        if (mavenDep != null) {
          // already identified
          continue;
        }
        File jar;
        try {
          final IdentificationJob job;
          if (projectDep.getDependencyKind() == ProjectDependency.DependencyKind.Project) {
            job =
                new IdentifyProjectJob(
                    "Search the Maven coordinates for " + projectDep.getPath(),
                    projectDep.getPath());
          } else if (projectDep.getDependencyKind() == ProjectDependency.DependencyKind.Archive) {
            jar = ConversionUtils.getFile(projectDep.getPath());
            job =
                new IdentifyJarJob(
                    "Search the Maven coordinates for " + jar.getAbsolutePath(),
                    fileIdentificationManager,
                    jar);
          } else {
            job =
                new DependencyResolutionJob(
                    "Resolve the Maven dependency for " + projectDep.getPath());
          }

          job.addJobChangeListener(
              new IJobChangeListener() {

                @Override
                public void sleeping(IJobChangeEvent event) {
                  // refreshUI();
                }

                @Override
                public void scheduled(IJobChangeEvent event) {
                  // refreshUI();
                }

                @Override
                public void running(IJobChangeEvent event) {
                  refreshUI();
                }

                @Override
                public void done(IJobChangeEvent event) {
                  Dependency d = job.getDependency();
                  dependencyMap.put(projectDep, d);
                  if (d != null) {
                    dependencyResolution.put(getKey(d), job.isResolvable());
                  }
                  refreshUI();
                }

                @Override
                public void awake(IJobChangeEvent event) {
                  // refreshUI();
                }

                @Override
                public void aboutToRun(IJobChangeEvent event) {
                  // refreshUI();
                }

                private void refreshUI() {
                  Display.getDefault()
                      .syncExec(
                          new Runnable() {
                            @Override
                            public void run() {
                              refresh(projectDep);
                            }
                          });
                }
              });
          identificationJobs.put(projectDep, job);
        } catch (CoreException e) {
          e.printStackTrace();
        }
      }
    }
  }