Java 类com.intellij.openapi.util.AsyncResult 实例源码

项目:intellij-ce-playground    文件:SwitchingSession.java   
public AsyncResult<SwitchTarget> finish(final boolean fadeAway) {
  myAlarm.cancelAllRequests();

  final AsyncResult<SwitchTarget> result = new AsyncResult<SwitchTarget>();
  final SwitchTarget selection = getSelection();
  if (selection != null) {
    selection.switchTo(true).doWhenDone(new Runnable() {
      public void run() {
        myManager.disposeCurrentSession(fadeAway);
        result.setDone(selection);
      }
    }).notifyWhenRejected(result);
  } else {
    Disposer.dispose(this);
    result.setDone();
  }

  return result;
}
项目:intellij-ce-playground    文件:LazyUiDisposable.java   
private static AsyncResult<Disposable> findDisposable(Disposable defaultValue, final DataKey<? extends Disposable> key) {
  if (defaultValue == null) {
    if (ApplicationManager.getApplication() != null) {
      final AsyncResult<Disposable> result = new AsyncResult<Disposable>();
      DataManager.getInstance().getDataContextFromFocus().doWhenDone(new Consumer<DataContext>() {
        public void consume(DataContext context) {
          Disposable disposable = key.getData(context);
          if (disposable == null) {
            disposable = Disposer.get("ui");
          }
          result.setDone(disposable);
        }
      });
      return result;
    }
    else {
      return null;
    }
  }
  else {
    return new AsyncResult.Done<Disposable>(defaultValue);
  }
}
项目:intellij-ce-playground    文件:Promise.java   
@NotNull
public static <T> Promise<T> wrap(@NotNull AsyncResult<T> asyncResult) {
  final AsyncPromise<T> promise = new AsyncPromise<T>();
  asyncResult.doWhenDone(new Consumer<T>() {
    @Override
    public void consume(T result) {
      promise.setResult(result);
    }
  }).doWhenRejected(new Consumer<String>() {
    @Override
    public void consume(String error) {
      promise.setError(error);
    }
  });
  return promise;
}
项目:intellij-ce-playground    文件:WindowSystemPlaybackCall.java   
public static AsyncResult<String> printFocus(final PlaybackContext context) {
  final AsyncResult result = new AsyncResult<String>();

  getUiReady(context).doWhenProcessed(new Runnable() {
    @Override
    public void run() {
      final LinkedHashMap<String, String> focusInfo = getFocusInfo();
      if (focusInfo == null) {
        result.setRejected("No component focused");
        return;
      }

      StringBuffer text = new StringBuffer();
      for (Iterator<String> iterator = focusInfo.keySet().iterator(); iterator.hasNext(); ) {
        String key = iterator.next();
        text.append(key + "=" + focusInfo.get(key));
        if (iterator.hasNext()) {
          text.append("|");
        }
      }
      result.setDone(text.toString());
    }
  });

  return result;
}
项目:intellij-ce-playground    文件:WindowSystemPlaybackCall.java   
public static AsyncResult<Project> findProject() {
  final AsyncResult<Project> project = new AsyncResult<Project>();
  final IdeFocusManager fm = IdeFocusManager.getGlobalInstance();
  fm.doWhenFocusSettlesDown(new Runnable() {
    @Override
    public void run() {
      Component parent = UIUtil.findUltimateParent(fm.getFocusOwner());
      if (parent instanceof IdeFrame) {
        IdeFrame frame = (IdeFrame)parent;
        if (frame.getProject() != null) {
          project.setDone(frame.getProject());
          return;
        }
      }

      project.setRejected();
    }
  });

  return project;
}
项目:intellij-ce-playground    文件:TodoTreeBuilder.java   
@Override
protected final AbstractTreeUpdater createUpdater() {
  return new AbstractTreeUpdater(this) {
    @Override
    protected ActionCallback beforeUpdate(final TreeUpdatePass pass) {
      if (!myDirtyFileSet.isEmpty()) { // suppress redundant cache validations
        final AsyncResult callback = new AsyncResult();
        DumbService.getInstance(myProject).runWhenSmart(new Runnable() {
          @Override
          public void run() {
            try {
              validateCache();
              getTodoTreeStructure().validateCache();
            }
            finally {
              callback.setDone();
            }
          }
        });
        return callback;
      }

      return ActionCallback.DONE;
    }
  };
}
项目:intellij-ce-playground    文件:DomStructureViewBuilder.java   
@Override
@NotNull
public StructureView createStructureView(final FileEditor fileEditor, @NotNull final Project project) {
  return new StructureViewComponent(fileEditor, createStructureViewModel(fileEditor instanceof TextEditor ? ((TextEditor)fileEditor).getEditor() : null), project, true) {
    @Override
    public AsyncResult<AbstractTreeNode> expandPathToElement(final Object element) {
      if (element instanceof XmlElement && ((XmlElement)element).isValid()) {
        final XmlElement xmlElement = (XmlElement)element;
        XmlTag tag = PsiTreeUtil.getParentOfType(xmlElement, XmlTag.class, false);
        while (tag != null) {
          final DomElement domElement = DomManager.getDomManager(xmlElement.getProject()).getDomElement(tag);
          if (domElement != null) {
            for (DomElement curElement = domElement; curElement != null; curElement = curElement.getParent()) {
              if (myDescriptor.fun(curElement) == DomService.StructureViewMode.SHOW) {
                return super.expandPathToElement(curElement.getXmlElement());
              }
            }
          }
          tag = PsiTreeUtil.getParentOfType(tag, XmlTag.class, true);
        }

      }
      return super.expandPathToElement(element);
    }
  };
}
项目:intellij-ce-playground    文件:MavenImportingTestCase.java   
protected MavenArtifactDownloader.DownloadResult downloadArtifacts(Collection<MavenProject> projects,
                                                                   List<MavenArtifact> artifacts) {
  final MavenArtifactDownloader.DownloadResult[] unresolved = new MavenArtifactDownloader.DownloadResult[1];

  AsyncResult<MavenArtifactDownloader.DownloadResult> result = new AsyncResult<MavenArtifactDownloader.DownloadResult>();
  result.doWhenDone(new Consumer<MavenArtifactDownloader.DownloadResult>() {
    @Override
    public void consume(MavenArtifactDownloader.DownloadResult unresolvedArtifacts) {
      unresolved[0] = unresolvedArtifacts;
    }
  });

  myProjectsManager.scheduleArtifactsDownloading(projects, artifacts, true, true, result);
  myProjectsManager.waitForArtifactsDownloadingCompletion();

  return unresolved[0];
}
项目:intellij-ce-playground    文件:RenameFix.java   
@Override
public void doFix(final Project project, final ProblemDescriptor descriptor) {
  final PsiElement nameIdentifier = descriptor.getPsiElement();
  final PsiElement elementToRename = nameIdentifier.getParent();
  if (m_targetName == null) {
    final AsyncResult<DataContext> contextFromFocus = DataManager.getInstance().getDataContextFromFocus();
    contextFromFocus.doWhenDone(new Consumer<DataContext>() {
      @Override
      public void consume(DataContext context) {
        final RenameHandler renameHandler = RenameHandlerRegistry.getInstance().getRenameHandler(context);
        if (renameHandler == null) {
          return;
        }
        renameHandler.invoke(project, new PsiElement[]{elementToRename}, context);
      }
    });
  }
  else {
    final RefactoringFactory factory = RefactoringFactory.getInstance(project);
    final RenameRefactoring renameRefactoring =
      factory.createRename(elementToRename, m_targetName, m_searchInStrings, m_searchInNonJavaFiles);
    renameRefactoring.run();
  }
}
项目:intellij-ce-playground    文件:StaticMethodOnlyUsedInOneClassInspection.java   
@Override
protected void doFix(@NotNull final Project project, ProblemDescriptor descriptor) throws IncorrectOperationException {
  final PsiElement location = descriptor.getPsiElement();
  final PsiMethod method = (PsiMethod)location.getParent();
  final RefactoringActionHandler moveHandler = RefactoringActionHandlerFactory.getInstance().createMoveHandler();
  final AsyncResult<DataContext> result = DataManager.getInstance().getDataContextFromFocus();
  result.doWhenDone(new Consumer<DataContext>() {
    @Override
    public void consume(final DataContext originalContext) {
      final DataContext dataContext = new DataContext() {
        @Override
        public Object getData(@NonNls String name) {
          if (LangDataKeys.TARGET_PSI_ELEMENT.is(name)) {
            return usageClass.getElement();
          }
          return originalContext.getData(name);
        }
      };
      moveHandler.invoke(project, new PsiElement[]{method}, dataContext);
    }
  });
}
项目:tools-idea    文件:SwitchManager.java   
public ActionCallback applySwitch() {
  final ActionCallback result = new ActionCallback();
  if (isSessionActive()) {
    final boolean showSpots = mySession.isShowspots();
    mySession.finish(false).doWhenDone(new AsyncResult.Handler<SwitchTarget>() {
      public void run(final SwitchTarget switchTarget) {
        mySession = null;
        IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(new Runnable() {
          public void run() {
            tryToInitSessionFromFocus(switchTarget, showSpots).doWhenProcessed(result.createSetDoneRunnable());
          }
        });
      }
    });
  }
  else {
    result.setDone();
  }

  return result;
}
项目:tools-idea    文件:SwitchingSession.java   
public AsyncResult<SwitchTarget> finish(final boolean fadeAway) {
  myAlarm.cancelAllRequests();

  final AsyncResult<SwitchTarget> result = new AsyncResult<SwitchTarget>();
  final SwitchTarget selection = getSelection();
  if (selection != null) {
    selection.switchTo(true).doWhenDone(new Runnable() {
      public void run() {
        myManager.disposeCurrentSession(fadeAway);
        result.setDone(selection);
      }
    }).notifyWhenRejected(result);
  } else {
    Disposer.dispose(this);
    result.setDone();
  }

  return result;
}
项目:tools-idea    文件:LazyUiDisposable.java   
public final void showNotify() {
  if (myWasEverShown) return;

  try {
    findParentDisposable().doWhenDone(new AsyncResult.Handler<Disposable>() {
      public void run(Disposable parent) {
        Project project = null;
        if (ApplicationManager.getApplication() != null) {
          project = PlatformDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext());
        }
        initialize(parent, myChild, project);
        Disposer.register(parent, myChild);
      }
    });
  }
  finally {
    myWasEverShown = true;
  }
}
项目:tools-idea    文件:LazyUiDisposable.java   
private static AsyncResult<Disposable> findDisposable(Disposable defaultValue, final DataKey<? extends Disposable> key) {
  if (defaultValue == null) {
    if (ApplicationManager.getApplication() != null) {
      final AsyncResult<Disposable> result = new AsyncResult<Disposable>();
      DataManager.getInstance().getDataContextFromFocus().doWhenDone(new AsyncResult.Handler<DataContext>() {
        public void run(DataContext context) {
          Disposable disposable = key.getData(context);
          if (disposable == null) {
            disposable = Disposer.get("ui");
          }
          result.setDone(disposable);
        }
      });
      return result;
    }
    else {
      return null;
    }
  }
  else {
    return new AsyncResult.Done<Disposable>(defaultValue);
  }
}
项目:tools-idea    文件:WindowSystemPlaybackCall.java   
public static AsyncResult<String> printFocus(final PlaybackContext context) {
  final AsyncResult result = new AsyncResult<String>();

  getUiReady(context).doWhenProcessed(new Runnable() {
    @Override
    public void run() {
      final LinkedHashMap<String, String> focusInfo = getFocusInfo();
      if (focusInfo == null) {
        result.setRejected("No component focused");
        return;
      }

      StringBuffer text = new StringBuffer();
      for (Iterator<String> iterator = focusInfo.keySet().iterator(); iterator.hasNext(); ) {
        String key = iterator.next();
        text.append(key + "=" + focusInfo.get(key));
        if (iterator.hasNext()) {
          text.append("|");
        }
      }
      result.setDone(text.toString());
    }
  });

  return result;
}
项目:tools-idea    文件:WindowSystemPlaybackCall.java   
public static AsyncResult<Project> findProject() {
  final AsyncResult<Project> project = new AsyncResult<Project>();
  final IdeFocusManager fm = IdeFocusManager.getGlobalInstance();
  fm.doWhenFocusSettlesDown(new Runnable() {
    @Override
    public void run() {
      Component parent = UIUtil.findUltimateParent(fm.getFocusOwner());
      if (parent instanceof IdeFrame) {
        IdeFrame frame = (IdeFrame)parent;
        if (frame.getProject() != null) {
          project.setDone(frame.getProject());
          return;
        }
      }

      project.setRejected();
    }
  });

  return project;
}
项目:tools-idea    文件:TodoTreeBuilder.java   
@Override
protected final AbstractTreeUpdater createUpdater() {
  return new AbstractTreeUpdater(this) {
    @Override
    protected ActionCallback beforeUpdate(final TreeUpdatePass pass) {
      if (!myDirtyFileSet.isEmpty()) { // suppress redundant cache validations
        final AsyncResult callback = new AsyncResult();
        DumbService.getInstance(myProject).runWhenSmart(new Runnable() {
          @Override
          public void run() {
            try {
              validateCache();
              getTodoTreeStructure().validateCache();
            }
            finally {
              callback.setDone();
            }
          }
        });
        return callback;
      }

      return new ActionCallback.Done();
    }
  };
}
项目:tools-idea    文件:NavBarUpdateQueue.java   
private void queueRevalidate(@Nullable final Runnable after) {
  queue(new AfterModelUpdate(ID.REVALIDATE) {
    @Override
    protected void after() {
      final LightweightHint hint = myPanel.getHint();
      if (hint != null) {
        myPanel.getHintContainerShowPoint().doWhenDone(new AsyncResult.Handler<RelativePoint>() {
          @Override
          public void run(final RelativePoint relativePoint) {
            hint.setSize(myPanel.getPreferredSize());
            hint.setLocation(relativePoint);
            if (after != null) {
              after.run();
            }
          }
        });
      }
      else {
        if (after != null) {
          after.run();
        }
      }
    }
  });
}
项目:tools-idea    文件:SelectInNavBarTarget.java   
private static void selectInNavBar() {
  DataManager.getInstance().getDataContextFromFocus()
    .doWhenDone(new AsyncResult.Handler<DataContext>() {
      @Override
      public void run(DataContext context) {
        final IdeFrame frame = IdeFrame.KEY.getData(context);
        if (frame != null) {
          final IdeRootPaneNorthExtension navBarExt = frame.getNorthExtension(NavBarRootPaneExtension.NAV_BAR);
          if (navBarExt != null) {
            final JComponent c = navBarExt.getComponent();
            final NavBarPanel panel = (NavBarPanel)c.getClientProperty("NavBarPanel");
            panel.rebuildAndSelectTail(true);
          }
        }
      }
    });
}
项目:tools-idea    文件:DomStructureViewBuilder.java   
@Override
@NotNull
public StructureView createStructureView(final FileEditor fileEditor, final Project project) {
  return new StructureViewComponent(fileEditor, createStructureViewModel(fileEditor instanceof TextEditor ? ((TextEditor)fileEditor).getEditor() : null), project) {
    @Override
    public AsyncResult<AbstractTreeNode> expandPathToElement(final Object element) {
      if (element instanceof XmlElement) {
        final XmlElement xmlElement = (XmlElement)element;
        XmlTag tag = PsiTreeUtil.getParentOfType(xmlElement, XmlTag.class, false);
        while (tag != null) {
          final DomElement domElement = DomManager.getDomManager(xmlElement.getProject()).getDomElement(tag);
          if (domElement != null) {
            for (DomElement curElement = domElement; curElement != null; curElement = curElement.getParent()) {
              if (myDescriptor.fun(curElement) == DomService.StructureViewMode.SHOW) {
                return super.expandPathToElement(curElement.getXmlElement());
              }
            }
          }
          tag = PsiTreeUtil.getParentOfType(tag, XmlTag.class, true);
        }

      }
      return super.expandPathToElement(element);
    }
  };
}
项目:tools-idea    文件:MavenImportingTestCase.java   
protected MavenArtifactDownloader.DownloadResult downloadArtifacts(Collection<MavenProject> projects,
                                                                   List<MavenArtifact> artifacts) {
  final MavenArtifactDownloader.DownloadResult[] unresolved = new MavenArtifactDownloader.DownloadResult[1];

  AsyncResult<MavenArtifactDownloader.DownloadResult> result = new AsyncResult<MavenArtifactDownloader.DownloadResult>();
  result.doWhenDone(new AsyncResult.Handler<MavenArtifactDownloader.DownloadResult>() {
    @Override
    public void run(MavenArtifactDownloader.DownloadResult unresolvedArtifacts) {
      unresolved[0] = unresolvedArtifacts;
    }
  });

  myProjectsManager.scheduleArtifactsDownloading(projects, artifacts, true, true, result);
  myProjectsManager.waitForArtifactsDownloadingCompletion();

  return unresolved[0];
}
项目:tools-idea    文件:RenameFix.java   
@Override
public void doFix(final Project project, final ProblemDescriptor descriptor) {
  final PsiElement nameIdentifier = descriptor.getPsiElement();
  final PsiElement elementToRename = nameIdentifier.getParent();
  if (m_targetName == null) {
    final AsyncResult<DataContext> contextFromFocus = DataManager.getInstance().getDataContextFromFocus();
    contextFromFocus.doWhenDone(new AsyncResult.Handler<DataContext>() {
      @Override
      public void run(DataContext context) {
        final RenameHandler renameHandler = RenameHandlerRegistry.getInstance().getRenameHandler(context);
        if (renameHandler == null) {
          return;
        }
        renameHandler.invoke(project, new PsiElement[]{elementToRename}, context);
      }
    });
  }
  else {
    final RefactoringFactory factory = RefactoringFactory.getInstance(project);
    final RenameRefactoring renameRefactoring =
      factory.createRename(elementToRename, m_targetName, m_searchInStrings, m_searchInNonJavaFiles);
    renameRefactoring.run();
  }
}
项目:tools-idea    文件:StaticMethodOnlyUsedInOneClassInspection.java   
@Override
protected void doFix(@NotNull final Project project, ProblemDescriptor descriptor) throws IncorrectOperationException {
  final PsiElement location = descriptor.getPsiElement();
  final PsiMethod method = (PsiMethod)location.getParent();
  final RefactoringActionHandler moveHandler = RefactoringActionHandlerFactory.getInstance().createMoveHandler();
  final AsyncResult<DataContext> result = DataManager.getInstance().getDataContextFromFocus();
  result.doWhenDone(new AsyncResult.Handler<DataContext>() {
    @Override
    public void run(final DataContext originalContext) {
      final DataContext dataContext = new DataContext() {
        @Override
        public Object getData(@NonNls String name) {
          if (LangDataKeys.TARGET_PSI_ELEMENT.is(name)) {
            return usageClass.getElement();
          }
          return originalContext.getData(name);
        }
      };
      moveHandler.invoke(project, new PsiElement[]{method}, dataContext);
    }
  });
}
项目:consulo    文件:DialogWrapper.java   
@Nonnull
private AsyncResult<Boolean> invokeShow() {
  final AsyncResult<Boolean> result = new AsyncResult<>();

  ensureEventDispatchThread();
  registerKeyboardShortcuts();

  final Disposable uiParent = Disposer.get("ui");
  if (uiParent != null) { // may be null if no app yet (license agreement)
    Disposer.register(uiParent, myDisposable); // ensure everything is disposed on app quit
  }

  Disposer.register(myDisposable, new Disposable() {
    @Override
    public void dispose() {
      result.setDone(isOK());
    }
  });

  myPeer.show();

  return result;
}
项目:consulo    文件:LazyUiDisposable.java   
private static AsyncResult<Disposable> findDisposable(Disposable defaultValue, final Key<? extends Disposable> key) {
  if (defaultValue == null) {
    if (ApplicationManager.getApplication() != null) {
      final AsyncResult<Disposable> result = new AsyncResult<>();
      DataManager.getInstance().getDataContextFromFocus().doWhenDone(context -> {
        Disposable disposable = context.getData(key);
        if (disposable == null) {
          disposable = Disposer.get("ui");
        }
        result.setDone(disposable);
      });
      return result;
    }
    else {
      return null;
    }
  }
  else {
    return AsyncResult.done(defaultValue);
  }
}
项目:consulo    文件:TodoTreeBuilder.java   
@Override
protected final AbstractTreeUpdater createUpdater() {
  return new AbstractTreeUpdater(this) {
    @Override
    protected ActionCallback beforeUpdate(final TreeUpdatePass pass) {
      if (!myDirtyFileSet.isEmpty()) { // suppress redundant cache validations
        final AsyncResult callback = new AsyncResult();
        DumbService.getInstance(myProject).runWhenSmart(() -> {
          try {
            validateCache();
            getTodoTreeStructure().validateCache();
          }
          finally {
            callback.setDone();
          }
        });
        return callback;
      }

      return ActionCallback.DONE;
    }
  };
}
项目:consulo-java    文件:RenameFix.java   
@Override
public void doFix(final Project project, final ProblemDescriptor descriptor)
{
    final PsiElement nameIdentifier = descriptor.getPsiElement();
    final PsiElement elementToRename = nameIdentifier.getParent();
    if(m_targetName == null)
    {
        final AsyncResult<DataContext> contextFromFocus = DataManager.getInstance().getDataContextFromFocus();
        contextFromFocus.doWhenDone(context -> {
            final RenameHandler renameHandler = RenameHandlerRegistry.getInstance().getRenameHandler(context);
            if(renameHandler == null)
            {
                return;
            }
            renameHandler.invoke(project, new PsiElement[]{elementToRename}, context);
        });
    }
    else
    {
        final RefactoringFactory factory = RefactoringFactory.getInstance(project);
        final RenameRefactoring renameRefactoring = factory.createRename(elementToRename, m_targetName, m_searchInStrings, m_searchInNonJavaFiles);
        renameRefactoring.run();
    }
}
项目:intellij-ce-playground    文件:JavaDocReferenceInspection.java   
@Override
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
  final PsiElement element = PsiTreeUtil.getParentOfType(descriptor.getPsiElement(), PsiJavaCodeReferenceElement.class);
  if (element instanceof PsiJavaCodeReferenceElement) {
    final PsiJavaCodeReferenceElement referenceElement = (PsiJavaCodeReferenceElement)element;
    Collections.sort(originalClasses, new PsiProximityComparator(referenceElement.getElement()));
    final JList list = new JBList(originalClasses.toArray(new PsiClass[originalClasses.size()]));
    list.setCellRenderer(new FQNameCellRenderer());
    final Runnable runnable = new Runnable() {
      @Override
      public void run() {
        if (!element.isValid()) return;
        final int index = list.getSelectedIndex();
        if (index < 0) return;
        new WriteCommandAction(project, element.getContainingFile()){
          @Override
          protected void run(@NotNull final Result result) throws Throwable {
            final PsiClass psiClass = originalClasses.get(index);
            if (psiClass.isValid()) {
              PsiDocumentManager.getInstance(project).commitAllDocuments();
              referenceElement.bindToElement(psiClass);
            }
          }
        }.execute();
      }
    };
    final AsyncResult<DataContext> asyncResult = DataManager.getInstance().getDataContextFromFocus();
    asyncResult.doWhenDone(new Consumer<DataContext>() {
      @Override
      public void consume(DataContext dataContext) {
        new PopupChooserBuilder(list).
          setTitle(QuickFixBundle.message("add.qualifier.original.class.chooser.title")).
          setItemChoosenCallback(runnable).
          createPopup().
          showInBestPositionFor(dataContext);
      }
    });
  }
}
项目:intellij-ce-playground    文件:AbstractTreeBuilder.java   
@NotNull
public AsyncResult<Object> revalidateElement(Object element) {
  if (isDisposed()) return new AsyncResult.Rejected<Object>();

  AbstractTreeStructure structure = getTreeStructure();
  if (structure == null) return new AsyncResult.Rejected<Object>();

  return structure.revalidateElement(element);
}
项目:intellij-ce-playground    文件:WindowSystemPlaybackCall.java   
public static AsyncResult<String> waitForDialog(final PlaybackContext context, final String title) {
  final AsyncResult<String> result = new AsyncResult<String>();

  final Ref<AWTEventListener> listener = new Ref<AWTEventListener>();
  listener.set(new AWTEventListener() {
    @Override
    public void eventDispatched(AWTEvent event) {
      if (event.getID() == WindowEvent.WINDOW_ACTIVATED) {
        final Window wnd = ((WindowEvent)event).getWindow();
        if (wnd instanceof JDialog) {
          if (title.equals(((JDialog)wnd).getTitle())) {
            Toolkit.getDefaultToolkit().removeAWTEventListener(listener.get());
            SwingUtilities.invokeLater(new Runnable() {
              @Override
              public void run() {
                getUiReady(context).notify(result);
              }
            });
          }
        }
      }
    }
  });

  Toolkit.getDefaultToolkit().addAWTEventListener(listener.get(), WindowEvent.WINDOW_EVENT_MASK);

  SimpleTimer.getInstance().setUp(new Runnable() {
    @Override
    public void run() {
      Toolkit.getDefaultToolkit().removeAWTEventListener(listener.get());
      if (!result.isProcessed()) {
        result.setRejected("Timed out waiting for window: " + title);
      }
    }
  }, Registry.intValue("actionSystem.commandProcessingTimeout"));

  return result;
}
项目:intellij-ce-playground    文件:WindowSystemPlaybackCall.java   
public static AsyncResult<String> checkFocus(final PlaybackContext context, String expected) {
  final AsyncResult<String> result = new AsyncResult<String>();
  final Map<String, String> expectedMap = new LinkedHashMap<String, String>();

  if (expected.length() > 0) {
    final String[] keyValue = expected.split("\\|");
    for (String each : keyValue) {
      final String[] eachPair = each.split("=");
      if (eachPair.length != 2) {
        result.setRejected("Syntax error, must be |-separated pairs key=value");
        return result;
      }

      expectedMap.put(eachPair[0], eachPair[1]);
    }
  }

  getUiReady(context).doWhenDone(new Runnable() {
    @Override
    public void run() {
      try {
        doAssert(expectedMap, result, context);
      }
      catch (AssertionError error) {
        result.setRejected("Assertion failed: " + error.getMessage());
      }
    }
  });

  return result;
}
项目:intellij-ce-playground    文件:WindowSystemPlaybackCall.java   
public static AsyncResult<String> waitForToolWindow(final PlaybackContext context, final String id) {
  final AsyncResult<String> result = new AsyncResult<String>();

  findProject().doWhenDone(new Consumer<Project>() {
    @Override
    public void consume(Project project) {
      ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow(id);
      if (toolWindow == null) {
        result.setRejected("Cannot find tool window with id: " + id);
        return;
      }

      toolWindow.getReady(context).doWhenDone(result.createSetDoneRunnable()).doWhenRejected(new Runnable() {
        @Override
        public void run() {
          result.setRejected("Cannot activate tool window with id:" + id);
        }
      });
    }
  }).doWhenRejected(new Runnable() {
    @Override
    public void run() {
      result.setRejected("Cannot retrieve open project");
    }
  });

  return result;
}
项目:intellij-ce-playground    文件:ProjectPlaybackCall.java   
public static AsyncResult<String> openProjectClone(final PlaybackContext context, String path) {
  try {
    File parentDir = FileUtil.createTempDirectory("funcTest", "");
    File sourceDir = context.getPathMacro().resolveFile(path, context.getBaseDir());

    context.message("Cloning project: " + sourceDir.getAbsolutePath(), context.getCurrentLine());
    FileUtil.copyDir(sourceDir, parentDir);
    File projectDir = new File(parentDir, sourceDir.getName());
    return openProject(context, projectDir.getAbsolutePath());
  }
  catch (IOException e) {
    return new AsyncResult.Rejected<String>("Cannot create temp directory for clone");
  }
}
项目:intellij-ce-playground    文件:ProjectPlaybackCall.java   
public static AsyncResult<String> openProject(final PlaybackContext context, final String path) {
  final AsyncResult<String> result = new AsyncResult<String>();
  final ProjectManager pm = ProjectManager.getInstance();
  final Ref<ProjectManagerListener> listener = new Ref<ProjectManagerListener>();
  listener.set(new ProjectManagerAdapter() {
    @Override
    public void projectOpened(final Project project) {
      StartupManager.getInstance(project).registerPostStartupActivity(new Runnable() {
        @Override
        public void run() {
          pm.removeProjectManagerListener(listener.get());
          DumbService.getInstance(project).runWhenSmart(new Runnable() {
            @Override
            public void run() {
              result.setDone("Opened successfully: " + project.getPresentableUrl());
            }
          });
        }
      });
    }
  });
  pm.addProjectManagerListener(listener.get());

  UIUtil.invokeLaterIfNeeded(new Runnable() {
    @Override
    public void run() {
      try {
        pm.loadAndOpenProject(path);
      }
      catch (Exception e) {
        context.error(e.getMessage(), context.getCurrentLine());
        result.setRejected();
      }
    }
  });

  return result;
}
项目:intellij-ce-playground    文件:EditorPlaybackCall.java   
public static AsyncResult<String> assertEditorLine(final PlaybackContext context, final String expected) {
  final AsyncResult<String> result = new AsyncResult<String>();
  WindowSystemPlaybackCall.getUiReady(context).doWhenDone(new Runnable() {
    @Override
    public void run() {
      Editor editor = CommonDataKeys.EDITOR.getData(DataManager.getInstance().getDataContextFromFocus().getResult());
      if (editor == null) {
        editor = CommonDataKeys.EDITOR_EVEN_IF_INACTIVE.getData(DataManager.getInstance().getDataContextFromFocus().getResult());
      }

      if (editor == null) {
        result.setRejected("Cannot find editor");
        return;
      }


      final int line = editor.getCaretModel().getLogicalPosition().line;
      final int caret = editor.getCaretModel().getOffset();
      final int start = editor.getDocument().getLineStartOffset(line);
      final int end = editor.getDocument().getLineEndOffset(line);

      final StringBuffer actualText = new StringBuffer(editor.getDocument().getText(new TextRange(start, caret)));
      actualText.append("<caret>").append(editor.getDocument().getText(new TextRange(caret, end)));
      if (expected.equals(actualText.toString())) {
        result.setDone();
      } else {
        result.setRejected("Expected:" + expected + " but was:" + actualText);
      }
    }
  });

  return result;
}
项目:intellij-ce-playground    文件:EditorPlaybackCall.java   
public static AsyncResult<String> waitDaemonForFinish(final PlaybackContext context) {
  final AsyncResult<String> result = new AsyncResult<String>();
  final Disposable connection = Disposer.newDisposable();
  result.doWhenProcessed(new Runnable() {
    @Override
    public void run() {
      Disposer.dispose(connection);
    }
  });


  WindowSystemPlaybackCall.findProject().doWhenDone(new Consumer<Project>() {
    @Override
    public void consume(Project project) {
      final MessageBusConnection bus = project.getMessageBus().connect(connection);
      bus.subscribe(DaemonCodeAnalyzer.DAEMON_EVENT_TOPIC, new DaemonCodeAnalyzer.DaemonListenerAdapter() {
        @Override
        public void daemonFinished() {
          context.flushAwtAndRunInEdt(result.createSetDoneRunnable());
        }

        @Override
        public void daemonCancelEventOccurred(@NotNull String reason) {
          result.setDone();
        }
      });
    }
  }).doWhenRejected(new Runnable() {
    @Override
    public void run() {
      result.setRejected("Cannot find project");
    }
  });

  return result;
}
项目:intellij-ce-playground    文件:DataManagerImpl.java   
@Override
public AsyncResult<DataContext> getDataContextFromFocus() {
  final AsyncResult<DataContext> context = new AsyncResult<DataContext>();

  IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(new Runnable() {
    @Override
    public void run() {
      context.setDone(getDataContext());
    }
  });

  return context;
}
项目:intellij-ce-playground    文件:ChooseComponentsToExportDialog.java   
@NotNull
public static AsyncResult<String> chooseSettingsFile(String oldPath, Component parent, final String title, final String description) {
  FileChooserDescriptor chooserDescriptor = FileChooserDescriptorFactory.createSingleLocalFileDescriptor();
  chooserDescriptor.setDescription(description);
  chooserDescriptor.setHideIgnored(false);
  chooserDescriptor.setTitle(title);

  VirtualFile initialDir;
  if (oldPath != null) {
    final File oldFile = new File(oldPath);
    initialDir = LocalFileSystem.getInstance().findFileByIoFile(oldFile);
    if (initialDir == null && oldFile.getParentFile() != null) {
      initialDir = LocalFileSystem.getInstance().findFileByIoFile(oldFile.getParentFile());
    }
  }
  else {
    initialDir = null;
  }
  final AsyncResult<String> result = new AsyncResult<String>();
  FileChooser.chooseFiles(chooserDescriptor, null, parent, initialDir, new FileChooser.FileChooserConsumer() {
    @Override
    public void consume(List<VirtualFile> files) {
      VirtualFile file = files.get(0);
      if (file.isDirectory()) {
        result.setDone(file.getPath() + '/' + new File(DEFAULT_PATH).getName());
      }
      else {
        result.setDone(file.getPath());
      }
    }

    @Override
    public void cancelled() {
      result.setRejected();
    }
  });
  return result;
}
项目:intellij-ce-playground    文件:NavBarPanel.java   
AsyncResult<RelativePoint> getHintContainerShowPoint() {
  final AsyncResult<RelativePoint> result = new AsyncResult<RelativePoint>();
  if (myLocationCache == null) {
    if (myHintContainer != null) {
      final Point p = AbstractPopup.getCenterOf(myHintContainer, this);
      p.y -= myHintContainer.getVisibleRect().height / 4;
      myLocationCache = RelativePoint.fromScreen(p);
    } else {
      if (myContextComponent != null) {
        myLocationCache = JBPopupFactory.getInstance().guessBestPopupLocation(DataManager.getInstance().getDataContext(myContextComponent));
      } else {
        DataManager.getInstance().getDataContextFromFocus().doWhenDone(new Consumer<DataContext>() {
          @Override
          public void consume(DataContext dataContext) {
            myContextComponent = PlatformDataKeys.CONTEXT_COMPONENT.getData(dataContext);
            myLocationCache = JBPopupFactory.getInstance().guessBestPopupLocation(DataManager.getInstance().getDataContext(myContextComponent));
          }
        });
      }
    }
  }
  final Component c = myLocationCache.getComponent();
  if (!(c instanceof JComponent && c.isShowing())) {
    //Yes. It happens sometimes.
    // 1. Empty frame. call nav bar, select some package and open it in Project View
    // 2. Call nav bar, then Esc
    // 3. Hide all tool windows (Ctrl+Shift+F12), so we've got empty frame again
    // 4. Call nav bar. NPE. ta da
    final JComponent ideFrame = WindowManager.getInstance().getIdeFrame(getProject()).getComponent();
    final JRootPane rootPane = UIUtil.getRootPane(ideFrame);
    myLocationCache = JBPopupFactory.getInstance().guessBestPopupLocation(rootPane);
  }
  result.setDone(myLocationCache);
  return result;
}
项目:intellij-ce-playground    文件:MavenProjectsProcessorArtifactsDownloadingTask.java   
public MavenProjectsProcessorArtifactsDownloadingTask(Collection<MavenProject> projects,
                                                      Collection<MavenArtifact> artifacts,
                                                      MavenProjectsTree tree,
                                                      boolean downloadSources,
                                                      boolean downloadDocs,
                                                      AsyncResult<MavenArtifactDownloader.DownloadResult> callbackResult) {
  myProjects = projects;
  myArtifacts = artifacts;
  myTree = tree;
  myDownloadSources = downloadSources;
  myDownloadDocs = downloadDocs;
  myCallbackResult = callbackResult;
}