@Override public Node createValueVisualisation() { comboBox = new ComboBox<>(); comboBox.getItems().add(0, null); comboBox.getItems().addAll(possibleValuesProvider.get()); comboBox.valueProperty().bindBidirectional(observableAttributeValue); comboBox.setEditable(false); comboBox.disableProperty().bind(readOnly); comboBox.setConverter(new StringConverter<>() { @Override public String toString(T object) { return object == null ? "" : object.internal().getDisplayText(); } @Override public T fromString(String string) { throw new UnsupportedOperationException(); } }); comboBox.setMinWidth(300); return comboBox; } }
/** * Setup of the binding between the view model and the UI controls. */ private void setupBinding() { tfName.textProperty().bindBidirectional(sportTypeViewModel.name); cbRecordDistance.selectedProperty().bindBidirectional(sportTypeViewModel.recordDistance); cbSpeedMode.valueProperty().bindBidirectional(sportTypeViewModel.speedMode); cpColor.valueProperty().bindBidirectional(sportTypeViewModel.color); // the record distance mode can only be changed, when no exercises exists for // this sport type => disable checkbox, when such exercises were found Optional<Exercise> oExercise = document.getExerciseList().stream() .filter(exercise -> exercise.getSportType().getId() == sportTypeViewModel.id) .findFirst(); cbRecordDistance.setDisable(oExercise.isPresent()); // speed mode can only be configured when distance is being recorded cbSpeedMode.disableProperty().bind(cbRecordDistance.selectedProperty().not()); // Edit and Delete buttons must be disabled when there is no selection in the appropriate list final BooleanBinding sportSubtypeSelected = Bindings.isNull( liSportSubtypes.getSelectionModel().selectedItemProperty()); btSportSubtypeEdit.disableProperty().bind(sportSubtypeSelected); btSportSubtypeDelete.disableProperty().bind(sportSubtypeSelected); final BooleanBinding equipmentSelected = Bindings.isNull( liEquipments.getSelectionModel().selectedItemProperty()); btEquipmentEdit.disableProperty().bind(equipmentSelected); btEquipmentDelete.disableProperty().bind(equipmentSelected); }