Remove HBoxes and VBoxes from TreeVisualizer and add new abstract Visualizer class

This commit is contained in:
Rohit Awate 2018-08-09 11:34:55 +05:30
parent 56fab0d48d
commit f735667d42
No known key found for this signature in database
GPG key ID: 1051D7B79CF2EE25
4 changed files with 41 additions and 49 deletions

View file

@ -23,6 +23,8 @@ import com.rohitawate.everest.controllers.codearea.highlighters.HighlighterFacto
import com.rohitawate.everest.controllers.state.ComposerState;
import com.rohitawate.everest.controllers.state.DashboardState;
import com.rohitawate.everest.controllers.state.FieldState;
import com.rohitawate.everest.controllers.visualizers.TreeVisualizer;
import com.rohitawate.everest.controllers.visualizers.Visualizer;
import com.rohitawate.everest.exceptions.RedirectException;
import com.rohitawate.everest.exceptions.UnreliableResponseException;
import com.rohitawate.everest.format.FormatterFactory;
@ -191,7 +193,7 @@ public class DashboardController implements Initializable {
responseArea.setHighlighter(HighlighterFactory.getHighlighter(type));
});
visualizer = new Visualizer();
visualizer = new TreeVisualizer();
visualizerTab.setContent(visualizer);
responseArea = new EverestCodeArea();

View file

@ -14,50 +14,42 @@
* limitations under the License.
*/
package com.rohitawate.everest.controllers;
package com.rohitawate.everest.controllers.visualizers;
import com.fasterxml.jackson.databind.JsonNode;
import com.rohitawate.everest.misc.EverestUtilities;
import javafx.scene.control.*;
import javafx.scene.layout.HBox;
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
class Visualizer extends ScrollPane {
private TreeView<HBox> visualizer;
public class TreeVisualizer extends Visualizer {
private TreeView<String> visualizer;
Visualizer() {
public TreeVisualizer() {
visualizer = new TreeView<>();
visualizer.setShowRoot(false);
setContent(this.visualizer);
setFitToHeight(true);
setFitToWidth(true);
setContent(visualizer);
}
void populate(String body) throws IOException {
public void populate(String body) throws IOException {
JsonNode tree = EverestUtilities.jsonMapper.readTree(body);
this.populate(new TreeItem<>(), "root", tree);
}
private void populate(TreeItem<HBox> rootItem, String rootName, JsonNode root) {
private void populate(TreeItem<String> rootItem, String rootName, JsonNode root) {
if (rootName.equals("root")) {
visualizer.setRoot(rootItem);
}
Label rootLabel = new Label(rootName);
rootLabel.getStyleClass().addAll("visualizerRootLabel", "visualizerLabel");
rootItem.setValue(new HBox(rootLabel));
rootItem.setValue(rootName);
JsonNode currentNode;
Label valueLabel;
HBox valueContainer;
List<TreeItem<HBox>> items = new LinkedList<>();
Tooltip valueTooltip;
List<TreeItem<String>> items = new ArrayList<>();
if (root.isArray()) {
Iterator<JsonNode> iterator = root.elements();
@ -67,16 +59,9 @@ class Visualizer extends ScrollPane {
currentNode = iterator.next();
if (currentNode.isValueNode()) {
valueLabel = new Label(i++ + ": " + currentNode.toString());
valueLabel.getStyleClass().addAll("visualizerValueLabel", "visualizerLabel");
valueLabel.setWrapText(true);
valueTooltip = new Tooltip(currentNode.toString());
valueLabel.setTooltip(valueTooltip);
valueContainer = new HBox(valueLabel);
items.add(new TreeItem<>(valueContainer));
items.add(new TreeItem<>(i++ + ": " + EverestUtilities.trimString(currentNode.toString())));
} else if (currentNode.isObject()) {
TreeItem<HBox> newRoot = new TreeItem<>();
TreeItem<String> newRoot = new TreeItem<>();
items.add(newRoot);
populate(newRoot, i++ + ": [Anonymous Object]", currentNode);
}
@ -84,29 +69,16 @@ class Visualizer extends ScrollPane {
} else {
Iterator<Map.Entry<String, JsonNode>> iterator = root.fields();
Map.Entry<String, JsonNode> currentEntry;
Label keyLabel;
Tooltip keyTooltip;
while (iterator.hasNext()) {
currentEntry = iterator.next();
currentNode = currentEntry.getValue();
if (currentNode.isValueNode()) {
keyLabel = new Label(currentEntry.getKey() + ": ");
keyLabel.getStyleClass().addAll("visualizerKeyLabel", "visualizerLabel");
keyTooltip = new Tooltip(currentEntry.getKey());
keyLabel.setTooltip(keyTooltip);
valueLabel = new Label(currentNode.toString());
valueLabel.getStyleClass().addAll("visualizerValueLabel", "visualizerLabel");
valueLabel.setWrapText(true);
valueTooltip = new Tooltip(currentNode.toString());
valueLabel.setTooltip(valueTooltip);
valueContainer = new HBox(keyLabel, valueLabel);
items.add(new TreeItem<>(valueContainer));
items.add(new TreeItem<>(currentEntry.getKey() + ": "
+ EverestUtilities.trimString(currentNode.toString())));
} else if (currentNode.isArray() || currentNode.isObject()) {
TreeItem<HBox> newRoot = new TreeItem<>();
TreeItem<String> newRoot = new TreeItem<>();
items.add(newRoot);
populate(newRoot, currentEntry.getKey(), currentNode);
}

View file

@ -0,0 +1,15 @@
package com.rohitawate.everest.controllers.visualizers;
import javafx.scene.control.ScrollPane;
public abstract class Visualizer extends ScrollPane {
Visualizer() {
setFitToHeight(true);
setFitToWidth(true);
}
public abstract void populate(String body) throws Exception;
public abstract void clear();
}

View file

@ -294,7 +294,7 @@
-fx-font-size: 15px;
}
/* Response Visualizer */
/* ---------------------------- TreeVisualizer ------------------------- */
#responseTabPane:bottom .tab-header-area .tab-header-background,
#responseTabPane:bottom .tab-header-area .headers-region .tab:bottom {
-fx-background-color: #282828;
@ -338,8 +338,8 @@
-fx-text-fill: #959595;
}
/* Visualizer tree */
.tree-view {
-fx-padding: 5px;
-fx-background-color: #353535;
}
@ -354,6 +354,9 @@
.tree-cell {
-fx-background-color: #282828;
-fx-text-fill: azure;
-fx-font-size: 15px;
-fx-font-family: "Liberation Mono", monospace;
-fx-border-width: 0px;
}
@ -377,7 +380,7 @@
-fx-padding: 0;
}
/* SnackBar */
/* Snackbar */
.jfx-snackbar-content {
-fx-background-color: black;
}