Search in sources :

Example 11 with RepeatingCommand

use of com.google.gwt.core.client.Scheduler.RepeatingCommand in project gwt-test-utils by gwt-test-utils.

the class BrowserSimulatorImpl method executeReaptingCommnand.

private void executeReaptingCommnand(List<RepeatingCommand> commands) {
    List<RepeatingCommand> toRemove = new ArrayList<RepeatingCommand>();
    int i = 0;
    while (i < commands.size()) {
        RepeatingCommand current = commands.get(i);
        if (!current.execute()) {
            toRemove.add(current);
        }
        i++;
    }
    for (RepeatingCommand rc : toRemove) {
        commands.remove(rc);
    }
}
Also used : RepeatingCommand(com.google.gwt.core.client.Scheduler.RepeatingCommand) ArrayList(java.util.ArrayList)

Example 12 with RepeatingCommand

use of com.google.gwt.core.client.Scheduler.RepeatingCommand in project gwt-test-utils by gwt-test-utils.

the class SchedulerTest method scheduledRepeatingCommandOrder.

@Test
public void scheduledRepeatingCommandOrder() {
    // Given
    i = j = 0;
    final StringBuilder sb = new StringBuilder();
    Scheduler.get().scheduleEntry(new RepeatingCommand() {

        public boolean execute() {
            sb.append("entry").append(i).append(" ");
            return 3 > i++;
        }
    });
    Scheduler.get().scheduleFinally(new RepeatingCommand() {

        public boolean execute() {
            sb.append("finally").append(j).append(" ");
            Scheduler.get().scheduleEntry(new RepeatingCommand() {

                public boolean execute() {
                    sb.append("subentry").append(j).append(" ");
                    return false;
                }
            });
            Scheduler.get().scheduleFinally(new RepeatingCommand() {

                public boolean execute() {
                    sb.append("subfinally").append(j).append(" ");
                    return false;
                }
            });
            return 3 > j++;
        }
    });
    // When
    getBrowserSimulator().fireLoopEnd();
    // Then
    assertThat(sb.toString()).isEqualTo("finally0 subfinally1 entry0 subentry1 finally1 subfinally2 entry1 subentry2 finally2 subfinally3 entry2 subentry3 finally3 subfinally4 entry3 subentry4 ");
}
Also used : RepeatingCommand(com.google.gwt.core.client.Scheduler.RepeatingCommand) Test(org.junit.Test)

Example 13 with RepeatingCommand

use of com.google.gwt.core.client.Scheduler.RepeatingCommand in project rstudio by rstudio.

the class ExternalJavaScriptLoader method onLoaded.

private void onLoaded() {
    state_ = State.Loaded;
    Scheduler.get().scheduleIncremental(new RepeatingCommand() {

        public boolean execute() {
            if (!callbacks_.isEmpty())
                callbacks_.remove().onLoaded();
            return !callbacks_.isEmpty();
        }
    });
}
Also used : RepeatingCommand(com.google.gwt.core.client.Scheduler.RepeatingCommand)

Example 14 with RepeatingCommand

use of com.google.gwt.core.client.Scheduler.RepeatingCommand in project rstudio by rstudio.

the class RmdOutputPanel method createFrame.

@Override
protected AnchorableFrame createFrame(String url) {
    AnchorableFrame frame = new AnchorableFrame();
    // allow full screen
    Element el = frame.getElement();
    el.setAttribute("webkitallowfullscreen", "");
    el.setAttribute("mozallowfullscreen", "");
    el.setAttribute("allowfullscreen", "");
    frame.navigate(url);
    final Operation initSlides = new Operation() {

        @Override
        public void execute() {
            if (getNavigationMenu().isVisible()) {
                fireSlideIndexChanged();
                slideChangeMonitor_.scheduleRepeating(100);
            }
        }
    };
    if (isShiny_) {
        shinyFrame_.initialize(url, new Operation() {

            @Override
            public void execute() {
                shinyFrame_.setScrollPosition(scrollPosition_);
                initSlides.execute();
            }
        });
    } else {
        // poll for document availability then perform initialization
        // tasks once it's available (addLoadHandler wasn't always 
        // getting called at least under Cocoa WebKit)
        Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {

            @Override
            public boolean execute() {
                // see if the document is ready
                AnchorableFrame frame = getFrame();
                if (frame == null)
                    return true;
                IFrameElementEx iframe = frame.getIFrame();
                if (iframe == null)
                    return true;
                Document doc = iframe.getContentDocument();
                if (doc == null)
                    return true;
                initSlides.execute();
                // Even though the document exists, it may not have rendered all
                // its content yet
                ScrollUtil.setScrollPositionOnLoad(frame, scrollPosition_);
                return false;
            }
        }, 50);
    }
    return frame;
}
Also used : Element(com.google.gwt.dom.client.Element) RepeatingCommand(com.google.gwt.core.client.Scheduler.RepeatingCommand) IFrameElementEx(org.rstudio.core.client.dom.IFrameElementEx) Operation(org.rstudio.core.client.widget.Operation) AnchorableFrame(org.rstudio.core.client.widget.AnchorableFrame) Document(com.google.gwt.dom.client.Document)

Example 15 with RepeatingCommand

use of com.google.gwt.core.client.Scheduler.RepeatingCommand in project rstudio by rstudio.

the class NewRSConnectAuthPage method pollForAuthCompleted.

private void pollForAuthCompleted() {
    Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {

        @Override
        public boolean execute() {
            // don't keep polling once auth is complete or window is closed
            if (!waitingForAuth_.getValue())
                return false;
            // returned for some reason, just wait for it to finish
            if (runningAuthCompleteCheck_)
                return true;
            runningAuthCompleteCheck_ = true;
            server_.getUserFromToken(result_.getServerInfo().getUrl(), result_.getPreAuthToken(), new ServerRequestCallback<RSConnectAuthUser>() {

                @Override
                public void onResponseReceived(RSConnectAuthUser user) {
                    runningAuthCompleteCheck_ = false;
                    // just wait and try again
                    if (!user.isValidUser())
                        return;
                    // user is valid--cache account info and close the
                    // window
                    result_.setAuthUser(user);
                    waitingForAuth_.setValue(false, true);
                    if (Desktop.isDesktop()) {
                        // on the desktop, we can close the window by name
                        Desktop.getFrame().closeNamedWindow(AUTH_WINDOW_NAME);
                    }
                    onUserAuthVerified();
                }

                @Override
                public void onError(ServerError error) {
                    // ignore this error
                    runningAuthCompleteCheck_ = false;
                }
            });
            return true;
        }
    }, 1000);
}
Also used : RSConnectAuthUser(org.rstudio.studio.client.rsconnect.model.RSConnectAuthUser) ServerError(org.rstudio.studio.client.server.ServerError) RepeatingCommand(com.google.gwt.core.client.Scheduler.RepeatingCommand) ServerRequestCallback(org.rstudio.studio.client.server.ServerRequestCallback)

Aggregations

RepeatingCommand (com.google.gwt.core.client.Scheduler.RepeatingCommand)21 JsArrayString (com.google.gwt.core.client.JsArrayString)3 Element (com.google.gwt.dom.client.Element)3 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)2 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)2 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 Coordinates (org.opennms.features.vaadin.nodemaps.internal.gwt.client.Coordinates)2 JSNodeMarker (org.opennms.features.vaadin.nodemaps.internal.gwt.client.JSNodeMarker)2 Breakpoint (org.rstudio.studio.client.common.debugging.model.Breakpoint)2 ServerError (org.rstudio.studio.client.server.ServerError)2 ServerRequestCallback (org.rstudio.studio.client.server.ServerRequestCallback)2 Position (org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position)2 CommentInfo (com.google.gerrit.client.changes.CommentInfo)1 NativeMap (com.google.gerrit.client.rpc.NativeMap)1 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)1 JsArray (com.google.gwt.core.client.JsArray)1 DivElement (com.google.gwt.dom.client.DivElement)1 Document (com.google.gwt.dom.client.Document)1