use of com.intellij.openapi.ui.popup.JBPopup in project intellij-community by JetBrains.
the class Utils method showCompletionPopup.
public static void showCompletionPopup(JComponent toolbarComponent, final JList list, String title, final JTextComponent textField, String ad) {
final Runnable callback = () -> {
String selectedValue = (String) list.getSelectedValue();
if (selectedValue != null) {
textField.setText(selectedValue);
}
};
final PopupChooserBuilder builder = JBPopupFactory.getInstance().createListPopupBuilder(list);
if (title != null) {
builder.setTitle(title);
}
final JBPopup popup = builder.setMovable(false).setResizable(false).setRequestFocus(true).setItemChoosenCallback(callback).createPopup();
if (ad != null) {
popup.setAdText(ad, SwingConstants.LEFT);
}
if (toolbarComponent != null) {
popup.showUnderneathOf(toolbarComponent);
} else {
popup.showUnderneathOf(textField);
}
}
use of com.intellij.openapi.ui.popup.JBPopup in project intellij-community by JetBrains.
the class SearchEverywhereAction method resetFields.
protected void resetFields() {
if (myBalloon != null) {
final JBPopup balloonToBeCanceled = myBalloon;
//noinspection SSBasedInspection
SwingUtilities.invokeLater(() -> balloonToBeCanceled.cancel());
myBalloon = null;
}
myCurrentWorker.doWhenProcessed(() -> {
myFileModel = null;
if (myFileChooseByName != null) {
myFileChooseByName.close(false);
myFileChooseByName = null;
}
if (myClassChooseByName != null) {
myClassChooseByName.close(false);
myClassChooseByName = null;
}
if (mySymbolsChooseByName != null) {
mySymbolsChooseByName.close(false);
mySymbolsChooseByName = null;
}
final Object lock = myCalcThread;
if (lock != null) {
synchronized (lock) {
myClassModel = null;
myActionProvider = null;
mySymbolsModel = null;
myConfigurables.clear();
myFocusComponent = null;
myContextComponent = null;
myFocusOwner = null;
myRenderer.myProject = null;
myPopup = null;
myHistoryIndex = 0;
myPopupActualWidth = 0;
myCurrentWorker = ActionCallback.DONE;
showAll.set(false);
myCalcThread = null;
myEditor = null;
myFileEditor = null;
myStructureModel = null;
myDisabledActions.clear();
}
}
});
mySkipFocusGain = false;
}
use of com.intellij.openapi.ui.popup.JBPopup in project intellij-community by JetBrains.
the class GotoTargetHandler method show.
private void show(@NotNull final Project project, @NotNull Editor editor, @NotNull PsiFile file, @NotNull final GotoData gotoData) {
final PsiElement[] targets = gotoData.targets;
final List<AdditionalAction> additionalActions = gotoData.additionalActions;
if (targets.length == 0 && additionalActions.isEmpty()) {
HintManager.getInstance().showErrorHint(editor, getNotFoundMessage(project, editor, file));
return;
}
boolean finished = gotoData.listUpdaterTask == null || gotoData.listUpdaterTask.isFinished();
if (targets.length == 1 && additionalActions.isEmpty() && finished) {
navigateToElement(targets[0]);
return;
}
for (PsiElement eachTarget : targets) {
gotoData.renderers.put(eachTarget, createRenderer(gotoData, eachTarget));
}
final String name = ((PsiNamedElement) gotoData.source).getName();
final String title = getChooserTitle(gotoData.source, name, targets.length, finished);
if (shouldSortTargets()) {
Arrays.sort(targets, createComparator(gotoData.renderers, gotoData));
}
List<Object> allElements = new ArrayList<>(targets.length + additionalActions.size());
Collections.addAll(allElements, targets);
allElements.addAll(additionalActions);
final JBList list = new JBList(new CollectionListModel<>(allElements));
HintUpdateSupply.installSimpleHintUpdateSupply(list);
list.setFont(EditorUtil.getEditorFont());
list.setCellRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
if (value == null)
return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (value instanceof AdditionalAction) {
return myActionElementRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
}
PsiElementListCellRenderer renderer = getRenderer(value, gotoData.renderers, gotoData);
return renderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
}
});
final Runnable runnable = () -> {
int[] ids = list.getSelectedIndices();
if (ids == null || ids.length == 0)
return;
Object[] selectedElements = list.getSelectedValues();
for (Object element : selectedElements) {
if (element instanceof AdditionalAction) {
((AdditionalAction) element).execute();
} else {
Navigatable nav = element instanceof Navigatable ? (Navigatable) element : EditSourceUtil.getDescriptor((PsiElement) element);
try {
if (nav != null && nav.canNavigate()) {
navigateToElement(nav);
}
} catch (IndexNotReadyException e) {
DumbService.getInstance(project).showDumbModeNotification("Navigation is not available while indexing");
}
}
}
};
final PopupChooserBuilder builder = new PopupChooserBuilder(list);
builder.setFilteringEnabled(o -> {
if (o instanceof AdditionalAction) {
return ((AdditionalAction) o).getText();
}
return getRenderer(o, gotoData.renderers, gotoData).getElementText((PsiElement) o);
});
final Ref<UsageView> usageView = new Ref<>();
final JBPopup popup = builder.setTitle(title).setItemChoosenCallback(runnable).setMovable(true).setCancelCallback(() -> {
HintUpdateSupply.hideHint(list);
final ListBackgroundUpdaterTask task = gotoData.listUpdaterTask;
if (task != null) {
task.cancelTask();
}
return true;
}).setCouldPin(popup1 -> {
usageView.set(FindUtil.showInUsageView(gotoData.source, gotoData.targets, getFindUsagesTitle(gotoData.source, name, gotoData.targets.length), gotoData.source.getProject()));
popup1.cancel();
return false;
}).setAdText(getAdText(gotoData.source, targets.length)).createPopup();
builder.getScrollPane().setBorder(null);
builder.getScrollPane().setViewportBorder(null);
if (gotoData.listUpdaterTask != null) {
Alarm alarm = new Alarm(popup);
alarm.addRequest(() -> popup.showInBestPositionFor(editor), 300);
gotoData.listUpdaterTask.init((AbstractPopup) popup, list, usageView);
ProgressManager.getInstance().run(gotoData.listUpdaterTask);
} else {
popup.showInBestPositionFor(editor);
}
}
use of com.intellij.openapi.ui.popup.JBPopup in project intellij-community by JetBrains.
the class FindPopupPanel method showUI.
public void showUI() {
if (myBalloon != null && myBalloon.isVisible()) {
return;
}
if (myBalloon != null && !myBalloon.isDisposed()) {
myBalloon.cancel();
}
if (myBalloon == null || myBalloon.isDisposed()) {
final ComponentPopupBuilder builder = JBPopupFactory.getInstance().createComponentPopupBuilder(this, mySearchComponent);
myBalloon = builder.setProject(myHelper.getProject()).setMovable(true).setResizable(true).setMayBeParent(true).setCancelOnClickOutside(true).setModalContext(false).setRequestFocus(true).setCancelCallback(() -> {
if (!myCanClose.get())
return false;
if (!ApplicationManager.getApplication().isActive())
return false;
List<JBPopup> popups = JBPopupFactory.getInstance().getChildPopups(this);
if (!popups.isEmpty()) {
for (JBPopup popup : popups) {
popup.cancel();
}
return false;
}
if (myScopeUI.hideAllPopups()) {
return false;
}
DimensionService.getInstance().setSize(SERVICE_KEY, myBalloon.getSize(), myHelper.getProject());
DimensionService.getInstance().setLocation(SERVICE_KEY, myBalloon.getLocationOnScreen(), myHelper.getProject());
return true;
}).createPopup();
Disposer.register(myBalloon, myDisposable);
registerCloseAction(myBalloon);
final Window window = WindowManager.getInstance().suggestParentWindow(myProject);
Component parent = UIUtil.findUltimateParent(window);
RelativePoint showPoint = null;
Point screenPoint = DimensionService.getInstance().getLocation(SERVICE_KEY);
if (screenPoint != null) {
showPoint = new RelativePoint(screenPoint);
}
if (parent != null && showPoint == null) {
int height = UISettings.getInstance().getShowNavigationBar() ? 135 : 115;
if (parent instanceof IdeFrameImpl && ((IdeFrameImpl) parent).isInFullScreen()) {
height -= 20;
}
showPoint = new RelativePoint(parent, new Point((parent.getSize().width - getPreferredSize().width) / 2, height));
}
mySearchComponent.selectAll();
WindowMoveListener windowListener = new WindowMoveListener(this);
myTitleLabel.addMouseListener(windowListener);
myTitleLabel.addMouseMotionListener(windowListener);
Dimension panelSize = getPreferredSize();
Dimension prev = DimensionService.getInstance().getSize(SERVICE_KEY);
if (!myCbPreserveCase.isVisible()) {
panelSize.width += myCbPreserveCase.getPreferredSize().width + 8;
}
panelSize.height *= 2;
if (prev != null && prev.height < panelSize.height)
prev.height = panelSize.height;
myBalloon.setMinimumSize(panelSize);
if (prev == null)
panelSize.height = panelSize.height * 3 / 2;
myBalloon.setSize(prev != null ? prev : panelSize);
if (showPoint != null && showPoint.getComponent() != null) {
myBalloon.show(showPoint);
} else {
myBalloon.showCenteredInCurrentWindow(myProject);
}
}
}
use of com.intellij.openapi.ui.popup.JBPopup in project intellij-community by JetBrains.
the class RegExHelpPopup method createRegExLinkRunnable.
@NotNull
public static Runnable createRegExLinkRunnable(@Nullable final Component owner, @Nullable final Logger logger) {
return new Runnable() {
JBPopup helpPopup;
@Override
public void run() {
try {
if (helpPopup != null && !helpPopup.isDisposed() && helpPopup.isVisible()) {
return;
}
helpPopup = createRegExHelpPopup();
Disposer.register(helpPopup, new Disposable() {
@Override
public void dispose() {
destroyPopup();
}
});
if (owner != null) {
helpPopup.showInCenterOf(owner);
} else {
helpPopup.showInFocusCenter();
}
} catch (BadLocationException ex) {
if (logger != null)
logger.info(ex);
}
}
private void destroyPopup() {
helpPopup = null;
}
};
}
Aggregations