use of eu.fthevenet.binjr.data.adapters.TimeSeriesBinding in project selenium_java by sergueik.
the class MainViewController method addToNewWorksheet.
private void addToNewWorksheet(TreeItem<TimeSeriesBinding<Double>> treeItem) {
// Schedule for later execution in order to let other UI components worksheetTabFactory refreshed
// before modal dialog gets displayed (fixes unsightly UI glitches on Linux)
Platform.runLater(() -> {
try {
TimeSeriesBinding<Double> binding = treeItem.getValue();
ZonedDateTime toDateTime;
ZonedDateTime fromDateTime;
ZoneId zoneId;
if (getSelectedWorksheetController() != null && getSelectedWorksheetController().getWorksheet() != null) {
toDateTime = getSelectedWorksheetController().getWorksheet().getToDateTime();
fromDateTime = getSelectedWorksheetController().getWorksheet().getFromDateTime();
zoneId = getSelectedWorksheetController().getWorksheet().getTimeZone();
} else {
toDateTime = ZonedDateTime.now();
fromDateTime = toDateTime.minus(24, ChronoUnit.HOURS);
zoneId = ZoneId.systemDefault();
}
List<Chart<Double>> chartList = new ArrayList<>();
chartList.add(new Chart<>(binding.getLegend(), binding.getGraphType(), binding.getUnitName(), binding.getUnitPrefix()));
Worksheet<Double> worksheet = new Worksheet<Double>(binding.getLegend(), chartList, zoneId, fromDateTime, toDateTime);
if (editWorksheet(worksheet) && getSelectedWorksheetController() != null) {
List<TimeSeriesBinding<Double>> bindings = new ArrayList<>();
getAllBindingsFromBranch(treeItem, bindings);
getSelectedWorksheetController().addBindings(bindings, getSelectedWorksheetController().getWorksheet().getDefaultChart());
}
} catch (Exception e) {
Dialogs.notifyException("Error adding bindings to new worksheet", e, root);
}
});
}
use of eu.fthevenet.binjr.data.adapters.TimeSeriesBinding in project selenium_java by sergueik.
the class WorksheetController method handleDragDroppedOnWorksheetView.
private void handleDragDroppedOnWorksheetView(DragEvent event) {
Dragboard db = event.getDragboard();
if (db.hasContent(MainViewController.TIME_SERIES_BINDING_FORMAT)) {
TreeView<TimeSeriesBinding<Double>> treeView = parentController.getSelectedTreeView();
if (treeView != null) {
TreeItem<TimeSeriesBinding<Double>> item = treeView.getSelectionModel().getSelectedItem();
if (item != null) {
Stage targetStage = (Stage) ((Node) event.getSource()).getScene().getWindow();
if (targetStage != null) {
targetStage.requestFocus();
}
if (TransferMode.MOVE.equals(event.getAcceptedTransferMode())) {
try {
TitledPane droppedPane = (TitledPane) event.getSource();
droppedPane.setExpanded(true);
ChartViewPort<Double> viewPort = (ChartViewPort<Double>) droppedPane.getUserData();
List<TimeSeriesBinding<Double>> bindings = new ArrayList<>();
parentController.getAllBindingsFromBranch(item, bindings);
addBindings(bindings, viewPort.getDataStore());
} catch (Exception e) {
Dialogs.notifyException("Error adding bindings to existing worksheet", e, root);
}
logger.debug("dropped to " + event.toString());
} else {
logger.warn("Unsupported drag and drop transfer mode: " + event.getAcceptedTransferMode());
}
} else {
logger.warn("Cannot complete drag and drop operation: selected TreeItem is null");
}
} else {
logger.warn("Cannot complete drag and drop operation: selected TreeView is null");
}
event.consume();
}
}
use of eu.fthevenet.binjr.data.adapters.TimeSeriesBinding in project selenium_java by sergueik.
the class JrdsDataAdapter method attachNode.
private void attachNode(TreeItem<TimeSeriesBinding<Double>> tree, String id, Map<String, JsonJrdsItem> nodes) throws DataAdapterException {
JsonJrdsItem n = nodes.get(id);
String currentPath = normalizeId(n.id);
TreeItem<TimeSeriesBinding<Double>> newBranch = new TreeItem<>(bindingFactory.of(tree.getValue().getTreeHierarchy(), n.name, currentPath, this));
if (JRDS_FILTER.equals(n.type)) {
// add a dummy node so that the branch can be expanded
newBranch.getChildren().add(new TreeItem<>(null));
// add a listener that will get the treeview filtered according to the selected filter/tag
newBranch.expandedProperty().addListener(new FilteredViewListener(n, newBranch));
} else {
if (n.children != null) {
for (JsonJrdsItem.JsonTreeRef ref : n.children) {
attachNode(newBranch, ref._reference, nodes);
}
} else {
// add a dummy node so that the branch can be expanded
newBranch.getChildren().add(new TreeItem<>(null));
// add a listener so that bindings for individual datastore are added lazily to avoid
// dozens of individual call to "graphdesc" when the tree is built.
newBranch.expandedProperty().addListener(new GraphDescListener(currentPath, newBranch, tree));
}
}
tree.getChildren().add(newBranch);
}
use of eu.fthevenet.binjr.data.adapters.TimeSeriesBinding in project selenium_java by sergueik.
the class JrdsDataAdapter method getBindingTree.
// region [DataAdapter Members]
@Override
public TreeItem<TimeSeriesBinding<Double>> getBindingTree() throws DataAdapterException {
Gson gson = new Gson();
try {
JsonJrdsTree t = gson.fromJson(getJsonTree(treeViewTab.getCommand(), treeViewTab.getArgument(), filter), JsonJrdsTree.class);
Map<String, JsonJrdsItem> m = Arrays.stream(t.items).collect(Collectors.toMap(o -> o.id, (o -> o)));
TreeItem<TimeSeriesBinding<Double>> tree = new TreeItem<>(bindingFactory.of("", getSourceName(), "/", this));
for (JsonJrdsItem branch : Arrays.stream(t.items).filter(jsonJrdsItem -> JRDS_TREE.equals(jsonJrdsItem.type) || JRDS_FILTER.equals(jsonJrdsItem.type)).collect(Collectors.toList())) {
attachNode(tree, branch.id, m);
}
return tree;
} catch (JsonParseException e) {
throw new DataAdapterException("An error occurred while parsing the json response to getBindingTree request", e);
} catch (URISyntaxException e) {
throw new SourceCommunicationException("Error building URI for request", e);
}
}
use of eu.fthevenet.binjr.data.adapters.TimeSeriesBinding in project selenium_java by sergueik.
the class WorksheetController method addBindings.
// region *** protected members ***
protected void addBindings(Collection<TimeSeriesBinding<Double>> bindings, Chart<Double> targetChart) {
InvalidationListener isVisibleListener = (observable) -> {
viewPorts.stream().filter(v -> v.getDataStore().equals(targetChart)).findFirst().ifPresent(v -> {
boolean andAll = true;
boolean orAll = false;
for (TimeSeriesInfo<?> t : targetChart.getSeries()) {
andAll &= t.isSelected();
orAll |= t.isSelected();
}
CheckBox showAllCheckBox = (CheckBox) v.getSeriesTable().getColumns().get(0).getGraphic();
showAllCheckBox.setIndeterminate(Boolean.logicalXor(andAll, orAll));
showAllCheckBox.setSelected(andAll);
});
};
for (TimeSeriesBinding<Double> b : bindings) {
TimeSeriesInfo<Double> newSeries = TimeSeriesInfo.fromBinding(b);
bindingManager.attachListener(newSeries.selectedProperty(), (observable, oldValue, newValue) -> viewPorts.stream().filter(v -> v.getDataStore().equals(targetChart)).findFirst().ifPresent(v -> invalidate(v, false, false)));
bindingManager.attachListener(newSeries.selectedProperty(), isVisibleListener);
targetChart.addSeries(newSeries);
// Explicitly call the listener to initialize the proper status of the checkbox
isVisibleListener.invalidated(null);
}
invalidateAll(false, false, false);
}
Aggregations