Java 类com.intellij.lang.documentation.ExternalDocumentationProvider 实例源码

项目:intellij-ce-playground    文件:DocumentationComponent.java   
@Override
public void update(AnActionEvent e) {
  final Presentation presentation = e.getPresentation();
  presentation.setEnabled(false);
  if (myElement != null) {
    final PsiElement element = myElement.getElement();
    final DocumentationProvider provider = DocumentationManager.getProviderFromElement(element);
    final PsiElement originalElement = DocumentationManager.getOriginalElement(element);
    if (provider instanceof ExternalDocumentationProvider) {
      presentation.setEnabled(element != null && ((ExternalDocumentationProvider)provider).hasDocumentationFor(element, originalElement));
    }
    else {
      final List<String> urls = provider.getUrlFor(element, originalElement);
      presentation.setEnabled(element != null && urls != null && !urls.isEmpty());
    }
  }
}
项目:tools-idea    文件:DocumentationComponent.java   
@Override
public void update(AnActionEvent e) {
  final Presentation presentation = e.getPresentation();
  presentation.setEnabled(false);
  if (myElement != null) {
    final PsiElement element = myElement.getElement();
    final DocumentationProvider provider = DocumentationManager.getProviderFromElement(element);
    final PsiElement originalElement = DocumentationManager.getOriginalElement(element);
    if (provider instanceof ExternalDocumentationProvider) {
      presentation.setEnabled(element != null && ((ExternalDocumentationProvider)provider).hasDocumentationFor(element, originalElement));
    }
    else {
      final List<String> urls = provider.getUrlFor(element, originalElement);
      presentation.setEnabled(element != null && urls != null && !urls.isEmpty());
    }
  }
}
项目:consulo    文件:DocumentationComponent.java   
@Override
public void update(AnActionEvent e) {
  final Presentation presentation = e.getPresentation();
  presentation.setEnabled(false);
  if (myElement != null) {
    final PsiElement element = myElement.getElement();
    final DocumentationProvider provider = DocumentationManager.getProviderFromElement(element);
    final PsiElement originalElement = DocumentationManager.getOriginalElement(element);
    if (provider instanceof ExternalDocumentationProvider) {
      presentation.setEnabled(element != null && ((ExternalDocumentationProvider)provider).hasDocumentationFor(element, originalElement));
    }
    else {
      final List<String> urls = provider.getUrlFor(element, originalElement);
      presentation.setEnabled(element != null && urls != null && !urls.isEmpty());
    }
  }
}
项目:intellij-ce-playground    文件:ExternalJavaDocAction.java   
@Override
public void update(AnActionEvent event) {
  Presentation presentation = event.getPresentation();
  DataContext dataContext = event.getDataContext();
  Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
  PsiElement element = getElement(dataContext, editor);
  final PsiElement originalElement = getOriginalElement(CommonDataKeys.PSI_FILE.getData(dataContext), editor);
  DocumentationManager.storeOriginalElement(CommonDataKeys.PROJECT.getData(dataContext), originalElement, element);
  final DocumentationProvider provider = DocumentationManager.getProviderFromElement(element);
  boolean enabled;
  if (provider instanceof ExternalDocumentationProvider) {
    final ExternalDocumentationProvider edProvider = (ExternalDocumentationProvider)provider;
    enabled = edProvider.hasDocumentationFor(element, originalElement) || edProvider.canPromptToConfigureDocumentation(element);
  }
  else {
    final List<String> urls = provider.getUrlFor(element, originalElement);
    enabled = urls != null && !urls.isEmpty();
  }
  if (editor != null) {
    presentation.setEnabled(enabled);
    if (ActionPlaces.isMainMenuOrActionSearch(event.getPlace())) {
      presentation.setVisible(true);
    }
    else {
      presentation.setVisible(enabled);
    }
  }
  else{
    presentation.setEnabled(enabled);
    presentation.setVisible(true);
  }
}
项目:intellij-ce-playground    文件:AndroidDomTest.java   
protected void doTestExternalDoc(String expectedPart) {
  final PsiElement originalElement = myFixture.getFile().findElementAt(
    myFixture.getEditor().getCaretModel().getOffset());
  final PsiElement docTargetElement = DocumentationManager.getInstance(getProject()).
    findTargetElement(myFixture.getEditor(), myFixture.getFile(), originalElement);
  final DocumentationProvider provider = DocumentationManager.getProviderFromElement(docTargetElement);
  final List<String> urls = provider.getUrlFor(docTargetElement, originalElement);
  final String doc = ((ExternalDocumentationProvider)provider).fetchExternalDocumentation(myFixture.getProject(), docTargetElement, urls);
  assertNotNull(doc);
  assertTrue("Can't find " + expectedPart + " in " + doc, doc.contains(expectedPart));
}
项目:tools-idea    文件:ExternalJavaDocAction.java   
@Override
public void update(AnActionEvent event) {
  Presentation presentation = event.getPresentation();
  DataContext dataContext = event.getDataContext();
  Editor editor = PlatformDataKeys.EDITOR.getData(dataContext);
  final PsiElement element = LangDataKeys.PSI_ELEMENT.getData(dataContext);
  final PsiElement originalElement = getOriginalElement(LangDataKeys.PSI_FILE.getData(dataContext), editor);
  DocumentationManager.storeOriginalElement(PlatformDataKeys.PROJECT.getData(dataContext), originalElement, element);
  final DocumentationProvider provider = DocumentationManager.getProviderFromElement(element);
  boolean enabled;
  if (provider instanceof ExternalDocumentationProvider) {
    final ExternalDocumentationProvider edProvider = (ExternalDocumentationProvider)provider;
    enabled = edProvider.hasDocumentationFor(element, originalElement) || edProvider.canPromptToConfigureDocumentation(element);
  }
  else {
    final List<String> urls = provider.getUrlFor(element, originalElement);
    enabled = urls != null && !urls.isEmpty();
  }
  if (editor != null) {
    presentation.setEnabled(enabled);
    if (event.getPlace().equals(ActionPlaces.MAIN_MENU)) {
      presentation.setVisible(true);
    }
    else {
      presentation.setVisible(enabled);
    }
  }
  else{
    presentation.setEnabled(enabled);
    presentation.setVisible(true);
  }
}
项目:consulo    文件:ExternalJavaDocAction.java   
@Override
public void update(AnActionEvent event) {
  Presentation presentation = event.getPresentation();
  DataContext dataContext = event.getDataContext();
  Editor editor = dataContext.getData(CommonDataKeys.EDITOR);
  PsiElement element = getElement(dataContext, editor);
  final PsiElement originalElement = getOriginalElement(dataContext.getData(CommonDataKeys.PSI_FILE), editor);
  DocumentationManager.storeOriginalElement(dataContext.getData(CommonDataKeys.PROJECT), originalElement, element);
  final DocumentationProvider provider = DocumentationManager.getProviderFromElement(element);
  boolean enabled;
  if (provider instanceof ExternalDocumentationProvider) {
    final ExternalDocumentationProvider edProvider = (ExternalDocumentationProvider)provider;
    enabled = edProvider.hasDocumentationFor(element, originalElement) || edProvider.canPromptToConfigureDocumentation(element);
  }
  else {
    final List<String> urls = provider.getUrlFor(element, originalElement);
    enabled = urls != null && !urls.isEmpty();
  }
  if (editor != null) {
    presentation.setEnabled(enabled);
    if (ActionPlaces.isMainMenuOrActionSearch(event.getPlace())) {
      presentation.setVisible(true);
    }
    else {
      presentation.setVisible(enabled);
    }
  }
  else{
    presentation.setEnabled(enabled);
    presentation.setVisible(true);
  }
}
项目:intellij-ce-playground    文件:ExternalJavaDocAction.java   
@Override
public void actionPerformed(AnActionEvent e) {
  DataContext dataContext = e.getDataContext();
  Project project = CommonDataKeys.PROJECT.getData(dataContext);
  if (project == null) {
    return;
  }

  Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
  PsiElement element = getElement(dataContext, editor);
  if (element == null) {
    Messages.showMessageDialog(
      project,
      IdeBundle.message("message.please.select.element.for.javadoc"),
      IdeBundle.message("title.no.element.selected"),
      Messages.getErrorIcon()
    );
    return;
  }


  PsiFile context = CommonDataKeys.PSI_FILE.getData(dataContext);

  PsiElement originalElement = getOriginalElement(context, editor);
  DocumentationManager.storeOriginalElement(project, originalElement, element);
  final DocumentationProvider provider = DocumentationManager.getProviderFromElement(element);

  if (provider instanceof ExternalDocumentationHandler && ((ExternalDocumentationHandler)provider).handleExternal(element, originalElement)) {
    return;
  }

  final List<String> urls = provider.getUrlFor(element, originalElement);
  if (urls != null && !urls.isEmpty()) {
    showExternalJavadoc(urls, PlatformDataKeys.CONTEXT_COMPONENT.getData(dataContext));
  }
  else if (provider instanceof ExternalDocumentationProvider) {
    final ExternalDocumentationProvider externalDocumentationProvider = (ExternalDocumentationProvider)provider;
    if (externalDocumentationProvider.canPromptToConfigureDocumentation(element)) {
      externalDocumentationProvider.promptToConfigureDocumentation(element);
    }
  }
}
项目:tools-idea    文件:ExternalJavaDocAction.java   
@Override
public void actionPerformed(AnActionEvent e) {
  DataContext dataContext = e.getDataContext();
  Project project = PlatformDataKeys.PROJECT.getData(dataContext);
  if (project == null) {
    return;
  }

  PsiElement element = LangDataKeys.PSI_ELEMENT.getData(dataContext);
  if (element == null) {
    Messages.showMessageDialog(
      project,
      IdeBundle.message("message.please.select.element.for.javadoc"),
      IdeBundle.message("title.no.element.selected"),
      Messages.getErrorIcon()
    );
    return;
  }


  PsiFile context = LangDataKeys.PSI_FILE.getData(dataContext);
  Editor editor = PlatformDataKeys.EDITOR.getData(dataContext);
  PsiElement originalElement = getOriginalElement(context, editor);
  DocumentationManager.storeOriginalElement(project, originalElement, element);
  final DocumentationProvider provider = DocumentationManager.getProviderFromElement(element);

  if (provider instanceof ExternalDocumentationHandler && ((ExternalDocumentationHandler)provider).handleExternal(element, originalElement)) {
    return;
  }

  final List<String> urls = provider.getUrlFor(element, originalElement);
  if (urls != null && !urls.isEmpty()) {
    showExternalJavadoc(urls);
  }
  else if (provider instanceof ExternalDocumentationProvider) {
    final ExternalDocumentationProvider externalDocumentationProvider = (ExternalDocumentationProvider)provider;
    if (externalDocumentationProvider.canPromptToConfigureDocumentation(element)) {
      externalDocumentationProvider.promptToConfigureDocumentation(element);
    }
  }
}
项目:consulo    文件:ExternalJavaDocAction.java   
public static void showExternalJavadoc(PsiElement element, PsiElement originalElement, String docUrl, DataContext dataContext) {
  DocumentationProvider provider = DocumentationManager.getProviderFromElement(element);
  if (provider instanceof ExternalDocumentationHandler &&
      ((ExternalDocumentationHandler)provider).handleExternal(element, originalElement)) {
    return;
  }
  Project project = dataContext.getData(CommonDataKeys.PROJECT);
  final Component contextComponent = dataContext.getData(PlatformDataKeys.CONTEXT_COMPONENT);
  ApplicationManager.getApplication().executeOnPooledThread(() -> {
    List<String> urls;
    if (StringUtil.isEmptyOrSpaces(docUrl)) {
      urls = ReadAction.compute(() -> provider.getUrlFor(element, originalElement));
    }
    else {
      urls = Collections.singletonList(docUrl);
    }
    if (provider instanceof ExternalDocumentationProvider && urls != null && urls.size() > 1) {
      for (String url : urls) {
        List<String> thisUrlList = Collections.singletonList(url);
        String doc = ((ExternalDocumentationProvider)provider).fetchExternalDocumentation(project, element, thisUrlList);
        if (doc != null) {
          urls = thisUrlList;
          break;
        }
      }
    }
    final List<String> finalUrls = urls;
    ApplicationManager.getApplication().invokeLater(() -> {
      if (ContainerUtil.isEmpty(finalUrls)) {
        if (element != null && provider instanceof ExternalDocumentationProvider) {
          ExternalDocumentationProvider externalDocumentationProvider = (ExternalDocumentationProvider)provider;
          if (externalDocumentationProvider.canPromptToConfigureDocumentation(element)) {
            externalDocumentationProvider.promptToConfigureDocumentation(element);
          }
        }
      }
      else if (finalUrls.size() == 1) {
        BrowserUtil.browse(finalUrls.get(0));
      }
      else {
        JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<String>("Choose external documentation root",
                                                                                   ArrayUtil.toStringArray(finalUrls)) {
          @Override
          public PopupStep onChosen(final String selectedValue, final boolean finalChoice) {
            BrowserUtil.browse(selectedValue);
            return FINAL_CHOICE;
          }
        }).showInBestPositionFor(DataManager.getInstance().getDataContext(contextComponent));
      }
    }, ModalityState.NON_MODAL);
  });

}