private static boolean showPopupIfNeedTo( @NotNull JBPopup popup, @NotNull RelativePoint popupPosition) { if (!popup.isDisposed() && !popup.isVisible()) { popup.show(popupPosition); return true; } else { return false; } }
@Nullable private JBPopup getOldHector() { if (myHectorRef == null) return null; final JBPopup hector = myHectorRef.get(); if (hector == null || !hector.isVisible()) { myHectorRef = null; return null; } return hector; }
@Override public boolean isVisible() { if (myIsRealPopup) { return myPopup != null && myPopup.isVisible(); } if (myCurrentIdeTooltip != null) { return myComponent.isShowing() || IdeTooltipManager.getInstance().isQueuedToShow(myCurrentIdeTooltip); } return myComponent.isShowing(); }
protected void showPopup() { if (myPopup == null || !myPopup.isVisible()) { final JList list = new JBList(myModel); final Runnable chooseRunnable = createItemChosenCallback(list); myPopup = JBPopupFactory.getInstance() .createListPopupBuilder(list) .setMovable(false) .setRequestFocus(true) .setItemChoosenCallback(chooseRunnable) .createPopup(); if (isShowing()) { myPopup.showUnderneathOf(getPopupLocationComponent()); } } }
// Event forwarding. We need it if user does press-and-drag gesture for opening popup and // choosing item there. // It works in JComboBox, here we provide the same behavior private void dispatchEventToPopup(MouseEvent e) { if (myPopup != null && myPopup.isVisible()) { JComponent content = myPopup.getContent(); Rectangle rectangle = content.getBounds(); Point location = rectangle.getLocation(); SwingUtilities.convertPointToScreen(location, content); Point eventPoint = e.getLocationOnScreen(); rectangle.setLocation(location); if (rectangle.contains(eventPoint)) { MouseEvent event = SwingUtilities.convertMouseEvent(e.getComponent(), e, myPopup.getContent()); Component component = SwingUtilities.getDeepestComponentAt(content, event.getX(), event.getY()); if (component != null) component.dispatchEvent(event); } } }
@Override public void actionPerformed(@NotNull AnActionEvent e) { final Project project = e.getProject(); if (project == null) return; if (myPopup != null && myPopup.isVisible()) return; final JBList list = new JBList(buildModel(project)); EditBookmarkDescriptionAction editDescriptionAction = new EditBookmarkDescriptionAction(project, list); DefaultActionGroup actions = new DefaultActionGroup(); actions.add(editDescriptionAction); actions.add(new DeleteBookmarkAction(project, list)); actions.add(new ToggleSortBookmarksAction()); actions.add(new MoveBookmarkUpAction(project, list)); actions.add(new MoveBookmarkDownAction(project, list)); myPopup = new MasterDetailPopupBuilder(project) .setList(list) .setDelegate(this) .setDetailView(new DetailViewImpl(project)) .setDimensionServiceKey("bookmarks") .setAddDetailViewToEast(true) .setActionsGroup(actions) .setPopupTuner( new Consumer<PopupChooserBuilder>() { @Override public void consume(PopupChooserBuilder builder) { builder.setCloseOnEnter(false).setCancelOnClickOutside(false); } }) .setDoneRunnable( new Runnable() { @Override public void run() { myPopup.cancel(); } }) .createMasterDetailPopup(); new AnAction() { @Override public void actionPerformed(AnActionEvent e) { @SuppressWarnings("deprecation") Object[] values = list.getSelectedValues(); for (Object item : values) { if (item instanceof BookmarkItem) { itemChosen((BookmarkItem) item, project, myPopup, true); } } } }.registerCustomShortcutSet(CommonShortcuts.getEditSource(), list); editDescriptionAction.setPopup(myPopup); myPopup.showCenteredInCurrentWindow(project); list.getEmptyText().setText("No Bookmarks"); list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); project .getMessageBus() .connect(myPopup) .subscribe( BookmarksListener.TOPIC, new BookmarksListener() { @Override public void bookmarkAdded(@NotNull Bookmark b) {} @Override public void bookmarkRemoved(@NotNull Bookmark b) {} @Override public void bookmarkChanged(@NotNull Bookmark b) {} @Override public void bookmarksOrderChanged() { doUpdate(); } private void doUpdate() { TreeSet selectedValues = new TreeSet(Arrays.asList(list.getSelectedValues())); DefaultListModel listModel = buildModel(project); list.setModel(listModel); ListSelectionModel selectionModel = list.getSelectionModel(); for (int i = 0; i < listModel.getSize(); i++) { if (selectedValues.contains(listModel.get(i))) { selectionModel.addSelectionInterval(i, i); } } } }); }
@Override public boolean isPopupDisplayed() { return myCurrentPopup != null && myCurrentPopup.isVisible(); }
void hidePopup() { if (myPopup != null && myPopup.isVisible()) { myPopup.cancel(); } }