Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8087555: [ChoiceBox] uncontained value not shown #191

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -185,13 +185,14 @@ public ChoiceBoxSkin(ChoiceBox<T> control) {
updatePopupItems();
updateSelectionModel();
updateSelection();
if(selectionModel != null && selectionModel.getSelectedIndex() == -1) {
label.setText(""); // clear label text when selectedIndex is -1
}
});
registerChangeListener(control.converterProperty(), e -> {
updateChoiceBoxItems();
updatePopupItems();
updateLabelText();
});
registerChangeListener(control.valueProperty(), e -> {
updateLabelText();
});
}

Expand Down Expand Up @@ -323,9 +324,19 @@ private void initialize() {

updateSelectionModel();
updateSelection();
if(selectionModel != null && selectionModel.getSelectedIndex() == -1) {
label.setText(""); // clear label text when selectedIndex is -1
updateLabelText();
}

private void updateLabelText() {
T value = getSkinnable().getValue();
label.setText(getDisplayText(value));
}

private String getDisplayText(T value) {
if (getSkinnable().getConverter() != null) {
return getSkinnable().getConverter().toString(value);
}
return value == null ? "" : value.toString();
}

private void updateChoiceBoxItems() {
Expand Down Expand Up @@ -356,9 +367,7 @@ private void addPopupItem(final T o, int i) {
} else if (o instanceof SeparatorMenuItem) {
popupItem = (SeparatorMenuItem) o;
} else {
StringConverter<T> c = getSkinnable().getConverter();
String displayString = (c == null) ? ((o == null) ? "" : o.toString()) : c.toString(o);
final RadioMenuItem item = new RadioMenuItem(displayString);
final RadioMenuItem item = new RadioMenuItem(getDisplayText(o));
item.setId("choice-box-menu-item");
item.setToggleGroup(toggleGroup);
item.setOnAction(e -> {
Expand Down Expand Up @@ -401,11 +410,11 @@ private void updateSelectionModel() {
private void updateSelection() {
if (selectionModel == null || selectionModel.isEmpty()) {
toggleGroup.selectToggle(null);
label.setText("");
} else {
} else {
int selectedIndex = selectionModel.getSelectedIndex();
if (selectedIndex == -1 || selectedIndex > popup.getItems().size()) {
label.setText(""); // clear label text
// FIXME: when do we get here?
// and if, shouldn't we unselect the toggles?
return;
}
if (selectedIndex < popup.getItems().size()) {
Expand All @@ -417,8 +426,6 @@ private void updateSelection() {
// to be selected
toggleGroup.selectToggle(null);
}
// update the label
label.setText(popup.getItems().get(selectedIndex).getText());
}
}
}
Expand Down