public CommonsChoiceBoxTableCell(ObservableList<CodeDVO> codes, StringConverter<CodeDVO> stringConverter) { this.codes = codes; this.stringConverter = stringConverter; choiceBox = new ChoiceBox<>(codes); choiceBox.setConverter(stringConverter); choiceBox.setOnAction(event -> { CodeDVO value = choiceBox.getValue(); if (value == null) return; ObservableValue<String> cellObservableValue = getTableColumn().getCellObservableValue(getIndex()); WritableStringValue writableStringValue = (WritableStringValue) cellObservableValue; if (cellObservableValue instanceof WritableStringValue) { writableStringValue.set(value.getCode()); } event.consume(); }); }
@Test public void testJavaFXStringUnidirectional() { Property<String> stringDolphinProperty = new MockedProperty<>(); StringProperty stringJavaFXProperty = new SimpleStringProperty(); WritableStringValue writableStringValue = new SimpleStringProperty(); stringDolphinProperty.set("Hello"); assertNotEquals(stringJavaFXProperty.get(), "Hello"); Binding binding = FXBinder.bind(stringJavaFXProperty).to(stringDolphinProperty); assertEquals(stringJavaFXProperty.get(), "Hello"); stringDolphinProperty.set("Hello JavaFX"); assertEquals(stringJavaFXProperty.get(), "Hello JavaFX"); stringDolphinProperty.set(null); assertEquals(stringJavaFXProperty.get(), null); binding.unbind(); stringDolphinProperty.set("Hello JavaFX"); assertEquals(stringJavaFXProperty.get(), null); binding = FXBinder.bind(writableStringValue).to(stringDolphinProperty); assertEquals(writableStringValue.get(), "Hello JavaFX"); stringDolphinProperty.set("Dolphin Platform"); assertEquals(writableStringValue.get(), "Dolphin Platform"); stringDolphinProperty.set(null); assertEquals(writableStringValue.get(), null); binding.unbind(); stringDolphinProperty.set("Dolphin Platform"); assertEquals(writableStringValue.get(), null); }