This is an automated email from the git hooks/post-receive script. New commit to branch develop-2.x in repository jaxx. See http://git.nuiton.org/jaxx.git commit b2cfbb8a463b826c532044cb6241fce903886e1a Author: Kevin Morin <morin@codelutin.com> Date: Mon Sep 7 15:14:49 2015 +0200 Having the choice of the wildcard character in the filterable combobox fixes #3776 --- .../swing/model/JaxxFilterableComboBoxModel.java | 40 +++++++++++++++++----- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/jaxx-runtime/src/main/java/jaxx/runtime/swing/model/JaxxFilterableComboBoxModel.java b/jaxx-runtime/src/main/java/jaxx/runtime/swing/model/JaxxFilterableComboBoxModel.java index c35d81f..fffc405 100644 --- a/jaxx-runtime/src/main/java/jaxx/runtime/swing/model/JaxxFilterableComboBoxModel.java +++ b/jaxx-runtime/src/main/java/jaxx/runtime/swing/model/JaxxFilterableComboBoxModel.java @@ -24,15 +24,16 @@ package jaxx.runtime.swing.model; import com.google.common.base.Predicate; import com.google.common.collect.Lists; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.regex.Pattern; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.nuiton.decorator.JXPathDecorator; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.regex.Pattern; + /** * ComboBoxModel which can filter the elements displayed in the popup. * @@ -46,10 +47,14 @@ public class JaxxFilterableComboBoxModel<E> extends JaxxDefaultComboBoxModel<E> /** Logger. */ private static final Log log = LogFactory.getLog(JaxxFilterableComboBoxModel.class); + public static final Character DEFAULT_WILDCARD_CHARACTER = '*'; + protected List<E> filteredItems = Lists.newArrayList(); protected String filterText; + protected Character wildcardCharacter = DEFAULT_WILDCARD_CHARACTER; + /** the decorator of data */ protected JXPathDecorator<E> decorator; @@ -143,6 +148,16 @@ public class JaxxFilterableComboBoxModel<E> extends JaxxDefaultComboBoxModel<E> refilter(); } + public Character getWildcardCharacter() { + return wildcardCharacter; + } + + public void setWildcardCharacter(Character wildcardCharacter) { + this.wildcardCharacter = wildcardCharacter; + refilter(); + + } + public JXPathDecorator<E> getDecorator() { return decorator; } @@ -173,16 +188,25 @@ public class JaxxFilterableComboBoxModel<E> extends JaxxDefaultComboBoxModel<E> protected void refilter() { filteredItems.clear(); - if (StringUtils.isEmpty(StringUtils.remove(filterText, '*')) + if ((StringUtils.isEmpty(filterText) + || wildcardCharacter != null && StringUtils.isEmpty(StringUtils.remove(filterText, wildcardCharacter))) && filters.isEmpty()) { filteredItems.addAll(delegate); } else { Pattern pattern = null; if (!StringUtils.isBlank(filterText)) { - String patternText = Pattern.quote(filterText).replace("*", "\\E.*\\Q") + ".*"; - pattern = Pattern.compile(patternText, Pattern.CASE_INSENSITIVE); + String patternText= Pattern.quote(filterText); + + if (wildcardCharacter == null) { + patternText = ".*" + patternText; + + } else { + patternText = patternText.replace(wildcardCharacter.toString(), "\\E.*\\Q"); + } + pattern = Pattern.compile(patternText + ".*", Pattern.CASE_INSENSITIVE); } + for (E element : delegate) { boolean addElement = true; for (Predicate<E> filter : filters) { @@ -203,7 +227,7 @@ public class JaxxFilterableComboBoxModel<E> extends JaxxDefaultComboBoxModel<E> } if (log.isInfoEnabled()) { - log.info("After refilter, nb items: "+getSize()); + log.info("After refilter, nb items: " + getSize()); } fireContentsChanged(this, 0, getSize()); -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.