public static JBPopup createPopup( final List<? extends GotoRelatedItem> items, final String title) { Object[] elements = new Object[items.size()]; // todo[nik] move presentation logic to GotoRelatedItem class final Map<PsiElement, GotoRelatedItem> itemsMap = new HashMap<PsiElement, GotoRelatedItem>(); for (int i = 0; i < items.size(); i++) { GotoRelatedItem item = items.get(i); elements[i] = item.getElement() != null ? item.getElement() : item; itemsMap.put(item.getElement(), item); } return getPsiElementPopup( elements, itemsMap, title, new Processor<Object>() { @Override public boolean process(Object element) { if (element instanceof PsiElement) { //noinspection SuspiciousMethodCalls itemsMap.get(element).navigate(); } else { ((GotoRelatedItem) element).navigate(); } return true; } }); }
/** * Returns navigation popup that shows list of related items from {@code items} list * * @param items * @param title * @param showContainingModules Whether the popup should show additional information that aligned * at the right side of the dialog.<br> * It's usually a module name or library name of corresponding navigation item.<br> * {@code false} by default * @return */ @NotNull public static JBPopup getRelatedItemsPopup( final List<? extends GotoRelatedItem> items, String title, boolean showContainingModules) { Object[] elements = new Object[items.size()]; // todo[nik] move presentation logic to GotoRelatedItem class final Map<PsiElement, GotoRelatedItem> itemsMap = new HashMap<PsiElement, GotoRelatedItem>(); for (int i = 0; i < items.size(); i++) { GotoRelatedItem item = items.get(i); elements[i] = item.getElement() != null ? item.getElement() : item; itemsMap.put(item.getElement(), item); } return getPsiElementPopup( elements, itemsMap, title, showContainingModules, element -> { if (element instanceof PsiElement) { //noinspection SuspiciousMethodCalls itemsMap.get(element).navigate(); } else { ((GotoRelatedItem) element).navigate(); } return true; }); }
@NotNull private static Collection<PsiClass> findRelatedActivities( @NotNull XmlFile file, @NotNull AndroidFacet facet, @NotNull DomFileDescription<?> description) { if (description instanceof LayoutDomFileDescription) { final Computable<List<GotoRelatedItem>> computable = AndroidGotoRelatedProvider.getLazyItemsForXmlFile(file, facet); if (computable == null) { return Collections.emptyList(); } final List<GotoRelatedItem> items = computable.compute(); if (items.isEmpty()) { return Collections.emptyList(); } final PsiClass activityClass = findActivityClass(facet.getModule()); if (activityClass == null) { return Collections.emptyList(); } final List<PsiClass> result = new ArrayList<PsiClass>(); for (GotoRelatedItem item : items) { final PsiElement element = item.getElement(); if (element instanceof PsiClass) { final PsiClass aClass = (PsiClass) element; if (aClass.isInheritor(activityClass, true)) { result.add(aClass); } } } return result; } else { return findRelatedActivitiesForMenu(file, facet); } }