Skip to content

Commit

Permalink
Merge pull request #76 from dheid/feature/delete-multiple-topics
Browse files Browse the repository at this point in the history
Delete multiple topics in batch. Closes #74
  • Loading branch information
patschuh authored Sep 18, 2024
2 parents 63b8d20 + 60dd3ae commit 40b3219
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
37 changes: 31 additions & 6 deletions src/main/java/at/esque/kafka/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -561,12 +561,37 @@ private ListCell<String> 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<String>
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);
}
}
}
});
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/at/esque/kafka/controls/FilterableListView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -88,7 +89,6 @@ private void setup() {
}
});
listView.setOnKeyPressed(generateListEventHandler());

bindButtonProperties();
}

Expand Down Expand Up @@ -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<T> comparator) {
this.sortedList.setComparator(comparator);
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/fxml/mainScene.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@
<center>
<FilterableListView fx:id="topicListView" onAddAction="#createTopicButtonClick"
onRefreshAction="#refreshButtonClick"
BorderPane.alignment="CENTER"/>
BorderPane.alignment="CENTER"
multiselect="true"/>
</center>
</BorderPane>
<BorderPane prefHeight="200.0" prefWidth="200.0">
Expand Down

0 comments on commit 40b3219

Please sign in to comment.