Search in sources :

Example 1 with CustomEvent

use of elemental2.dom.CustomEvent in project gwtproject by treblereel.

the class ClickLinkTest method testClickLink.

/* Tests against issue #572: Double unescaping of history tokens. */
@Test(timeout = 5000)
public Promise<Void> testClickLink() {
    return new Promise<>((resolve, reject) -> {
        HTMLAnchorElement anchorElement = Js.cast(DomGlobal.document.createElement("a"));
        anchorElement.href = "#href1";
        DomGlobal.document.body.appendChild(anchorElement);
        CustomEvent<String> clickEvent = new CustomEvent<>("click");
        // NativeEvent clickEvent =
        // DomGlobal.document.create.createEvent(0, 0, 0, 0, 0, false, false,
        // false, false);
        // 
        timer = new Timer() {

            @Override
            public void run() {
                anchorElement.dispatchEvent(clickEvent);
            }
        };
        try {
            History.newItem("something_as_base");
            addHistoryListenerImpl(event -> {
                assertEquals("href1", event.getValue());
                resolve.onInvoke((Void) null);
            });
            timer.schedule(1000);
        } finally {
            DomGlobal.document.body.removeChild(anchorElement);
        }
    });
}
Also used : CustomEvent(elemental2.dom.CustomEvent) Promise(elemental2.promise.Promise) HTMLAnchorElement(elemental2.dom.HTMLAnchorElement) Timer(org.gwtproject.timer.client.Timer) Test(org.junit.Test)

Example 2 with CustomEvent

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

the class FigureSubscription method subscribe.

private Promise<TableSubscription> subscribe(final Promise<JsTable> tablePromise) {
    assert currentData == null;
    return tablePromise.then(table -> {
        if (subscription == null) {
            // do we need this?
            table.close();
            // noinspection unchecked
            return (Promise<TableSubscription>) (Promise) Promise.reject("Already closed");
        }
        TableSubscription sub = table.subscribe(table.getColumns());
        // TODO, technically we can probably unsubscribe to the table at this point, since we're listening to the
        // subscription itself
        this.currentData = new ChartData(table);
        sub.addEventListener(TableSubscription.EVENT_UPDATED, e -> {
            // refire with specifics for the columns that we're watching here, after updating data arrays
            SubscriptionTableData.UpdateEventData subscriptionUpdateData = (SubscriptionTableData.UpdateEventData) ((CustomEvent) e).detail;
            currentData.update(subscriptionUpdateData);
            CustomEventInit event = CustomEventInit.create();
            event.setDetail(new DataUpdateEvent(includedSeries.toArray(new JsSeries[0]), currentData, subscriptionUpdateData));
            figure.fireEvent(JsFigure.EVENT_UPDATED, event);
            if (!firstEventFired) {
                firstEventFired = true;
                if (downsampleAxisRange != null) {
                    CustomEventInit successInit = CustomEventInit.create();
                    successInit.setDetail(includedSeries.toArray());
                    figure.fireEvent(JsFigure.EVENT_DOWNSAMPLEFINISHED, successInit);
                }
            }
        });
        return Promise.resolve(sub);
    });
}
Also used : Promise(elemental2.promise.Promise) CustomEventInit(elemental2.dom.CustomEventInit) SubscriptionTableData(io.deephaven.web.client.api.subscription.SubscriptionTableData) TableSubscription(io.deephaven.web.client.api.subscription.TableSubscription)

Aggregations

Promise (elemental2.promise.Promise)2 CustomEvent (elemental2.dom.CustomEvent)1 CustomEventInit (elemental2.dom.CustomEventInit)1 HTMLAnchorElement (elemental2.dom.HTMLAnchorElement)1 SubscriptionTableData (io.deephaven.web.client.api.subscription.SubscriptionTableData)1 TableSubscription (io.deephaven.web.client.api.subscription.TableSubscription)1 Timer (org.gwtproject.timer.client.Timer)1 Test (org.junit.Test)1