private void openSample(Project project, Editor editor) { EditorTextField field = new EditorTextField(editor.getDocument(), project, WeexFileType.INSTANCE, true, false) { @Override protected EditorEx createEditor() { EditorEx editor1 = super.createEditor(); editor1.setVerticalScrollbarVisible(true); editor1.setHorizontalScrollbarVisible(true); return editor1; } }; field.setFont(editor.getContentComponent().getFont()); JBPopup jbPopup = JBPopupFactory.getInstance().createComponentPopupBuilder(field, null) .createPopup(); jbPopup.setSize(new Dimension(500, 500)); jbPopup.showInBestPositionFor(editor); }
@Override public void evaluate(@NotNull final XFullValueEvaluationCallback callback) throws Exception { final T data = getData(); DebuggerUIUtil.invokeLater(new Runnable() { @Override public void run() { 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))); } }); }
@Override public void navigate(MouseEvent e, PsiElement nameIdentifier) { final PsiElement listOwner = nameIdentifier.getParent(); final PsiFile containingFile = listOwner.getContainingFile(); final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(listOwner); if (virtualFile != null && containingFile != null) { final Project project = listOwner.getProject(); final Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor(); if (editor != null) { editor.getCaretModel().moveToOffset(nameIdentifier.getTextOffset()); final PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument()); if (file != null && virtualFile.equals(file.getVirtualFile())) { final JBPopup popup = createActionGroupPopup(containingFile, project, editor); if (popup != null) { popup.show(new RelativePoint(e)); } } } } }
@Nullable protected JBPopup createActionGroupPopup(PsiFile file, Project project, Editor editor) { final DefaultActionGroup group = new DefaultActionGroup(); for (final IntentionAction action : IntentionManager.getInstance().getAvailableIntentionActions()) { if (shouldShowInGutterPopup(action) && action.isAvailable(project, editor, file)) { group.add(new ApplyIntentionAction(action, action.getText(), editor, file)); } } if (group.getChildrenCount() > 0) { final DataContext context = SimpleDataContext.getProjectContext(null); return JBPopupFactory.getInstance() .createActionGroupPopup(null, group, context, JBPopupFactory.ActionSelectionAid.SPEEDSEARCH, true); } return null; }
@Nullable public static Component getOwner(@Nullable Component c) { if (c == null) return null; final Window wnd = SwingUtilities.getWindowAncestor(c); if (wnd instanceof JWindow) { final JRootPane root = ((JWindow)wnd).getRootPane(); final JBPopup popup = (JBPopup)root.getClientProperty(JBPopup.KEY); if (popup == null) return c; final Component owner = popup.getOwner(); if (owner == null) return c; return getOwner(owner); } else { return c; } }
@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 Dimension(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; }
@Override public void adjustContainerWindow(Component c, Dimension oldSize, Dimension newSize) { if (c == null) return; Window wnd = SwingUtilities.getWindowAncestor(c); if (wnd instanceof JWindow) { JBPopup popup = (JBPopup)((JWindow)wnd).getRootPane().getClientProperty(JBPopup.KEY); if (popup != null) { if (oldSize.height < newSize.height) { Dimension size = popup.getSize(); size.height += newSize.height - oldSize.height; popup.setSize(size); popup.moveToFitScreen(); } } } }
public DialogPopupWrapper(Component owner, Component content, int x, int y, JBPopup jbPopup) { if (!owner.isShowing()) { throw new IllegalArgumentException("Popup owner must be showing"); } final Window wnd = UIUtil.getWindow(owner); if (wnd instanceof Frame) { myDialog = new JDialog((Frame)wnd); } else if (wnd instanceof Dialog) { myDialog = new JDialog((Dialog)wnd); } else { myDialog = new JDialog(); } myDialog.getContentPane().setLayout(new BorderLayout()); myDialog.getContentPane().add(content, BorderLayout.CENTER); myDialog.getRootPane().putClientProperty(JBPopup.KEY, jbPopup); myDialog.setUndecorated(true); myDialog.setBackground(UIUtil.getPanelBackground()); myDialog.pack(); myDialog.setLocation(x, y); }
@NotNull public static List<JBPopup> getChildPopups(@NotNull final Component component) { List<JBPopup> result = new ArrayList<JBPopup>(); final Window window = UIUtil.getWindow(component); if (window == null) return result; final List<FocusTrackback> stack = getCleanStackForRoot(findUtlimateParent(window)); for (FocusTrackback each : stack) { if (each.isChildFor(component) && each.getRequestor() instanceof JBPopup) { result.add((JBPopup)each.getRequestor()); } } return result; }
@Override public void actionPerformed(AnActionEvent e) { Disposable disposable = Disposer.newDisposable(); NewRecentProjectPanel panel = new NewRecentProjectPanel(disposable); JList list = UIUtil.findComponentOfType(panel, JList.class); JBPopup popup = JBPopupFactory.getInstance().createComponentPopupBuilder(panel, list) .setTitle("Recent Projects") .setFocusable(true) .setRequestFocus(true) .setMayBeParent(true) .setMovable(true) .createPopup(); Disposer.register(popup, disposable); Project project = e.getRequiredData(CommonDataKeys.PROJECT); popup.showCenteredInCurrentWindow(project); }
@NotNull @Override protected JBPopup createPopup(@NotNull AnActionEvent e) { Project project = e.getProject(); if (project == null) project = ProjectManager.getInstance().getDefaultProject(); Ref<JBPopup> popup = new Ref<JBPopup>(); ChangesBrowser cb = new MyChangesBrowser(project, getChanges(), getCurrentSelection(), popup); popup.set(JBPopupFactory.getInstance() .createComponentPopupBuilder(cb, cb.getPreferredFocusedComponent()) .setResizable(true) .setModalContext(false) .setFocusable(true) .setRequestFocus(true) .setCancelOnWindowDeactivation(true) .setCancelOnOtherWindowOpen(true) .setMovable(true) .setCancelKeyEnabled(true) .setCancelOnClickOutside(true) .setDimensionServiceKey(project, "Diff.GoToChangePopup", false) .createPopup()); return popup.get(); }
public MyChangesBrowser(@NotNull Project project, @NotNull List<Change> changes, @Nullable final Change currentChange, @NotNull Ref<JBPopup> popup) { super(project, null, changes, null, false, false, null, MyUseCase.LOCAL_CHANGES, null); setSelectionMode(ListSelectionModel.SINGLE_SELECTION); setChangesToDisplay(changes); UiNotifyConnector.doWhenFirstShown(this, new Runnable() { @Override public void run() { if (currentChange != null) select(Collections.singletonList(currentChange)); } }); myPopup = popup; }
@Override protected FlatComboButton createComboBoxButton(Presentation presentation) { if (myShowDisabledActions) { return new FlatComboButton(presentation) { @Override protected JBPopup createPopup(Runnable onDispose) { ListPopup popup = JBPopupFactory.getInstance().createActionGroupPopup( null, createPopupActionGroup(this), getDataContext(), JBPopupFactory.ActionSelectionAid.SPEEDSEARCH, true, onDispose, getMaxRows()); popup.setMinimumSize(new Dimension(getMinWidth(), getMinHeight())); return popup; } }; } return super.createComboBoxButton(presentation); }
@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; }
@NotNull public static JBPopup getRelatedItemsPopup(final List<? extends GotoRelatedItem> items, String title) { Object[] elements = new Object[items.size()]; //todo[nik] move presentation logic to GotoRelatedItem class final Map<PsiElement, GotoRelatedItem> itemsMap = new HashMap<PsiElement, GotoRelatedItem>(); for (int i = 0; i < items.size(); i++) { GotoRelatedItem item = items.get(i); elements[i] = item.getElement() != null ? item.getElement() : item; itemsMap.put(item.getElement(), item); } return getPsiElementPopup(elements, itemsMap, title, new Processor<Object>() { @Override public boolean process(Object element) { if (element instanceof PsiElement) { //noinspection SuspiciousMethodCalls itemsMap.get(element).navigate(); } else { ((GotoRelatedItem)element).navigate(); } return true; } } ); }
@Nullable private static JBPopup navigateOrCreatePopup(final NavigatablePsiElement[] targets, final String title, final String findUsagesTitle, final ListCellRenderer listRenderer, @Nullable final ListBackgroundUpdaterTask listUpdaterTask) { return navigateOrCreatePopup(targets, title, findUsagesTitle, listRenderer, listUpdaterTask, new Consumer<Object[]>() { @Override public void consume(Object[] selectedElements) { for (Object element : selectedElements) { PsiElement selected = (PsiElement)element; LOG.assertTrue(selected.isValid()); ((NavigatablePsiElement)selected).navigate(true); } } }); }
private static Component discoverPopup(final DataKey<JBPopup> datakey, Component focusOwner) { if (focusOwner == null) { focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); } if (focusOwner == null) return null; final DataContext dataContext = DataManager.getInstance().getDataContext(focusOwner); if (dataContext == null) return null; final JBPopup popup = datakey.getData(dataContext); if (popup != null && popup.isVisible()) { return popup.getContent(); } return null; }
@Override protected ComboBoxButton createComboBoxButton(Presentation presentation) { if (myShowDisabledActions) { return new ComboBoxButton(presentation) { @Override protected JBPopup createPopup(Runnable onDispose) { ListPopup popup = JBPopupFactory.getInstance().createActionGroupPopup( null, createPopupActionGroup(this), getDataContext(), JBPopupFactory.ActionSelectionAid.SPEEDSEARCH, true, onDispose, getMaxRows()); popup.setMinimumSize(new Dimension(getMinWidth(), getMinHeight())); return popup; } }; } return super.createComboBoxButton(presentation); }
private static void showHintPopUp(Project project, StudyState studyState, Editor editor, StudyToolWindow hintComponent) { final JBPopup popup = JBPopupFactory.getInstance().createComponentPopupBuilder(hintComponent, hintComponent) .setDimensionServiceKey(project, "StudyHint", false) .setResizable(true) .setMovable(true) .setRequestFocus(true) .setTitle(studyState.getTask().getName()) .createPopup(); Disposer.register(popup, hintComponent); final Component focusOwner = IdeFocusManager.getInstance(project).getFocusOwner(); DataContext dataContext = DataManager.getInstance().getDataContext(focusOwner); PopupPositionManager.positionPopupInBestPosition(popup, editor, dataContext); }
@Override public void invoke(@NotNull Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException { // filter libraries to only be Camel libraries Set<String> artifacts = ServiceManager.getService(project, CamelService.class).getLibraries(); // find the camel component from those libraries boolean consumerOnly = getCamelIdeaUtils().isConsumerEndpoint(element); List<String> names = findCamelComponentNamesInArtifact(artifacts, consumerOnly, project); // no camel endpoints then exit if (names.isEmpty()) { return; } // show popup to chose the component JBList list = new JBList(names.toArray(new Object[names.size()])); PopupChooserBuilder builder = JBPopupFactory.getInstance().createListPopupBuilder(list); builder.setAdText(names.size() + " components"); builder.setTitle("Add Camel Endpoint"); builder.setItemChoosenCallback(() -> { String line = (String) list.getSelectedValue(); int pos = editor.getCaretModel().getCurrentCaret().getOffset(); if (pos > 0) { // must run this as write action because we change the source code new WriteCommandAction(project, element.getContainingFile()) { @Override protected void run(@NotNull Result result) throws Throwable { String text = line + ":"; editor.getDocument().insertString(pos, text); editor.getCaretModel().moveToOffset(pos + text.length()); } }.execute(); } }); JBPopup popup = builder.createPopup(); popup.showInBestPositionFor(editor); }
@Override public void invoke(@NotNull final Project project, @Nullable final Editor editor, PsiFile file) { if (myModules.size() == 1) { addDependencyOnModule(project, editor, ContainerUtil.getFirstItem(myModules)); } else { final JBList list = new JBList(myModules); list.setCellRenderer(new ModuleListCellRenderer()); final JBPopup popup = JBPopupFactory.getInstance().createListPopupBuilder(list) .setTitle("Choose Module to Add Dependency on") .setMovable(false) .setResizable(false) .setRequestFocus(true) .setItemChoosenCallback(new Runnable() { @Override public void run() { final Object value = list.getSelectedValue(); if (value instanceof Module) { addDependencyOnModule(project, editor, (Module)value); } } }).createPopup(); if (editor != null) { popup.showInBestPositionFor(editor); } else { popup.showCenteredInCurrentWindow(project); } } }
public static String getDocumentationText(@NotNull PsiFile psiFile, int caretPosition) throws InterruptedException { Project project = psiFile.getProject(); Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile); assertNotNull(document); Editor editor = EditorFactory.getInstance().createEditor(document, project); try { if (caretPosition >= 0) { editor.getCaretModel().moveToOffset(caretPosition); } DocumentationManager documentationManager = DocumentationManager.getInstance(project); MockDocumentationComponent documentationComponent = new MockDocumentationComponent(documentationManager); try { documentationManager.setDocumentationComponent(documentationComponent); documentationManager.showJavaDocInfo(editor, psiFile, false); waitTillDone(documentationManager.getLastAction()); return documentationComponent.getText(); } finally { JBPopup hint = documentationComponent.getHint(); if (hint != null) Disposer.dispose(hint); Disposer.dispose(documentationComponent); } } finally { EditorFactory.getInstance().releaseEditor(editor); } }
public static JBPopup getPopupContainerFor(@Nullable Component c) { if (c == null) return null; final Window wnd = SwingUtilities.getWindowAncestor(c); if (wnd instanceof JWindow) { final JRootPane root = ((JWindow)wnd).getRootPane(); return (JBPopup)root.getClientProperty(JBPopup.KEY); } return null; }
@Override public void eventDispatched(AWTEvent event) { if (event.getID() == WindowEvent.WINDOW_OPENED) { final WindowEvent we = (WindowEvent)event; final List<JBPopup> popups = JBPopupFactory.getInstance().getChildPopups(this); if (popups != null) { for (JBPopup each : popups) { if (each.getContent() != null && SwingUtilities.isDescendingFrom(each.getContent(), we.getWindow())) { super.setPopupVisible(false); } } } } }
protected JBPopup createPopup(Runnable onDispose) { DefaultActionGroup group = createPopupActionGroup(this); DataContext context = getDataContext(); ListPopup popup = JBPopupFactory.getInstance().createActionGroupPopup( myPopupTitle, group, context, false, shouldShowDisabledActions(), false, onDispose, getMaxRows(), getPreselectCondition()); popup.setMinimumSize(new Dimension(getMinWidth(), getMinHeight())); return popup; }
private JBPopup createPopup() { return JBPopupFactory.getInstance(). createComponentPopupBuilder(this, myList). setCancelOnClickOutside(true). setCancelOnWindowDeactivation(true). setFocusable(true). setRequestFocus(true). setResizable(true). setDimensionServiceKey(myUi.getProject(), "Vcs.Log.Branch.Panel.RefGroup.Popup", false). createPopup(); }
@Override public void actionPerformed(@NotNull AnActionEvent e) { Project project = e.getProject(); if (project == null) { return; } Filter filter = myFilterModel.getFilter(); final MultilinePopupBuilder popupBuilder = new MultilinePopupBuilder(project, myVariants, getPopupText(getTextValues(filter)), supportsNegativeValues()); JBPopup popup = popupBuilder.createPopup(); popup.addListener(new JBPopupAdapter() { @Override public void onClosed(LightweightWindowEvent event) { if (event.isOk()) { Collection<String> selectedValues = popupBuilder.getSelectedValues(); if (selectedValues.isEmpty()) { myFilterModel.setFilter(null); } else { myFilterModel.setFilter(createFilter(selectedValues)); rememberValuesInSettings(selectedValues); } } } }); popup.showUnderneathOf(MultipleValueFilterPopupComponent.this); }
private void showPopup() { IdeEventQueue.getInstance().getPopupManager().closeAllPopups(); ArrayList<String> names = new ArrayList<String>(); for (Pair<String, JComponent> tab : myContent.getTabs()) { names.add(tab.first); } final JBList list = new JBList(names); list.installCellRenderer(new NotNullFunction<Object, JComponent>() { final JLabel label = new JLabel(); { label.setBorder(new EmptyBorder(UIUtil.getListCellPadding())); } @NotNull @Override public JComponent fun(Object dom) { label.setText(dom.toString()); return label; } }); final JBPopup popup = JBPopupFactory.getInstance().createListPopupBuilder(list) .setItemChoosenCallback(new Runnable() { @Override public void run() { int index = list.getSelectedIndex(); if (index != -1) { myContent.selectContent(index); } } }).createPopup(); Disposer.register(this, popup); popup.showUnderneathOf(this); }
@Override public Component getFocusedDescendantFor(Component comp) { final Component focused = getFocusOwner(); if (focused == null) return null; if (focused == comp || SwingUtilities.isDescendingFrom(focused, comp)) return focused; List<JBPopup> popups = FocusTrackback.getChildPopups(comp); for (JBPopup each : popups) { if (each.isFocused()) return focused; } return null; }
@Override public void onPopupShown(JBPopup popup, boolean inStack) { if (inStack) { myStack.push(popup); if (ApplicationManager.getApplication() != null) { IdeEventQueue.getInstance().getPopupManager().push(getInstance()); } } else if (popup.isPersistent()) { myPersistentPopups.add(popup); } myAllPopups.add(popup); }
@Override public void onPopupHidden(JBPopup popup) { boolean wasInStack = myStack.remove(popup); myPersistentPopups.remove(popup); if (wasInStack && myStack.isEmpty()) { if (ApplicationManager.getApplication() != null) { IdeEventQueue.getInstance().getPopupManager().remove(this); } } myAllPopups.remove(popup); }
@Override public void hidePersistentPopups() { List<JBPopup> list = myPersistentPopups; for (JBPopup each : list) { if (each.isNativePopup()) { each.setUiVisible(false); } } }
@Override public void restorePersistentPopups() { List<JBPopup> list = myPersistentPopups; for (JBPopup each : list) { if (each.isNativePopup()) { each.setUiVisible(true); } } }
@Override protected JBPopup findPopup() { while(true) { if (myStack.isEmpty()) break; final AbstractPopup each = (AbstractPopup)myStack.peek(); if (each == null || each.isDisposed()) { myStack.pop(); } else { return each; } } return null; }
@Override public boolean dispatchKeyEvent(final KeyEvent e) { final boolean closeRequest = AbstractPopup.isCloseRequest(e); JBPopup popup = closeRequest ? findPopup() : getFocusedPopup(); return popup != null && popup.dispatchKeyEvent(e); }
@Override public void setRestoreFocusSilentely() { if (myStack.isEmpty()) return; for (JBPopup each : myAllPopups) { if (each instanceof AbstractPopup) { ((AbstractPopup)each).setOk(true); } } }
public PopupComponent getPopup(Component owner, Component content, int x, int y, JBPopup jbPopup) { if (OurHeavyWeightPopup.isEnabled()) { return new AwtPopupWrapper(new OurHeavyWeightPopup(owner, content, x, y), jbPopup); } final PopupFactory factory = PopupFactory.getSharedInstance(); final int oldType = PopupUtil.getPopupType(factory); PopupUtil.setPopupType(factory, 2); final Popup popup = factory.getPopup(owner, content, x, y); if (oldType >= 0) PopupUtil.setPopupType(factory, oldType); return new AwtPopupWrapper(popup, jbPopup); }
public void hide(boolean dispose) { myDialog.setVisible(false); if (dispose) { myDialog.dispose(); myDialog.getRootPane().putClientProperty(JBPopup.KEY, null); } }
public JComponent createCustomComponent(final Presentation presentation) { ComboBoxButton button = new ComboBoxButton(presentation) { @Override protected JBPopup createPopup(Runnable onDispose) { return SwitchTaskAction.createPopup(DataManager.getInstance().getDataContext(this), onDispose, false); } }; button.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 2)); return button; }