use of com.intellij.ide.util.DefaultPsiElementCellRenderer in project intellij-community by JetBrains.
the class CreateParameterForFieldIntention method performForConstructor.
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(() -> {
final Object[] selectedValues = list.getSelectedValues();
CommandProcessor.getInstance().executeCommand(project, () -> {
for (Object selectedValue : selectedValues) {
LOG.assertTrue(((GrField) selectedValue).isValid());
addParameter(((GrField) selectedValue), constructor, project);
}
}, GroovyIntentionsBundle.message("create.parameter.for.field.intention.name"), null);
}).createPopup().showInBestPositionFor(editor);
}
use of com.intellij.ide.util.DefaultPsiElementCellRenderer in project intellij-community by JetBrains.
the class AddImportAction method chooseClassAndImport.
private void chooseClassAndImport() {
CodeInsightUtil.sortIdenticalShortNamedMembers(myTargetClasses, myReference);
final BaseListPopupStep<PsiClass> step = new BaseListPopupStep<PsiClass>(QuickFixBundle.message("class.to.import.chooser.title"), myTargetClasses) {
@Override
public boolean isAutoSelectionEnabled() {
return false;
}
@Override
public boolean isSpeedSearchEnabled() {
return true;
}
@Override
public PopupStep onChosen(PsiClass selectedValue, boolean finalChoice) {
if (selectedValue == null) {
return FINAL_CHOICE;
}
if (finalChoice) {
return doFinalStep(() -> {
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
addImport(myReference, selectedValue);
});
}
return getExcludesStep(selectedValue.getQualifiedName(), myProject);
}
@Override
public boolean hasSubstep(PsiClass selectedValue) {
return true;
}
@NotNull
@Override
public String getTextFor(PsiClass value) {
return ObjectUtils.assertNotNull(value.getQualifiedName());
}
@Override
public Icon getIconFor(PsiClass aValue) {
return aValue.getIcon(0);
}
};
ListPopupImpl popup = new ListPopupImpl(step) {
@Override
protected ListCellRenderer getListElementRenderer() {
final PopupListElementRenderer baseRenderer = (PopupListElementRenderer) super.getListElementRenderer();
final DefaultPsiElementCellRenderer psiRenderer = new DefaultPsiElementCellRenderer();
return new ListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
JPanel panel = new JPanel(new BorderLayout());
baseRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
panel.add(baseRenderer.getNextStepLabel(), BorderLayout.EAST);
panel.add(psiRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus));
return panel;
}
};
}
};
NavigationUtil.hidePopupIfDumbModeStarts(popup, myProject);
popup.showInBestPositionFor(myEditor);
}
use of com.intellij.ide.util.DefaultPsiElementCellRenderer in project intellij-plugins by JetBrains.
the class DartServerOverrideMarkerProvider method tryCreateOverrideMarker.
@Nullable
private static LineMarkerInfo tryCreateOverrideMarker(@NotNull final DartComponentName componentName, @Nullable final DartComponent superclassComponent, @NotNull final List<DartComponent> interfaceComponents) {
if (superclassComponent == null && interfaceComponents.isEmpty()) {
return null;
}
final String name = componentName.getName();
final boolean overrides;
final DartComponent superComponent;
if (superclassComponent != null) {
overrides = true;
superComponent = superclassComponent;
} else {
overrides = false;
superComponent = interfaceComponents.iterator().next();
}
final Icon icon = overrides ? AllIcons.Gutter.OverridingMethod : AllIcons.Gutter.ImplementingMethod;
return new LineMarkerInfo<>(componentName, componentName.getTextRange(), icon, Pass.LINE_MARKERS, element -> {
final DartClass superClass = PsiTreeUtil.getParentOfType(superComponent, DartClass.class);
if (superClass == null)
return "null";
if (overrides) {
return DartBundle.message(superclassComponent.isOperator() ? "overrides.operator.in" : "overrides.method.in", name, superClass.getName());
}
return DartBundle.message("implements.method.in", name, superClass.getName());
}, (GutterIconNavigationHandler<PsiElement>) (e, elt) -> {
List<DartComponent> superComponents = Lists.newArrayList();
if (superclassComponent != null) {
superComponents.add(superclassComponent);
}
superComponents.addAll(interfaceComponents);
PsiElementListNavigator.openTargets(e, DartResolveUtil.getComponentNameArray(superComponents), DaemonBundle.message("navigation.title.super.method", name), DaemonBundle.message("navigation.findUsages.title.super.method", name), new DefaultPsiElementCellRenderer());
}, GutterIconRenderer.Alignment.LEFT);
}
use of com.intellij.ide.util.DefaultPsiElementCellRenderer in project android by JetBrains.
the class AndroidUtils method navigateTo.
public static void navigateTo(@NotNull PsiElement[] targets, @Nullable RelativePoint pointToShowPopup) {
if (targets.length == 0) {
final JComponent renderer = HintUtil.createErrorLabel("Empty text");
final JBPopup popup = JBPopupFactory.getInstance().createComponentPopupBuilder(renderer, renderer).createPopup();
if (pointToShowPopup != null) {
popup.show(pointToShowPopup);
}
return;
}
if (targets.length == 1 || pointToShowPopup == null) {
PsiNavigateUtil.navigate(targets[0]);
} else {
DefaultPsiElementCellRenderer renderer = new DefaultPsiElementCellRenderer() {
@Override
public String getElementText(PsiElement element) {
final PsiFile file = getContainingFile(element);
return file != null ? file.getName() : super.getElementText(element);
}
@Override
public String getContainerText(PsiElement element, String name) {
final PsiFile file = getContainingFile(element);
final PsiDirectory dir = file != null ? file.getContainingDirectory() : null;
return dir == null ? "" : '(' + dir.getName() + ')';
}
};
final JBPopup popup = NavigationUtil.getPsiElementPopup(targets, renderer, null);
popup.show(pointToShowPopup);
}
}
use of com.intellij.ide.util.DefaultPsiElementCellRenderer in project intellij-community by JetBrains.
the class GotoDeclarationAction method chooseAmbiguousTarget.
// returns true if processor is run or is going to be run after showing popup
public static boolean chooseAmbiguousTarget(@NotNull Editor editor, int offset, @NotNull PsiElementProcessor<PsiElement> processor, @NotNull String titlePattern, @Nullable PsiElement[] elements) {
if (TargetElementUtil.inVirtualSpace(editor, offset)) {
return false;
}
final PsiReference reference = TargetElementUtil.findReference(editor, offset);
if (elements == null || elements.length == 0) {
elements = reference == null ? PsiElement.EMPTY_ARRAY : PsiUtilCore.toPsiElementArray(underModalProgress(reference.getElement().getProject(), "Resolving Reference...", () -> suggestCandidates(reference)));
}
if (elements.length == 1) {
PsiElement element = elements[0];
LOG.assertTrue(element != null);
processor.execute(element);
return true;
}
if (elements.length > 1) {
String title;
if (reference == null) {
title = titlePattern;
} else {
final TextRange range = reference.getRangeInElement();
final String elementText = reference.getElement().getText();
LOG.assertTrue(range.getStartOffset() >= 0 && range.getEndOffset() <= elementText.length(), Arrays.toString(elements) + ";" + reference);
final String refText = range.substring(elementText);
title = MessageFormat.format(titlePattern, refText);
}
NavigationUtil.getPsiElementPopup(elements, new DefaultPsiElementCellRenderer(), title, processor).showInBestPositionFor(editor);
return true;
}
return false;
}
Aggregations