From 11cc974a52eeacbe33ca9c856ea9e6e18dcc6a45 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Thu, 12 Apr 2012 13:06:43 +0200 Subject: [PATCH] make it work with any custom filter component --- .../speedSearch/NameFilteringListModel.java | 41 +++++++++++++++---- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/platform/platform-api/src/com/intellij/ui/speedSearch/NameFilteringListModel.java b/platform/platform-api/src/com/intellij/ui/speedSearch/NameFilteringListModel.java index b9bb77a9b28e..dec5b3c3e482 100644 --- a/platform/platform-api/src/com/intellij/ui/speedSearch/NameFilteringListModel.java +++ b/platform/platform-api/src/com/intellij/ui/speedSearch/NameFilteringListModel.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2012 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,23 +19,50 @@ */ package com.intellij.ui.speedSearch; +import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.text.StringUtilRt; import com.intellij.util.Function; import javax.swing.*; +/** + * @param list elements generic type + * + * @author max + * @author Konstantin Bulenkov + */ public class NameFilteringListModel extends FilteringListModel { private final Function myNamer; - private int myFullMatchIndex = -1; private int myStartsWithIndex = -1; - private final SpeedSearch mySpeedSearch; + private final Computable myPattern; - public NameFilteringListModel(JList list, final Function namer, final Condition filter, - SpeedSearch speedSearch) { + public NameFilteringListModel(JList list, + final Function namer, + final Condition filter, + final SpeedSearch speedSearch) { + this(list, namer, filter, new Computable() { + @Override + public String compute() { + return speedSearch.getFilter(); + } + }); + } + + public NameFilteringListModel(JList list, final Function namer, final Condition filter, final SpeedSearchSupply speedSearch) { + this(list, namer, filter, new Computable() { + @Override + public String compute() { + final String prefix = speedSearch.getEnteredPrefix(); + return prefix == null ? "" : prefix; + } + }); + } + + public NameFilteringListModel(JList list, final Function namer, final Condition filter, Computable pattern) { super(list); - mySpeedSearch = speedSearch; + myPattern = pattern; myNamer = namer; setFilter(namer != null ? new Condition() { public boolean value(T t) { @@ -49,7 +76,7 @@ public class NameFilteringListModel extends FilteringListModel { super.addToFiltered(elt); if (myNamer != null) { - String filterString = StringUtilRt.toUpperCase(mySpeedSearch.getFilter()); + String filterString = StringUtilRt.toUpperCase(myPattern.compute()); String candidateString = StringUtilRt.toUpperCase(myNamer.fun(elt)); int index = getSize() - 1;