Search in sources :

Example 1 with ComponentPopupBuilder

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

the class FindPopupPanel method showUI.

public void showUI() {
    if (myBalloon != null && myBalloon.isVisible()) {
        return;
    }
    if (myBalloon != null && !myBalloon.isDisposed()) {
        myBalloon.cancel();
    }
    if (myBalloon == null || myBalloon.isDisposed()) {
        final ComponentPopupBuilder builder = JBPopupFactory.getInstance().createComponentPopupBuilder(this, mySearchComponent);
        myBalloon = builder.setProject(myHelper.getProject()).setMovable(true).setResizable(true).setMayBeParent(true).setCancelOnClickOutside(true).setModalContext(false).setRequestFocus(true).setCancelCallback(() -> {
            if (!myCanClose.get())
                return false;
            if (!ApplicationManager.getApplication().isActive())
                return false;
            List<JBPopup> popups = JBPopupFactory.getInstance().getChildPopups(this);
            if (!popups.isEmpty()) {
                for (JBPopup popup : popups) {
                    popup.cancel();
                }
                return false;
            }
            if (myScopeUI.hideAllPopups()) {
                return false;
            }
            DimensionService.getInstance().setSize(SERVICE_KEY, myBalloon.getSize(), myHelper.getProject());
            DimensionService.getInstance().setLocation(SERVICE_KEY, myBalloon.getLocationOnScreen(), myHelper.getProject());
            return true;
        }).createPopup();
        Disposer.register(myBalloon, myDisposable);
        registerCloseAction(myBalloon);
        final Window window = WindowManager.getInstance().suggestParentWindow(myProject);
        Component parent = UIUtil.findUltimateParent(window);
        RelativePoint showPoint = null;
        Point screenPoint = DimensionService.getInstance().getLocation(SERVICE_KEY);
        if (screenPoint != null) {
            showPoint = new RelativePoint(screenPoint);
        }
        if (parent != null && showPoint == null) {
            int height = UISettings.getInstance().getShowNavigationBar() ? 135 : 115;
            if (parent instanceof IdeFrameImpl && ((IdeFrameImpl) parent).isInFullScreen()) {
                height -= 20;
            }
            showPoint = new RelativePoint(parent, new Point((parent.getSize().width - getPreferredSize().width) / 2, height));
        }
        mySearchComponent.selectAll();
        WindowMoveListener windowListener = new WindowMoveListener(this);
        myTitleLabel.addMouseListener(windowListener);
        myTitleLabel.addMouseMotionListener(windowListener);
        Dimension panelSize = getPreferredSize();
        Dimension prev = DimensionService.getInstance().getSize(SERVICE_KEY);
        if (!myCbPreserveCase.isVisible()) {
            panelSize.width += myCbPreserveCase.getPreferredSize().width + 8;
        }
        panelSize.height *= 2;
        if (prev != null && prev.height < panelSize.height)
            prev.height = panelSize.height;
        myBalloon.setMinimumSize(panelSize);
        if (prev == null)
            panelSize.height = panelSize.height * 3 / 2;
        myBalloon.setSize(prev != null ? prev : panelSize);
        if (showPoint != null && showPoint.getComponent() != null) {
            myBalloon.show(showPoint);
        } else {
            myBalloon.showCenteredInCurrentWindow(myProject);
        }
    }
}
Also used : IdeFrameImpl(com.intellij.openapi.wm.impl.IdeFrameImpl) ComponentPopupBuilder(com.intellij.openapi.ui.popup.ComponentPopupBuilder) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) JBPopup(com.intellij.openapi.ui.popup.JBPopup) RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 2 with ComponentPopupBuilder

use of com.intellij.openapi.ui.popup.ComponentPopupBuilder in project google-cloud-intellij by GoogleCloudPlatform.

the class RepositorySelector method showPopup.

@Override
public void showPopup(RelativePoint showTarget) {
    Optional<CredentialedUser> user = cloudProject == null ? Optional.empty() : Services.getLoginService().getLoggedInUser(cloudProject.googleUsername());
    if (user.isPresent()) {
        if (popup == null || popup.isDisposed()) {
            panel = new RepositoryPanel();
            ComponentPopupBuilder popupBuilder = JBPopupFactory.getInstance().createComponentPopupBuilder(panel, null);
            popup = popupBuilder.createPopup();
        }
        if (!popup.isVisible()) {
            popup.show(showTarget);
        }
    } else {
        panel = new ProjectNotSelectedPanel();
        ComponentPopupBuilder popupBuilder = JBPopupFactory.getInstance().createComponentPopupBuilder(panel, null);
        popup = popupBuilder.createPopup();
        popup.show(showTarget);
    }
}
Also used : ComponentPopupBuilder(com.intellij.openapi.ui.popup.ComponentPopupBuilder) CredentialedUser(com.google.cloud.tools.intellij.login.CredentialedUser)

Example 3 with ComponentPopupBuilder

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

the class TaskDefaultFavoriteListProvider method showNotePopup.

private void showNotePopup(Project project, final DnDAwareTree tree, final Consumer<String> after, final String initText) {
    final JTextArea textArea = new JTextArea(3, 50);
    textArea.setFont(UIUtil.getTreeFont());
    textArea.setText(initText);
    final JBScrollPane pane = new JBScrollPane(textArea);
    final ComponentPopupBuilder builder = JBPopupFactory.getInstance().createComponentPopupBuilder(pane, textArea).setCancelOnClickOutside(true).setAdText(KeymapUtil.getShortcutsText(CommonShortcuts.CTRL_ENTER.getShortcuts()) + " to finish").setTitle("Comment").setMovable(true).setRequestFocus(true).setResizable(true).setMayBeParent(true);
    final JBPopup popup = builder.createPopup();
    final JComponent content = popup.getContent();
    final AnAction action = new AnAction() {

        @Override
        public void actionPerformed(AnActionEvent e) {
            popup.closeOk(e.getInputEvent());
            unregisterCustomShortcutSet(content);
            after.consume(textArea.getText());
        }
    };
    action.registerCustomShortcutSet(CommonShortcuts.CTRL_ENTER, content);
    ApplicationManager.getApplication().invokeLater(() -> popup.showInCenterOf(tree), ModalityState.NON_MODAL, project.getDisposed());
}
Also used : ComponentPopupBuilder(com.intellij.openapi.ui.popup.ComponentPopupBuilder) JBPopup(com.intellij.openapi.ui.popup.JBPopup) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) JBScrollPane(com.intellij.ui.components.JBScrollPane)

Example 4 with ComponentPopupBuilder

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

Example 5 with ComponentPopupBuilder

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

the class ChooseByNamePopup method showList.

@Override
protected void showList() {
    final JLayeredPane layeredPane = myTextField.getRootPane().getLayeredPane();
    Rectangle bounds = new Rectangle(layeredPane.getLocationOnScreen(), myTextField.getSize());
    bounds.y += layeredPane.getHeight();
    final Dimension preferredScrollPaneSize = myListScrollPane.getPreferredSize();
    int lastVisibleRow = Math.min(myList.getVisibleRowCount(), myList.getModel().getSize()) - 1;
    Rectangle visibleBounds = lastVisibleRow < 0 ? null : myList.getCellBounds(0, lastVisibleRow);
    preferredScrollPaneSize.height = visibleBounds != null ? visibleBounds.height : UIManager.getFont("Label.font").getSize();
    preferredScrollPaneSize.width = Math.max(myTextFieldPanel.getWidth(), preferredScrollPaneSize.width);
    Rectangle preferredBounds = new Rectangle(bounds.x, bounds.y, preferredScrollPaneSize.width, preferredScrollPaneSize.height);
    Rectangle original = new Rectangle(preferredBounds);
    ScreenUtil.fitToScreen(preferredBounds);
    JScrollBar hsb = myListScrollPane.getHorizontalScrollBar();
    if (original.width > preferredBounds.width && (!SystemInfo.isMac || hsb.isOpaque())) {
        int height = hsb.getPreferredSize().height;
        preferredBounds.y -= height;
        preferredBounds.height += height;
    }
    if (original.y > preferredBounds.y) {
        int height = original.y - preferredBounds.y;
        preferredBounds.y += height;
        preferredBounds.height -= height;
    }
    myListScrollPane.setVisible(true);
    myListScrollPane.setBorder(null);
    String adText = getAdText();
    if (myDropdownPopup == null) {
        ComponentPopupBuilder builder = JBPopupFactory.getInstance().createComponentPopupBuilder(myListScrollPane, myListScrollPane);
        builder.setFocusable(false).setLocateWithinScreenBounds(false).setRequestFocus(false).setCancelKeyEnabled(false).setFocusOwners(new JComponent[] { myTextField }).setBelongsToGlobalPopupStack(false).setModalContext(false).setAdText(adText).setMayBeParent(true);
        builder.setCancelCallback(() -> Boolean.TRUE);
        myDropdownPopup = builder.createPopup();
        myDropdownPopup.setLocation(preferredBounds.getLocation());
        myDropdownPopup.setSize(preferredBounds.getSize());
        myDropdownPopup.show(layeredPane);
    } else {
        myDropdownPopup.setLocation(preferredBounds.getLocation());
        // in 'focus follows mouse' mode, to avoid focus escaping to editor, don't reduce popup size when list size is reduced
        final Dimension currentSize = myDropdownPopup.getSize();
        if (UISettings.getInstance().getHideNavigationOnFocusLoss() || preferredBounds.width > currentSize.width || preferredBounds.height > currentSize.height) {
            myDropdownPopup.setSize(preferredBounds.getSize());
        }
    }
}
Also used : ComponentPopupBuilder(com.intellij.openapi.ui.popup.ComponentPopupBuilder)

Aggregations

ComponentPopupBuilder (com.intellij.openapi.ui.popup.ComponentPopupBuilder)9 JBPopup (com.intellij.openapi.ui.popup.JBPopup)5 AnAction (com.intellij.openapi.actionSystem.AnAction)2 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)2 Project (com.intellij.openapi.project.Project)2 IdeFrameImpl (com.intellij.openapi.wm.impl.IdeFrameImpl)2 RelativePoint (com.intellij.ui.awt.RelativePoint)2 CredentialedUser (com.google.cloud.tools.intellij.login.CredentialedUser)1 HintManager (com.intellij.codeInsight.hint.HintManager)1 ImplementationViewComponent (com.intellij.codeInsight.hint.ImplementationViewComponent)1 CoverageDataManager (com.intellij.coverage.CoverageDataManager)1 CoverageSuite (com.intellij.coverage.CoverageSuite)1 CoverageSuitesBundle (com.intellij.coverage.CoverageSuitesBundle)1 PropertiesComponent (com.intellij.ide.util.PropertiesComponent)1 com.intellij.openapi.actionSystem (com.intellij.openapi.actionSystem)1 Logger (com.intellij.openapi.diagnostic.Logger)1 Editor (com.intellij.openapi.editor.Editor)1 ProgressManager (com.intellij.openapi.progress.ProgressManager)1 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)1 DumbService (com.intellij.openapi.project.DumbService)1