Search in sources :

Example 1 with ViewportData

use of io.deephaven.web.client.api.subscription.ViewportData in project deephaven-core by deephaven.

the class JsTable method processSnapshot.

protected void processSnapshot() {
    try {
        if (debounce == null) {
            JsLog.debug("Skipping snapshot b/c debounce is null");
            return;
        }
        if (debounce.state != currentState) {
            JsLog.debug("Skipping snapshot because state has changed ", debounce.state, " != ", currentState);
            return;
        }
        if (isClosed()) {
            JsLog.debug("Skipping snapshot because table is closed", this);
            return;
        }
        JsArray<Column> viewportColumns = getColumns().filter((item, index, all) -> debounce.columns.get(item.getIndex()));
        ViewportData data = new ViewportData(debounce.includedRows, debounce.dataColumns, viewportColumns, currentState.getRowFormatColumn() == null ? NO_ROW_FORMAT_COLUMN : currentState.getRowFormatColumn().getIndex(), debounce.maxRows);
        this.currentViewportData = data;
        CustomEventInit updatedEvent = CustomEventInit.create();
        updatedEvent.setDetail(data);
        fireEvent(EVENT_UPDATED, updatedEvent);
        // also fire rowadded events - TODO also fire some kind of remove event for now-missing rows?
        for (int i = 0; i < data.getRows().length; i++) {
            CustomEventInit addedEvent = CustomEventInit.create();
            addedEvent.setDetail(wrap(data.getRows().getAt(i), i));
            fireEvent(EVENT_ROWADDED, addedEvent);
        }
    } finally {
        debounce = null;
    }
}
Also used : ViewportData(io.deephaven.web.client.api.subscription.ViewportData) CustomEventInit(elemental2.dom.CustomEventInit)

Example 2 with ViewportData

use of io.deephaven.web.client.api.subscription.ViewportData in project deephaven-core by deephaven.

the class JsTable method handleDelta.

public void handleDelta(ClientTableState current, DeltaUpdates updates) {
    current.onRunning(s -> {
        if (current != state()) {
            return;
        }
        if (nonViewportSub != null) {
            nonViewportSub.handleDelta(updates);
            return;
        }
        final ViewportData vpd = currentViewportData;
        if (vpd == null) {
            // if the current viewport data is null, we're waiting on an initial snapshot to arrive for a different
            // part of the viewport
            JsLog.debug("Received delta while waiting for reinitialization");
            return;
        }
        MergeResults mergeResults = vpd.merge(updates);
        if (mergeResults.added.size() == 0 && mergeResults.modified.size() == 0 && mergeResults.removed.size() == 0) {
            return;
        }
        CustomEventInit event = CustomEventInit.create();
        event.setDetail(vpd);
        // user might call setViewport, and wind up nulling our currentViewportData
        fireEvent(EVENT_UPDATED, event);
        // here
        for (Integer index : mergeResults.added) {
            CustomEventInit addedEvent = CustomEventInit.create();
            addedEvent.setDetail(wrap(vpd.getRows().getAt(index), index));
            fireEvent(EVENT_ROWADDED, addedEvent);
        }
        for (Integer index : mergeResults.modified) {
            CustomEventInit addedEvent = CustomEventInit.create();
            addedEvent.setDetail(wrap(vpd.getRows().getAt(index), index));
            fireEvent(EVENT_ROWUPDATED, addedEvent);
        }
        for (Integer index : mergeResults.removed) {
            CustomEventInit addedEvent = CustomEventInit.create();
            addedEvent.setDetail(wrap(vpd.getRows().getAt(index), index));
            fireEvent(EVENT_ROWREMOVED, addedEvent);
        }
    }, JsRunnable.doNothing());
}
Also used : ViewportData(io.deephaven.web.client.api.subscription.ViewportData) CustomEventInit(elemental2.dom.CustomEventInit) MergeResults(io.deephaven.web.client.api.subscription.ViewportData.MergeResults)

Example 3 with ViewportData

use of io.deephaven.web.client.api.subscription.ViewportData in project deephaven-core by deephaven.

the class JsTable method refreshViewport.

public void refreshViewport(ClientTableState state, Viewport vp) {
    assert state() == state : "Called refreshViewport with wrong state (" + state + " instead of " + state() + ")";
    assert state.getResolution() == ClientTableState.ResolutionState.RUNNING : "Do not call refreshViewport for a state that is not running! (" + state + ")";
    // ignore any deltas for past viewports
    currentViewportData = null;
    workerConnection.scheduleCheck(state);
    // will be here soon, and will fire its own event)
    if (state.getSize() != ClientTableState.SIZE_UNINITIALIZED && state.getSize() <= vp.getRows().getFirstRow()) {
        JsLog.debug("Preparing to send a 'fake' update event since " + state.getSize() + "<=" + vp.getRows().getFirstRow(), state);
        LazyPromise.runLater(() -> {
            if (state != state()) {
                return;
            }
            // get the column expected to be in the snapshot
            JsArray<Column> columns = Js.uncheckedCast(getBinding().getColumns());
            Column[] allColumns = state.getColumns();
            if (columns == null) {
                columns = Js.uncheckedCast(allColumns);
            }
            // build an array of empty column data for this snapshot
            Object[] dataColumns = new Object[allColumns.length];
            for (int i = 0; i < columns.length; i++) {
                Column c = columns.getAt(i);
                dataColumns[c.getIndex()] = JsData.newArray(c.getType());
                if (c.getFormatStringColumnIndex() != null) {
                    dataColumns[c.getFormatStringColumnIndex()] = JsData.newArray("java.lang.String");
                }
                if (c.getStyleColumnIndex() != null) {
                    dataColumns[c.getStyleColumnIndex()] = JsData.newArray("long");
                }
            }
            if (currentState.getRowFormatColumn() != null) {
                dataColumns[currentState.getRowFormatColumn().getIndex()] = JsData.newArray("long");
            }
            ViewportData data = new ViewportData(RangeSet.empty(), dataColumns, columns, currentState.getRowFormatColumn() == null ? NO_ROW_FORMAT_COLUMN : currentState.getRowFormatColumn().getIndex(), 0);
            this.currentViewportData = data;
            CustomEventInit updatedEvent = CustomEventInit.create();
            updatedEvent.setDetail(data);
            JsLog.debug("Sending 'fake' update event since " + state.getSize() + "<=" + vp.getRows().getFirstRow(), vp, state);
            fireEvent(EVENT_UPDATED, updatedEvent);
        });
    }
}
Also used : ViewportData(io.deephaven.web.client.api.subscription.ViewportData) CustomEventInit(elemental2.dom.CustomEventInit)

Aggregations

CustomEventInit (elemental2.dom.CustomEventInit)3 ViewportData (io.deephaven.web.client.api.subscription.ViewportData)3 MergeResults (io.deephaven.web.client.api.subscription.ViewportData.MergeResults)1