diff options
author | Steffen Kriese | 2010-10-04 10:03:18 -0400 |
---|---|---|
committer | Steffen Kriese | 2010-10-04 10:03:18 -0400 |
commit | 915af42cf76545f8591b42b49039869fecfc953f (patch) | |
tree | 0cf30bd8b6c8f6247945b51084429e3a3657bc45 | |
parent | bacc2a5ba89648d3255aeaeff11a77a941346084 (diff) | |
download | org.eclipse.riena-915af42cf76545f8591b42b49039869fecfc953f.zip org.eclipse.riena-915af42cf76545f8591b42b49039869fecfc953f.tar.gz org.eclipse.riena-915af42cf76545f8591b42b49039869fecfc953f.tar.xz |
Fix for #326916: CompletionCombo with unsorted list (jump to next entry, when character is entered multiple times)
-rw-r--r-- | org.eclipse.riena.ui.swt/src/org/eclipse/riena/ui/swt/CompletionCombo.java | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/org.eclipse.riena.ui.swt/src/org/eclipse/riena/ui/swt/CompletionCombo.java b/org.eclipse.riena.ui.swt/src/org/eclipse/riena/ui/swt/CompletionCombo.java index f8e3db5..5ba0edf 100644 --- a/org.eclipse.riena.ui.swt/src/org/eclipse/riena/ui/swt/CompletionCombo.java +++ b/org.eclipse.riena.ui.swt/src/org/eclipse/riena/ui/swt/CompletionCombo.java @@ -71,7 +71,7 @@ public abstract class CompletionCombo extends Composite { private static final SWTFacade SWT_FACADE = SWTFacade.getDefault(); /** * Stores all allowed input characters that are not letters or digits. This - * date is computed as items are added to the CompletionCombo and used in + * data is computed as items are added to the CompletionCombo and used in * {@link #isInputChar(char)}. */ private final Set<Character> inputChars = new HashSet<Character>(); @@ -2280,23 +2280,67 @@ public abstract class CompletionCombo extends Composite { boolean result = false; if (prefix != null) { if (prefix.length() == 0) { + clearImage(); text.setText(""); //$NON-NLS-1$ result = true; } else { - final int prefixLength = prefix.length(); + + int prefixLength = prefix.length(); for (final String item : getItems(list)) { + + if (item.equals(text.getText())) { + continue; + } if (matchesWord(prefix, item)) { setMatchingTextAndSelection(prefixLength, item); result = true; break; } } + + // when nothing was found and the prefix consists of more than 1 character of the same type e.g. "aa" + // jump to the next match of "a" + if (!result && !isAllowMissmatch() && isMultipleInputOfSameChar(prefix)) { + + final String singleCharPrefix = prefix.substring(0, 1); + prefixLength = singleCharPrefix.length(); + + final String[] items = getItems(); + + for (int i = getSelectionIndex() + 1; i < items.length; i++) { + + final String item = items[i]; + + if (matchesWord(singleCharPrefix, item)) { + setMatchingTextAndSelection(prefixLength, item); + result = true; + break; + } + } + } } } return result; } + private boolean isMultipleInputOfSameChar(final String prefix) { + if (prefix.length() < 2) { + return false; + } + + final String lowerPrefix = prefix.toLowerCase(); + + final char first = lowerPrefix.charAt(0); + for (int i = 1; i < lowerPrefix.length(); i++) { + final char current = lowerPrefix.charAt(i); + if (current != first) { + return false; + } + } + return true; + } + private void setMatchingTextAndSelection(final int selectionStart, final String item) { final int index = indexOf(item); Assert.isLegal(index > -1); |