Search in sources :

Example 1 with FakePsiElement

use of com.intellij.psi.impl.FakePsiElement in project android by JetBrains.

the class ShowJavadocAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    EditedStyleItem item = myCurrentItem;
    if (item == null) {
        return;
    }
    Project project = myContext.getProject();
    DocumentationManager documentationManager = DocumentationManager.getInstance(project);
    final DocumentationComponent docComponent = new DocumentationComponent(documentationManager);
    String tooltip = ThemeEditorUtils.generateToolTipText(item.getSelectedValue(), myContext.getCurrentContextModule(), myContext.getConfiguration());
    // images will not work unless we pass a valid PsiElement {@link DocumentationComponent#myImageProvider}
    docComponent.setText(tooltip, new FakePsiElement() {

        @Override
        public boolean isValid() {
            // this needs to return true for the DocumentationComponent to accept this PsiElement {@link DocumentationComponent#setData(PsiElement, String, boolean, String, String)}
            return true;
        }

        @NotNull
        @Override
        public Project getProject() {
            // superclass implementation throws an exception
            return myContext.getProject();
        }

        @Override
        public PsiElement getParent() {
            return null;
        }

        @Override
        public PsiFile getContainingFile() {
            // superclass implementation throws an exception
            return null;
        }
    }, true);
    JBPopup hint = JBPopupFactory.getInstance().createComponentPopupBuilder(docComponent, docComponent).setProject(project).setDimensionServiceKey(project, DocumentationManager.JAVADOC_LOCATION_AND_SIZE, false).setResizable(true).setMovable(true).setRequestFocus(true).setTitle(item.getName()).setCancelCallback(new Computable<Boolean>() {

        @Override
        public Boolean compute() {
            Disposer.dispose(docComponent);
            return Boolean.TRUE;
        }
    }).createPopup();
    docComponent.setHint(hint);
    Disposer.register(hint, docComponent);
    hint.show(new RelativePoint(myAttributesTable.getParent(), ORIGIN));
}
Also used : DocumentationComponent(com.intellij.codeInsight.documentation.DocumentationComponent) FakePsiElement(com.intellij.psi.impl.FakePsiElement) RelativePoint(com.intellij.ui.awt.RelativePoint) NotNull(org.jetbrains.annotations.NotNull) EditedStyleItem(com.android.tools.idea.editors.theme.datamodels.EditedStyleItem) Project(com.intellij.openapi.project.Project) DocumentationManager(com.intellij.codeInsight.documentation.DocumentationManager) PsiFile(com.intellij.psi.PsiFile) JBPopup(com.intellij.openapi.ui.popup.JBPopup) FakePsiElement(com.intellij.psi.impl.FakePsiElement) PsiElement(com.intellij.psi.PsiElement) Computable(com.intellij.openapi.util.Computable)

Aggregations

EditedStyleItem (com.android.tools.idea.editors.theme.datamodels.EditedStyleItem)1 DocumentationComponent (com.intellij.codeInsight.documentation.DocumentationComponent)1 DocumentationManager (com.intellij.codeInsight.documentation.DocumentationManager)1 Project (com.intellij.openapi.project.Project)1 JBPopup (com.intellij.openapi.ui.popup.JBPopup)1 Computable (com.intellij.openapi.util.Computable)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 FakePsiElement (com.intellij.psi.impl.FakePsiElement)1 RelativePoint (com.intellij.ui.awt.RelativePoint)1 NotNull (org.jetbrains.annotations.NotNull)1