Java 类com.intellij.openapi.ui.popup.PopupChooserBuilder 实例源码

项目:intellij-ce-playground    文件:CustomFoldingRegionsPopup.java   
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();
}
项目:intellij-ce-playground    文件:PsiElementListCellRenderer.java   
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();
      }
    }
  });
}
项目:intellij-ce-playground    文件:GroovyStaticImportMethodFix.java   
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);
}
项目:tools-idea    文件:JBListWithHintProvider.java   
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);
        }
      }
    }
  });
}
项目:tools-idea    文件:JBTreeWithHintProvider.java   
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);
          }
        }
      }
    }
  });
}
项目:tools-idea    文件:JBTableWithHintProvider.java   
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);
        }
      }
    }
  });
}
项目:tools-idea    文件:PsiElementListCellRenderer.java   
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();
      }
    }
  });
}
项目:tools-idea    文件:GroovyStaticImportMethodFix.java   
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);
}
项目:nosql4idea    文件:OperatorCompletionAction.java   
@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);
}
项目:intellij-plugin-v4    文件:ShowAmbigTreesDialog.java   
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;
}
项目:intellij-plugin-v4    文件:ShowAmbigTreesDialog.java   
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;
}
项目:consulo    文件:CustomFoldingRegionsPopup.java   
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();
}
项目:camel-idea-plugin    文件:CamelAddEndpointIntention.java   
@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);
}
项目:intellij-ce-playground    文件:YourkitFilter.java   
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);
}
项目:intellij-ce-playground    文件:JavaDocReferenceInspection.java   
@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);
      }
    });
  }
}
项目:intellij-ce-playground    文件:CreateFromUsageBaseFix.java   
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);
}
项目:intellij-ce-playground    文件:RecentChangesPopup.java   
private void showList(JList list, Runnable selectAction) {
  new PopupChooserBuilder(list).
    setTitle(getTitle()).
    setItemChoosenCallback(selectAction).
    createPopup().
    showCenteredInCurrentWindow(myProject);
}
项目:intellij-ce-playground    文件:SchemesToImportPopup.java   
private void showList(JList list, Runnable selectAction) {
  new PopupChooserBuilder(list).
    setTitle("Import Scheme").
    setItemChoosenCallback(selectAction).
    createPopup().
    showInCenterOf(myParent);
}
项目:intellij-ce-playground    文件:CompareWithSelectedRevisionAction.java   
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() {
    @Override
    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);

  final int lastRow = treeTable.getRowCount() - 1;
  if (lastRow < 0) return;
  treeTable.getSelectionModel().addSelectionInterval(lastRow, lastRow);
  treeTable.scrollRectToVisible(treeTable.getCellRect(lastRow, 0, true));
}
项目:intellij-ce-playground    文件:Utils.java   
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);
  }
}
项目:intellij-ce-playground    文件:ImportFromExistingAction.java   
private void selectSourceAndDo() {
  // GUI part
  ImportCandidateHolder[] items = mySources.toArray(new ImportCandidateHolder[mySources.size()]); // silly JList can't handle modern collections
  final JList list = new JBList(items);
  list.setCellRenderer(new CellRenderer(myName));

  final Runnable runnable = new Runnable() {
    public void run() {
      final Object selected = list.getSelectedValue();
      if (selected instanceof ImportCandidateHolder) {
        final ImportCandidateHolder item = (ImportCandidateHolder)selected;
        PsiDocumentManager.getInstance(myTarget.getProject()).commitAllDocuments();
        doWriteAction(item);
      }
    }
  };

  DataManager.getInstance().getDataContextFromFocus().doWhenDone(new Consumer<DataContext>() {
    @Override
    public void consume(DataContext dataContext) {
      new PopupChooserBuilder(list)
        .setTitle(myUseQualifiedImport? PyBundle.message("ACT.qualify.with.module") : PyBundle.message("ACT.from.some.module.import"))
        .setItemChoosenCallback(runnable)
        .setFilteringEnabled(new Function<Object, String>() {
          @Override
          public String fun(Object o) {
            return ((ImportCandidateHolder) o).getPresentableText(myName);
          }
        })
        .createPopup()
        .showInBestPositionFor(dataContext);
    }
  });
}
项目:intellij-ce-playground    文件:PyPep8NamingInspection.java   
@Override
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
  final JBList list = new JBList(myBaseClassNames);
  final Runnable updateBlackList = new Runnable() {
    @Override
    public void run() {
      final InspectionProfile profile = InspectionProjectProfileManager.getInstance(project).getInspectionProfile();
      profile.modifyProfile(new Consumer<ModifiableModel>() {
        @Override
        public void consume(ModifiableModel model) {
          final PyPep8NamingInspection inspection = (PyPep8NamingInspection)model
            .getUnwrappedTool(PyPep8NamingInspection.class.getSimpleName(), descriptor.getPsiElement());
          addIfNotNull(inspection.ignoredBaseClasses, (String)list.getSelectedValue());
        }
      });
    }
  };
  DataManager.getInstance().getDataContextFromFocus().doWhenDone(new Consumer<DataContext>() {
    @Override
    public void consume(DataContext dataContext) {
      new PopupChooserBuilder(list)
        .setTitle("Ignore base class")
        .setItemChoosenCallback(updateBlackList)
        .setFilteringEnabled(new Function<Object, String>() {
          @Override
          public String fun(Object o) {
            return (String)o;
          }
        })
        .createPopup()
        .showInBestPositionFor(dataContext);
    }
  });
}
项目:intellij-ce-playground    文件:TagsPanel.java   
private void showTags() {
  DefaultListModel model = new DefaultListModel();
  myList.setModel(model);
  for (final String myTag : myTags) {
    model.addElement(myTag);
  }

  new PopupChooserBuilder(myList).
    setTitle(myPopupTitle).
    createPopup().
    showUnderneathOf(myMoreLabel);
}
项目:intellij-ce-playground    文件:GrCreateFromUsageBaseFix.java   
private void chooseClass(List<PsiClass> classes, Editor editor) {
  final Project project = classes.get(0).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);

  Runnable runnable = new Runnable() {
    @Override
    public void run() {
      int index = list.getSelectedIndex();
      if (index < 0) return;
      final PsiClass aClass = (PsiClass)list.getSelectedValue();
      CommandProcessor.getInstance().executeCommand(project, new Runnable() {
        @Override
        public void run() {
          ApplicationManager.getApplication().runWriteAction(new Runnable() {
            @Override
            public void run() {
              invokeImpl(project, aClass);
            }
          });
        }
      }, getText(), null);
    }
  };

  builder.
    setTitle(QuickFixBundle.message("target.class.chooser.title")).
    setItemChoosenCallback(runnable).
    createPopup().
    showInBestPositionFor(editor);
}
项目:intellij-ce-playground    文件:CreateParameterForFieldIntention.java   
private static void performForConstructor(PsiElement element, final Project project, Editor editor, List<GrField> candidates) {
  final GrMethod constructor = PsiTreeUtil.getParentOfType(element, GrMethod.class);
  if (candidates.isEmpty()) return;
  if (ApplicationManager.getApplication().isUnitTestMode()) {
    for (GrField candidate : candidates) {
      addParameter(candidate, constructor, project);
    }
    return;
  }
  final JList list = new JBList(candidates.toArray(new GrField[candidates.size()]));
  list.setCellRenderer(new DefaultPsiElementCellRenderer());

  new PopupChooserBuilder(list).setTitle(GroovyIntentionsBundle.message("create.parameter.for.field.intention.name")).
    setMovable(true).
    setItemChoosenCallback(new Runnable() {
      @Override
      public void run() {
        final Object[] selectedValues = list.getSelectedValues();
        CommandProcessor.getInstance().executeCommand(project, new Runnable() {
          @Override
          public void run() {
            AccessToken accessToken = WriteAction.start();
            try {
              for (Object selectedValue : selectedValues) {
                LOG.assertTrue(((GrField)selectedValue).isValid());
                addParameter(((GrField)selectedValue), constructor, project);
              }
            }
            finally {
              accessToken.finish();
            }
          }
        }, GroovyIntentionsBundle.message("create.parameter.for.field.intention.name"), null);
      }
    }).createPopup().showInBestPositionFor(editor);
}
项目:epigraph    文件:ImportTypeIntentionFix.java   
@SuppressWarnings("unchecked")
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
  if (!FileModificationService.getInstance().prepareFileForWrite(file)) return;
  if (typeRef.resolve() != null) return;

  final List<String> importOptions = calculateImportOptions();
  if (importOptions.isEmpty()) return;

  if (importOptions.size() > 1) {
    final JList list = new JBList(importOptions);
    list.setCellRenderer(SchemaNamespaceRenderer.INSTANCE);

    Runnable runnable = () -> {
      final int index = list.getSelectedIndex();
      if (index < 0) return;
      PsiDocumentManager.getInstance(project).commitAllDocuments();

      CommandProcessor.getInstance().executeCommand(project, () ->
              ApplicationManager.getApplication().runWriteAction(() ->
                  ImportTypeAction.addImport((SchemaFile) file, importOptions.get(index))
              ),
          getText(), getFamilyName()
      );
    };

    new PopupChooserBuilder(list).
        setTitle(SchemaBundle.message("actions.select.namespace.to.import")).
        setItemChoosenCallback(runnable).
        createPopup().
        showInBestPositionFor(editor);
  } else {
    ImportTypeAction.addImport((SchemaFile) file, importOptions.get(0));
  }
}
项目:epigraph    文件:ImportTypeAction.java   
@SuppressWarnings("unchecked")
@Override
public boolean execute() {

  final JList list = new JBList(importOptions);
  list.setCellRenderer(SchemaNamespaceRenderer.INSTANCE);
  list.setSelectedIndex(0);

  final Runnable runnable = () -> {
    final String namespace = (String) list.getSelectedValue();
    if (namespace != null) {
      final Project project = file.getProject();
      new WriteCommandAction.Simple(project, file) {
        @Override
        protected void run() throws Throwable {
          addImport(file, namespace);
        }
      }.execute();
    }
  };

  if (list.getModel().getSize() == 1) {
    runnable.run();
  } else {
    new PopupChooserBuilder(list)
        .setTitle("Select namespace to import")
        .setItemChoosenCallback(runnable)
        .createPopup()
        .showInBestPositionFor(editor);
  }


  return true;
}
项目:glsl4idea    文件:VectorComponentsIntention.java   
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();

    createComponentVariants(components);

    String[] variants = new String[]{components + " -> " + results[0], components + " -> " + results[1]};
    //http://www.jetbrains.net/devnet/message/5208622#5208622
    final JBList list = new JBList((Object[])variants);
    PopupChooserBuilder builder = new PopupChooserBuilder(list);
    builder.setTitle("Select Variant");
    builder.setItemChoosenCallback(new Runnable() {
        public void run() {
            WriteCommandAction writeAction = new WriteCommandAction(element.getProject(), element.getContainingFile()) {
                @Override
                protected void run(@NotNull Result result) throws Throwable {
                    replaceIdentifierElement(element, results[list.getSelectedIndex()]);
                }
            };
            writeAction.execute();
        }
    });
    JBPopup popup = builder.createPopup();
    popup.showInBestPositionFor(getEditor());
}
项目:tools-idea    文件:YourkitFilter.java   
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 = PlatformDataKeys.EDITOR.getData(DataManager.getInstance().getDataContext());

  builder.
    setTitle("Choose file").
    setItemChoosenCallback(runnable).
    createPopup().showInBestPositionFor(editor);
}
项目:tools-idea    文件:JavaDocReferenceInspection.java   
@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(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 AsyncResult.Handler<DataContext>() {
      @Override
      public void run(DataContext dataContext) {
        new PopupChooserBuilder(list).
          setTitle(QuickFixBundle.message("add.qualifier.original.class.chooser.title")).
          setItemChoosenCallback(runnable).
          createPopup().
          showInBestPositionFor(dataContext);
      }
    });
  }
}
项目:tools-idea    文件:CreateFromUsageBaseFix.java   
private void chooseTargetClass(List<PsiClass> classes, final Editor editor) {
  final Project project = classes.get(0).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);

  Runnable runnable = new Runnable() {
    @Override
    public void run() {
      int index = list.getSelectedIndex();
      if (index < 0) return;
      final PsiClass aClass = (PsiClass) list.getSelectedValue();
      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);
}
项目:tools-idea    文件:RecentChangesPopup.java   
private void showList(JList list, Runnable selectAction) {
  new PopupChooserBuilder(list).
    setTitle(getTitle()).
    setItemChoosenCallback(selectAction).
    createPopup().
    showCenteredInCurrentWindow(myProject);
}
项目:tools-idea    文件:SchemesToImportPopup.java   
private void showList(JList list, Runnable selectAction) {
  new PopupChooserBuilder(list).
    setTitle(getTitle()).
    setItemChoosenCallback(selectAction).
    createPopup().
    showInCenterOf(myParent);
}
项目:tools-idea    文件:CompareWithSelectedRevisionAction.java   
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);
}
项目:tools-idea    文件:NavigationUtil.java   
@NotNull
public static <T extends PsiElement> JBPopup getPsiElementPopup(@NotNull T[] elements,
                                                                @NotNull final PsiElementListCellRenderer<T> renderer,
                                                                @Nullable final String title,
                                                                @NotNull final PsiElementProcessor<T> processor,
                                                                @Nullable final T selection) {
  final JList list = new JBListWithHintProvider(elements) {
    @Nullable
    @Override
    protected PsiElement getPsiElementForHint(Object selectedValue) {
      return (PsiElement)selectedValue;
    }
  };
  list.setCellRenderer(renderer);
  if (selection != null) {
    list.setSelectedValue(selection, true);
  }

  final Runnable runnable = new Runnable() {
    @Override
    public void run() {
      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);

  return builder.setItemChoosenCallback(runnable).createPopup();
}
项目:tools-idea    文件:Utils.java   
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);
  }
}
项目:tools-idea    文件:TagsPanel.java   
private void showTags() {
  DefaultListModel model = new DefaultListModel();
  myList.setModel(model);
  for (final String myTag : myTags) {
    model.addElement(myTag);
  }

  new PopupChooserBuilder(myList).
    setTitle(myPopupTitle).
    createPopup().
    showUnderneathOf(myMoreLabel);
}
项目:tools-idea    文件:GrCreateFromUsageBaseFix.java   
private void chooseClass(List<PsiClass> classes, Editor editor) {
  final Project project = classes.get(0).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);

  Runnable runnable = new Runnable() {
    @Override
    public void run() {
      int index = list.getSelectedIndex();
      if (index < 0) return;
      final PsiClass aClass = (PsiClass)list.getSelectedValue();
      CommandProcessor.getInstance().executeCommand(project, new Runnable() {
        @Override
        public void run() {
          ApplicationManager.getApplication().runWriteAction(new Runnable() {
            @Override
            public void run() {
              invokeImpl(project, aClass);
            }
          });
        }
      }, getText(), null);
    }
  };

  builder.
    setTitle(QuickFixBundle.message("target.class.chooser.title")).
    setItemChoosenCallback(runnable).
    createPopup().
    showInBestPositionFor(editor);
}
项目:tools-idea    文件:CreateParameterForFieldIntention.java   
private static void performForConstructor(PsiElement element, final Project project, Editor editor, List<GrField> candidates) {
  final GrMethod constructor = PsiTreeUtil.getParentOfType(element, GrMethod.class);
  if (candidates.size() == 0) return;
  if (ApplicationManager.getApplication().isUnitTestMode()) {
    for (GrField candidate : candidates) {
      addParameter(candidate, constructor, project);
    }
    return;
  }
  final JList list = new JBList(candidates.toArray(new GrField[candidates.size()]));
  list.setCellRenderer(new DefaultPsiElementCellRenderer());

  new PopupChooserBuilder(list).setTitle(GroovyIntentionsBundle.message("create.parameter.for.field.intention.name")).
    setMovable(true).
    setItemChoosenCallback(new Runnable() {
      public void run() {
        final Object[] selectedValues = list.getSelectedValues();
        CommandProcessor.getInstance().executeCommand(project, new Runnable() {
          @Override
          public void run() {
            AccessToken accessToken = WriteAction.start();
            try {
              for (Object selectedValue : selectedValues) {
                LOG.assertTrue(((GrField)selectedValue).isValid());
                addParameter(((GrField)selectedValue), constructor, project);
              }
            }
            finally {
              accessToken.finish();
            }
          }
        }, GroovyIntentionsBundle.message("create.parameter.for.field.intention.name"), null);
      }
    }).createPopup().showInBestPositionFor(editor);
}
项目:intellij-idea-plugin    文件:CommandListPopupBuilder.java   
private JBPopup buildPopup(final JBList list,
         final Map<Object, String> filterIndex)
{
   final PopupChooserBuilder listPopupBuilder = JBPopupFactory.getInstance().createListPopupBuilder(list);
   listPopupBuilder.setTitle("Run a Forge command");
   listPopupBuilder.setResizable(true);
   listPopupBuilder.addListener(new JBPopupAdapter()
   {
      @Override
      public void onClosed(LightweightWindowEvent event)
      {
         CommandListPopupBuilder.active = false;
      }
   });
   listPopupBuilder.setItemChoosenCallback((Runnable) () -> {
      Object selectedObject = list.getSelectedValue();
      if (selectedObject instanceof UICommand)
      {
         UICommand selectedCommand = (UICommand) selectedObject;

         // Make sure that this cached command is still enabled
         if (selectedCommand.isEnabled(uiContext))
         {
            openWizard(selectedCommand);
         }
      }
   });
   listPopupBuilder.setFilteringEnabled(filterIndex::get);

   return listPopupBuilder.createPopup();
}