Added combo-box to switch highlighting modes for responseArea

This commit is contained in:
Rohit Awate 2018-06-22 13:03:07 +05:30
parent 0b46331314
commit d5228a6349
No known key found for this signature in database
GPG key ID: 1051D7B79CF2EE25
4 changed files with 40 additions and 20 deletions

View file

@ -68,14 +68,14 @@ public class DashboardController implements Initializable {
@FXML
TextField addressField;
@FXML
ComboBox<String> httpMethodBox;
ComboBox<String> httpMethodBox, responseTypeBox;
@FXML
private VBox responseBox, loadingLayer, promptLayer, errorLayer, paramsBox;
@FXML
private HBox responseDetails;
@FXML
private Label statusCode, statusCodeDescription, responseTime,
responseSize, errorTitle, errorDetails, responseType;
responseSize, errorTitle, errorDetails;
@FXML
private JFXButton cancelButton, copyBodyButton;
@FXML
@ -157,6 +157,30 @@ public class DashboardController implements Initializable {
snackbar.show("Response body copied to clipboard.", 5000);
});
responseTypeBox.getItems().addAll("JSON", "XML", "HTML", "PLAIN TEXT");
responseTypeBox.valueProperty().addListener(change -> {
String type = responseTypeBox.getValue();
try {
switch (type) {
case "JSON":
JsonNode node = EverestUtilities.jsonMapper.readTree(responseArea.getText());
responseArea.setText(EverestUtilities.jsonMapper.writeValueAsString(node), HighlightMode.JSON);
break;
case "XML":
responseArea.setText(responseArea.getText(), HighlightMode.XML);
break;
case "HTML":
responseArea.setText(responseArea.getText(), HighlightMode.HTML);
break;
default:
responseArea.setText(responseArea.getText(), HighlightMode.PLAIN);
}
} catch (IOException e) {
Services.loggingService.logWarning("Response could not be parsed.", e, LocalDateTime.now());
}
});
errorTitle.setText("Oops... That's embarrassing!");
errorDetails.setText("Something went wrong. Try to make another request.\nRestart Everest if that doesn't work.");
@ -388,26 +412,26 @@ public class DashboardController implements Initializable {
switch (type.toLowerCase()) {
case "application/json":
responseType.setText("JSON");
JsonNode node = EverestUtilities.mapper.readTree(responseBody);
responseArea.setText(EverestUtilities.mapper.writeValueAsString(node), HighlightMode.JSON);
responseTypeBox.setValue("JSON");
JsonNode node = EverestUtilities.jsonMapper.readTree(responseBody);
responseArea.setText(EverestUtilities.jsonMapper.writeValueAsString(node), HighlightMode.JSON);
visualizerTab.setDisable(false);
visualizer.populate(node);
break;
case "application/xml":
responseType.setText("XML");
responseArea.setText(EverestUtilities.mapper.writeValueAsString(responseBody), HighlightMode.XML);
responseTypeBox.setValue("XML");
responseArea.setText(responseBody, HighlightMode.XML);
break;
case "text/html":
responseType.setText("HTML");
responseTypeBox.setValue("HTML");
responseArea.setText(responseBody, HighlightMode.HTML);
break;
default:
responseType.setText("PLAIN TEXT");
responseTypeBox.setValue("PLAIN TEXT");
responseArea.setText(responseBody, HighlightMode.PLAIN);
}
} else {
responseType.setText("PLAIN");
responseTypeBox.setValue("PLAIN");
responseArea.setText("No body found in the response.", HighlightMode.PLAIN);
}
} catch (Exception e) {

View file

@ -28,11 +28,11 @@ import java.nio.file.StandardCopyOption;
import java.time.LocalDateTime;
public class EverestUtilities {
public static ObjectMapper mapper;
public static ObjectMapper jsonMapper;
static {
mapper = new ObjectMapper();
mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
jsonMapper = new ObjectMapper();
jsonMapper.configure(SerializationFeature.INDENT_OUTPUT, true);
}
/**

View file

@ -43,7 +43,7 @@ public class SettingsLoader implements Runnable {
System.out.println("Settings file found. Loading settings... ");
nodes = EverestUtilities.mapper.readTree(settingsFile);
nodes = EverestUtilities.jsonMapper.readTree(settingsFile);
Settings.connectionTimeOutEnable = setBooleanSetting(Settings.connectionTimeOutEnable, "connectionTimeOutEnable");
if (Settings.connectionTimeOutEnable)

View file

@ -24,7 +24,7 @@
<?import javafx.scene.text.*?>
<StackPane fx:id="dashboard" stylesheets="@../../css/Adreana.css" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.rohitawate.everest.controllers.DashboardController">
<children>
<VBox prefHeight="200.0" prefWidth="100.0">
<VBox>
<children>
<HBox alignment="CENTER" maxHeight="100.0" minHeight="100.0" spacing="20.0" VBox.vgrow="ALWAYS">
<children>
@ -153,11 +153,7 @@
</Label>
</children>
</HBox>
<Label fx:id="responseType" text="JSON" textFill="#2dcd2d">
<font>
<Font name="Liberation Mono Bold" size="17.0" />
</font>
</Label>
<ComboBox fx:id="responseTypeBox" minHeight="30.0" prefWidth="100.0"/>
<Label fx:id="responseTime" text="151 ms" textFill="WHITE" HBox.hgrow="ALWAYS">
<HBox.margin>
<Insets />