diff --git a/xml/dom-openapi/src/com/intellij/codeInsight/navigation/NavigationGutterIconBuilder.java b/xml/dom-openapi/src/com/intellij/codeInsight/navigation/NavigationGutterIconBuilder.java index 23324548e9f6..52c215398912 100644 --- a/xml/dom-openapi/src/com/intellij/codeInsight/navigation/NavigationGutterIconBuilder.java +++ b/xml/dom-openapi/src/com/intellij/codeInsight/navigation/NavigationGutterIconBuilder.java @@ -25,6 +25,7 @@ import com.intellij.lang.annotation.HighlightSeverity; import com.intellij.navigation.GotoRelatedItem; import com.intellij.openapi.editor.markup.GutterIconRenderer; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.NotNullLazyValue; import com.intellij.psi.PsiElement; import com.intellij.psi.SmartPointerManager; @@ -70,7 +71,7 @@ public class NavigationGutterIconBuilder { private String myEmptyText; private String myTooltipTitle; private GutterIconRenderer.Alignment myAlignment = GutterIconRenderer.Alignment.CENTER; - private PsiElementListCellRenderer myCellRenderer; + private Computable myCellRenderer; private NullableFunction myNamer = ElementPresentationManager.namer(); private final NotNullFunction> myGotoRelatedItemProvider; public static final NotNullFunction> DEFAULT_DOM_CONVERTOR = new NotNullFunction>() { @@ -179,7 +180,7 @@ public class NavigationGutterIconBuilder { } public NavigationGutterIconBuilder setCellRenderer(@NotNull final PsiElementListCellRenderer cellRenderer) { - myCellRenderer = cellRenderer; + myCellRenderer = new Computable.PredefinedValueComputable(cellRenderer); return this; } @@ -267,11 +268,14 @@ public class NavigationGutterIconBuilder { myTooltipText = sb.toString(); } - if (myCellRenderer == null) { - myCellRenderer = new DefaultPsiElementCellRenderer(); - } - - return new MyNavigationGutterIconRenderer(this, myAlignment, myIcon, myTooltipText, pointers, empty); + Computable renderer = + myCellRenderer == null ? new Computable() { + @Override + public PsiElementListCellRenderer compute() { + return new DefaultPsiElementCellRenderer(); + } + } : myCellRenderer; + return new MyNavigationGutterIconRenderer(this, myAlignment, myIcon, myTooltipText, pointers, renderer, empty); } private boolean isEmpty() { @@ -300,10 +304,11 @@ public class NavigationGutterIconBuilder { public MyNavigationGutterIconRenderer(@NotNull NavigationGutterIconBuilder builder, final Alignment alignment, final Icon icon, - final String tooltipText, + @Nullable final String tooltipText, @NotNull NotNullLazyValue> pointers, + Computable cellRenderer, boolean empty) { - super(builder.myPopupTitle, builder.myEmptyText, builder.myCellRenderer, pointers); + super(builder.myPopupTitle, builder.myEmptyText, cellRenderer, pointers); myAlignment = alignment; myIcon = icon; myTooltipText = tooltipText; diff --git a/xml/dom-openapi/src/com/intellij/codeInsight/navigation/NavigationGutterIconRenderer.java b/xml/dom-openapi/src/com/intellij/codeInsight/navigation/NavigationGutterIconRenderer.java index b7f7271bd048..38aa9200570f 100644 --- a/xml/dom-openapi/src/com/intellij/codeInsight/navigation/NavigationGutterIconRenderer.java +++ b/xml/dom-openapi/src/com/intellij/codeInsight/navigation/NavigationGutterIconRenderer.java @@ -24,6 +24,7 @@ import com.intellij.openapi.editor.markup.GutterIconRenderer; import com.intellij.openapi.ui.popup.Balloon; import com.intellij.openapi.ui.popup.JBPopup; import com.intellij.openapi.ui.popup.JBPopupFactory; +import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.NotNullLazyValue; import com.intellij.psi.PsiElement; import com.intellij.psi.SmartPsiElementPointer; @@ -46,11 +47,11 @@ import java.util.List; public abstract class NavigationGutterIconRenderer extends GutterIconRenderer implements GutterIconNavigationHandler{ private final String myPopupTitle; private final String myEmptyText; - private final PsiElementListCellRenderer myCellRenderer; + private final Computable myCellRenderer; private final NotNullLazyValue> myPointers; - protected NavigationGutterIconRenderer(final String popupTitle, final String emptyText, @NotNull PsiElementListCellRenderer cellRenderer, - @NotNull NotNullLazyValue> pointers) { + protected NavigationGutterIconRenderer(final String popupTitle, final String emptyText, @NotNull Computable cellRenderer, + @NotNull NotNullLazyValue> pointers) { myPopupTitle = popupTitle; myEmptyText = emptyText; myCellRenderer = cellRenderer; @@ -90,10 +91,6 @@ public abstract class NavigationGutterIconRenderer extends GutterIconRenderer im return result; } - public PsiElementListCellRenderer getCellRenderer() { - return myCellRenderer; - } - @Nullable public AnAction getClickAction() { return new AnAction() { @@ -103,7 +100,7 @@ public abstract class NavigationGutterIconRenderer extends GutterIconRenderer im }; } - public void navigate(final MouseEvent event, final PsiElement elt) { + public void navigate(@Nullable final MouseEvent event, @Nullable final PsiElement elt) { final List list = getTargetElements(); if (list.isEmpty()) { if (myEmptyText != null) { @@ -125,7 +122,7 @@ public abstract class NavigationGutterIconRenderer extends GutterIconRenderer im } else { if (event != null) { - final JBPopup popup = NavigationUtil.getPsiElementPopup(PsiUtilCore.toPsiElementArray(list), myCellRenderer, myPopupTitle); + final JBPopup popup = NavigationUtil.getPsiElementPopup(PsiUtilCore.toPsiElementArray(list), myCellRenderer.compute(), myPopupTitle); popup.show(new RelativePoint(event)); } }