Search in sources :

Example 1 with TimeSeriesBinding

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);
        }
    });
}
Also used : ZoneId(java.time.ZoneId) DataAdapterException(eu.fthevenet.binjr.data.exceptions.DataAdapterException) URISyntaxException(java.net.URISyntaxException) NoAdapterFoundException(eu.fthevenet.binjr.data.exceptions.NoAdapterFoundException) CannotInitializeDataAdapterException(eu.fthevenet.binjr.data.exceptions.CannotInitializeDataAdapterException) JAXBException(javax.xml.bind.JAXBException) DiagnosticException(eu.fthevenet.util.diagnositic.DiagnosticException) IOException(java.io.IOException) TimeSeriesBinding(eu.fthevenet.binjr.data.adapters.TimeSeriesBinding) ZonedDateTime(java.time.ZonedDateTime)

Example 2 with TimeSeriesBinding

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();
    }
}
Also used : Node(javafx.scene.Node) NoAdapterFoundException(eu.fthevenet.binjr.data.exceptions.NoAdapterFoundException) IOException(java.io.IOException) TimeSeriesBinding(eu.fthevenet.binjr.data.adapters.TimeSeriesBinding) Stage(javafx.stage.Stage)

Example 3 with TimeSeriesBinding

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);
}
Also used : TimeSeriesBinding(eu.fthevenet.binjr.data.adapters.TimeSeriesBinding) TreeItem(javafx.scene.control.TreeItem) JsonJrdsItem(eu.fthevenet.binjr.sources.jrds.adapters.json.JsonJrdsItem)

Example 4 with TimeSeriesBinding

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);
    }
}
Also used : JsonParseException(com.google.gson.JsonParseException) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) java.util(java.util) JsonJrdsTree(eu.fthevenet.binjr.sources.jrds.adapters.json.JsonJrdsTree) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Dialogs(eu.fthevenet.binjr.dialogs.Dialogs) TreeItem(javafx.scene.control.TreeItem) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) ZonedDateTime(java.time.ZonedDateTime) JsonJrdsItem(eu.fthevenet.binjr.sources.jrds.adapters.json.JsonJrdsItem) StatusLine(org.apache.http.StatusLine) EntityUtils(org.apache.http.util.EntityUtils) Gson(com.google.gson.Gson) HttpDataAdapterBase(eu.fthevenet.binjr.data.adapters.HttpDataAdapterBase) BasicResponseHandler(org.apache.http.impl.client.BasicResponseHandler) AbstractResponseHandler(org.apache.http.impl.client.AbstractResponseHandler) URI(java.net.URI) JAXB(javax.xml.bind.JAXB) CsvDecoder(eu.fthevenet.binjr.data.codec.CsvDecoder) XmlAccessorType(javax.xml.bind.annotation.XmlAccessorType) MalformedURLException(java.net.MalformedURLException) XmlUtils(eu.fthevenet.util.xml.XmlUtils) HttpEntity(org.apache.http.HttpEntity) HttpResponseException(org.apache.http.client.HttpResponseException) eu.fthevenet.binjr.data.exceptions(eu.fthevenet.binjr.data.exceptions) IOException(java.io.IOException) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) XmlAccessType(javax.xml.bind.annotation.XmlAccessType) DataAdapter(eu.fthevenet.binjr.data.adapters.DataAdapter) Logger(org.apache.logging.log4j.Logger) TimeSeriesBinding(eu.fthevenet.binjr.data.adapters.TimeSeriesBinding) DateTimeFormatter(java.time.format.DateTimeFormatter) ObservableValue(javafx.beans.value.ObservableValue) Pattern(java.util.regex.Pattern) ChangeListener(javafx.beans.value.ChangeListener) NameValuePair(org.apache.http.NameValuePair) LogManager(org.apache.logging.log4j.LogManager) DoubleTimeSeriesProcessor(eu.fthevenet.binjr.data.timeseries.DoubleTimeSeriesProcessor) InputStream(java.io.InputStream) TreeItem(javafx.scene.control.TreeItem) Gson(com.google.gson.Gson) JsonJrdsTree(eu.fthevenet.binjr.sources.jrds.adapters.json.JsonJrdsTree) URISyntaxException(java.net.URISyntaxException) JsonParseException(com.google.gson.JsonParseException) TimeSeriesBinding(eu.fthevenet.binjr.data.adapters.TimeSeriesBinding) JsonJrdsItem(eu.fthevenet.binjr.sources.jrds.adapters.json.JsonJrdsItem)

Example 5 with TimeSeriesBinding

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);
}
Also used : TimeRangePicker(eu.fthevenet.util.javafx.controls.TimeRangePicker) HPos(javafx.geometry.HPos) Pos(javafx.geometry.Pos) BindingManager(eu.fthevenet.util.javafx.bindings.BindingManager) Initializable(javafx.fxml.Initializable) DoubleBinding(javafx.beans.binding.DoubleBinding) javafx.scene.layout(javafx.scene.layout) Dialogs(eu.fthevenet.binjr.dialogs.Dialogs) CacheHint(javafx.scene.CacheHint) javafx.scene.control(javafx.scene.control) URL(java.net.URL) ZonedDateTime(java.time.ZonedDateTime) NoAdapterFoundException(eu.fthevenet.binjr.data.exceptions.NoAdapterFoundException) Side(javafx.geometry.Side) InvalidationListener(javafx.beans.InvalidationListener) ColorTableCell(eu.fthevenet.util.javafx.controls.ColorTableCell) MaskerPane(org.controlsfx.control.MaskerPane) ListChangeListener(javafx.collections.ListChangeListener) ImageIO(javax.imageio.ImageIO) eu.fthevenet.binjr.data.workspace(eu.fthevenet.binjr.data.workspace) DelayedAction(eu.fthevenet.util.javafx.controls.DelayedAction) USE_COMPUTED_SIZE(javafx.scene.layout.Region.USE_COMPUTED_SIZE) PropertyValueFactory(javafx.scene.control.cell.PropertyValueFactory) ReadOnlyDoubleProperty(javafx.beans.property.ReadOnlyDoubleProperty) AsyncTaskManager(eu.fthevenet.binjr.data.async.AsyncTaskManager) Group(javafx.scene.Group) Collectors(java.util.stream.Collectors) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) DataAdapter(eu.fthevenet.binjr.data.adapters.DataAdapter) Duration(javafx.util.Duration) Logger(org.apache.logging.log4j.Logger) TimeSeriesBinding(eu.fthevenet.binjr.data.adapters.TimeSeriesBinding) javafx.scene.chart(javafx.scene.chart) CheckBoxTableCell(javafx.scene.control.cell.CheckBoxTableCell) ObservableList(javafx.collections.ObservableList) Path(javafx.scene.shape.Path) Profiler(eu.fthevenet.util.logging.Profiler) java.util(java.util) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Bindings(javafx.beans.binding.Bindings) Function(java.util.function.Function) Supplier(java.util.function.Supplier) VPos(javafx.geometry.VPos) FXMLLoader(javafx.fxml.FXMLLoader) GlobalPreferences(eu.fthevenet.binjr.preferences.GlobalPreferences) TextAlignment(javafx.scene.text.TextAlignment) Chart(eu.fthevenet.binjr.data.workspace.Chart) DecimalFormatTableCellFactory(eu.fthevenet.util.javafx.controls.DecimalFormatTableCellFactory) Color(javafx.scene.paint.Color) javafx.scene.input(javafx.scene.input) Node(javafx.scene.Node) Property(javafx.beans.property.Property) WritableImage(javafx.scene.image.WritableImage) IOException(java.io.IOException) File(java.io.File) Consumer(java.util.function.Consumer) eu.fthevenet.util.javafx.charts(eu.fthevenet.util.javafx.charts) FileChooser(javafx.stage.FileChooser) ActionEvent(javafx.event.ActionEvent) Stage(javafx.stage.Stage) DateTimeFormatter(java.time.format.DateTimeFormatter) SwingFXUtils(javafx.embed.swing.SwingFXUtils) ObservableValue(javafx.beans.value.ObservableValue) ChangeListener(javafx.beans.value.ChangeListener) LogManager(org.apache.logging.log4j.LogManager) InvalidationListener(javafx.beans.InvalidationListener)

Aggregations

TimeSeriesBinding (eu.fthevenet.binjr.data.adapters.TimeSeriesBinding)9 IOException (java.io.IOException)5 NoAdapterFoundException (eu.fthevenet.binjr.data.exceptions.NoAdapterFoundException)3 ZonedDateTime (java.time.ZonedDateTime)3 Node (javafx.scene.Node)3 Stage (javafx.stage.Stage)3 DataAdapter (eu.fthevenet.binjr.data.adapters.DataAdapter)2 ChartType (eu.fthevenet.binjr.data.workspace.ChartType)2 UnitPrefixes (eu.fthevenet.binjr.data.workspace.UnitPrefixes)2 Dialogs (eu.fthevenet.binjr.dialogs.Dialogs)2 JsonJrdsItem (eu.fthevenet.binjr.sources.jrds.adapters.json.JsonJrdsItem)2 InputStream (java.io.InputStream)2 URISyntaxException (java.net.URISyntaxException)2 URL (java.net.URL)2 ZoneId (java.time.ZoneId)2 DateTimeFormatter (java.time.format.DateTimeFormatter)2 java.util (java.util)2 Collectors (java.util.stream.Collectors)2 TreeItem (javafx.scene.control.TreeItem)2 Color (javafx.scene.paint.Color)2