use of org.apache.pivot.wtk.ListViewItemStateListener in project pivot by apache.
the class CheckedListViewTest method startup.
@Override
public void startup(Display display, Map<String, String> properties) throws Exception {
BXMLSerializer serializer = new BXMLSerializer();
mainWindow = (Window) serializer.readObject(CheckedListViewTest.class, "checked_list_view_test.bxml");
serializer.bind(this);
allowMixedStateCheckbox.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
listView.setAllowTriStateCheckmarks(button.isSelected());
// Not sure why, but changing this setting clears all the checks but doesn't
// trigger the item state listener (it's documented, but ...)
selectedItemsLabel.setText("");
}
});
showMixedAsSelectedCheckbox.getButtonPressListeners().add(new ButtonPressListener() {
@Override
public void buttonPressed(Button button) {
listView.setCheckmarksMixedAsChecked(button.isSelected());
}
});
listView.getComponentKeyListeners().add(new ComponentKeyListener() {
@Override
public boolean keyPressed(Component component, int keyCode, Keyboard.KeyLocation keyLocation) {
if (keyCode == Keyboard.KeyCode.DELETE) {
@SuppressWarnings("unchecked") List<Object> listData = (List<Object>) listView.getListData();
Sequence<Span> selectedRanges = listView.getSelectedRanges();
for (int i = selectedRanges.getLength() - 1; i >= 0; i--) {
Span selectedRange = selectedRanges.get(i);
listData.remove(selectedRange.start, selectedRange.end - selectedRange.start + 1);
}
}
return false;
}
});
listView.getListViewItemStateListeners().add(new ListViewItemStateListener() {
private void displayCheckedItems(ListView listView) {
List<?> listData = listView.getListData();
StringBuffer buf = new StringBuffer();
for (Integer i : listView.getCheckedIndexes()) {
if (buf.length() > 0) {
buf.append(",");
}
Object item = listData.get(i);
buf.append(item.toString());
}
selectedItemsLabel.setText(buf.toString());
}
@Override
public void itemCheckedChanged(ListView listView, int index) {
displayCheckedItems(listView);
}
@Override
public void itemCheckedStateChanged(ListView listView, int index) {
displayCheckedItems(listView);
}
});
listView.setItemChecked(0, true);
listView.setItemChecked(2, true);
mainWindow.open(display);
}
Aggregations