Search in sources :

Example 1 with DefaultPsiElementCellRenderer

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);
}
Also used : GrField(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField) DefaultPsiElementCellRenderer(com.intellij.ide.util.DefaultPsiElementCellRenderer) GrMethod(org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod) JBList(com.intellij.ui.components.JBList) PopupChooserBuilder(com.intellij.openapi.ui.popup.PopupChooserBuilder)

Example 2 with DefaultPsiElementCellRenderer

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);
}
Also used : DefaultPsiElementCellRenderer(com.intellij.ide.util.DefaultPsiElementCellRenderer) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) ListPopupImpl(com.intellij.ui.popup.list.ListPopupImpl) PsiClass(com.intellij.psi.PsiClass) PopupListElementRenderer(com.intellij.ui.popup.list.PopupListElementRenderer)

Example 3 with DefaultPsiElementCellRenderer

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);
}
Also used : DartResolveUtil(com.jetbrains.lang.dart.util.DartResolveUtil) DartClass(com.jetbrains.lang.dart.psi.DartClass) AllIcons(com.intellij.icons.AllIcons) GutterIconRenderer(com.intellij.openapi.editor.markup.GutterIconRenderer) VirtualFile(com.intellij.openapi.vfs.VirtualFile) DartComponentName(com.jetbrains.lang.dart.psi.DartComponentName) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) Lists(com.google.common.collect.Lists) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) DartHierarchyUtil(com.jetbrains.lang.dart.ide.hierarchy.DartHierarchyUtil) DartAnalysisServerService(com.jetbrains.lang.dart.analyzer.DartAnalysisServerService) DartServerData(com.jetbrains.lang.dart.analyzer.DartServerData) PsiElementListNavigator(com.intellij.codeInsight.daemon.impl.PsiElementListNavigator) OverriddenMember(org.dartlang.analysis.server.protocol.OverriddenMember) Collection(java.util.Collection) DartComponent(com.jetbrains.lang.dart.psi.DartComponent) DartBundle(com.jetbrains.lang.dart.DartBundle) Pass(com.intellij.codeHighlighting.Pass) DefaultPsiElementCellRenderer(com.intellij.ide.util.DefaultPsiElementCellRenderer) Nullable(org.jetbrains.annotations.Nullable) DaemonBundle(com.intellij.codeInsight.daemon.DaemonBundle) List(java.util.List) GutterIconNavigationHandler(com.intellij.codeInsight.daemon.GutterIconNavigationHandler) LineMarkerProvider(com.intellij.codeInsight.daemon.LineMarkerProvider) NotNull(org.jetbrains.annotations.NotNull) javax.swing(javax.swing) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) DartComponent(com.jetbrains.lang.dart.psi.DartComponent) DartClass(com.jetbrains.lang.dart.psi.DartClass) DefaultPsiElementCellRenderer(com.intellij.ide.util.DefaultPsiElementCellRenderer) List(java.util.List) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with DefaultPsiElementCellRenderer

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);
    }
}
Also used : DefaultPsiElementCellRenderer(com.intellij.ide.util.DefaultPsiElementCellRenderer) JBPopup(com.intellij.openapi.ui.popup.JBPopup)

Example 5 with DefaultPsiElementCellRenderer

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;
}
Also used : DefaultPsiElementCellRenderer(com.intellij.ide.util.DefaultPsiElementCellRenderer) PsiReference(com.intellij.psi.PsiReference) TextRange(com.intellij.openapi.util.TextRange) PsiElement(com.intellij.psi.PsiElement)

Aggregations

DefaultPsiElementCellRenderer (com.intellij.ide.util.DefaultPsiElementCellRenderer)10 PsiElement (com.intellij.psi.PsiElement)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 DartComponent (com.jetbrains.lang.dart.psi.DartComponent)4 Pass (com.intellij.codeHighlighting.Pass)3 DaemonBundle (com.intellij.codeInsight.daemon.DaemonBundle)3 GutterIconNavigationHandler (com.intellij.codeInsight.daemon.GutterIconNavigationHandler)3 LineMarkerInfo (com.intellij.codeInsight.daemon.LineMarkerInfo)3 LineMarkerProvider (com.intellij.codeInsight.daemon.LineMarkerProvider)3 PsiElementListNavigator (com.intellij.codeInsight.daemon.impl.PsiElementListNavigator)3 AllIcons (com.intellij.icons.AllIcons)3 GutterIconRenderer (com.intellij.openapi.editor.markup.GutterIconRenderer)3 DartAnalysisServerService (com.jetbrains.lang.dart.analyzer.DartAnalysisServerService)3 DartServerData (com.jetbrains.lang.dart.analyzer.DartServerData)3 DartComponentName (com.jetbrains.lang.dart.psi.DartComponentName)3 DartResolveUtil (com.jetbrains.lang.dart.util.DartResolveUtil)3 Collection (java.util.Collection)3 List (java.util.List)3 TypeHierarchyItem (org.dartlang.analysis.server.protocol.TypeHierarchyItem)3 NotNull (org.jetbrains.annotations.NotNull)3