Skip to content

Commit

Permalink
Fix null pointers in sendable chooser stuff (#449)
Browse files Browse the repository at this point in the history
Was caused by the combobox getting de-selected and setting the selected option to null instead of the default option
  • Loading branch information
SamCarlberg authored Mar 21, 2018
1 parent c87faf2 commit 71320e2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.util.Arrays;
import java.util.Map;
import java.util.Objects;

/**
* Represents data options sent by the robot that may be selected by the drivers.
Expand Down Expand Up @@ -32,9 +33,9 @@ public SendableChooserData(Map<String, Object> map) {

@SuppressWarnings("JavadocMethod")
public SendableChooserData(String[] options, String defaultOption, String selectedOption) {
this.options = options.clone();
this.defaultOption = defaultOption;
this.selectedOption = selectedOption;
this.options = Objects.requireNonNull(options, "options").clone();
this.defaultOption = Objects.requireNonNull(defaultOption, "defaultOption");
this.selectedOption = Objects.requireNonNull(selectedOption, "selectedOption");
}

public String[] getOptions() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package edu.wpi.first.shuffleboard.plugin.base.widget;

import edu.wpi.first.shuffleboard.api.widget.ComplexAnnotatedWidget;
import edu.wpi.first.shuffleboard.api.widget.Description;
import edu.wpi.first.shuffleboard.api.widget.ParametrizedController;
import edu.wpi.first.shuffleboard.plugin.base.data.SendableChooserData;
import edu.wpi.first.shuffleboard.plugin.base.data.types.SendableChooserType;

import java.util.Map;

import edu.wpi.first.shuffleboard.api.widget.ComplexAnnotatedWidget;
import edu.wpi.first.shuffleboard.api.widget.Description;
import edu.wpi.first.shuffleboard.api.widget.ParametrizedController;
import javafx.fxml.FXML;
import javafx.scene.control.ComboBox;
import javafx.scene.layout.Pane;
Expand Down Expand Up @@ -37,7 +37,16 @@ private void initialize() {
});
comboBox.getSelectionModel()
.selectedItemProperty()
.addListener((__, oldValue, newValue) -> setData(getData().withSelectedOption(newValue)));
.addListener((__, oldValue, newValue) -> {
SendableChooserData currentData = getData();
if (newValue == null) {
String defaultOption = currentData.getDefaultOption();
setData(currentData.withSelectedOption(defaultOption));
comboBox.getSelectionModel().select(defaultOption);
} else {
setData(currentData.withSelectedOption(newValue));
}
});
}

private void updateOptions(String... options) {
Expand Down

0 comments on commit 71320e2

Please sign in to comment.