Search in sources :

Example 6 with CustomEventInit

use of elemental2.dom.CustomEventInit in project deephaven-core by deephaven.

the class JsTable method setSize.

public void setSize(double s) {
    boolean changed = this.size != s;
    if (changed) {
        JsLog.debug("Table ", this, " size changed from ", this.size, " to ", s);
    }
    this.size = s;
    TableViewportSubscription subscription = subscriptions.get(getHandle());
    if (changed && (subscription == null || subscription.getStatus() == TableViewportSubscription.Status.DONE)) {
        // If the size changed, and we have no subscription active, fire. Otherwise, we want to let the
        // subscription itself manage this, so that the size changes are synchronized with data changes,
        // and consumers won't be confused by the table size not matching data.
        CustomEventInit event = CustomEventInit.create();
        event.setDetail(s);
        fireEvent(JsTable.EVENT_SIZECHANGED, event);
    }
    fireEvent(JsTable.INTERNAL_EVENT_SIZELISTENER);
}
Also used : CustomEventInit(elemental2.dom.CustomEventInit) TableViewportSubscription(io.deephaven.web.client.api.subscription.TableViewportSubscription)

Example 7 with CustomEventInit

use of elemental2.dom.CustomEventInit in project deephaven-core by deephaven.

the class JsTable method setState.

@Override
public void setState(final ClientTableState state) {
    state.onRunning(s -> {
        if (state == currentState) {
            lastVisibleState = state;
            hasInputTable = s.getTableDef().getAttributes().isInputTable();
            // defer the size change so that is there is a viewport sub also waiting for onRunning, it gets it first
            LazyPromise.runLater(() -> {
                if (state == state()) {
                    setSize(state.getSize());
                }
            });
        }
    }, JsRunnable.doNothing());
    final ClientTableState was = currentState;
    if (was != state) {
        state.onRunning(s -> {
            // If already closed, we can ignore this, since we already cleaned those up
            if (!isClosed() && was != null && was != state()) {
                // if we held a subscription
                TableViewportSubscription existingSubscription = subscriptions.remove(was.getHandle());
                if (existingSubscription != null && existingSubscription.getStatus() != TableViewportSubscription.Status.DONE) {
                    JsLog.debug("closing old viewport", state(), existingSubscription.state());
                    // with the replacement state successfully running, we can shut down the old viewport (unless
                    // something
                    // external retained it)
                    existingSubscription.internalClose();
                }
            }
        }, JsRunnable.doNothing());
        boolean historyChanged = false;
        if (was != null) {
            // check if the new state is derived from the current state
            historyChanged = !state.isAncestor(was);
            was.pause(this);
            JsLog.debug("Table state change (new history? ", historyChanged, ") " + "from ", was.getHandle().toString(), was, " to ", state.getHandle().toString(), state);
        }
        currentState = state;
        ActiveTableBinding active = state.getActiveBinding(this);
        if (active == null) {
            state.createBinding(this);
        } else {
            active.changeState(state);
        }
        if (historyChanged) {
            // when the new state is not derived from the current state,
            // then, when the new state succeeds, we will totally releaseTable the previous table,
            // allowing it to be automatically released (if nobody else needs it).
            state.onRunning(success -> {
                if (isClosed()) {
                    // if already closed, we should have already released that handle too
                    return;
                }
                if (currentState != state) {
                    // ancestor
                    return;
                }
                final boolean shouldRelease = !state().isAncestor(was);
                JsLog.debug("History changing state update complete; release? ", shouldRelease, " state: ", was, LazyString.of(was::toStringMinimal));
                if (shouldRelease) {
                    was.releaseTable(this);
                }
            }, () -> {
                LazyPromise.runLater(() -> {
                    if (isClosed()) {
                        // if already closed, we should have already released that handle too
                        return;
                    }
                    if (currentState != state) {
                        // ancestor
                        return;
                    }
                    final boolean shouldRelease = !currentState.isAncestor(was);
                    JsLog.debug("History changing state update failed; release? ", shouldRelease, " state: ", was, LazyString.of(was::toStringMinimal));
                    if (shouldRelease) {
                        was.releaseTable(this);
                    }
                });
            });
        }
        final CustomEventInit init = CustomEventInit.create();
        init.setDetail(state);
        fireEvent(INTERNAL_EVENT_STATECHANGED, init);
    }
}
Also used : ActiveTableBinding(io.deephaven.web.client.state.ActiveTableBinding) ClientTableState(io.deephaven.web.client.state.ClientTableState) CustomEventInit(elemental2.dom.CustomEventInit) TableViewportSubscription(io.deephaven.web.client.api.subscription.TableViewportSubscription)

Example 8 with CustomEventInit

use of elemental2.dom.CustomEventInit in project deephaven-core by deephaven.

the class TableMap method refetch.

/**
 * Fetches (or re-fetches) the TableMap so it can be used internally
 */
@JsIgnore
public Promise<TableMap> refetch() {
    return Callbacks.promise(this, fetch).then(decl -> {
        workerConnection.registerTableMap(decl.getHandle(), this);
        tableMapHandle = decl.getHandle();
        for (Object key : (Object[]) decl.getKeys().getData()) {
            LocalKey k = LocalKey.of(key);
            put(key, k);
        }
        unsuppressEvents();
        fireEvent(EVENT_RECONNECT);
        return Promise.resolve(this);
    }).catch_(err -> {
        final CustomEventInit init = CustomEventInit.create();
        init.setDetail(err);
        unsuppressEvents();
        fireEvent(EVENT_RECONNECTFAILED, init);
        suppressEvents();
        // noinspection unchecked
        return (Promise<TableMap>) (Promise) Promise.reject(err);
    });
}
Also used : TableMapHandle(io.deephaven.web.shared.data.TableMapHandle) Arrays(java.util.Arrays) TableMapDeclaration(io.deephaven.web.shared.data.TableMapDeclaration) HashMap(java.util.HashMap) ClientTableState(io.deephaven.web.client.state.ClientTableState) CustomEventInit(elemental2.dom.CustomEventInit) Promise(elemental2.promise.Promise) JsSet(elemental2.core.JsSet) JsProperty(jsinterop.annotations.JsProperty) Consumer(java.util.function.Consumer) JsIgnore(jsinterop.annotations.JsIgnore) Map(java.util.Map) JsType(jsinterop.annotations.JsType) JsObject(elemental2.core.JsObject) Promise(elemental2.promise.Promise) CustomEventInit(elemental2.dom.CustomEventInit) JsObject(elemental2.core.JsObject) JsIgnore(jsinterop.annotations.JsIgnore)

Example 9 with CustomEventInit

use of elemental2.dom.CustomEventInit in project deephaven-core by deephaven.

the class JsFigure method refetch.

@JsIgnore
public Promise<JsFigure> refetch() {
    plotHandlesToTables = new HashMap<>();
    return Callbacks.grpcUnaryPromise(fetch::fetch).then(response -> {
        this.descriptor = FigureDescriptor.deserializeBinary(response.getData_asU8());
        charts = descriptor.getChartsList().asList().stream().map(chartDescriptor -> new JsChart(chartDescriptor, this)).toArray(JsChart[]::new);
        JsObject.freeze(charts);
        return this.tableFetch.fetch(this, response);
    }).then(tableFetchData -> {
        // all tables are wired up, need to map them to the series instances
        tables = tableFetchData.tables;
        tableMaps = tableFetchData.tableMaps;
        plotHandlesToTableMaps = tableFetchData.plotHandlesToTableMaps;
        onClose = tableFetchData.onClose;
        for (int i = 0; i < tables.length; i++) {
            JsTable table = tables[i];
            registerTableWithId(table, Js.cast(JsArray.of((double) i)));
        }
        Arrays.stream(charts).flatMap(c -> Arrays.stream(c.getSeries())).forEach(s -> s.initSources(plotHandlesToTables, plotHandlesToTableMaps));
        Arrays.stream(charts).flatMap(c -> Arrays.stream(c.getMultiSeries())).forEach(s -> s.initSources(plotHandlesToTableMaps));
        return null;
    }).then(ignore -> {
        unsuppressEvents();
        fireEvent(EVENT_RECONNECT);
        return Promise.resolve(this);
    }, err -> {
        final FigureFetchError fetchError = new FigureFetchError(LazyPromise.ofObject(err), this.descriptor != null ? this.descriptor.getErrorsList() : new JsArray<>());
        final CustomEventInit init = CustomEventInit.create();
        init.setDetail(fetchError);
        unsuppressEvents();
        fireEvent(EVENT_RECONNECTFAILED, init);
        suppressEvents();
        // noinspection unchecked,rawtypes
        return (Promise<JsFigure>) (Promise) Promise.reject(fetchError);
    });
}
Also used : Arrays(java.util.Arrays) JsOptional(jsinterop.annotations.JsOptional) JsBiConsumer(io.deephaven.web.shared.fu.JsBiConsumer) HashMap(java.util.HashMap) HasEventHandling(io.deephaven.web.client.api.HasEventHandling) Promise(elemental2.promise.Promise) JsPropertyMap(jsinterop.base.JsPropertyMap) Callbacks(io.deephaven.web.client.api.Callbacks) JsProperty(jsinterop.annotations.JsProperty) HashSet(java.util.HashSet) Js(jsinterop.base.Js) FetchObjectResponse(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.object_pb.FetchObjectResponse) WorkerConnection(io.deephaven.web.client.api.WorkerConnection) JsTable(io.deephaven.web.client.api.JsTable) Map(java.util.Map) JsType(jsinterop.annotations.JsType) NoSuchElementException(java.util.NoSuchElementException) LazyPromise(io.deephaven.web.client.fu.LazyPromise) JsObject(elemental2.core.JsObject) TableMap(io.deephaven.web.client.api.TableMap) AxisDescriptor(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.console_pb.figuredescriptor.AxisDescriptor) JsLog(io.deephaven.web.client.fu.JsLog) FigureDescriptor(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.console_pb.FigureDescriptor) Set(java.util.Set) ClientTableState(io.deephaven.web.client.state.ClientTableState) CustomEventInit(elemental2.dom.CustomEventInit) ExportedTableCreationResponse(io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.table_pb.ExportedTableCreationResponse) Collectors(java.util.stream.Collectors) JsArray(elemental2.core.JsArray) JsIgnore(jsinterop.annotations.JsIgnore) Stream(java.util.stream.Stream) Promise(elemental2.promise.Promise) LazyPromise(io.deephaven.web.client.fu.LazyPromise) JsTable(io.deephaven.web.client.api.JsTable) JsArray(elemental2.core.JsArray) CustomEventInit(elemental2.dom.CustomEventInit) JsIgnore(jsinterop.annotations.JsIgnore)

Example 10 with CustomEventInit

use of elemental2.dom.CustomEventInit in project deephaven-core by deephaven.

the class JsFigure method downsampleNeeded.

@JsIgnore
public void downsampleNeeded(String message, Set<JsSeries> series, double tableSize) {
    CustomEventInit failInit = CustomEventInit.create();
    failInit.setDetail(JsPropertyMap.of("series", series, "message", message, "size", tableSize));
    fireEvent(EVENT_DOWNSAMPLENEEDED, failInit);
}
Also used : CustomEventInit(elemental2.dom.CustomEventInit) JsIgnore(jsinterop.annotations.JsIgnore)

Aggregations

CustomEventInit (elemental2.dom.CustomEventInit)28 Promise (elemental2.promise.Promise)6 JsIgnore (jsinterop.annotations.JsIgnore)6 JsTable (io.deephaven.web.client.api.JsTable)4 ClientTableState (io.deephaven.web.client.state.ClientTableState)4 Map (java.util.Map)4 JsArray (elemental2.core.JsArray)3 CustomEvent (elemental2.dom.CustomEvent)3 TableMap (io.deephaven.web.client.api.TableMap)3 SubscriptionTableData (io.deephaven.web.client.api.subscription.SubscriptionTableData)3 TableSubscription (io.deephaven.web.client.api.subscription.TableSubscription)3 ViewportData (io.deephaven.web.client.api.subscription.ViewportData)3 JsLog (io.deephaven.web.client.fu.JsLog)3 HashMap (java.util.HashMap)3 JsProperty (jsinterop.annotations.JsProperty)3 JsObject (elemental2.core.JsObject)2 FigureDescriptor (io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.console_pb.FigureDescriptor)2 io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.console_pb.figuredescriptor (io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.console_pb.figuredescriptor)2 FetchObjectResponse (io.deephaven.javascript.proto.dhinternal.io.deephaven.proto.object_pb.FetchObjectResponse)2 DateWrapper (io.deephaven.web.client.api.DateWrapper)2