Java Code Examples for com.intellij.openapi.ui.popup.PopupChooserBuilder#setTitle()

The following examples show how to use com.intellij.openapi.ui.popup.PopupChooserBuilder#setTitle() . 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 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 2
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 3
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());
}
 
Example 4
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;
}