Skip to content

Commit

Permalink
Add setting to disable code highlighting
Browse files Browse the repository at this point in the history
Add show method to *Alert Classes that accepts an owner Window
  • Loading branch information
patschuh committed Nov 18, 2021
1 parent f28297e commit 163060c
Show file tree
Hide file tree
Showing 18 changed files with 210 additions and 84 deletions.
5 changes: 4 additions & 1 deletion README.md
Expand Up @@ -103,5 +103,8 @@ Check the settings.yaml in the <user.home>/.kafkaesque directory for cluster ind
* <span style="color:gray">default: true</span>
* trace.quick.select.duration.list: configures the values of the quick select buttons as a comma separated list of [Duration](https://docs.oracle.com/javase/8/docs/api/java/time/Duration.html) Strings
* <span style="color:gray">default: PT2H, P1D, P7D</span>

![Trace Quick Select](https://kafka.esque.at/images/screenshots/quickselectTrace.png "Trace Quick Select")
* syntax.highlight.threshold.enabled: Enables the syntax highlight threshold, if enabled JSON syntax highlighting will be disabled for if the codearea contains more characters than the threshold <span style="color:gray">(syntax.highlight.threshold.characters)</span>.
* <span style="color:gray">default: true</span>
* syntax.highlight.threshold.characters: configures the maximum number of characters allowed in a codeArea before syntax highlighting is disabled if the threshold is enabled <span style="color:gray">(syntax.highlight.threshold.enabled)</span>.
* <span style="color:gray">default: 50000</span>
51 changes: 27 additions & 24 deletions src/main/java/at/esque/kafka/Controller.java
Expand Up @@ -253,6 +253,9 @@ public void setup(Stage controlledStage) {
topicListView.getListView().setCellFactory(lv -> topicListCellFactory());
topicListView.setListComparator(String::compareTo);

configHandler.configureKafkaEsqueCodeArea(keyTextArea);
configHandler.configureKafkaEsqueCodeArea(valueTextArea);

setupJsonFormatToggle();

setupClusterCombobox();
Expand Down Expand Up @@ -297,7 +300,7 @@ private void openInTextEditor(KafkaMessage value, String suffix) {

Desktop.getDesktop().open(temp);
} catch (IOException e) {
Platform.runLater(() -> ErrorAlert.show(e));
Platform.runLater(() -> ErrorAlert.show(e, controlledStage));
}
}).start();
}
Expand Down Expand Up @@ -413,7 +416,7 @@ private ListCell<String> topicListCellFactory() {
trace(topicMessageTypeConfig, consumerConfig, (ConsumerRecord cr) -> StringUtils.equals(cr.key().toString(), traceKeyInput.getSearch()), partition, traceKeyInput.getEpoch());
});
} catch (Exception e) {
ErrorAlert.show(e);
ErrorAlert.show(e, controlledStage);
}
});

Expand Down Expand Up @@ -443,7 +446,7 @@ private ListCell<String> topicListCellFactory() {
}, null, traceInput.getEpoch());
});
} catch (Exception e) {
ErrorAlert.show(e);
ErrorAlert.show(e, controlledStage);
}
});

Expand All @@ -456,7 +459,7 @@ private ListCell<String> topicListCellFactory() {
adminClient.deleteTopic(cell.itemProperty().get());
SuccessAlert.show("Delete Topic", null, "Topic [" + cell.itemProperty().get() + "] marked for deletion.");
} catch (Exception e) {
ErrorAlert.show(e);
ErrorAlert.show(e, controlledStage);
}
}
});
Expand Down Expand Up @@ -532,7 +535,7 @@ public void getMessagesClick(ActionEvent event) {
getMessagesContinuously(topicMessageTypeConfig, consumerConfig);
}
} catch (IOException e) {
ErrorAlert.show(e);
ErrorAlert.show(e, controlledStage);
}
}

Expand Down Expand Up @@ -574,7 +577,7 @@ public void schemaRegistryClick(ActionEvent event) {
stage.show();
centerStageOnControlledStage(stage);
} catch (Exception e) {
ErrorAlert.show(e);
ErrorAlert.show(e, controlledStage);
}
}

Expand Down Expand Up @@ -606,7 +609,7 @@ public void kafkaConnectClick(ActionEvent actionEvent) {
stage.show();
centerStageOnControlledStage(stage);
} catch (Exception e) {
ErrorAlert.show(e);
ErrorAlert.show(e, controlledStage);
}
}

Expand Down Expand Up @@ -638,7 +641,7 @@ public void kafkaConnectInstalledPluginClick(ActionEvent actionEvent) {
stage.show();
centerStageOnControlledStage(stage);
} catch (Exception e) {
ErrorAlert.show(e);
ErrorAlert.show(e, controlledStage);
}
}

Expand All @@ -659,7 +662,7 @@ public void crossClusterClick(ActionEvent actionEvent) {
stage.show();
centerStageOnControlledStage(stage);
} catch (Exception e) {
ErrorAlert.show(e);
ErrorAlert.show(e, controlledStage);
}
}

Expand All @@ -686,7 +689,7 @@ public void lagViewerClick(ActionEvent actionEvent) {
consumerHandler.deregisterConsumer(consumerId);
});
} catch (Exception e) {
ErrorAlert.show(e);
ErrorAlert.show(e, controlledStage);
}
}

Expand All @@ -710,7 +713,7 @@ public void aclViewer(ActionEvent actionEvent) {
controller.stop();
});
} catch (Exception e) {
ErrorAlert.show(e);
ErrorAlert.show(e, controlledStage);
}
}

Expand All @@ -720,7 +723,7 @@ private void getOldestMessages(TopicMessageTypeConfig topic, Map<String, String>
try {
consumerId = consumerHandler.registerConsumer(selectedCluster(), topic, consumerConfig);
} catch (MissingSchemaRegistryException e) {
Platform.runLater(() -> ErrorAlert.show(e));
Platform.runLater(() -> ErrorAlert.show(e, controlledStage));
return;
}
try {
Expand Down Expand Up @@ -795,7 +798,7 @@ private void getNewestMessages(TopicMessageTypeConfig topic, Map<String, String>
try {
tempconsumerId = consumerHandler.registerConsumer(selectedCluster(), topic, consumerConfig);
} catch (MissingSchemaRegistryException e) {
Platform.runLater(() -> ErrorAlert.show(e));
Platform.runLater(() -> ErrorAlert.show(e, controlledStage));
return;
}
UUID consumerId = tempconsumerId;
Expand Down Expand Up @@ -845,7 +848,7 @@ private <KT, VT> void getMessagesContinuously(TopicMessageTypeConfig topic, Map<
try {
tempconsumerId = consumerHandler.registerConsumer(selectedCluster(), topic, consumerConfig);
} catch (MissingSchemaRegistryException e) {
Platform.runLater(() -> ErrorAlert.show(e));
Platform.runLater(() -> ErrorAlert.show(e, controlledStage));
return;
}
UUID consumerId = tempconsumerId;
Expand Down Expand Up @@ -880,7 +883,7 @@ private <KT, VT> void trace(TopicMessageTypeConfig topic, Map<String, String> co
try {
consumerId = consumerHandler.registerConsumer(selectedCluster(), topic, consumerConfig);
} catch (MissingSchemaRegistryException e) {
Platform.runLater(() -> ErrorAlert.show(e));
Platform.runLater(() -> ErrorAlert.show(e, controlledStage));
return;
}
try {
Expand Down Expand Up @@ -984,7 +987,7 @@ private void getMessagesFromSpecificOffset(TopicMessageTypeConfig topic, Map<Str
try {
consumerId = consumerHandler.registerConsumer(selectedCluster(), topic, consumerConfig);
} catch (MissingSchemaRegistryException e) {
ErrorAlert.show(e);
ErrorAlert.show(e, controlledStage);
return;
}
try {
Expand Down Expand Up @@ -1085,7 +1088,7 @@ private void showPublishMessageDialog(KafkaMessage kafkaMessage) {
stage.show();
centerStageOnControlledStage(stage);
} catch (Exception e) {
ErrorAlert.show(e);
ErrorAlert.show(e, controlledStage);
}
}

Expand All @@ -1108,7 +1111,7 @@ private void showCreateTopicDialog() {
stage.show();
centerStageOnControlledStage(stage);
} catch (Exception e) {
ErrorAlert.show(e);
ErrorAlert.show(e, controlledStage);
}
}

Expand All @@ -1128,7 +1131,7 @@ private void showDescribeTopicDialog(String topic) {
stage.show();
centerStageOnControlledStage(stage);
} catch (Exception e) {
ErrorAlert.show(e);
ErrorAlert.show(e, controlledStage);
}
}

Expand Down Expand Up @@ -1168,7 +1171,7 @@ public void applyTopicTemplatesClick(ActionEvent event) {
topicsToCreate = yamlMapper.readValue(selectedFile, new TypeReference<List<Topic>>() {
});
} catch (Exception e) {
ErrorAlert.show(e);
ErrorAlert.show(e, controlledStage);
return;
}
runInDaemonThread(() -> {
Expand All @@ -1189,12 +1192,12 @@ public void applyTopicTemplatesClick(ActionEvent event) {
if (e.getCause() instanceof TopicExistsException) {
alreadyExistedTopics.add(currentTopic);
} else {
Platform.runLater(() -> ErrorAlert.show(e));
Platform.runLater(() -> ErrorAlert.show(e, controlledStage));
}
}
Platform.runLater(() -> backGroundTaskHolder.setProgressMessage("Created Topic " + createdTopics.size() + " of " + topicsToCreate.size() + " (" + alreadyExistedTopics.size() + " already existed)"));
});
Platform.runLater(() -> TopicTemplateAppliedAlert.show(createdTopics, alreadyExistedTopics));
Platform.runLater(() -> TopicTemplateAppliedAlert.show(createdTopics, alreadyExistedTopics, topicListView.getScene().getWindow()));
} finally {
backGroundTaskHolder.backgroundTaskStopped();
}
Expand Down Expand Up @@ -1248,7 +1251,7 @@ public void playMessageBook(ActionEvent event) {
}
});
} catch (Exception e) {
Platform.runLater(() -> ErrorAlert.show(e));
Platform.runLater(() -> ErrorAlert.show(e, controlledStage));
} finally {
stopWatch.stop();
topicToProducerMap.values().forEach(uuid -> producerHandler.deregisterProducer(uuid));
Expand All @@ -1274,7 +1277,7 @@ private void addMessagesToSend(List<KafkaMessagBookWrapper> messagesToSend, File
messagesToSend.addAll(messages.stream().map(message -> new KafkaMessagBookWrapper(playFile.getName(), message))
.collect(Collectors.toList()));
} catch (FileNotFoundException e) {
Platform.runLater(() -> ErrorAlert.show(e));
Platform.runLater(() -> ErrorAlert.show(e, controlledStage));
}
}

Expand Down
17 changes: 11 additions & 6 deletions src/main/java/at/esque/kafka/CreateConnectorController.java
Expand Up @@ -20,6 +20,7 @@
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
import javafx.stage.Window;
import org.apache.avro.Schema;
import org.apache.commons.lang3.StringUtils;
import org.sourcelab.kafka.connect.apiclient.request.dto.ConnectorPluginConfigValidationResults;
Expand Down Expand Up @@ -139,17 +140,17 @@ public void addConnector(ActionEvent actionEvent) {
if(newConnectorMode == true) {
kafkaesqueConnectClient.createConnector(connectorName, connectorClass, paramMap);

SuccessAlert.show("Success", null, "Connector added successfully!");
SuccessAlert.show("Success", null, "Connector added successfully!", getWindow());
}
else
{
kafkaesqueConnectClient.updateConnector(connectorName, connectorClass, paramMap);
SuccessAlert.show("Success", null, "Connector updated successfully!");
SuccessAlert.show("Success", null, "Connector updated successfully!", getWindow());
}

stage.close();
} catch (Exception e) {
ErrorAlert.show(e);
ErrorAlert.show(e, getWindow());
}

}
Expand Down Expand Up @@ -198,7 +199,7 @@ public void validateConfig(ActionEvent actionEvent) {
ValidationResult validationResult = kafkaesqueConnectClient.validateConnectorConfig(connectorName, connectorClass, paramMap);

if (validationResult.getErrorCount() == 0) {
SuccessAlert.show("Success", null, "No validation error found!");
SuccessAlert.show("Success", null, "No validation error found!", getWindow());
} else {
StringBuilder errorProtocol = new StringBuilder();

Expand All @@ -212,12 +213,16 @@ public void validateConfig(ActionEvent actionEvent) {
}
}

WarningAlert.show(String.format("%d validation errors found!", validationResult.getErrorCount()), null, errorProtocol.toString());
WarningAlert.show(String.format("%d validation errors found!", validationResult.getErrorCount()), null, errorProtocol.toString(), getWindow());
}


} catch (Exception e) {
ErrorAlert.show(e);
ErrorAlert.show(e, getWindow());
}
}

private Window getWindow() {
return connectorConfigTextArea.getScene().getWindow();
}
}
11 changes: 8 additions & 3 deletions src/main/java/at/esque/kafka/CreateSchemaController.java
Expand Up @@ -9,6 +9,7 @@
import javafx.scene.control.TextField;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
import javafx.stage.Window;
import org.apache.avro.Schema;

import java.io.File;
Expand All @@ -34,9 +35,9 @@ public void addSchema(ActionEvent actionEvent) {
try {
parser.parse(schemaTextArea.getText());
restService.registerSchema(schemaTextArea.getText(), subjectTextField.getText());
SuccessAlert.show("Success", null, "Schema added successfully!");
SuccessAlert.show("Success", null, "Schema added successfully!", getWindow());
} catch (Exception e) {
ErrorAlert.show(e);
ErrorAlert.show(e, getWindow());
}
}

Expand All @@ -50,10 +51,14 @@ public void loadSchemaFile(ActionEvent actionEvent) {
String schemaString = new String(Files.readAllBytes(Paths.get(selectedFile.getPath())));
schemaTextArea.setText(schemaString);
} catch (IOException e) {
ErrorAlert.show(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;
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/at/esque/kafka/CrossClusterController.java
Expand Up @@ -26,6 +26,7 @@
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleButton;
import javafx.scene.control.Tooltip;
import javafx.stage.Window;
import org.apache.commons.lang3.StringUtils;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.ConsumerRecords;
Expand Down Expand Up @@ -123,7 +124,7 @@ public void setup() {
return FontIcon.of(FontAwesome.STOP_CIRCLE);
default:
if(cell.getItem().finishedExceptionaly()) {
cell.setOnMouseClicked(mouseEvent -> ErrorAlert.show(cell.getItem().getException()));
cell.setOnMouseClicked(mouseEvent -> ErrorAlert.show(cell.getItem().getException(), getWindow()));
}
return FontIcon.of(FontAwesome.WARNING);
}
Expand Down Expand Up @@ -166,7 +167,7 @@ private void startOperation(UUID operationId) {
consumerHandler.seekToOffset(consumerId, -2);
}
} catch (IOException | MissingSchemaRegistryException e) {
ErrorAlert.show(e);
ErrorAlert.show(e, getWindow());
return;
}
Optional<KafkaConsumer> consumer = consumerHandler.getConsumer(consumerId);
Expand Down Expand Up @@ -246,10 +247,14 @@ public void startOperationClick(ActionEvent actionEvent) {
refreshOperationList(null);
startOperation(operationId);
} catch (Exception e) {
ErrorAlert.show(e);
ErrorAlert.show(e, getWindow());
}
}

private Window getWindow() {
return fromClusterTopicsList.getScene().getWindow();
}

@FXML
public void refreshOperationList(ActionEvent actionEvent) {
runningOperationsList.setItems(crossClusterOperationHandler.getOperations());
Expand Down
Expand Up @@ -8,6 +8,7 @@
import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.stage.Window;


public class InstalledConnectorPluginsController {
Expand All @@ -29,8 +30,12 @@ public void refreshConnectorPlugins(ActionEvent actionEvent) {
try {
connectorPluginListView.setItems(FXCollections.observableArrayList(kafkaesqueConnectClient.getInstalledConnectorPlugins()));
} catch (Exception e) {
ErrorAlert.show(e);
ErrorAlert.show(e, getWindow());
}
}

private Window getWindow() {
return connectorPluginListView.getScene().getWindow();
}

}

0 comments on commit 163060c

Please sign in to comment.