/
CreateSchemaController.java
73 lines (60 loc) · 2.25 KB
/
CreateSchemaController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package at.esque.kafka;
import at.esque.kafka.alerts.ErrorAlert;
import at.esque.kafka.alerts.SuccessAlert;
import at.esque.kafka.controls.KafkaEsqueCodeArea;
import io.confluent.kafka.schemaregistry.client.rest.RestService;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.TextField;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
import javafx.stage.Window;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
public class CreateSchemaController {
@FXML
private TextField subjectTextField;
@FXML
private KafkaEsqueCodeArea schemaTextArea;
private RestService restService;
private Stage stage;
public void addSchema(ActionEvent actionEvent) {
try {
restService.registerSchema(schemaTextArea.getText(), subjectTextField.getText());
SuccessAlert.show("Success", null, "Schema added successfully!", getWindow());
} catch (Exception e) {
ErrorAlert.show(e, getWindow());
}
}
public void loadSchemaFile(ActionEvent actionEvent) {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Load Schema");
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("JSON File (*.json)", "*.json"));
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Any File (*)", "*"));
File selectedFile = fileChooser.showOpenDialog(stage);
try {
String schemaString = new String(Files.readAllBytes(Paths.get(selectedFile.getPath())));
schemaTextArea.setText(schemaString);
} catch (IOException e) {
ErrorAlert.show(e, getWindow());
}
}
private Window getWindow() {
return schemaTextArea.getScene().getWindow();
}
public void setup(String selectedSubject, RestService restService, Stage stage) {
this.restService = restService;
this.stage = stage;
if (selectedSubject != null) {
subjectTextField.setText(selectedSubject);
subjectTextField.setDisable(true);
}
}
public void cleanup() {
restService = null;
subjectTextField.setDisable(false);
stage = null;
}
}