Source:
public LeftListWidgetChooser(List<CombinedListWidget<E>> listWidgets) { super(); this.listWidgets = listWidgets; this.getStyleClass().add("listChooser"); this.onChoose = Optional.empty(); this.toggleGroup = new ToggleGroup(); EventHandler filter = (EventHandler<ActionEvent>) actionEvent -> { ToggleButton source = (ToggleButton) actionEvent.getSource(); if (source.getToggleGroup() == null || !source.isSelected()) { source.fire(); } }; this.iconsListButton = new ToggleButton(); this.iconsListButton.setToggleGroup(toggleGroup); this.iconsListButton.getStyleClass().addAll("listIcon", "iconsList"); this.iconsListButton .setOnAction(event -> { listWidgets.forEach(widget -> widget.showList(ListWidgetType.ICONS_LIST)); this.onChoose.ifPresent(consumer -> consumer.accept(ListWidgetType.ICONS_LIST)); }); this.iconsListButton.addEventFilter(ActionEvent.ANY, filter); this.compactListButton = new ToggleButton(); this.compactListButton.setToggleGroup(toggleGroup); this.compactListButton.getStyleClass().addAll("listIcon", "compactList"); this.compactListButton .setOnAction(event -> listWidgets.forEach(widget -> { widget.showList(ListWidgetType.COMPACT_LIST); this.onChoose.ifPresent(consumer -> consumer.accept(ListWidgetType.COMPACT_LIST)); })); this.compactListButton.addEventFilter(ActionEvent.ANY, filter); this.detailsListButton = new ToggleButton(); this.detailsListButton.setToggleGroup(toggleGroup); this.detailsListButton.getStyleClass().addAll("listIcon", "detailsList"); this.detailsListButton .setOnAction(event -> listWidgets.forEach(widget -> { widget.showList(ListWidgetType.DETAILS_LIST); this.onChoose.ifPresent(consumer -> consumer.accept(ListWidgetType.DETAILS_LIST)); })); this.detailsListButton.addEventFilter(ActionEvent.ANY, filter); this.getChildren().setAll(iconsListButton, compactListButton, detailsListButton); this.choose(ListWidgetType.ICONS_LIST); }

Target:
public LeftListWidgetChooser(List<CombinedListWidget<E>> listWidgets) { super(); this.listWidgets = listWidgets; this.getStyleClass().add("listChooser"); this.onChoose = Optional.empty(); this.toggleGroup = new ToggleGroup(); EventHandler filter = (EventHandler<ActionEvent>) actionEvent -> { ToggleButton source = (ToggleButton) actionEvent.getSource(); if (source.getToggleGroup() == null || !source.isSelected()) { source.fire(); } }; this.iconsListButton = new ToggleButton(); this.iconsListButton.setToggleGroup(toggleGroup); this.iconsListButton.getStyleClass().addAll("listIcon", "iconsList"); this.iconsListButton .setOnAction(event -> { listWidgets.forEach(widget -> widget.showList(ListWidgetType.ICONS_LIST)); this.onChoose.ifPresent(consumer -> consumer.accept(ListWidgetType.ICONS_LIST)); }); this.iconsListButton.addEventFilter(ActionEvent.ANY, filter); this.compactListButton = new ToggleButton(); this.compactListButton.setToggleGroup(toggleGroup); this.compactListButton.getStyleClass().addAll("listIcon", "compactList"); this.compactListButton .setOnAction(event -> { listWidgets.forEach(widget -> widget.showList(ListWidgetType.COMPACT_LIST)); this.onChoose.ifPresent(consumer -> consumer.accept(ListWidgetType.COMPACT_LIST)); }); this.compactListButton.addEventFilter(ActionEvent.ANY, filter); this.detailsListButton = new ToggleButton(); this.detailsListButton.setToggleGroup(toggleGroup); this.detailsListButton.getStyleClass().addAll("listIcon", "detailsList"); this.detailsListButton .setOnAction(event -> { listWidgets.forEach(widget -> widget.showList(ListWidgetType.DETAILS_LIST)); this.onChoose.ifPresent(consumer -> consumer.accept(ListWidgetType.DETAILS_LIST)); }); this.detailsListButton.addEventFilter(ActionEvent.ANY, filter); this.getChildren().setAll(iconsListButton, compactListButton, detailsListButton); this.choose(ListWidgetType.ICONS_LIST); }