Search in sources :

Example 31 with BaseListPopupStep

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

the class DeannotateIntentionAction method invoke.

@Override
public void invoke(@NotNull final Project project, Editor editor, final PsiFile file) throws IncorrectOperationException {
    final PsiModifierListOwner listOwner = getContainer(editor, file);
    LOG.assertTrue(listOwner != null);
    final ExternalAnnotationsManager annotationsManager = ExternalAnnotationsManager.getInstance(project);
    final PsiAnnotation[] externalAnnotations = annotationsManager.findExternalAnnotations(listOwner);
    LOG.assertTrue(externalAnnotations != null && externalAnnotations.length > 0);
    if (externalAnnotations.length == 1) {
        deannotate(externalAnnotations[0], project, file, annotationsManager, listOwner);
        return;
    }
    JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<PsiAnnotation>(CodeInsightBundle.message("deannotate.intention.chooser.title"), externalAnnotations) {

        @Override
        public PopupStep onChosen(final PsiAnnotation selectedValue, final boolean finalChoice) {
            deannotate(selectedValue, project, file, annotationsManager, listOwner);
            return PopupStep.FINAL_CHOICE;
        }

        @Override
        @NotNull
        public String getTextFor(final PsiAnnotation value) {
            final String qualifiedName = value.getQualifiedName();
            LOG.assertTrue(qualifiedName != null);
            return qualifiedName;
        }
    }).showInBestPositionFor(editor);
}
Also used : BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) ExternalAnnotationsManager(com.intellij.codeInsight.ExternalAnnotationsManager)

Example 32 with BaseListPopupStep

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

the class ExternalJavaDocAction method showExternalJavadoc.

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 = PlatformDataKeys.CONTEXT_COMPONENT.getData(dataContext);
    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);
    });
}
Also used : Project(com.intellij.openapi.project.Project) ExternalDocumentationProvider(com.intellij.lang.documentation.ExternalDocumentationProvider) ExternalDocumentationHandler(com.intellij.lang.documentation.ExternalDocumentationHandler) ExternalDocumentationProvider(com.intellij.lang.documentation.ExternalDocumentationProvider) DocumentationProvider(com.intellij.lang.documentation.DocumentationProvider) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) PopupStep(com.intellij.openapi.ui.popup.PopupStep)

Example 33 with BaseListPopupStep

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

the class StudyNewProjectPanel method setupBrowseButton.

private void setupBrowseButton() {
    if (SystemInfo.isMac && !UIUtil.isUnderDarcula())
        myBrowseButton.putClientProperty("JButton.buttonType", null);
    myBrowseButton.setIcon(InteractiveLearningIcons.InterpreterGear);
    final FileChooserDescriptor fileChooser = new FileChooserDescriptor(true, false, false, true, false, false) {

        @Override
        public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
            return file.isDirectory() || StudyUtils.isZip(file.getName());
        }

        @Override
        public boolean isFileSelectable(VirtualFile file) {
            return StudyUtils.isZip(file.getName());
        }
    };
    myBrowseButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            final BaseListPopupStep<String> popupStep = new BaseListPopupStep<String>("", "Add local course", LOGIN_TO_STEPIC) {

                @Override
                public PopupStep onChosen(final String selectedValue, boolean finalChoice) {
                    return doFinalStep(() -> {
                        if ("Add local course".equals(selectedValue)) {
                            Project[] projects = ProjectManager.getInstance().getOpenProjects();
                            FileChooser.chooseFile(fileChooser, null, projects.length == 0 ? null : projects[0].getBaseDir(), file -> {
                                String fileName = file.getPath();
                                int oldSize = myAvailableCourses.size();
                                CourseInfo courseInfo = myGenerator.addLocalCourse(fileName);
                                if (courseInfo != null) {
                                    if (oldSize != myAvailableCourses.size()) {
                                        myCoursesComboBox.addItem(courseInfo);
                                    }
                                    myCoursesComboBox.setSelectedItem(courseInfo);
                                    setOK();
                                } else {
                                    setError(INVALID_COURSE);
                                    myCoursesComboBox.removeAllItems();
                                    myCoursesComboBox.addItem(CourseInfo.INVALID_COURSE);
                                    for (CourseInfo course : myAvailableCourses) {
                                        myCoursesComboBox.addItem(course);
                                    }
                                    myCoursesComboBox.setSelectedItem(CourseInfo.INVALID_COURSE);
                                }
                            });
                        } else if (LOGIN_TO_STEPIC.equals(selectedValue)) {
                            showLoginDialog(true, "Signing In And Getting Stepik Course List");
                        }
                    });
                }
            };
            final ListPopup popup = JBPopupFactory.getInstance().createListPopup(popupStep);
            popup.showInScreenCoordinates(myBrowseButton, myBrowseButton.getLocationOnScreen());
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) UIUtil(com.intellij.util.ui.UIUtil) AllIcons(com.intellij.icons.AllIcons) ActionListener(java.awt.event.ActionListener) VirtualFile(com.intellij.openapi.vfs.VirtualFile) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) StudyUtils(com.jetbrains.edu.learning.StudyUtils) DefaultProjectFactory(com.intellij.openapi.project.DefaultProjectFactory) ArrayList(java.util.ArrayList) FacetValidatorsManager(com.intellij.facet.ui.FacetValidatorsManager) DefaultProjectFactoryImpl(com.intellij.openapi.project.DefaultProjectFactoryImpl) ProjectManager(com.intellij.openapi.project.ProjectManager) StudyProjectGenerator(com.jetbrains.edu.learning.courseGeneration.StudyProjectGenerator) Project(com.intellij.openapi.project.Project) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) AncestorEvent(javax.swing.event.AncestorEvent) ComboBox(com.intellij.openapi.ui.ComboBox) ProgressManager(com.intellij.openapi.progress.ProgressManager) InteractiveLearningIcons(icons.InteractiveLearningIcons) com.jetbrains.edu.learning.stepic(com.jetbrains.edu.learning.stepic) StringUtil(com.intellij.openapi.util.text.StringUtil) ValidationResult(com.intellij.facet.ui.ValidationResult) FixedSizeButton(com.intellij.openapi.ui.FixedSizeButton) ActionEvent(java.awt.event.ActionEvent) SystemInfo(com.intellij.openapi.util.SystemInfo) JBScrollPane(com.intellij.ui.components.JBScrollPane) VerticalFlowLayout(com.intellij.openapi.ui.VerticalFlowLayout) java.awt(java.awt) ListPopup(com.intellij.openapi.ui.popup.ListPopup) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) AncestorListenerAdapter(com.intellij.ui.AncestorListenerAdapter) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) CourseInfo(com.jetbrains.edu.learning.courseFormat.CourseInfo) PopupStep(com.intellij.openapi.ui.popup.PopupStep) ApplicationManager(com.intellij.openapi.application.ApplicationManager) PanelWithAnchor(com.intellij.ui.PanelWithAnchor) LabeledComponent(com.intellij.openapi.ui.LabeledComponent) NotNull(org.jetbrains.annotations.NotNull) FileChooser(com.intellij.openapi.fileChooser.FileChooser) Course(com.jetbrains.edu.learning.courseFormat.Course) javax.swing(javax.swing) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) ActionEvent(java.awt.event.ActionEvent) ListPopup(com.intellij.openapi.ui.popup.ListPopup) CourseInfo(com.jetbrains.edu.learning.courseFormat.CourseInfo) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) PopupStep(com.intellij.openapi.ui.popup.PopupStep) ActionListener(java.awt.event.ActionListener) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep)

Aggregations

BaseListPopupStep (com.intellij.openapi.ui.popup.util.BaseListPopupStep)33 PopupStep (com.intellij.openapi.ui.popup.PopupStep)18 NotNull (org.jetbrains.annotations.NotNull)15 ListPopup (com.intellij.openapi.ui.popup.ListPopup)10 ListPopupImpl (com.intellij.ui.popup.list.ListPopupImpl)10 RelativePoint (com.intellij.ui.awt.RelativePoint)8 Project (com.intellij.openapi.project.Project)7 JBPopupFactory (com.intellij.openapi.ui.popup.JBPopupFactory)5 JBPopup (com.intellij.openapi.ui.popup.JBPopup)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 PsiFile (com.intellij.psi.PsiFile)4 Nullable (org.jetbrains.annotations.Nullable)3 AllIcons (com.intellij.icons.AllIcons)2 DefaultPsiElementCellRenderer (com.intellij.ide.util.DefaultPsiElementCellRenderer)2 Result (com.intellij.openapi.application.Result)2 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)2 Editor (com.intellij.openapi.editor.Editor)2 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)2 FileChooser (com.intellij.openapi.fileChooser.FileChooser)2 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)2