Archived
0

fix: при ручном измененнии значений Spinner не обновлял данные

This commit is contained in:
2018-06-07 15:00:03 +03:00
parent 1919da1f3c
commit 3e4f35635e

View File

@@ -8,6 +8,7 @@ import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import javafx.stage.FileChooser; import javafx.stage.FileChooser;
import javafx.stage.Stage; import javafx.stage.Stage;
import javafx.util.StringConverter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import ru.dmitriymx.corrector1s.Corrector1S; import ru.dmitriymx.corrector1s.Corrector1S;
@@ -105,10 +106,32 @@ public class MainController {
return alert; return alert;
} }
private <T> void commitEditorText(Spinner<T> spinner) {
if (!spinner.isEditable()) return;
String text = spinner.getEditor().getText();
SpinnerValueFactory<T> valueFactory = spinner.getValueFactory();
if (valueFactory != null) {
StringConverter<T> converter = valueFactory.getConverter();
if (converter != null) {
T value = converter.fromString(text);
valueFactory.setValue(value);
}
}
}
@FXML @FXML
public void initialize() { public void initialize() {
honorarium.setValueFactory(honorariumValueFactory); honorarium.setValueFactory(honorariumValueFactory);
honorarium.focusedProperty().addListener((observable, oldValue, newValue) -> {
if (newValue) return; // what?
commitEditorText(honorarium);
});
fss.setValueFactory(fssValueFactory); fss.setValueFactory(fssValueFactory);
fss.focusedProperty().addListener((observable, oldValue, newValue) -> {
if (newValue) return; // what?
commitEditorText(fss);
});
saveAsCheckBox.selectedProperty().addListener((observable, oldValue, newValue) -> { saveAsCheckBox.selectedProperty().addListener((observable, oldValue, newValue) -> {
saveAsFilePath.setDisable(!newValue); saveAsFilePath.setDisable(!newValue);