Search in sources :

Example 16 with JBPopup

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

the class ImageDuplicateResultsDialog method createCenterPanel.

@Override
protected JComponent createCenterPanel() {
    final JPanel panel = new JPanel(new BorderLayout());
    DataManager.registerDataProvider(panel, new DataProvider() {

        @Override
        public Object getData(@NonNls String dataId) {
            final TreePath path = myTree.getSelectionPath();
            if (path != null) {
                Object component = path.getLastPathComponent();
                VirtualFile file = null;
                if (component instanceof MyFileNode) {
                    component = ((MyFileNode) component).getParent();
                }
                if (component instanceof MyDuplicatesNode) {
                    file = ((MyDuplicatesNode) component).getUserObject().iterator().next();
                }
                if (CommonDataKeys.VIRTUAL_FILE.is(dataId)) {
                    return file;
                }
                if (CommonDataKeys.VIRTUAL_FILE_ARRAY.is(dataId) && file != null) {
                    return new VirtualFile[] { file };
                }
            }
            return null;
        }
    });
    final JBList list = new JBList(new ResourceModules().getModuleNames());
    final NotNullFunction<Object, JComponent> modulesRenderer = dom -> new JLabel(dom instanceof Module ? ((Module) dom).getName() : dom.toString(), PlatformIcons.SOURCE_FOLDERS_ICON, SwingConstants.LEFT);
    list.installCellRenderer(modulesRenderer);
    final JPanel modulesPanel = ToolbarDecorator.createDecorator(list).setAddAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            final Module[] all = ModuleManager.getInstance(myProject).getModules();
            Arrays.sort(all, (o1, o2) -> o1.getName().compareTo(o2.getName()));
            final JBList modules = new JBList(all);
            modules.installCellRenderer(modulesRenderer);
            JBPopupFactory.getInstance().createListPopupBuilder(modules).setTitle("Add Resource Module").setFilteringEnabled(o -> ((Module) o).getName()).setItemChoosenCallback(() -> {
                final Object value = modules.getSelectedValue();
                if (value instanceof Module && !myResourceModules.contains((Module) value)) {
                    myResourceModules.add((Module) value);
                    ((DefaultListModel) list.getModel()).addElement(((Module) value).getName());
                }
                ((DefaultTreeModel) myTree.getModel()).reload();
                TreeUtil.expandAll(myTree);
            }).createPopup().show(button.getPreferredPopupPoint());
        }
    }).setRemoveAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            final Object[] values = list.getSelectedValues();
            for (Object value : values) {
                myResourceModules.remove((String) value);
                ((DefaultListModel) list.getModel()).removeElement(value);
            }
            ((DefaultTreeModel) myTree.getModel()).reload();
            TreeUtil.expandAll(myTree);
        }
    }).disableDownAction().disableUpAction().createPanel();
    modulesPanel.setPreferredSize(new Dimension(-1, 60));
    final JPanel top = new JPanel(new BorderLayout());
    top.add(new JLabel("Image modules:"), BorderLayout.NORTH);
    top.add(modulesPanel, BorderLayout.CENTER);
    panel.add(top, BorderLayout.NORTH);
    panel.add(new JBScrollPane(myTree), BorderLayout.CENTER);
    new AnAction() {

        @Override
        public void actionPerformed(AnActionEvent e) {
            VirtualFile file = getFileFromSelection();
            if (file != null) {
                final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file);
                if (psiFile != null) {
                    final ImplementationViewComponent viewComponent = new ImplementationViewComponent(new PsiElement[] { psiFile }, 0);
                    final TreeSelectionListener listener = new TreeSelectionListener() {

                        @Override
                        public void valueChanged(TreeSelectionEvent e) {
                            final VirtualFile selection = getFileFromSelection();
                            if (selection != null) {
                                final PsiFile newElement = PsiManager.getInstance(myProject).findFile(selection);
                                if (newElement != null) {
                                    viewComponent.update(new PsiElement[] { newElement }, 0);
                                }
                            }
                        }
                    };
                    myTree.addTreeSelectionListener(listener);
                    final JBPopup popup = JBPopupFactory.getInstance().createComponentPopupBuilder(viewComponent, viewComponent.getPreferredFocusableComponent()).setProject(myProject).setDimensionServiceKey(myProject, ImageDuplicateResultsDialog.class.getName(), false).setResizable(true).setMovable(true).setRequestFocus(false).setCancelCallback(() -> {
                        myTree.removeTreeSelectionListener(listener);
                        return true;
                    }).setTitle("Image Preview").createPopup();
                    final Window window = ImageDuplicateResultsDialog.this.getWindow();
                    popup.show(new RelativePoint(window, new Point(window.getWidth(), 0)));
                    viewComponent.setHint(popup, "Image Preview");
                }
            }
        }
    }.registerCustomShortcutSet(CustomShortcutSet.fromString("ENTER"), panel);
    int total = myDuplicates.values().stream().mapToInt(Set::size).sum() - myDuplicates.size();
    final JLabel label = new JLabel("<html>Press <b>Enter</b> to preview image<br>Total images found: " + myImages.size() + ". Total duplicates found: " + total + "</html>");
    panel.add(label, BorderLayout.SOUTH);
    return panel;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) UIUtil(com.intellij.util.ui.UIUtil) java.util(java.util) ModuleManager(com.intellij.openapi.module.ModuleManager) VirtualFile(com.intellij.openapi.vfs.VirtualFile) NonNls(org.jetbrains.annotations.NonNls) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) PsiManager(com.intellij.psi.PsiManager) ModuleUtil(com.intellij.openapi.module.ModuleUtil) TreeSelectionListener(javax.swing.event.TreeSelectionListener) PropertyName(com.intellij.ide.util.PropertyName) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) Tree(com.intellij.ui.treeStructure.Tree) FileUtil(com.intellij.openapi.util.io.FileUtil) Module(com.intellij.openapi.module.Module) DataManager(com.intellij.ide.DataManager) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) PlatformIcons(com.intellij.util.PlatformIcons) JBList(com.intellij.ui.components.JBList) TreeUtil(com.intellij.util.ui.tree.TreeUtil) PropertiesComponent(com.intellij.ide.util.PropertiesComponent) TreePath(javax.swing.tree.TreePath) StringUtil(com.intellij.openapi.util.text.StringUtil) NotNullFunction(com.intellij.util.NotNullFunction) com.intellij.ui(com.intellij.ui) ActionEvent(java.awt.event.ActionEvent) Collectors(java.util.stream.Collectors) JBPopup(com.intellij.openapi.ui.popup.JBPopup) File(java.io.File) JBScrollPane(com.intellij.ui.components.JBScrollPane) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) java.awt(java.awt) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) NotNull(org.jetbrains.annotations.NotNull) ImplementationViewComponent(com.intellij.codeInsight.hint.ImplementationViewComponent) RelativePoint(com.intellij.ui.awt.RelativePoint) javax.swing(javax.swing) TreeSelectionListener(javax.swing.event.TreeSelectionListener) RelativePoint(com.intellij.ui.awt.RelativePoint) PsiFile(com.intellij.psi.PsiFile) JBPopup(com.intellij.openapi.ui.popup.JBPopup) PsiElement(com.intellij.psi.PsiElement) ImplementationViewComponent(com.intellij.codeInsight.hint.ImplementationViewComponent) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) TreePath(javax.swing.tree.TreePath) JBList(com.intellij.ui.components.JBList) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) Module(com.intellij.openapi.module.Module) JBScrollPane(com.intellij.ui.components.JBScrollPane)

Example 17 with JBPopup

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

the class DocumentationManager method doShowJavaDocInfo.

private void doShowJavaDocInfo(@NotNull final PsiElement element, boolean requestFocus, PopupUpdateProcessor updateProcessor, final PsiElement originalElement, @Nullable final Runnable closeCallback) {
    Project project = getProject(element);
    if (!project.isOpen())
        return;
    storeOriginalElement(project, originalElement, element);
    myPreviouslyFocused = WindowManagerEx.getInstanceEx().getFocusedComponent(project);
    JBPopup _oldHint = getDocInfoHint();
    if (PreviewManager.SERVICE.preview(myProject, DocumentationPreviewPanelProvider.ID, Couple.of(element, originalElement), requestFocus) != null) {
        return;
    }
    if (myToolWindow == null && PropertiesComponent.getInstance().isTrueValue(SHOW_DOCUMENTATION_IN_TOOL_WINDOW)) {
        createToolWindow(element, originalElement);
    } else if (myToolWindow != null) {
        Content content = myToolWindow.getContentManager().getSelectedContent();
        if (content != null) {
            DocumentationComponent component = (DocumentationComponent) content.getComponent();
            boolean sameElement = element.getManager().areElementsEquivalent(component.getElement(), element);
            if (sameElement) {
                JComponent preferredFocusableComponent = content.getPreferredFocusableComponent();
                // focus toolwindow on the second actionPerformed
                boolean focus = requestFocus || CommandProcessor.getInstance().getCurrentCommand() != null;
                if (preferredFocusableComponent != null && focus) {
                    IdeFocusManager.getInstance(myProject).requestFocus(preferredFocusableComponent, true);
                }
            }
            if (!sameElement || !component.isUpToDate()) {
                content.setDisplayName(getTitle(element, true));
                fetchDocInfo(getDefaultCollector(element, originalElement), component, true);
            }
        }
        if (!myToolWindow.isVisible()) {
            myToolWindow.show(null);
        }
    } else if (_oldHint != null && _oldHint.isVisible() && _oldHint instanceof AbstractPopup) {
        DocumentationComponent oldComponent = (DocumentationComponent) ((AbstractPopup) _oldHint).getComponent();
        fetchDocInfo(getDefaultCollector(element, originalElement), oldComponent);
    } else {
        showInPopup(element, requestFocus, updateProcessor, originalElement, closeCallback);
    }
}
Also used : Project(com.intellij.openapi.project.Project) AbstractPopup(com.intellij.ui.popup.AbstractPopup) Content(com.intellij.ui.content.Content) JBPopup(com.intellij.openapi.ui.popup.JBPopup)

Example 18 with JBPopup

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

the class ProjectStartupConfigurable method selectAndAddConfiguration.

private void selectAndAddConfiguration(final AnActionButton button) {
    final Executor executor = DefaultRunExecutor.getRunExecutorInstance();
    final List<ChooseRunConfigurationPopup.ItemWrapper> wrappers = new ArrayList<>();
    wrappers.add(createNewWrapper(button));
    final ChooseRunConfigurationPopup.ItemWrapper[] allSettings = ChooseRunConfigurationPopup.createSettingsList(myProject, new ExecutorProvider() {

        @Override
        public Executor getExecutor() {
            return executor;
        }
    }, false);
    final Set<RunnerAndConfigurationSettings> existing = new HashSet<>(myModel.getAllConfigurations());
    for (ChooseRunConfigurationPopup.ItemWrapper setting : allSettings) {
        if (setting.getValue() instanceof RunnerAndConfigurationSettings) {
            final RunnerAndConfigurationSettings settings = (RunnerAndConfigurationSettings) setting.getValue();
            if (!settings.isTemporary() && ProjectStartupRunner.canBeRun(settings) && !existing.contains(settings)) {
                wrappers.add(setting);
            }
        }
    }
    final JBList list = new JBList(wrappers);
    list.setCellRenderer(new ColoredListCellRenderer() {

        @Override
        protected void customizeCellRenderer(@NotNull JList list, Object value, int index, boolean selected, boolean hasFocus) {
            if (value instanceof ChooseRunConfigurationPopup.ItemWrapper) {
                setIcon(((ChooseRunConfigurationPopup.ItemWrapper) value).getIcon());
                append(((ChooseRunConfigurationPopup.ItemWrapper) value).getText());
            }
        }
    });
    final JBPopup popup = JBPopupFactory.getInstance().createListPopupBuilder(list).setItemChoosenCallback(() -> {
        final int index = list.getSelectedIndex();
        if (index < 0)
            return;
        final ChooseRunConfigurationPopup.ItemWrapper at = (ChooseRunConfigurationPopup.ItemWrapper) list.getModel().getElementAt(index);
        if (at.getValue() instanceof RunnerAndConfigurationSettings) {
            final RunnerAndConfigurationSettings added = (RunnerAndConfigurationSettings) at.getValue();
            addConfiguration(added);
        } else {
            at.perform(myProject, executor, button.getDataContext());
        }
    }).createPopup();
    showPopup(button, popup);
}
Also used : RelativePoint(com.intellij.ui.awt.RelativePoint) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) ChooseRunConfigurationPopup(com.intellij.execution.actions.ChooseRunConfigurationPopup) JBList(com.intellij.ui.components.JBList) ExecutorProvider(com.intellij.execution.actions.ExecutorProvider) JBPopup(com.intellij.openapi.ui.popup.JBPopup)

Example 19 with JBPopup

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

the class ToggleBookmarkWithMnemonicAction method actionPerformed.

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
    super.actionPerformed(e);
    final Project project = e.getProject();
    if (project == null)
        return;
    final BookmarkInContextInfo info = new BookmarkInContextInfo(e.getDataContext(), project).invoke();
    final Bookmark bookmark = info.getBookmarkAtPlace();
    final BookmarkManager bookmarks = BookmarkManager.getInstance(project);
    if (bookmark != null) {
        final JBPopup[] popup = new JBPopup[1];
        MnemonicChooser mc = new MnemonicChooser() {

            @Override
            protected void onMnemonicChosen(char c) {
                popup[0].cancel();
                bookmarks.setMnemonic(bookmark, c);
            }

            @Override
            protected void onCancelled() {
                popup[0].cancel();
                bookmarks.removeBookmark(bookmark);
            }

            @Override
            protected boolean isOccupied(char c) {
                return bookmarks.findBookmarkForMnemonic(c) != null;
            }
        };
        popup[0] = JBPopupFactory.getInstance().createComponentPopupBuilder(mc, mc).setTitle("Bookmark Mnemonic").setFocusable(true).setRequestFocus(true).setMovable(false).setCancelKeyEnabled(false).setAdText(bookmarks.hasBookmarksWithMnemonics() ? (UIUtil.isUnderDarcula() ? "Brown" : "Yellow") + " cells are in use" : null).setResizable(false).createPopup();
        popup[0].showInBestPositionFor(e.getDataContext());
    }
}
Also used : Project(com.intellij.openapi.project.Project) Bookmark(com.intellij.ide.bookmarks.Bookmark) JBPopup(com.intellij.openapi.ui.popup.JBPopup) BookmarkManager(com.intellij.ide.bookmarks.BookmarkManager)

Example 20 with JBPopup

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

the class CustomPopupFullValueEvaluator method evaluate.

@Override
public void evaluate(@NotNull final XFullValueEvaluationCallback callback) {
    final T data = getData();
    DebuggerUIUtil.invokeLater(() -> {
        if (callback.isObsolete())
            return;
        final JComponent comp = createComponent(data);
        Project project = getEvaluationContext().getProject();
        JBPopup popup = DebuggerUIUtil.createValuePopup(project, comp, null);
        JFrame frame = WindowManager.getInstance().getFrame(project);
        Dimension frameSize = frame.getSize();
        Dimension size = new Dimension(frameSize.width / 2, frameSize.height / 2);
        popup.setSize(size);
        if (comp instanceof Disposable) {
            Disposer.register(popup, (Disposable) comp);
        }
        callback.evaluated("");
        popup.show(new RelativePoint(frame, new Point(size.width / 2, size.height / 2)));
    });
}
Also used : Disposable(com.intellij.openapi.Disposable) Project(com.intellij.openapi.project.Project) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) JBPopup(com.intellij.openapi.ui.popup.JBPopup)

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