throws Exception {
WTKXSerializer wtkxSerializer = new WTKXSerializer();
Component content =
(Component)wtkxSerializer.readObject("pivot/tutorials/lists/list_views.wtkx");
final Label selectionLabel =
(Label)wtkxSerializer.getObjectByName("selectionLabel");
ListView listView = (ListView)wtkxSerializer.getObjectByName("listView");
listView.getListViewSelectionListeners().add(new ListViewSelectionListener() {
public void selectedRangeAdded(ListView listView, int rangeStart, int rangeEnd) {
updateSelection(listView);
}
public void selectedRangeRemoved(ListView listView, int rangeStart, int rangeEnd) {
updateSelection(listView);
}
public void selectedRangesChanged(ListView listView, Sequence<Span> previousSelectedRanges) {
updateSelection(listView);
}
private void updateSelection(ListView listView) {
String selectionText = "";
Sequence<Span> selectedRanges = listView.getSelectedRanges();
for (int i = 0, n = selectedRanges.getLength(); i < n; i++) {
Span selectedRange = selectedRanges.get(i);
for (int j = selectedRange.getStart();
j <= selectedRange.getEnd();
j++) {
if (selectionText.length() > 0) {
selectionText += ", ";
}
String text = (String)listView.getListData().get(j);
selectionText += text;
}
}
selectionLabel.setText(selectionText);
}
});
window = new Window();
window.setContent(content);