Skip to content

Commit

Permalink
Added JsonTreeView to Schema Registry Browser; Format Schemas as Json;
Browse files Browse the repository at this point in the history
  • Loading branch information
patschuh committed Feb 25, 2019
1 parent 3974ce0 commit 58d7d67
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 20 deletions.
4 changes: 3 additions & 1 deletion src/main/java/at/esque/kafka/ConsumerHandler.java
Expand Up @@ -53,7 +53,9 @@ public UUID registerConsumer(ClusterConfig config, TopicMessageTypeConfig topicM
consumerProps.setProperty(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, "false");
consumerProps.setProperty(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, topicMessageTypeConfig.getKeyType().equals(MessageType.AVRO)? "io.confluent.kafka.serializers.KafkaAvroDeserializer" : "org.apache.kafka.common.serialization.StringDeserializer");
consumerProps.setProperty(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, topicMessageTypeConfig.getValueType().equals(MessageType.AVRO)? "io.confluent.kafka.serializers.KafkaAvroDeserializer" : "org.apache.kafka.common.serialization.StringDeserializer");
consumerProps.setProperty("schema.registry.url", config.getSchemaRegistry());
if(config.getSchemaRegistry() != null && !config.getSchemaRegistry().isEmpty()) {
consumerProps.setProperty("schema.registry.url", config.getSchemaRegistry());
}

consumerProps.putAll(consumerConfigs);

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/at/esque/kafka/Controller.java
Expand Up @@ -283,7 +283,7 @@ public void setup(Stage controlledStage) {
topicFilterTextField.textProperty().addListener(((observable, oldValue, newValue) ->
((FilteredList<String>) topicListView.getItems()).setPredicate(t -> StringUtils.containsIgnoreCase(t, newValue))
));
jsonTreeView.jsonStringPropertyProperty().bind(valueTextArea.textProperty());
jsonTreeView.jsonStringProperty().bind(valueTextArea.textProperty());
jsonTreeView.visibleProperty().bind(formatJsonToggle.selectedProperty());
bindDisableProperties();
}
Expand Down
@@ -1,6 +1,7 @@
package at.esque.kafka;

import at.esque.kafka.alerts.ErrorAlert;
import at.esque.kafka.controls.JsonTreeView;
import io.confluent.kafka.schemaregistry.client.rest.RestService;
import javafx.collections.FXCollections;
import javafx.fxml.FXML;
Expand All @@ -18,17 +19,20 @@ public class SchemaRegistryBrowserController {
private TextArea schemaTextArea;
@FXML
private ComboBox<Integer> versionComboBox;
@FXML
private JsonTreeView jsonTreeView;

public void setup(String schemaregistryUrl) {
schemaRegistryRestService = new RestService(schemaregistryUrl);
jsonTreeView.jsonStringProperty().bind(schemaTextArea.textProperty());
try {
versionComboBox.getSelectionModel().selectedItemProperty().addListener(((observable1, oldValue1, newValue1) -> {
if(newValue1 == null){
schemaTextArea.setText(null);
return;
}
try {
schemaTextArea.setText(schemaRegistryRestService.getVersion(subjectListView.getSelectionModel().getSelectedItem(), newValue1).getSchema());
schemaTextArea.setText(JsonUtils.formatJson(schemaRegistryRestService.getVersion(subjectListView.getSelectionModel().getSelectedItem(), newValue1).getSchema()));
} catch (Exception e) {
ErrorAlert.show(e);
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/at/esque/kafka/controls/JsonTreeView.java
Expand Up @@ -18,7 +18,7 @@ public JsonTreeView() {
jsonString.addListener((observable, oldValue, newValue) -> {
TreeItem<String> root;
try {
if (newValue != null && isVisible()) {
if (newValue != null && !newValue.isEmpty() && isVisible()) {
root = JsonUtils.buildTreeFromJson(newValue);
} else {
root = null;
Expand All @@ -31,15 +31,15 @@ public JsonTreeView() {
});
}

public String getJsonStringProperty() {
public String getJsonString() {
return jsonString.get();
}

public StringProperty jsonStringPropertyProperty() {
public StringProperty jsonStringProperty() {
return jsonString;
}

public void setJsonStringProperty(String jsonStringProperty) {
this.jsonString.set(jsonStringProperty);
public void setJsonString(String jsonString) {
this.jsonString.set(jsonString);
}
}
32 changes: 20 additions & 12 deletions src/main/resources/fxml/schemaRegistryBrowser.fxml
@@ -1,25 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0"
prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="at.esque.kafka.SchemaRegistryBrowserController">
<?import at.esque.kafka.controls.JsonTreeView?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.control.TextArea?>
<?import javafx.scene.control.ToolBar?>
<?import javafx.scene.layout.BorderPane?>

<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.172-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="at.esque.kafka.SchemaRegistryBrowserController">
<center>
<SplitPane dividerPositions="0.23244147157190637" prefHeight="160.0" prefWidth="200.0"
BorderPane.alignment="CENTER">
<SplitPane dividerPositions="0.23244147157190637" prefHeight="160.0" prefWidth="200.0" BorderPane.alignment="CENTER">
<items>
<ListView fx:id="subjectListView" prefHeight="200.0" prefWidth="200.0"/>
<ListView fx:id="subjectListView" prefHeight="200.0" prefWidth="200.0" />
<BorderPane prefHeight="200.0" prefWidth="200.0">
<center>
<TextArea fx:id="schemaTextArea" editable="false" prefHeight="200.0" prefWidth="200.0"
BorderPane.alignment="CENTER"/>
<SplitPane dividerPositions="0.5" BorderPane.alignment="CENTER">
<items>
<JsonTreeView fx:id="jsonTreeView" maxWidth="1.7976931348623157E308" prefHeight="358.0" prefWidth="166.0" />
<TextArea fx:id="schemaTextArea" editable="false" prefHeight="200.0" prefWidth="200.0" />
</items>
</SplitPane>
</center>
<top>
<ToolBar prefHeight="40.0" prefWidth="200.0" BorderPane.alignment="CENTER">
<items>
<Label text="Version:"/>
<ComboBox fx:id="versionComboBox" prefWidth="150.0"/>
<Label text="Version:" />
<ComboBox fx:id="versionComboBox" prefWidth="150.0" />
</items>
</ToolBar>
</top>
Expand Down

0 comments on commit 58d7d67

Please sign in to comment.