本文整理汇总了Java中com.intellij.openapi.ui.popup.PopupChooserBuilder类的典型用法代码示例。如果您正苦于以下问题:Java PopupChooserBuilder类的具体用法?Java PopupChooserBuilder怎么用?Java PopupChooserBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PopupChooserBuilder类属于com.intellij.openapi.ui.popup包,在下文中一共展示了PopupChooserBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: CustomFoldingRegionsPopup
import com.intellij.openapi.ui.popup.PopupChooserBuilder; //导入依赖的package包/类
CustomFoldingRegionsPopup(@NotNull Collection<FoldingDescriptor> descriptors,
@NotNull final Editor editor,
@NotNull final Project project) {
myEditor = editor;
myRegionsList = new JBList();
//noinspection unchecked
myRegionsList.setModel(new MyListModel(orderByPosition(descriptors)));
myRegionsList.setSelectedIndex(0);
final PopupChooserBuilder popupBuilder = JBPopupFactory.getInstance().createListPopupBuilder(myRegionsList);
myPopup = popupBuilder
.setTitle(IdeBundle.message("goto.custom.region.command"))
.setResizable(false)
.setMovable(false)
.setItemChoosenCallback(new Runnable() {
@Override
public void run() {
PsiElement navigationElement = getNavigationElement();
if (navigationElement != null) {
navigateTo(editor, navigationElement);
IdeDocumentHistory.getInstance(project).includeCurrentCommandAsNavigation();
}
}
}).createPopup();
}
示例2: installSpeedSearch
import com.intellij.openapi.ui.popup.PopupChooserBuilder; //导入依赖的package包/类
public void installSpeedSearch(PopupChooserBuilder builder, final boolean includeContainerText) {
builder.setFilteringEnabled(new Function<Object, String>() {
@Override
public String fun(Object o) {
if (o instanceof PsiElement) {
final String elementText = getElementText((T)o);
if (includeContainerText) {
return elementText + " " + getContainerText((T)o, elementText);
}
return elementText;
}
else {
return o.toString();
}
}
});
}
示例3: chooseAndImport
import com.intellij.openapi.ui.popup.PopupChooserBuilder; //导入依赖的package包/类
private void chooseAndImport(Editor editor) {
final JList list = new JBList(getCandidates().toArray(new PsiMethod[getCandidates().size()]));
list.setCellRenderer(new MethodCellRenderer(true));
new PopupChooserBuilder(list).
setTitle(QuickFixBundle.message("static.import.method.choose.method.to.import")).
setMovable(true).
setItemChoosenCallback(new Runnable() {
@Override
public void run() {
PsiMethod selectedValue = (PsiMethod)list.getSelectedValue();
if (selectedValue == null) return;
LOG.assertTrue(selectedValue.isValid());
doImport(selectedValue);
}
}).createPopup().
showInBestPositionFor(editor);
}
示例4: addSelectionListener
import com.intellij.openapi.ui.popup.PopupChooserBuilder; //导入依赖的package包/类
private void addSelectionListener() {
addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(final ListSelectionEvent e) {
if (getClientProperty(PopupChooserBuilder.SELECTED_BY_MOUSE_EVENT) != Boolean.TRUE) {
final Object[] selectedValues = ((JList)e.getSource()).getSelectedValues();
if (selectedValues.length != 1) return;
final PsiElement element = getPsiElementForHint(selectedValues[0]);
if (element != null && element.isValid()) {
updateHint(element);
}
}
}
});
}
示例5: addSelectionListener
import com.intellij.openapi.ui.popup.PopupChooserBuilder; //导入依赖的package包/类
private void addSelectionListener() {
addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(final TreeSelectionEvent e) {
if (isHintBeingShown() && getClientProperty(PopupChooserBuilder.SELECTED_BY_MOUSE_EVENT) != Boolean.TRUE) {
final TreePath path = getSelectionPath();
if (path != null) {
final PsiElement psiElement = getPsiElementForHint(path.getLastPathComponent());
if (psiElement != null && psiElement.isValid()) {
updateHint(psiElement);
}
}
}
}
});
}
示例6: addSelectionListener
import com.intellij.openapi.ui.popup.PopupChooserBuilder; //导入依赖的package包/类
private void addSelectionListener() {
getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(final ListSelectionEvent e) {
if (getClientProperty(PopupChooserBuilder.SELECTED_BY_MOUSE_EVENT) != Boolean.TRUE) {
final int selected = ((ListSelectionModel)e.getSource()).getLeadSelectionIndex();
int rowCount = getRowCount();
if (selected == -1 || rowCount == 0) return;
PsiElement element = getPsiElementForHint(getValueAt(Math.min(selected, rowCount -1), 0));
if (element != null && element.isValid()) {
updateHint(element);
}
}
}
});
}
示例7: chooseAndImport
import com.intellij.openapi.ui.popup.PopupChooserBuilder; //导入依赖的package包/类
private void chooseAndImport(Editor editor) {
final JList list = new JBList(getCandidates().toArray(new PsiMethod[getCandidates().size()]));
list.setCellRenderer(new MethodCellRenderer(true));
new PopupChooserBuilder(list).
setTitle(QuickFixBundle.message("static.import.method.choose.method.to.import")).
setMovable(true).
setItemChoosenCallback(new Runnable() {
public void run() {
PsiMethod selectedValue = (PsiMethod)list.getSelectedValue();
if (selectedValue == null) return;
LOG.assertTrue(selectedValue.isValid());
doImport(selectedValue);
}
}).createPopup().
showInBestPositionFor(editor);
}
示例8: actionPerformed
import com.intellij.openapi.ui.popup.PopupChooserBuilder; //导入依赖的package包/类
@Override
public void actionPerformed(AnActionEvent anActionEvent) {
final Document document = editor.getDocument();
CaretModel caretModel = editor.getCaretModel();
final int offset = caretModel.getOffset();
new PopupChooserBuilder(QUERY_OPERATOR_LIST)
.setMovable(false)
.setCancelKeyEnabled(true)
.setItemChoosenCallback(new Runnable() {
public void run() {
final String selectedQueryOperator = (String) QUERY_OPERATOR_LIST.getSelectedValue();
if (selectedQueryOperator == null) return;
new WriteCommandAction(project, MONGO_OPERATOR_COMPLETION) {
@Override
protected void run(@NotNull Result result) throws Throwable {
document.insertString(offset, selectedQueryOperator);
}
}.execute();
}
})
.createPopup()
.showInBestPositionFor(editor);
}
示例9: createAmbigTreesPopup
import com.intellij.openapi.ui.popup.PopupChooserBuilder; //导入依赖的package包/类
public static JBPopup createAmbigTreesPopup(final PreviewState previewState,
final AmbiguityInfo ambigInfo) {
final JBList list = new JBList("Show all phrase interpretations");
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
JBPopupFactory factory = JBPopupFactory.getInstance();
PopupChooserBuilder builder = factory.createListPopupBuilder(list);
builder.setItemChoosenCallback(
new Runnable() {
@Override
public void run() {
popupAmbigTreesDialog(previewState, ambigInfo);
}
}
);
JBPopup popup = builder.createPopup();
return popup;
}
示例10: createLookaheadTreesPopup
import com.intellij.openapi.ui.popup.PopupChooserBuilder; //导入依赖的package包/类
public static JBPopup createLookaheadTreesPopup(final PreviewState previewState,
final LookaheadEventInfo lookaheadInfo) {
final JBList list = new JBList("Show all lookahead interpretations");
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
JBPopupFactory factory = JBPopupFactory.getInstance();
PopupChooserBuilder builder = factory.createListPopupBuilder(list);
builder.setItemChoosenCallback(
new Runnable() {
@Override
public void run() {
popupLookaheadTreesDialog(previewState, lookaheadInfo);
}
}
);
JBPopup popup = builder.createPopup();
return popup;
}
示例11: CustomFoldingRegionsPopup
import com.intellij.openapi.ui.popup.PopupChooserBuilder; //导入依赖的package包/类
CustomFoldingRegionsPopup(@Nonnull Collection<FoldingDescriptor> descriptors,
@Nonnull final Editor editor,
@Nonnull final Project project) {
myEditor = editor;
myRegionsList = new JBList();
//noinspection unchecked
myRegionsList.setModel(new MyListModel(orderByPosition(descriptors)));
myRegionsList.setSelectedIndex(0);
final PopupChooserBuilder popupBuilder = JBPopupFactory.getInstance().createListPopupBuilder(myRegionsList);
myPopup = popupBuilder
.setTitle(IdeBundle.message("goto.custom.region.command"))
.setResizable(false)
.setMovable(false)
.setItemChoosenCallback(new Runnable() {
@Override
public void run() {
PsiElement navigationElement = getNavigationElement();
if (navigationElement != null) {
navigateTo(editor, navigationElement);
IdeDocumentHistory.getInstance(project).includeCurrentCommandAsNavigation();
}
}
}).createPopup();
}
示例12: invoke
import com.intellij.openapi.ui.popup.PopupChooserBuilder; //导入依赖的package包/类
@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);
}
示例13: navigate
import com.intellij.openapi.ui.popup.PopupChooserBuilder; //导入依赖的package包/类
public void navigate(final Project project) {
DefaultPsiElementListCellRenderer renderer = new DefaultPsiElementListCellRenderer();
final JList list = new JBList(myPsiFiles);
list.setCellRenderer(renderer);
final PopupChooserBuilder builder = new PopupChooserBuilder(list);
renderer.installSpeedSearch(builder);
final Runnable runnable = new Runnable() {
public void run() {
int[] ids = list.getSelectedIndices();
if (ids == null || ids.length == 0) return;
Object[] selectedElements = list.getSelectedValues();
for (Object element : selectedElements) {
Navigatable descriptor = EditSourceUtil.getDescriptor((PsiElement)element);
if (descriptor != null && descriptor.canNavigate()) {
descriptor.navigate(true);
}
}
}
};
final Editor editor = CommonDataKeys.EDITOR.getData(DataManager.getInstance().getDataContext());
builder.
setTitle("Choose file").
setItemChoosenCallback(runnable).
createPopup().showInBestPositionFor(editor);
}
示例14: applyFix
import com.intellij.openapi.ui.popup.PopupChooserBuilder; //导入依赖的package包/类
@Override
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
final PsiElement element = PsiTreeUtil.getParentOfType(descriptor.getPsiElement(), PsiJavaCodeReferenceElement.class);
if (element instanceof PsiJavaCodeReferenceElement) {
final PsiJavaCodeReferenceElement referenceElement = (PsiJavaCodeReferenceElement)element;
Collections.sort(originalClasses, new PsiProximityComparator(referenceElement.getElement()));
final JList list = new JBList(originalClasses.toArray(new PsiClass[originalClasses.size()]));
list.setCellRenderer(new FQNameCellRenderer());
final Runnable runnable = new Runnable() {
@Override
public void run() {
if (!element.isValid()) return;
final int index = list.getSelectedIndex();
if (index < 0) return;
new WriteCommandAction(project, element.getContainingFile()){
@Override
protected void run(@NotNull final Result result) throws Throwable {
final PsiClass psiClass = originalClasses.get(index);
if (psiClass.isValid()) {
PsiDocumentManager.getInstance(project).commitAllDocuments();
referenceElement.bindToElement(psiClass);
}
}
}.execute();
}
};
final AsyncResult<DataContext> asyncResult = DataManager.getInstance().getDataContextFromFocus();
asyncResult.doWhenDone(new Consumer<DataContext>() {
@Override
public void consume(DataContext dataContext) {
new PopupChooserBuilder(list).
setTitle(QuickFixBundle.message("add.qualifier.original.class.chooser.title")).
setItemChoosenCallback(runnable).
createPopup().
showInBestPositionFor(dataContext);
}
});
}
}
示例15: chooseTargetClass
import com.intellij.openapi.ui.popup.PopupChooserBuilder; //导入依赖的package包/类
private void chooseTargetClass(List<PsiClass> classes, final Editor editor) {
final PsiClass firstClass = classes.get(0);
final Project project = firstClass.getProject();
final JList list = new JBList(classes);
PsiElementListCellRenderer renderer = new PsiClassListCellRenderer();
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.setCellRenderer(renderer);
final PopupChooserBuilder builder = new PopupChooserBuilder(list);
renderer.installSpeedSearch(builder);
final PsiClass preselection = AnonymousTargetClassPreselectionUtil.getPreselection(classes, firstClass);
if (preselection != null) {
list.setSelectedValue(preselection, true);
}
Runnable runnable = new Runnable() {
@Override
public void run() {
int index = list.getSelectedIndex();
if (index < 0) return;
final PsiClass aClass = (PsiClass) list.getSelectedValue();
AnonymousTargetClassPreselectionUtil.rememberSelection(aClass, firstClass);
CommandProcessor.getInstance().executeCommand(project, new Runnable() {
@Override
public void run() {
doInvoke(project, aClass);
}
}, getText(), null);
}
};
builder.
setTitle(QuickFixBundle.message("target.class.chooser.title")).
setItemChoosenCallback(runnable).
createPopup().
showInBestPositionFor(editor);
}