Java Code Examples for com.intellij.openapi.ui.popup.PopupChooserBuilder#createPopup()
The following examples show how to use
com.intellij.openapi.ui.popup.PopupChooserBuilder#createPopup() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CamelAddEndpointIntention.java From camel-idea-plugin with Apache License 2.0 | 5 votes |
@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); }
Example 2
Source File: ShowAmbigTreesDialog.java From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License | 5 votes |
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(() -> popupAmbigTreesDialog(previewState, ambigInfo)); return builder.createPopup(); }
Example 3
Source File: ShowAmbigTreesDialog.java From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License | 5 votes |
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(() -> popupLookaheadTreesDialog(previewState, lookaheadInfo)); return builder.createPopup(); }
Example 4
Source File: VectorComponentsIntention.java From glsl4idea with GNU Lesser General Public License v3.0 | 4 votes |
protected void processIntention(PsiElement psiElement) { GLSLIdentifier elementTemp = null; if(psiElement instanceof GLSLIdentifier){ elementTemp = (GLSLIdentifier) psiElement; }else{ PsiElement parent = psiElement.getParent(); if(parent instanceof GLSLIdentifier){ elementTemp = (GLSLIdentifier) parent; } } if(elementTemp == null){ Logger.getInstance(VectorComponentsIntention.class).warn("Could not find GLSLIdentifier for psiElement: "+psiElement); return; } final GLSLIdentifier element = elementTemp; String components = element.getText(); final String[] results = createComponentVariants(components); String[] variants = new String[]{components + " -> " + results[0], components + " -> " + results[1]}; //http://www.jetbrains.net/devnet/message/5208622#5208622 final JBList<String> list = new JBList<>(variants); PopupChooserBuilder builder = new PopupChooserBuilder(list); builder.setTitle("Select Variant"); builder.setItemChoosenCallback(new Runnable() { public void run() { try { WriteCommandAction.writeCommandAction(element.getProject(), element.getContainingFile()).run(new ThrowableRunnable<Throwable>() { @Override public void run() { replaceIdentifierElement(element, results[list.getSelectedIndex()]); } }); } catch (Throwable t) { LOG.error("replaceIdentifierElement failed", t); } } }); JBPopup popup = builder.createPopup(); popup.showInBestPositionFor(getEditor()); }