com.intellij.openapi.ui.popup.PopupChooserBuilder Java Examples

The following examples show how to use com.intellij.openapi.ui.popup.PopupChooserBuilder. 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: OperatorCompletionAction.java    From nosql4idea with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #2
Source File: CustomFoldingRegionsPopup.java    From consulo with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example #3
Source File: ShowAmbigTreesDialog.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 #4
Source File: ShowAmbigTreesDialog.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 #5
Source File: RecentChangesPopup.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void showList(JList list, Runnable selectAction) {
  new PopupChooserBuilder(list).
    setTitle(getTitle()).
    setItemChoosenCallback(selectAction).
    createPopup().
    showCenteredInCurrentWindow(myProject);
}
 
Example #6
Source File: SchemesToImportPopup.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void showList(JList list, Runnable selectAction) {
  new PopupChooserBuilder(list).
          setTitle("Import Scheme").
          setItemChoosenCallback(selectAction).
          createPopup().
          showInCenterOf(myParent);
}
 
Example #7
Source File: Utils.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void showCompletionPopup(JComponent toolbarComponent,
                                       final JList list,
                                       String title,
                                       final JTextComponent textField,
                                       String ad) {

  final Runnable callback = new Runnable() {
    @Override
    public void run() {
      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);
  }
}
 
Example #8
Source File: CamelAddEndpointIntention.java    From camel-idea-plugin with Apache License 2.0 5 votes vote down vote up
@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 #9
Source File: CompareWithSelectedRevisionAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void showTreePopup(final List<TreeItem<VcsFileRevision>> roots, final VirtualFile file, final Project project, final DiffProvider diffProvider) {
  final TreeTableView treeTable = new TreeTableView(new ListTreeTableModelOnColumns(new TreeNodeAdapter(null, null, roots),
                                                                                    new ColumnInfo[]{BRANCH_COLUMN, REVISION_COLUMN,
                                                                                    DATE_COLUMN, AUTHOR_COLUMN}));
  Runnable runnable = new Runnable() {
    public void run() {
      int index = treeTable.getSelectionModel().getMinSelectionIndex();
      if (index == -1) {
        return;
      }
      VcsFileRevision revision = getRevisionAt(treeTable, index);
      if (revision != null) {
        DiffActionExecutor.showDiff(diffProvider, revision.getRevisionNumber(), file, project, VcsBackgroundableActions.COMPARE_WITH);
      }
    }
  };

  treeTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

  new PopupChooserBuilder(treeTable).
    setTitle(VcsBundle.message("lookup.title.vcs.file.revisions")).
    setItemChoosenCallback(runnable).
    setSouthComponent(createCommentsPanel(treeTable)).
    setResizable(true).
    setDimensionServiceKey("Vcs.CompareWithSelectedRevision.Popup").
    createPopup().
    showCenteredInCurrentWindow(project);
}
 
Example #10
Source File: PopupListAdapter.java    From consulo with Apache License 2.0 4 votes vote down vote up
PopupListAdapter(PopupChooserBuilder builder, JList list) {
  myBuilder = builder;
  myList = list;
}
 
Example #11
Source File: PsiElementListCellRenderer.java    From consulo with Apache License 2.0 4 votes vote down vote up
/**
 * @deprecated use {@link #installSpeedSearch(IPopupChooserBuilder, boolean)} instead
 */
@Deprecated
public void installSpeedSearch(PopupChooserBuilder<?> builder, boolean includeContainerText) {
  installSpeedSearch((IPopupChooserBuilder)builder, includeContainerText);
}
 
Example #12
Source File: PsiElementListCellRenderer.java    From consulo with Apache License 2.0 4 votes vote down vote up
/**
 * @deprecated use {@link #installSpeedSearch(IPopupChooserBuilder)} instead
 */
@Deprecated
public void installSpeedSearch(PopupChooserBuilder<?> builder) {
  installSpeedSearch((IPopupChooserBuilder)builder);
}
 
Example #13
Source File: NavigationUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public static <T extends PsiElement> JBPopup getPsiElementPopup(@Nonnull T[] elements,
                                                                @Nonnull final PsiElementListCellRenderer<T> renderer,
                                                                @Nullable final String title,
                                                                @Nonnull final PsiElementProcessor<T> processor,
                                                                @Nullable final T selection) {
  final JList list = new JBList(elements);
  HintUpdateSupply.installSimpleHintUpdateSupply(list);
  list.setCellRenderer(renderer);

  list.setFont(EditorUtil.getEditorFont());

  if (selection != null) {
    list.setSelectedValue(selection, true);
  }

  final Runnable runnable = () -> {
    int[] ids = list.getSelectedIndices();
    if (ids == null || ids.length == 0) return;
    for (Object element : list.getSelectedValues()) {
      if (element != null) {
        processor.execute((T)element);
      }
    }
  };

  PopupChooserBuilder builder = new PopupChooserBuilder(list);
  if (title != null) {
    builder.setTitle(title);
  }
  renderer.installSpeedSearch(builder, true);

  JBPopup popup = builder.setItemChoosenCallback(runnable).createPopup();

  builder.getScrollPane().setBorder(null);
  builder.getScrollPane().setViewportBorder(null);

  hidePopupIfDumbModeStarts(popup, elements[0].getProject());

  return popup;
}
 
Example #14
Source File: ChooseOneOrAllRunnable.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void run() {
  if (myClasses.length == 1) {
    //TODO: cdr this place should produce at least warning
    // selected(myClasses[0]);
    selected((T[])ArrayUtil.toObjectArray(myClasses[0].getClass(), myClasses[0]));
  }
  else if (myClasses.length > 0) {
    PsiElementListCellRenderer<T> renderer = createRenderer();

    Arrays.sort(myClasses, renderer.getComparator());

    if (ApplicationManager.getApplication().isUnitTestMode()) {
      selected(myClasses);
      return;
    }
    Vector<Object> model = new Vector<Object>(Arrays.asList(myClasses));
    model.insertElementAt(CodeInsightBundle.message("highlight.thrown.exceptions.chooser.all.entry"), 0);

    myList = new JBList(model);
    myList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    myList.setCellRenderer(renderer);

    final PopupChooserBuilder builder = new PopupChooserBuilder(myList);
    renderer.installSpeedSearch(builder);

    final Runnable callback = new Runnable() {
      @Override
      public void run() {
        int idx = myList.getSelectedIndex();
        if (idx < 0) return;
        if (idx > 0) {
          selected((T[])ArrayUtil.toObjectArray(myClasses[idx-1].getClass(), myClasses[idx-1]));
        }
        else {
          selected(myClasses);
        }
      }
    };

    ApplicationManager.getApplication().invokeLater(new Runnable() {
      @Override
      public void run() {
        builder.
          setTitle(myTitle).
          setItemChoosenCallback(callback).
          createPopup().
          showInBestPositionFor(myEditor);
      }
    });
  }
}
 
Example #15
Source File: MergeableLineMarkerInfo.java    From consulo with Apache License 2.0 4 votes vote down vote up
public boolean configurePopupAndRenderer(@Nonnull PopupChooserBuilder builder, @Nonnull JBList list, @Nonnull List<MergeableLineMarkerInfo> markers) {
  return false;
}
 
Example #16
Source File: PopupTreeAdapter.java    From consulo with Apache License 2.0 4 votes vote down vote up
PopupTreeAdapter(PopupChooserBuilder builder, JTree tree) {
  myBuilder = builder;
  myTree = tree;
}
 
Example #17
Source File: PopupTableAdapter.java    From consulo with Apache License 2.0 4 votes vote down vote up
PopupTableAdapter(PopupChooserBuilder builder, JTable table) {
  myBuilder = builder;
  myTable = table;
}
 
Example #18
Source File: VectorComponentsIntention.java    From glsl4idea with GNU Lesser General Public License v3.0 4 votes vote down vote up
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());
}