@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 void show() { // final long time = System.currentTimeMillis(); JComponent panel = createCenterPanel(); new MnemonicHelper().register(panel); boolean shouldSetWidth = DimensionService.getInstance().getSize(getDimensionServiceKey(), myProject) == null; myPopup = JBPopupFactory.getInstance() .createComponentPopupBuilder(panel, null) .setTitle(myTitle) .setResizable(true) .setModalContext(false) .setFocusable(true) .setMovable(true) .setBelongsToGlobalPopupStack(true) // .setCancelOnClickOutside(false) //for debug and snapshots .setCancelKeyEnabled(false) .setDimensionServiceKey(null, getDimensionServiceKey(), false) .setCancelCallback( new Computable<Boolean>() { @Override public Boolean compute() { DimensionService.getInstance() .setLocation( getDimensionServiceKey(), myPopup.getLocationOnScreen(), myProject); return true; } }) .createPopup(); myTree.addTreeSelectionListener( new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { if (myPopup.isVisible()) { final PopupUpdateProcessor updateProcessor = myPopup.getUserData(PopupUpdateProcessor.class); if (updateProcessor != null) { final AbstractTreeNode node = getSelectedNode(); updateProcessor.updatePopup(node); } } } }); Disposer.register(myPopup, this); Disposer.register( myPopup, new Disposable() { @Override public void dispose() { if (!myTreeHasBuilt.isDone()) { myTreeHasBuilt.setRejected(); } } }); myTree.getEmptyText().setText("Loading..."); final Point location = DimensionService.getInstance().getLocation(getDimensionServiceKey(), myProject); if (location != null) { myPopup.showInScreenCoordinates(myEditor.getContentComponent(), location); } else { myPopup.showCenteredInCurrentWindow(myProject); } ((AbstractPopup) myPopup).setShowHints(true); if (shouldSetWidth) { myPopup.setSize(new Dimension(myPreferredWidth + 10, myPopup.getSize().height)); } IdeFocusManager.getInstance(myProject).requestFocus(myTree, true); ApplicationManager.getApplication() .executeOnPooledThread( new Runnable() { @Override public void run() { final AccessToken token = ApplicationManager.getApplication().acquireReadActionLock(); try { myFilteringStructure.rebuild(); } finally { token.finish(); } SwingUtilities.invokeLater( new Runnable() { @Override public void run() { myAbstractTreeBuilder .queueUpdate() .doWhenDone( new Runnable() { @Override public void run() { myTreeHasBuilt.setDone(); //noinspection SSBasedInspection SwingUtilities.invokeLater( new Runnable() { @Override public void run() { selectPsiElement(myInitialPsiElement); } }); } }); } }); installUpdater(); } }); }