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);
}
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);
}
}
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);
});
}
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);
});
}
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);
}
Aggregations