Skip to content

Commit

Permalink
sort items in drop downs and dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
shlurbee committed Jun 17, 2011
1 parent b74e2f1 commit cbc2085
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package edu.ucla.cens.mobilize.client.model;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public void onSuccess(List<ClassInfo> result) {
for (ClassInfo classInfo : result) {
participants.addAll(classInfo.getMemberLogins());
}
Collections.sort(participants);
view.setParticipantList(participants);
if (participantToSelect != null) {
view.selectParticipant(participantToSelect);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand Down
16 changes: 13 additions & 3 deletions src/edu/ucla/cens/mobilize/client/ui/MultiSelectDialog.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package edu.ucla.cens.mobilize.client.ui;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -49,8 +50,10 @@ public void onClick(ClickEvent event) {

// use this version if display text and value (id) are the same
public void setItems(List<String> items) {
List<String> sortedItems = new ArrayList<String>(items);
Collections.sort(sortedItems);
listBox.clear();
for (String item : items) {
for (String item : sortedItems) {
listBox.addItem(item, item); // value and display text are the same
}
giveListBoxMinimumWidth();
Expand All @@ -59,9 +62,16 @@ public void setItems(List<String> items) {
// use this version if you want to display a user friendly string
// but get back an id as the selected item value
public void setItems(Map<String, String> itemIdToDisplayNameMap) {
listBox.clear();
List<String> valuesAndKeys = new ArrayList<String>();
for (String key : itemIdToDisplayNameMap.keySet()) {
listBox.addItem(itemIdToDisplayNameMap.get(key), key); // key becomes value
String value = itemIdToDisplayNameMap.get(key);
valuesAndKeys.add(value + "###" + key);
}
Collections.sort(valuesAndKeys); // sort by value first, then key
for (String valueKeyPair : valuesAndKeys) {
String[] arr = valueKeyPair.split("###"); // 0=value, 1=key
// value becomes display string, key becomes listItem "value"
listBox.addItem(arr[0], arr[1]);
}
giveListBoxMinimumWidth();
}
Expand Down
5 changes: 3 additions & 2 deletions src/edu/ucla/cens/mobilize/client/ui/MultiSelectDialog.ui.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
}
.instructions {
font-size: 0.9em;
margin-top: 10px;
margin: 5px 0px;
padding: 10px 40px;
}
.listBox {
margin: 10px 40px;
height: 100px;
margin: 0px 40px 15px;
}
</ui:style>
<g:HTMLPanel>
Expand Down

0 comments on commit cbc2085

Please sign in to comment.