Search in sources :

Example 41 with JBPopup

use of com.intellij.openapi.ui.popup.JBPopup in project android by JetBrains.

the class AndroidAddLibraryDependencyAction method invoke.

@Override
public void invoke(@NotNull final Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
    final GradleBuildModel buildModel = getGradleBuildModel(project, file);
    if (buildModel == null) {
        return;
    }
    ImmutableCollection<String> dependencies = findAllDependencies(buildModel);
    if (dependencies.isEmpty()) {
        return;
    }
    final JList list = new JBList(dependencies);
    JBPopup popup = new PopupChooserBuilder(list).setItemChoosenCallback(new Runnable() {

        @Override
        public void run() {
            for (Object selectedValue : list.getSelectedValues()) {
                if (selectedValue == null) {
                    return;
                }
                addDependency(project, buildModel, (String) selectedValue);
            }
        }
    }).createPopup();
    popup.showInBestPositionFor(editor);
}
Also used : GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel) JBList(com.intellij.ui.components.JBList) JBPopup(com.intellij.openapi.ui.popup.JBPopup) PopupChooserBuilder(com.intellij.openapi.ui.popup.PopupChooserBuilder)

Example 42 with JBPopup

use of com.intellij.openapi.ui.popup.JBPopup in project android by JetBrains.

the class ShowCustomIssueExplanationFix method apply.

@Override
public void apply(@NotNull PsiElement startElement, @NotNull PsiElement endElement, @NotNull AndroidQuickfixContexts.Context context) {
    Project project = myElement.getProject();
    DocumentationManager manager = DocumentationManager.getInstance(project);
    DocumentationComponent component = new DocumentationComponent(manager);
    component.setText("<html>" + myIssue.getExplanation(TextFormat.HTML) + "</html>", myElement, false);
    JBPopup popup = JBPopupFactory.getInstance().createComponentPopupBuilder(component, component).setDimensionServiceKey(project, DocumentationManager.JAVADOC_LOCATION_AND_SIZE, false).setResizable(true).setMovable(true).setRequestFocus(true).createPopup();
    component.setHint(popup);
    if (context.getType() == AndroidQuickfixContexts.EditorContext.TYPE) {
        popup.showInBestPositionFor(((AndroidQuickfixContexts.EditorContext) context).getEditor());
    } else {
        popup.showCenteredInCurrentWindow(project);
    }
    Disposer.dispose(component);
}
Also used : Project(com.intellij.openapi.project.Project) DocumentationManager(com.intellij.codeInsight.documentation.DocumentationManager) DocumentationComponent(com.intellij.codeInsight.documentation.DocumentationComponent) AndroidQuickfixContexts(org.jetbrains.android.inspections.lint.AndroidQuickfixContexts) JBPopup(com.intellij.openapi.ui.popup.JBPopup)

Example 43 with JBPopup

use of com.intellij.openapi.ui.popup.JBPopup 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)

Example 44 with JBPopup

use of com.intellij.openapi.ui.popup.JBPopup in project intellij-plugins by JetBrains.

the class DependenciesConfigurable method addItem.

private void addItem(AnActionButton button) {
    initPopupActions();
    final JBPopup popup = JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<AddItemPopupAction>(FlexBundle.message("add.dependency.popup.title"), myPopupActions) {

        @Override
        public Icon getIconFor(AddItemPopupAction aValue) {
            return aValue.getIcon();
        }

        @Override
        public boolean hasSubstep(AddItemPopupAction selectedValue) {
            return selectedValue.hasSubStep();
        }

        public boolean isMnemonicsNavigationEnabled() {
            return true;
        }

        public PopupStep onChosen(final AddItemPopupAction selectedValue, final boolean finalChoice) {
            if (selectedValue.hasSubStep()) {
                return selectedValue.createSubStep();
            }
            return doFinalStep(() -> selectedValue.run());
        }

        @NotNull
        public String getTextFor(AddItemPopupAction value) {
            return "&" + value.getIndex() + "  " + value.getTitle();
        }
    });
    popup.show(button.getPreferredPopupPoint());
}
Also used : JBPopup(com.intellij.openapi.ui.popup.JBPopup) NotNull(org.jetbrains.annotations.NotNull) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) PopupStep(com.intellij.openapi.ui.popup.PopupStep)

Example 45 with JBPopup

use of com.intellij.openapi.ui.popup.JBPopup in project intellij-community by JetBrains.

the class CompareWithSelectedRevisionAction method showListPopup.

public static void showListPopup(final List<VcsFileRevision> revisions, final Project project, final Consumer<VcsFileRevision> selectedRevisionConsumer, final boolean showComments) {
    ColumnInfo[] columns = new ColumnInfo[] { REVISION_TABLE_COLUMN, DATE_TABLE_COLUMN, AUTHOR_TABLE_COLUMN };
    for (VcsFileRevision revision : revisions) {
        if (revision.getBranchName() != null) {
            columns = new ColumnInfo[] { REVISION_TABLE_COLUMN, BRANCH_TABLE_COLUMN, DATE_TABLE_COLUMN, AUTHOR_TABLE_COLUMN };
            break;
        }
    }
    final TableView<VcsFileRevision> table = new TableView<>(new ListTableModel<>(columns, revisions, 0));
    table.setShowHorizontalLines(false);
    table.setTableHeader(null);
    Runnable runnable = new Runnable() {

        @Override
        public void run() {
            VcsFileRevision revision = table.getSelectedObject();
            if (revision != null) {
                selectedRevisionConsumer.consume(revision);
            }
        }
    };
    if (table.getModel().getRowCount() == 0) {
        table.clearSelection();
    }
    new SpeedSearchBase<TableView>(table) {

        @Override
        protected int getSelectedIndex() {
            return table.getSelectedRow();
        }

        @Override
        protected int convertIndexToModel(int viewIndex) {
            return table.convertRowIndexToModel(viewIndex);
        }

        @Override
        protected Object[] getAllElements() {
            return revisions.toArray();
        }

        @Override
        protected String getElementText(Object element) {
            VcsFileRevision revision = (VcsFileRevision) element;
            return revision.getRevisionNumber().asString() + " " + revision.getBranchName() + " " + revision.getAuthor();
        }

        @Override
        protected void selectElement(Object element, String selectedText) {
            VcsFileRevision revision = (VcsFileRevision) element;
            TableUtil.selectRows(myComponent, new int[] { myComponent.convertRowIndexToView(revisions.indexOf(revision)) });
            TableUtil.scrollSelectionToVisible(myComponent);
        }
    };
    table.setMinimumSize(new Dimension(300, 50));
    final PopupChooserBuilder builder = new PopupChooserBuilder(table);
    if (showComments) {
        builder.setSouthComponent(createCommentsPanel(table));
    }
    builder.setTitle(VcsBundle.message("lookup.title.vcs.file.revisions")).setItemChoosenCallback(runnable).setResizable(true).setDimensionServiceKey("Vcs.CompareWithSelectedRevision.Popup").setMinSize(new Dimension(300, 300));
    final JBPopup popup = builder.createPopup();
    popup.showCenteredInCurrentWindow(project);
}
Also used : ColumnInfo(com.intellij.util.ui.ColumnInfo) PopupChooserBuilder(com.intellij.openapi.ui.popup.PopupChooserBuilder) JBPopup(com.intellij.openapi.ui.popup.JBPopup) TreeTableView(com.intellij.ui.dualView.TreeTableView) TableView(com.intellij.ui.table.TableView)

Aggregations

JBPopup (com.intellij.openapi.ui.popup.JBPopup)76 Project (com.intellij.openapi.project.Project)21 NotNull (org.jetbrains.annotations.NotNull)20 RelativePoint (com.intellij.ui.awt.RelativePoint)19 JBList (com.intellij.ui.components.JBList)18 PopupChooserBuilder (com.intellij.openapi.ui.popup.PopupChooserBuilder)15 Editor (com.intellij.openapi.editor.Editor)13 PsiElement (com.intellij.psi.PsiElement)11 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 Nullable (org.jetbrains.annotations.Nullable)8 JBPopupFactory (com.intellij.openapi.ui.popup.JBPopupFactory)7 Ref (com.intellij.openapi.util.Ref)7 DocumentationManager (com.intellij.codeInsight.documentation.DocumentationManager)6 com.intellij.openapi.actionSystem (com.intellij.openapi.actionSystem)6 AbstractPopup (com.intellij.ui.popup.AbstractPopup)6 ActionEvent (java.awt.event.ActionEvent)6 List (java.util.List)6 javax.swing (javax.swing)6 Disposable (com.intellij.openapi.Disposable)5 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)5