use of com.intellij.openapi.ui.popup.JBPopup in project intellij-community by JetBrains.
the class ImageDuplicateResultsDialog method createCenterPanel.
@Override
protected JComponent createCenterPanel() {
final JPanel panel = new JPanel(new BorderLayout());
DataManager.registerDataProvider(panel, new DataProvider() {
@Override
public Object getData(@NonNls String dataId) {
final TreePath path = myTree.getSelectionPath();
if (path != null) {
Object component = path.getLastPathComponent();
VirtualFile file = null;
if (component instanceof MyFileNode) {
component = ((MyFileNode) component).getParent();
}
if (component instanceof MyDuplicatesNode) {
file = ((MyDuplicatesNode) component).getUserObject().iterator().next();
}
if (CommonDataKeys.VIRTUAL_FILE.is(dataId)) {
return file;
}
if (CommonDataKeys.VIRTUAL_FILE_ARRAY.is(dataId) && file != null) {
return new VirtualFile[] { file };
}
}
return null;
}
});
final JBList list = new JBList(new ResourceModules().getModuleNames());
final NotNullFunction<Object, JComponent> modulesRenderer = dom -> new JLabel(dom instanceof Module ? ((Module) dom).getName() : dom.toString(), PlatformIcons.SOURCE_FOLDERS_ICON, SwingConstants.LEFT);
list.installCellRenderer(modulesRenderer);
final JPanel modulesPanel = ToolbarDecorator.createDecorator(list).setAddAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
final Module[] all = ModuleManager.getInstance(myProject).getModules();
Arrays.sort(all, (o1, o2) -> o1.getName().compareTo(o2.getName()));
final JBList modules = new JBList(all);
modules.installCellRenderer(modulesRenderer);
JBPopupFactory.getInstance().createListPopupBuilder(modules).setTitle("Add Resource Module").setFilteringEnabled(o -> ((Module) o).getName()).setItemChoosenCallback(() -> {
final Object value = modules.getSelectedValue();
if (value instanceof Module && !myResourceModules.contains((Module) value)) {
myResourceModules.add((Module) value);
((DefaultListModel) list.getModel()).addElement(((Module) value).getName());
}
((DefaultTreeModel) myTree.getModel()).reload();
TreeUtil.expandAll(myTree);
}).createPopup().show(button.getPreferredPopupPoint());
}
}).setRemoveAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
final Object[] values = list.getSelectedValues();
for (Object value : values) {
myResourceModules.remove((String) value);
((DefaultListModel) list.getModel()).removeElement(value);
}
((DefaultTreeModel) myTree.getModel()).reload();
TreeUtil.expandAll(myTree);
}
}).disableDownAction().disableUpAction().createPanel();
modulesPanel.setPreferredSize(new Dimension(-1, 60));
final JPanel top = new JPanel(new BorderLayout());
top.add(new JLabel("Image modules:"), BorderLayout.NORTH);
top.add(modulesPanel, BorderLayout.CENTER);
panel.add(top, BorderLayout.NORTH);
panel.add(new JBScrollPane(myTree), BorderLayout.CENTER);
new AnAction() {
@Override
public void actionPerformed(AnActionEvent e) {
VirtualFile file = getFileFromSelection();
if (file != null) {
final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file);
if (psiFile != null) {
final ImplementationViewComponent viewComponent = new ImplementationViewComponent(new PsiElement[] { psiFile }, 0);
final TreeSelectionListener listener = new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
final VirtualFile selection = getFileFromSelection();
if (selection != null) {
final PsiFile newElement = PsiManager.getInstance(myProject).findFile(selection);
if (newElement != null) {
viewComponent.update(new PsiElement[] { newElement }, 0);
}
}
}
};
myTree.addTreeSelectionListener(listener);
final JBPopup popup = JBPopupFactory.getInstance().createComponentPopupBuilder(viewComponent, viewComponent.getPreferredFocusableComponent()).setProject(myProject).setDimensionServiceKey(myProject, ImageDuplicateResultsDialog.class.getName(), false).setResizable(true).setMovable(true).setRequestFocus(false).setCancelCallback(() -> {
myTree.removeTreeSelectionListener(listener);
return true;
}).setTitle("Image Preview").createPopup();
final Window window = ImageDuplicateResultsDialog.this.getWindow();
popup.show(new RelativePoint(window, new Point(window.getWidth(), 0)));
viewComponent.setHint(popup, "Image Preview");
}
}
}
}.registerCustomShortcutSet(CustomShortcutSet.fromString("ENTER"), panel);
int total = myDuplicates.values().stream().mapToInt(Set::size).sum() - myDuplicates.size();
final JLabel label = new JLabel("<html>Press <b>Enter</b> to preview image<br>Total images found: " + myImages.size() + ". Total duplicates found: " + total + "</html>");
panel.add(label, BorderLayout.SOUTH);
return panel;
}
use of com.intellij.openapi.ui.popup.JBPopup in project intellij-community by JetBrains.
the class DocumentationManager method doShowJavaDocInfo.
private void doShowJavaDocInfo(@NotNull final PsiElement element, boolean requestFocus, PopupUpdateProcessor updateProcessor, final PsiElement originalElement, @Nullable final Runnable closeCallback) {
Project project = getProject(element);
if (!project.isOpen())
return;
storeOriginalElement(project, originalElement, element);
myPreviouslyFocused = WindowManagerEx.getInstanceEx().getFocusedComponent(project);
JBPopup _oldHint = getDocInfoHint();
if (PreviewManager.SERVICE.preview(myProject, DocumentationPreviewPanelProvider.ID, Couple.of(element, originalElement), requestFocus) != null) {
return;
}
if (myToolWindow == null && PropertiesComponent.getInstance().isTrueValue(SHOW_DOCUMENTATION_IN_TOOL_WINDOW)) {
createToolWindow(element, originalElement);
} else if (myToolWindow != null) {
Content content = myToolWindow.getContentManager().getSelectedContent();
if (content != null) {
DocumentationComponent component = (DocumentationComponent) content.getComponent();
boolean sameElement = element.getManager().areElementsEquivalent(component.getElement(), element);
if (sameElement) {
JComponent preferredFocusableComponent = content.getPreferredFocusableComponent();
// focus toolwindow on the second actionPerformed
boolean focus = requestFocus || CommandProcessor.getInstance().getCurrentCommand() != null;
if (preferredFocusableComponent != null && focus) {
IdeFocusManager.getInstance(myProject).requestFocus(preferredFocusableComponent, true);
}
}
if (!sameElement || !component.isUpToDate()) {
content.setDisplayName(getTitle(element, true));
fetchDocInfo(getDefaultCollector(element, originalElement), component, true);
}
}
if (!myToolWindow.isVisible()) {
myToolWindow.show(null);
}
} else if (_oldHint != null && _oldHint.isVisible() && _oldHint instanceof AbstractPopup) {
DocumentationComponent oldComponent = (DocumentationComponent) ((AbstractPopup) _oldHint).getComponent();
fetchDocInfo(getDefaultCollector(element, originalElement), oldComponent);
} else {
showInPopup(element, requestFocus, updateProcessor, originalElement, closeCallback);
}
}
use of com.intellij.openapi.ui.popup.JBPopup in project intellij-community by JetBrains.
the class ProjectStartupConfigurable method selectAndAddConfiguration.
private void selectAndAddConfiguration(final AnActionButton button) {
final Executor executor = DefaultRunExecutor.getRunExecutorInstance();
final List<ChooseRunConfigurationPopup.ItemWrapper> wrappers = new ArrayList<>();
wrappers.add(createNewWrapper(button));
final ChooseRunConfigurationPopup.ItemWrapper[] allSettings = ChooseRunConfigurationPopup.createSettingsList(myProject, new ExecutorProvider() {
@Override
public Executor getExecutor() {
return executor;
}
}, false);
final Set<RunnerAndConfigurationSettings> existing = new HashSet<>(myModel.getAllConfigurations());
for (ChooseRunConfigurationPopup.ItemWrapper setting : allSettings) {
if (setting.getValue() instanceof RunnerAndConfigurationSettings) {
final RunnerAndConfigurationSettings settings = (RunnerAndConfigurationSettings) setting.getValue();
if (!settings.isTemporary() && ProjectStartupRunner.canBeRun(settings) && !existing.contains(settings)) {
wrappers.add(setting);
}
}
}
final JBList list = new JBList(wrappers);
list.setCellRenderer(new ColoredListCellRenderer() {
@Override
protected void customizeCellRenderer(@NotNull JList list, Object value, int index, boolean selected, boolean hasFocus) {
if (value instanceof ChooseRunConfigurationPopup.ItemWrapper) {
setIcon(((ChooseRunConfigurationPopup.ItemWrapper) value).getIcon());
append(((ChooseRunConfigurationPopup.ItemWrapper) value).getText());
}
}
});
final JBPopup popup = JBPopupFactory.getInstance().createListPopupBuilder(list).setItemChoosenCallback(() -> {
final int index = list.getSelectedIndex();
if (index < 0)
return;
final ChooseRunConfigurationPopup.ItemWrapper at = (ChooseRunConfigurationPopup.ItemWrapper) list.getModel().getElementAt(index);
if (at.getValue() instanceof RunnerAndConfigurationSettings) {
final RunnerAndConfigurationSettings added = (RunnerAndConfigurationSettings) at.getValue();
addConfiguration(added);
} else {
at.perform(myProject, executor, button.getDataContext());
}
}).createPopup();
showPopup(button, popup);
}
use of com.intellij.openapi.ui.popup.JBPopup in project intellij-community by JetBrains.
the class ToggleBookmarkWithMnemonicAction method actionPerformed.
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
super.actionPerformed(e);
final Project project = e.getProject();
if (project == null)
return;
final BookmarkInContextInfo info = new BookmarkInContextInfo(e.getDataContext(), project).invoke();
final Bookmark bookmark = info.getBookmarkAtPlace();
final BookmarkManager bookmarks = BookmarkManager.getInstance(project);
if (bookmark != null) {
final JBPopup[] popup = new JBPopup[1];
MnemonicChooser mc = new MnemonicChooser() {
@Override
protected void onMnemonicChosen(char c) {
popup[0].cancel();
bookmarks.setMnemonic(bookmark, c);
}
@Override
protected void onCancelled() {
popup[0].cancel();
bookmarks.removeBookmark(bookmark);
}
@Override
protected boolean isOccupied(char c) {
return bookmarks.findBookmarkForMnemonic(c) != null;
}
};
popup[0] = JBPopupFactory.getInstance().createComponentPopupBuilder(mc, mc).setTitle("Bookmark Mnemonic").setFocusable(true).setRequestFocus(true).setMovable(false).setCancelKeyEnabled(false).setAdText(bookmarks.hasBookmarksWithMnemonics() ? (UIUtil.isUnderDarcula() ? "Brown" : "Yellow") + " cells are in use" : null).setResizable(false).createPopup();
popup[0].showInBestPositionFor(e.getDataContext());
}
}
use of com.intellij.openapi.ui.popup.JBPopup in project intellij-community by JetBrains.
the class CustomPopupFullValueEvaluator method evaluate.
@Override
public void evaluate(@NotNull final XFullValueEvaluationCallback callback) {
final T data = getData();
DebuggerUIUtil.invokeLater(() -> {
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)));
});
}
Aggregations