Search in sources :

Example 61 with JBPopup

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

the class QuickDocOnMouseOverManager method closeQuickDocIfPossible.

private void closeQuickDocIfPossible() {
    myAlarm.cancelAllRequests();
    DocumentationManager docManager = getDocManager();
    if (docManager == null) {
        return;
    }
    JBPopup hint = docManager.getDocInfoHint();
    if (hint == null) {
        return;
    }
    hint.cancel();
    myDocumentationManager = null;
}
Also used : JBPopup(com.intellij.openapi.ui.popup.JBPopup)

Example 62 with JBPopup

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

the class QuickDocUtil method getActiveDocComponent.

@Nullable
public static DocumentationComponent getActiveDocComponent(@NotNull Project project) {
    DocumentationManager documentationManager = DocumentationManager.getInstance(project);
    DocumentationComponent component;
    JBPopup hint = documentationManager.getDocInfoHint();
    if (hint != null) {
        component = (DocumentationComponent) ((AbstractPopup) hint).getComponent();
    } else if (documentationManager.hasActiveDockedDocWindow()) {
        ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.DOCUMENTATION);
        Content selectedContent = toolWindow == null ? null : toolWindow.getContentManager().getSelectedContent();
        component = selectedContent == null ? null : (DocumentationComponent) selectedContent.getComponent();
    } else {
        component = null;
    }
    return component;
}
Also used : AbstractPopup(com.intellij.ui.popup.AbstractPopup) ToolWindow(com.intellij.openapi.wm.ToolWindow) Content(com.intellij.ui.content.Content) JBPopup(com.intellij.openapi.ui.popup.JBPopup) Nullable(org.jetbrains.annotations.Nullable)

Example 63 with JBPopup

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

the class StopAction method actionPerformed.

@Override
public void actionPerformed(final AnActionEvent e) {
    final DataContext dataContext = e.getDataContext();
    Project project = e.getProject();
    List<Pair<TaskInfo, ProgressIndicator>> cancellableProcesses = getCancellableProcesses(project);
    List<RunContentDescriptor> stoppableDescriptors = getActiveStoppableDescriptors(dataContext);
    if (isPlaceGlobal(e)) {
        int todoSize = cancellableProcesses.size() + stoppableDescriptors.size();
        if (todoSize == 1) {
            if (!stoppableDescriptors.isEmpty()) {
                ExecutionManagerImpl.stopProcess(stoppableDescriptors.get(0));
            } else {
                cancellableProcesses.get(0).second.cancel();
            }
            return;
        }
        Pair<List<HandlerItem>, HandlerItem> handlerItems = getItemsList(cancellableProcesses, stoppableDescriptors, getRecentlyStartedContentDescriptor(dataContext));
        if (handlerItems == null || handlerItems.first.isEmpty()) {
            return;
        }
        final JBList list = new JBList(handlerItems.first);
        if (handlerItems.second != null)
            list.setSelectedValue(handlerItems.second, true);
        list.setCellRenderer(new GroupedItemsListRenderer(new ListItemDescriptorAdapter() {

            @Nullable
            @Override
            public String getTextFor(Object value) {
                return value instanceof HandlerItem ? ((HandlerItem) value).displayName : null;
            }

            @Nullable
            @Override
            public Icon getIconFor(Object value) {
                return value instanceof HandlerItem ? ((HandlerItem) value).icon : null;
            }

            @Override
            public boolean hasSeparatorAboveOf(Object value) {
                return value instanceof HandlerItem && ((HandlerItem) value).hasSeparator;
            }
        }));
        JBPopup popup = JBPopupFactory.getInstance().createListPopupBuilder(list).setMovable(true).setTitle(handlerItems.first.size() == 1 ? "Confirm process stop" : "Stop process").setFilteringEnabled(o -> ((HandlerItem) o).displayName).setItemChoosenCallback(() -> {
            List valuesList = list.getSelectedValuesList();
            for (Object o : valuesList) {
                if (o instanceof HandlerItem)
                    ((HandlerItem) o).stop();
            }
        }).setRequestFocus(true).createPopup();
        InputEvent inputEvent = e.getInputEvent();
        Component component = inputEvent != null ? inputEvent.getComponent() : null;
        if (component != null && ActionPlaces.MAIN_TOOLBAR.equals(e.getPlace())) {
            popup.showUnderneathOf(component);
        } else if (project == null) {
            popup.showInBestPositionFor(dataContext);
        } else {
            popup.showCenteredInCurrentWindow(project);
        }
    } else {
        ExecutionManagerImpl.stopProcess(getRecentlyStartedContentDescriptor(dataContext));
    }
}
Also used : InputEvent(java.awt.event.InputEvent) AllIcons(com.intellij.icons.AllIcons) ExecutionManager(com.intellij.execution.ExecutionManager) ArrayList(java.util.ArrayList) Project(com.intellij.openapi.project.Project) ExecutionBundle(com.intellij.execution.ExecutionBundle) JBList(com.intellij.ui.components.JBList) TaskInfo(com.intellij.openapi.progress.TaskInfo) StringUtil(com.intellij.openapi.util.text.StringUtil) ListItemDescriptorAdapter(com.intellij.openapi.ui.popup.ListItemDescriptorAdapter) RunProfile(com.intellij.execution.configurations.RunProfile) JBPopup(com.intellij.openapi.ui.popup.JBPopup) ProcessHandler(com.intellij.execution.process.ProcessHandler) KillableProcess(com.intellij.execution.KillableProcess) java.awt(java.awt) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) List(java.util.List) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) GroupedItemsListRenderer(com.intellij.ui.popup.list.GroupedItemsListRenderer) Pair(com.intellij.openapi.util.Pair) ExecutionManagerImpl(com.intellij.execution.impl.ExecutionManagerImpl) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) IconUtil(com.intellij.util.IconUtil) javax.swing(javax.swing) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) ListItemDescriptorAdapter(com.intellij.openapi.ui.popup.ListItemDescriptorAdapter) Project(com.intellij.openapi.project.Project) GroupedItemsListRenderer(com.intellij.ui.popup.list.GroupedItemsListRenderer) ArrayList(java.util.ArrayList) JBList(com.intellij.ui.components.JBList) List(java.util.List) JBList(com.intellij.ui.components.JBList) InputEvent(java.awt.event.InputEvent) JBPopup(com.intellij.openapi.ui.popup.JBPopup) Pair(com.intellij.openapi.util.Pair)

Example 64 with JBPopup

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

the class StudyEditInputAction method showInput.

public void showInput(final Project project) {
    final Editor selectedEditor = StudyUtils.getSelectedEditor(project);
    if (selectedEditor != null) {
        FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
        final VirtualFile openedFile = fileDocumentManager.getFile(selectedEditor.getDocument());
        final StudyTaskManager studyTaskManager = StudyTaskManager.getInstance(project);
        assert openedFile != null;
        TaskFile taskFile = StudyUtils.getTaskFile(project, openedFile);
        assert taskFile != null;
        final Task currentTask = taskFile.getTask();
        tabbedPane = new JBEditorTabs(project, ActionManager.getInstance(), IdeFocusManager.findInstance(), project);
        tabbedPane.addListener(new TabsListener.Adapter() {

            @Override
            public void selectionChanged(TabInfo oldSelection, TabInfo newSelection) {
                if (newSelection.getIcon() != null) {
                    int tabCount = tabbedPane.getTabCount();
                    VirtualFile taskDir = StudyUtils.getTaskDir(openedFile);
                    VirtualFile testsDir = taskDir.findChild(EduNames.USER_TESTS);
                    assert testsDir != null;
                    UserTest userTest = createUserTest(testsDir, currentTask, studyTaskManager);
                    userTest.setEditable(true);
                    StudyTestContentPanel testContentPanel = new StudyTestContentPanel(userTest);
                    TabInfo testTab = addTestTab(tabbedPane.getTabCount(), testContentPanel, currentTask, true);
                    myEditableTabs.put(testTab, userTest);
                    tabbedPane.addTabSilently(testTab, tabCount - 1);
                    tabbedPane.select(testTab, true);
                }
            }
        });
        List<UserTest> userTests = studyTaskManager.getUserTests(currentTask);
        int i = 1;
        for (UserTest userTest : userTests) {
            String inputFileText = StudyUtils.getFileText(null, userTest.getInput(), false, "UTF-8");
            String outputFileText = StudyUtils.getFileText(null, userTest.getOutput(), false, "UTF-8");
            StudyTestContentPanel myContentPanel = new StudyTestContentPanel(userTest);
            myContentPanel.addInputContent(inputFileText);
            myContentPanel.addOutputContent(outputFileText);
            TabInfo testTab = addTestTab(i, myContentPanel, currentTask, userTest.isEditable());
            tabbedPane.addTabSilently(testTab, i - 1);
            if (userTest.isEditable()) {
                myEditableTabs.put(testTab, userTest);
            }
            i++;
        }
        TabInfo plusTab = new TabInfo(new JPanel());
        plusTab.setIcon(PlatformIcons.ADD_ICON);
        tabbedPane.addTabSilently(plusTab, tabbedPane.getTabCount());
        final JBPopup hint = JBPopupFactory.getInstance().createComponentPopupBuilder(tabbedPane.getComponent(), tabbedPane.getComponent()).setResizable(true).setMovable(true).setRequestFocus(true).createPopup();
        StudyEditor selectedStudyEditor = StudyUtils.getSelectedStudyEditor(project);
        assert selectedStudyEditor != null;
        hint.showInCenterOf(selectedStudyEditor.getComponent());
        hint.addListener(new HintClosedListener(currentTask, studyTaskManager));
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) TaskFile(com.jetbrains.edu.learning.courseFormat.TaskFile) Task(com.jetbrains.edu.learning.courseFormat.Task) StudyTestContentPanel(com.jetbrains.edu.learning.ui.StudyTestContentPanel) UserTest(com.jetbrains.edu.learning.courseFormat.UserTest) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) StudyTaskManager(com.jetbrains.edu.learning.StudyTaskManager) TabsListener(com.intellij.ui.tabs.TabsListener) TabInfo(com.intellij.ui.tabs.TabInfo) StudyEditor(com.jetbrains.edu.learning.editor.StudyEditor) StudyEditor(com.jetbrains.edu.learning.editor.StudyEditor) Editor(com.intellij.openapi.editor.Editor) JBPopup(com.intellij.openapi.ui.popup.JBPopup) JBEditorTabs(com.intellij.ui.tabs.impl.JBEditorTabs)

Example 65 with JBPopup

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

the class ShowCoveringTestsAction method actionPerformed.

public void actionPerformed(final AnActionEvent e) {
    final DataContext context = e.getDataContext();
    final Project project = e.getProject();
    LOG.assertTrue(project != null);
    final Editor editor = e.getData(CommonDataKeys.EDITOR);
    LOG.assertTrue(editor != null);
    final CoverageSuitesBundle currentSuite = CoverageDataManager.getInstance(project).getCurrentSuitesBundle();
    LOG.assertTrue(currentSuite != null);
    final File[] traceFiles = getTraceFiles(project);
    final Set<String> tests = new HashSet<>();
    Runnable runnable = () -> {
        for (File traceFile : traceFiles) {
            DataInputStream in = null;
            try {
                in = new DataInputStream(new FileInputStream(traceFile));
                extractTests(traceFile, in, tests);
            } catch (Exception ex) {
                LOG.error(traceFile.getName(), ex);
            } finally {
                try {
                    in.close();
                } catch (IOException ex) {
                    LOG.error(ex);
                }
            }
        }
    };
    if (ProgressManager.getInstance().runProcessWithProgressSynchronously(runnable, "Extract information about tests", false, project)) {
        //todo cache them? show nothing found message
        final String[] testNames = ArrayUtil.toStringArray(tests);
        Arrays.sort(testNames);
        if (testNames.length == 0) {
            HintManager.getInstance().showErrorHint(editor, "Failed to load covered tests");
            return;
        }
        final List<PsiElement> elements = currentSuite.getCoverageEngine().findTestsByNames(testNames, project);
        final ImplementationViewComponent component;
        final String title = "Tests covering line " + myClassFQName + ":" + myLineData.getLineNumber();
        final ComponentPopupBuilder popupBuilder;
        if (!elements.isEmpty()) {
            component = new ImplementationViewComponent(PsiUtilCore.toPsiElementArray(elements), 0);
            popupBuilder = JBPopupFactory.getInstance().createComponentPopupBuilder(component, component.getPreferredFocusableComponent()).setDimensionServiceKey(project, "ShowTestsPopup", false).setCouldPin(popup -> {
                component.showInUsageView();
                popup.cancel();
                return false;
            });
        } else {
            component = null;
            final JPanel panel = new PanelWithText("Following test" + (testNames.length > 1 ? "s" : "") + " could not be found: " + StringUtil.join(testNames, "<br/>").replace("_", "."));
            popupBuilder = JBPopupFactory.getInstance().createComponentPopupBuilder(panel, null);
        }
        final JBPopup popup = popupBuilder.setRequestFocusCondition(project, NotLookupOrSearchCondition.INSTANCE).setProject(project).setResizable(true).setMovable(true).setTitle(title).createPopup();
        popup.showInBestPositionFor(editor);
        if (component != null) {
            component.setHint(popup, title);
        }
    }
}
Also used : DataInputStream(java.io.DataInputStream) java.util(java.util) ArrayUtil(com.intellij.util.ArrayUtil) HashSet(com.intellij.util.containers.HashSet) LineCoverage(com.intellij.rt.coverage.data.LineCoverage) Comparing(com.intellij.openapi.util.Comparing) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) PlatformIcons(com.intellij.util.PlatformIcons) ProgressManager(com.intellij.openapi.progress.ProgressManager) LineData(com.intellij.rt.coverage.data.LineData) CoverageSuitesBundle(com.intellij.coverage.CoverageSuitesBundle) ComponentPopupBuilder(com.intellij.openapi.ui.popup.ComponentPopupBuilder) StringUtil(com.intellij.openapi.util.text.StringUtil) PanelWithText(com.intellij.openapi.ui.PanelWithText) CoverageDataManager(com.intellij.coverage.CoverageDataManager) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Editor(com.intellij.openapi.editor.Editor) JBPopup(com.intellij.openapi.ui.popup.JBPopup) File(java.io.File) CoverageSuite(com.intellij.coverage.CoverageSuite) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) Nullable(org.jetbrains.annotations.Nullable) PsiUtilCore(com.intellij.psi.util.PsiUtilCore) NotLookupOrSearchCondition(com.intellij.ui.popup.NotLookupOrSearchCondition) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) HintManager(com.intellij.codeInsight.hint.HintManager) ImplementationViewComponent(com.intellij.codeInsight.hint.ImplementationViewComponent) javax.swing(javax.swing) ImplementationViewComponent(com.intellij.codeInsight.hint.ImplementationViewComponent) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) CoverageSuitesBundle(com.intellij.coverage.CoverageSuitesBundle) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) Project(com.intellij.openapi.project.Project) PanelWithText(com.intellij.openapi.ui.PanelWithText) ComponentPopupBuilder(com.intellij.openapi.ui.popup.ComponentPopupBuilder) Editor(com.intellij.openapi.editor.Editor) JBPopup(com.intellij.openapi.ui.popup.JBPopup) File(java.io.File) PsiElement(com.intellij.psi.PsiElement) HashSet(com.intellij.util.containers.HashSet)

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