List of usage examples for javafx.scene.control ChoiceBox getSelectionModel
public final SingleSelectionModel<T> getSelectionModel()
From source file:de.pixida.logtest.designer.logreader.LogReaderEditor.java
public void createInputForHandlingOfNonHeadlineLines(final List<Triple<String, Node, String>> formItems) { final Map<HandlingOfNonHeadlineLines, String> mapValueToChoice = new HashMap<>(); mapValueToChoice.put(HandlingOfNonHeadlineLines.FAIL, "Abort - Each line in the log file is assumed to be a log entry"); mapValueToChoice.put(HandlingOfNonHeadlineLines.CREATE_MULTILINE_ENTRY, "Append to payload - This will create multiline payloads"); mapValueToChoice.put(HandlingOfNonHeadlineLines.ASSUME_LAST_TIMESTAMP, "Create new log entry and use timestamp of recent log entry"); mapValueToChoice.put(HandlingOfNonHeadlineLines.ASSUME_LAST_TIMESTAMP_AND_CHANNEL, "Create new log entry and use timestamp and channel of recent log entry"); final ChoiceBox<HandlingOfNonHeadlineLines> handlingOfNonHeadlineLinesInput = new ChoiceBox<>( FXCollections.observableArrayList(HandlingOfNonHeadlineLines.values())); handlingOfNonHeadlineLinesInput.setConverter(new StringConverter<HandlingOfNonHeadlineLines>() { @Override/* w w w . j a va 2s.com*/ public String toString(final HandlingOfNonHeadlineLines object) { return mapValueToChoice.get(object); } @Override public HandlingOfNonHeadlineLines fromString(final String string) { for (final Entry<HandlingOfNonHeadlineLines, String> entry : mapValueToChoice.entrySet()) { if (entry.getValue() == string) // Intentionally comparing references to obtain a bijection { return entry.getKey(); } } return null; // Should never happen } }); handlingOfNonHeadlineLinesInput.getSelectionModel().select(this.logReader.getHandlingOfNonHeadlineLines()); handlingOfNonHeadlineLinesInput.getSelectionModel().selectedIndexProperty() .addListener((ChangeListener<Number>) (observable, oldValue, newValue) -> { this.logReader.setHandlingOfNonHeadlineLines( handlingOfNonHeadlineLinesInput.getItems().get(newValue.intValue())); this.setChanged(true); }); formItems.add(Triple.of("Dangling Lines", handlingOfNonHeadlineLinesInput, "Define what to do if dangling lines are spotted. Dangling lines are lines which do not match the headline pattern, i.e." + " which do not introduce a new log entry.")); }