diff --git a/src/main/java/at/esque/kafka/Controller.java b/src/main/java/at/esque/kafka/Controller.java index edfe04e..8efc95b 100644 --- a/src/main/java/at/esque/kafka/Controller.java +++ b/src/main/java/at/esque/kafka/Controller.java @@ -561,12 +561,37 @@ private ListCell topicListCellFactory() { deleteItem.setGraphic(new FontIcon(FontAwesome.TRASH)); deleteItem.textProperty().set("delete"); deleteItem.setOnAction(event -> { - if (ConfirmationAlert.show("Delete Topic", "Topic [" + cell.itemProperty().get() + "] will be marked for deletion.", "Are you sure you want to delete this topic")) { - try { - adminClient.deleteTopic(cell.itemProperty().get()); - SuccessAlert.show("Delete Topic", null, "Topic [" + cell.itemProperty().get() + "] marked for deletion."); - } catch (Exception e) { - ErrorAlert.show(e, controlledStage); + ObservableList + selectedTopics = + cell.getListView().getSelectionModel().getSelectedItems(); + if (selectedTopics.size() == 1) { + String topic = selectedTopics.get(0); + if (ConfirmationAlert.show("Delete Topic", "Topic [" + topic + "] will be marked for deletion.", "Are you sure you want to delete this topic?")) { + try { + adminClient.deleteTopic(cell.itemProperty().get()); + SuccessAlert.show("Delete Topic", null, "Topic [" + topic + "] marked for deletion."); + } catch (Exception e) { + ErrorAlert.show(e, controlledStage); + } + } + } else if (selectedTopics.size() > 1) { + if (ConfirmationAlert.show( + "Delete Topics", + "Topics will be marked for deletion.", + "Are you sure you want to delete the selected topics?" + )) { + try { + for (String topic : selectedTopics) { + adminClient.deleteTopic(topic); + } + SuccessAlert.show( + "Delete Topics", + null, + "Topics marked for deletion." + ); + } catch (Exception e) { + ErrorAlert.show(e, controlledStage); + } } } }); diff --git a/src/main/java/at/esque/kafka/controls/FilterableListView.java b/src/main/java/at/esque/kafka/controls/FilterableListView.java index c1dc125..35310c9 100644 --- a/src/main/java/at/esque/kafka/controls/FilterableListView.java +++ b/src/main/java/at/esque/kafka/controls/FilterableListView.java @@ -16,6 +16,7 @@ import javafx.fxml.FXMLLoader; import javafx.scene.control.Button; import javafx.scene.control.ListView; +import javafx.scene.control.SelectionMode; import javafx.scene.control.TextField; import javafx.scene.input.KeyCode; import javafx.scene.input.KeyCodeCombination; @@ -88,7 +89,6 @@ private void setup() { } }); listView.setOnKeyPressed(generateListEventHandler()); - bindButtonProperties(); } @@ -213,6 +213,14 @@ public String getName() { } }; + public final void setMultiselect(boolean value) { + listView.getSelectionModel().setSelectionMode(value ? SelectionMode.MULTIPLE : SelectionMode.SINGLE); + } + + public final boolean getMultiselect() { + return listView.getSelectionModel().getSelectionMode() == SelectionMode.MULTIPLE; + } + public void setListComparator(Comparator comparator) { this.sortedList.setComparator(comparator); } diff --git a/src/main/resources/fxml/mainScene.fxml b/src/main/resources/fxml/mainScene.fxml index b2fb93c..db36e90 100644 --- a/src/main/resources/fxml/mainScene.fxml +++ b/src/main/resources/fxml/mainScene.fxml @@ -100,7 +100,8 @@
+ BorderPane.alignment="CENTER" + multiselect="true"/>