summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Ehrnhoefer2011-07-15 21:41:33 (EDT)
committer Steffen Pingel2011-07-15 21:41:33 (EDT)
commit18dc0dbb3f95d58ca744a0f1c8f541bae168e62d (patch)
treed184872e34ca6e5bf0bc0d1e94883a8b0719f4c5
parent75678454416eba1a9fafc157d016336f3e10c2c4 (diff)
downloadorg.eclipse.mylyn.tasks-18dc0dbb3f95d58ca744a0f1c8f541bae168e62d.zip
org.eclipse.mylyn.tasks-18dc0dbb3f95d58ca744a0f1c8f541bae168e62d.tar.gz
org.eclipse.mylyn.tasks-18dc0dbb3f95d58ca744a0f1c8f541bae168e62d.tar.bz2
NEW - bug 351120: [patch] include "pretty name" in person content assist
https://bugs.eclipse.org/bugs/show_bug.cgi?id=351120
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/PersonProposalProviderTest.java81
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/PersonProposalProvider.java13
2 files changed, 93 insertions, 1 deletions
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/PersonProposalProviderTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/PersonProposalProviderTest.java
index 9f1e012..7dba45e 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/PersonProposalProviderTest.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/PersonProposalProviderTest.java
@@ -12,6 +12,11 @@
package org.eclipse.mylyn.tasks.tests;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.Map;
+
import junit.framework.TestCase;
import org.eclipse.jface.fieldassist.IContentProposal;
@@ -203,4 +208,80 @@ public class PersonProposalProviderTest extends TestCase {
assertTrue(((PersonContentProposal) result[0]).isCurrentUser());
}
+ public void testGetProposalByPrettyName() throws Exception {
+ Map<String, String> users = new HashMap<String, String>();
+ users.put("11", "foo");
+ users.put("22", "bar");
+ users.put("33", "far");
+ users.put("21", "boo");
+ MockTask task1 = new MockTask(null, "1", null);
+ task1.setOwner("11");
+
+ PersonProposalProvider provider = new PersonProposalProvider(task1, (TaskData) null, users);
+ IContentProposal[] result = provider.getProposals("", 0);
+ Arrays.sort(result, new Comparator<IContentProposal>() {
+ public int compare(IContentProposal o1, IContentProposal o2) {
+ return o1.getContent().compareTo(o2.getContent());
+ }
+ });
+ assertNotNull(result);
+ assertEquals(4, result.length);
+ assertEquals("11", result[0].getContent());
+ assertEquals("21", result[1].getContent());
+ assertEquals("22", result[2].getContent());
+ assertEquals("33", result[3].getContent());
+
+ result = provider.getProposals("f", 1);
+ Arrays.sort(result, new Comparator<IContentProposal>() {
+ public int compare(IContentProposal o1, IContentProposal o2) {
+ return o1.getContent().compareTo(o2.getContent());
+ }
+ });
+ assertNotNull(result);
+ assertEquals(2, result.length);
+ assertEquals("11", result[0].getContent());
+ assertEquals("33", result[1].getContent());
+
+ result = provider.getProposals("b", 1);
+ Arrays.sort(result, new Comparator<IContentProposal>() {
+ public int compare(IContentProposal o1, IContentProposal o2) {
+ return o1.getContent().compareTo(o2.getContent());
+ }
+ });
+ assertNotNull(result);
+ assertEquals(2, result.length);
+ assertEquals("21", result[0].getContent());
+ assertEquals("22", result[1].getContent());
+
+ result = provider.getProposals("1", 1);
+ Arrays.sort(result, new Comparator<IContentProposal>() {
+ public int compare(IContentProposal o1, IContentProposal o2) {
+ return o1.getContent().compareTo(o2.getContent());
+ }
+ });
+ assertNotNull(result);
+ assertEquals(1, result.length);
+ assertEquals("11", result[0].getContent());
+
+ result = provider.getProposals("3", 1);
+ Arrays.sort(result, new Comparator<IContentProposal>() {
+ public int compare(IContentProposal o1, IContentProposal o2) {
+ return o1.getContent().compareTo(o2.getContent());
+ }
+ });
+ assertNotNull(result);
+ assertEquals(1, result.length);
+ assertEquals("33", result[0].getContent());
+
+ result = provider.getProposals("2", 1);
+ Arrays.sort(result, new Comparator<IContentProposal>() {
+ public int compare(IContentProposal o1, IContentProposal o2) {
+ return o1.getContent().compareTo(o2.getContent());
+ }
+ });
+ assertNotNull(result);
+ assertEquals(2, result.length);
+ assertEquals("21", result[0].getContent());
+ assertEquals("22", result[1].getContent());
+ }
}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/PersonProposalProvider.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/PersonProposalProvider.java
index 2a6ce9f..1b30d77 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/PersonProposalProvider.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/PersonProposalProvider.java
@@ -117,7 +117,8 @@ public class PersonProposalProvider implements IContentProposalProvider {
searchText = searchText.toLowerCase();
char[] nextWord = searchText.toCharArray();
nextWord[searchText.length() - 1]++;
- addressSet = addressSet.subSet(searchText, new String(nextWord));
+ addressSet = new TreeSet<String>(addressSet.subSet(searchText, new String(nextWord)));
+ addPrettyNameAddresses(searchText, addressSet);
}
IContentProposal[] result = new IContentProposal[addressSet.size()];
@@ -130,6 +131,16 @@ public class PersonProposalProvider implements IContentProposalProvider {
return result;
}
+ private void addPrettyNameAddresses(String searchText, SortedSet<String> addressSet) {
+ if (proposals != null) {
+ for (String key : proposals.keySet()) {
+ if (proposals.get(key) != null && proposals.get(key).startsWith(searchText)) {
+ addressSet.add(key);
+ }
+ }
+ }
+ }
+
protected PersonContentProposal createPersonProposal(String address, boolean isCurrentUser, String replacementText,
int cursorPosition) {
return new PersonContentProposal(getPrettyName(address), isCurrentUser, replacementText, cursorPosition);