Search in sources :

Example 66 with JBPopup

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

the class ShowByteCodeAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final DataContext dataContext = e.getDataContext();
    final Project project = e.getProject();
    if (project == null)
        return;
    final Editor editor = e.getData(CommonDataKeys.EDITOR);
    final PsiElement psiElement = getPsiElement(dataContext, project, editor);
    if (psiElement == null)
        return;
    if (ByteCodeViewerManager.getContainingClass(psiElement) == null) {
        Messages.showWarningDialog(project, "The selection should contain a class", "Unable to Find Class to Show Bytecode");
        return;
    }
    final String psiElementTitle = ByteCodeViewerManager.getInstance(project).getTitle(psiElement);
    final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(psiElement);
    if (virtualFile == null)
        return;
    final RelativePoint bestPopupLocation = JBPopupFactory.getInstance().guessBestPopupLocation(dataContext);
    final SmartPsiElementPointer element = SmartPointerManager.getInstance(project).createSmartPsiElementPointer(psiElement);
    ProgressManager.getInstance().run(new Task.Backgroundable(project, "Looking for Bytecode...") {

        private String myByteCode;

        private String myErrorMessage;

        private String myErrorTitle;

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            if (ProjectRootManager.getInstance(project).getFileIndex().isInContent(virtualFile) && isMarkedForCompilation(project, virtualFile)) {
                myErrorMessage = "Unable to show bytecode for '" + psiElementTitle + "'. Class file does not exist or is out-of-date.";
                myErrorTitle = "Class File Out-Of-Date";
            } else {
                myByteCode = ReadAction.compute(() -> ByteCodeViewerManager.getByteCode(psiElement));
            }
        }

        @Override
        public void onSuccess() {
            if (project.isDisposed())
                return;
            if (myErrorMessage != null && myTitle != null) {
                Messages.showWarningDialog(project, myErrorMessage, myErrorTitle);
                return;
            }
            final PsiElement targetElement = element.getElement();
            if (targetElement == null)
                return;
            final ByteCodeViewerManager codeViewerManager = ByteCodeViewerManager.getInstance(project);
            if (codeViewerManager.hasActiveDockedDocWindow()) {
                codeViewerManager.doUpdateComponent(targetElement, myByteCode);
            } else {
                if (myByteCode == null) {
                    Messages.showErrorDialog(project, "Unable to parse class file for '" + psiElementTitle + "'.", "Bytecode not Found");
                    return;
                }
                final ByteCodeViewerComponent component = new ByteCodeViewerComponent(project, null);
                component.setText(myByteCode, targetElement);
                Processor<JBPopup> pinCallback = popup -> {
                    codeViewerManager.recreateToolWindow(targetElement, targetElement);
                    popup.cancel();
                    return false;
                };
                final JBPopup popup = JBPopupFactory.getInstance().createComponentPopupBuilder(component, null).setProject(project).setDimensionServiceKey(project, ShowByteCodeAction.class.getName(), false).setResizable(true).setMovable(true).setRequestFocus(LookupManager.getActiveLookup(editor) == null).setTitle(psiElementTitle + " Bytecode").setCouldPin(pinCallback).createPopup();
                Disposer.register(popup, component);
                if (editor != null) {
                    popup.showInBestPositionFor(editor);
                } else {
                    popup.show(bestPopupLocation);
                }
            }
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Task(com.intellij.openapi.progress.Task) Processor(com.intellij.util.Processor) RelativePoint(com.intellij.ui.awt.RelativePoint) Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) Editor(com.intellij.openapi.editor.Editor) JBPopup(com.intellij.openapi.ui.popup.JBPopup)

Example 67 with JBPopup

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

the class MultilinePopupBuilder method createPopup.

@NotNull
JBPopup createPopup() {
    JPanel panel = new JPanel(new BorderLayout());
    panel.add(myTextField, BorderLayout.CENTER);
    ComponentPopupBuilder builder = JBPopupFactory.getInstance().createComponentPopupBuilder(panel, myTextField).setCancelOnClickOutside(true).setAdText(KeymapUtil.getShortcutsText(CommonShortcuts.CTRL_ENTER.getShortcuts()) + " to finish").setRequestFocus(true).setResizable(true).setMayBeParent(true);
    final JBPopup popup = builder.createPopup();
    popup.setMinimumSize(new JBDimension(200, 90));
    AnAction okAction = new DumbAwareAction() {

        @Override
        public void actionPerformed(@NotNull AnActionEvent e) {
            unregisterCustomShortcutSet(popup.getContent());
            popup.closeOk(e.getInputEvent());
        }
    };
    okAction.registerCustomShortcutSet(CommonShortcuts.CTRL_ENTER, popup.getContent());
    return popup;
}
Also used : ComponentPopupBuilder(com.intellij.openapi.ui.popup.ComponentPopupBuilder) JBDimension(com.intellij.util.ui.JBDimension) JBPopup(com.intellij.openapi.ui.popup.JBPopup) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) NotNull(org.jetbrains.annotations.NotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 68 with JBPopup

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

the class ShowJavadocAction method actionPerformed.

public void actionPerformed(final AnActionEvent e) {
    final PropertyInspectorTable inspector = PropertyInspectorTable.DATA_KEY.getData(e.getDataContext());
    final IntrospectedProperty introspectedProperty = inspector.getSelectedIntrospectedProperty();
    final PsiClass aClass = inspector.getComponentClass();
    final PsiMethod getter = PropertyUtil.findPropertyGetter(aClass, introspectedProperty.getName(), false, true);
    LOG.assertTrue(getter != null);
    final PsiMethod setter = PropertyUtil.findPropertySetter(aClass, introspectedProperty.getName(), false, true);
    LOG.assertTrue(setter != null);
    final DocumentationManager documentationManager = DocumentationManager.getInstance(aClass.getProject());
    final DocumentationComponent component1 = new DocumentationComponent(documentationManager);
    final DocumentationComponent component2 = new DocumentationComponent(documentationManager);
    final Disposable disposable = Disposer.newDisposable();
    final TabbedPaneWrapper tabbedPane = new TabbedPaneWrapper(disposable);
    tabbedPane.addTab(UIDesignerBundle.message("tab.getter"), component1);
    tabbedPane.addTab(UIDesignerBundle.message("tab.setter"), component2);
    documentationManager.fetchDocInfo(getter, component1);
    documentationManager.queueFetchDocInfo(setter, component2).doWhenProcessed(() -> {
        final JBPopup hint = JBPopupFactory.getInstance().createComponentPopupBuilder(tabbedPane.getComponent(), component1).setDimensionServiceKey(aClass.getProject(), DocumentationManager.JAVADOC_LOCATION_AND_SIZE, false).setResizable(true).setMovable(true).setRequestFocus(true).setTitle(UIDesignerBundle.message("property.javadoc.title", introspectedProperty.getName())).createPopup();
        component1.setHint(hint);
        component2.setHint(hint);
        Disposer.register(hint, component1);
        Disposer.register(hint, component2);
        Disposer.register(hint, disposable);
        hint.show(new RelativePoint(inspector, new Point(0, 0)));
    //component1.requestFocus();
    });
}
Also used : Disposable(com.intellij.openapi.Disposable) DocumentationManager(com.intellij.codeInsight.documentation.DocumentationManager) PropertyInspectorTable(com.intellij.uiDesigner.propertyInspector.PropertyInspectorTable) PsiMethod(com.intellij.psi.PsiMethod) DocumentationComponent(com.intellij.codeInsight.documentation.DocumentationComponent) TabbedPaneWrapper(com.intellij.ui.TabbedPaneWrapper) IntrospectedProperty(com.intellij.uiDesigner.propertyInspector.IntrospectedProperty) PsiClass(com.intellij.psi.PsiClass) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint) JBPopup(com.intellij.openapi.ui.popup.JBPopup)

Example 69 with JBPopup

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

the class ExternalProjectPathField method createPanel.

@NotNull
public static MyPathAndProjectButtonPanel createPanel(@NotNull final Project project, @NotNull final ProjectSystemId externalSystemId) {
    final EditorTextField textField = createTextField(project, externalSystemId);
    final FixedSizeButton selectRegisteredProjectButton = new FixedSizeButton();
    selectRegisteredProjectButton.setIcon(AllIcons.Actions.Module);
    String tooltipText = ExternalSystemBundle.message("run.configuration.tooltip.choose.registered.project", externalSystemId.getReadableName());
    selectRegisteredProjectButton.setToolTipText(tooltipText);
    selectRegisteredProjectButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            final Ref<JBPopup> popupRef = new Ref<>();
            final Tree tree = buildRegisteredProjectsTree(project, externalSystemId);
            tree.setBorder(IdeBorderFactory.createEmptyBorder(8));
            Runnable treeSelectionCallback = () -> {
                TreePath path = tree.getSelectionPath();
                if (path != null) {
                    Object lastPathComponent = path.getLastPathComponent();
                    if (lastPathComponent instanceof ExternalSystemNode) {
                        Object e1 = ((ExternalSystemNode) lastPathComponent).getDescriptor().getElement();
                        if (e1 instanceof ExternalProjectPojo) {
                            ExternalProjectPojo pojo = (ExternalProjectPojo) e1;
                            textField.setText(pojo.getPath());
                            Editor editor = textField.getEditor();
                            if (editor != null) {
                                collapseIfPossible(editor, externalSystemId, project);
                            }
                        }
                    }
                }
                popupRef.get().closeOk(null);
            };
            JBPopup popup = new PopupChooserBuilder(tree).setTitle(ExternalSystemBundle.message("run.configuration.title.choose.registered.project", externalSystemId.getReadableName())).setResizable(true).setItemChoosenCallback(treeSelectionCallback).setAutoselectOnMouseMove(true).setCloseOnEnter(false).createPopup();
            popupRef.set(popup);
            popup.showUnderneathOf(selectRegisteredProjectButton);
        }
    });
    return new MyPathAndProjectButtonPanel(textField, selectRegisteredProjectButton);
}
Also used : ActionEvent(java.awt.event.ActionEvent) ExternalSystemNode(com.intellij.openapi.externalSystem.service.task.ui.ExternalSystemNode) Ref(com.intellij.openapi.util.Ref) ActionListener(java.awt.event.ActionListener) TreePath(javax.swing.tree.TreePath) EditorTextField(com.intellij.ui.EditorTextField) Tree(com.intellij.ui.treeStructure.Tree) ExternalSystemTasksTree(com.intellij.openapi.externalSystem.service.task.ui.ExternalSystemTasksTree) Editor(com.intellij.openapi.editor.Editor) PopupChooserBuilder(com.intellij.openapi.ui.popup.PopupChooserBuilder) JBPopup(com.intellij.openapi.ui.popup.JBPopup) FixedSizeButton(com.intellij.openapi.ui.FixedSizeButton) ExternalProjectPojo(com.intellij.openapi.externalSystem.model.project.ExternalProjectPojo) NotNull(org.jetbrains.annotations.NotNull)

Example 70 with JBPopup

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

the class ClasspathPanelImpl method createTableWithButtons.

private JComponent createTableWithButtons() {
    final boolean isAnalyzeShown = false;
    final ClasspathPanelAction removeAction = new ClasspathPanelAction(this) {

        @Override
        public void run() {
            removeSelectedItems(TableUtil.removeSelectedItems(myEntryTable));
        }
    };
    final AnActionButton analyzeButton = new AnActionButton(ProjectBundle.message("classpath.panel.analyze"), null, IconUtil.getAnalyzeIcon()) {

        @Override
        public void actionPerformed(@NotNull AnActionEvent e) {
            AnalyzeDependenciesDialog.show(getRootModel().getModule());
        }
    };
    //addButton.setShortcut(CustomShortcutSet.fromString("alt A", "INSERT"));
    //removeButton.setShortcut(CustomShortcutSet.fromString("alt DELETE"));
    //upButton.setShortcut(CustomShortcutSet.fromString("alt UP"));
    //downButton.setShortcut(CustomShortcutSet.fromString("alt DOWN"));
    final ToolbarDecorator decorator = ToolbarDecorator.createDecorator(myEntryTable);
    AnActionButtonUpdater moveUpDownUpdater = new AnActionButtonUpdater() {

        @Override
        public boolean isEnabled(AnActionEvent e) {
            for (RowSorter.SortKey key : myEntryTable.getRowSorter().getSortKeys()) {
                if (key.getSortOrder() != SortOrder.UNSORTED) {
                    return false;
                }
            }
            return true;
        }
    };
    decorator.setAddAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            initPopupActions();
            final JBPopup popup = JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep<AddItemPopupAction<?>>(null, myPopupActions) {

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

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

                @Override
                public boolean isMnemonicsNavigationEnabled() {
                    return true;
                }

                @Override
                public PopupStep onChosen(final AddItemPopupAction<?> selectedValue, final boolean finalChoice) {
                    if (selectedValue.hasSubStep()) {
                        return selectedValue.createSubStep();
                    }
                    return doFinalStep(() -> selectedValue.execute());
                }

                @Override
                @NotNull
                public String getTextFor(AddItemPopupAction<?> value) {
                    return "&" + value.getIndex() + "  " + value.getTitle();
                }
            });
            popup.show(button.getPreferredPopupPoint());
        }
    }).setRemoveAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            removeAction.actionPerformed(null);
        }
    }).setRemoveActionUpdater(new AnActionButtonUpdater() {

        @Override
        public boolean isEnabled(AnActionEvent e) {
            final int[] selectedRows = myEntryTable.getSelectedRows();
            for (final int selectedRow : selectedRows) {
                if (!getItemAt(selectedRow).isRemovable()) {
                    return false;
                }
            }
            return selectedRows.length > 0;
        }
    }).setMoveUpAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            moveSelectedRows(-1);
        }
    }).setMoveUpActionUpdater(moveUpDownUpdater).setMoveUpActionName("Move Up (disabled if items are shown in sorted order)").setMoveDownAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            moveSelectedRows(+1);
        }
    }).setMoveDownActionUpdater(moveUpDownUpdater).setMoveDownActionName("Move Down (disabled if items are shown in sorted order)").addExtraAction(myEditButton);
    if (isAnalyzeShown) {
        decorator.addExtraAction(analyzeButton);
    }
    final JPanel panel = decorator.createPanel();
    myRemoveButton = ToolbarDecorator.findRemoveButton(panel);
    return panel;
}
Also used : TableRowSorter(javax.swing.table.TableRowSorter) NotNull(org.jetbrains.annotations.NotNull) RelativePoint(com.intellij.ui.awt.RelativePoint) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) PopupStep(com.intellij.openapi.ui.popup.PopupStep) 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