Example #1
0
  /** @return a copy of the tree node structure (nodes copied, same data and image) */
  public DataAndImageTreeNode<X> createCopy(DataAndImageTreeNode<X> parent) {
    DataAndImageTreeNode<X> newRoot = new DataAndImageTreeNode<X>(parent, this.data, this.image);
    for (DataAndImageTreeNode<X> child : children) {
      child.createCopy(newRoot);
    }

    return newRoot;
  }
    @Override
    protected IStatus run(IProgressMonitor monitor) {
      boolean selectingElementsInDialog = fSynchManager.getSelectingElementsInDialog();
      if (selectingElementsInDialog) {
        // No point in starting a process if the user already has a dialog related to this process
        // open.
        if (SynchSystemModulesManager.DEBUG) {
          System.out.println("Dialog already showing: rescheduling new check for later.");
        }
        this.scheduleLater(20000);
        return Status.OK_STATUS;
      }
      if (SynchSystemModulesManager.DEBUG) {
        System.out.println("Running SynchJob!");
      }

      if (monitor == null) {
        monitor = new NullProgressMonitor();
      }
      ManagerInfoToUpdate managerToNameToInfo;
      synchronized (fManagerToNameToInfoLock) {
        if (this.fManagerToNameToInfo == null || this.fManagerToNameToInfo.size() == 0) {
          return Status.OK_STATUS; // nothing to do if there's nothing there...
        }
        managerToNameToInfo = new ManagerInfoToUpdate(this.fManagerToNameToInfo);
        this.fManagerToNameToInfo = null;
      }

      long initialTime = System.currentTimeMillis();
      ThreadPriorityHelper priorityHelper = new ThreadPriorityHelper(this.getThread());
      priorityHelper.setMinPriority();

      try {
        final DataAndImageTreeNode root = new DataAndImageTreeNode(null, null, null);
        if (monitor.isCanceled()) {
          return Status.OK_STATUS;
        }

        fSynchManager.updateStructures(
            monitor, root, managerToNameToInfo, new CreateInterpreterInfoCallback());
        long delta = System.currentTimeMillis() - initialTime;
        if (SynchSystemModulesManager.DEBUG) {
          System.out.println(
              "Time to check polling for changes in interpreters: " + delta / 1000.0 + " secs.");
        }

        List<TreeNode> initialSelection = new ArrayList<>(0);
        if (root.hasChildren()) {
          initialSelection =
              fSynchManager.createInitialSelectionForDialogConsideringPreviouslyIgnored(
                  root, PydevPrefs.getPreferences());
        }

        if (root.hasChildren() && initialSelection.size() > 0) {
          if (SynchSystemModulesManager.DEBUG) {
            System.out.println("Changes found in PYTHONPATH.");
          }
          fSynchManager.asyncSelectAndScheduleElementsToChangePythonpath(
              root, managerToNameToInfo, initialSelection);
        } else {
          if (SynchSystemModulesManager.DEBUG) {
            System.out.println("PYTHONPATH remained the same.");
          }
          fSynchManager.synchronizeManagerToNameToInfoPythonpath(
              monitor, managerToNameToInfo, null);
        }

      } finally {
        // As jobs are from a thread pool, restore the priority afterwards
        priorityHelper.restoreInitialPriority();
      }
      return Status.OK_STATUS;
    }