Search in sources :

Example 86 with Timer

use of com.google.gwt.user.client.Timer in project rstudio by rstudio.

the class TimedProgressIndicator method onTimedProgress.

/**
    * Displays a message on the progress indicator for at least the given length
    * of time, even after the progress operation is complete.
    * 
    * @param message The message to display.
    * @param minDisplayTime The minimum length of time to display the message.
    */
public void onTimedProgress(String message, int minDisplayTime) {
    onProgress(message);
    if (timer_ == null) {
        timer_ = new Timer() {

            @Override
            public void run() {
                // now
                if (completed_)
                    onCompleted();
            }
        };
    }
    timer_.schedule(minDisplayTime);
}
Also used : Timer(com.google.gwt.user.client.Timer)

Example 87 with Timer

use of com.google.gwt.user.client.Timer in project rstudio by rstudio.

the class ProjectPackratPreferencesPane method verifyPrerequisites.

private void verifyPrerequisites() {
    final ProgressIndicator indicator = getProgressIndicator();
    indicator.onProgress("Verifying prequisites...");
    server_.getPackratPrerequisites(new ServerRequestCallback<PackratPrerequisites>() {

        @Override
        public void onResponseReceived(PackratPrerequisites prereqs) {
            indicator.onCompleted();
            if (prereqs.getBuildToolsAvailable()) {
                if (prereqs.getPackageAvailable()) {
                    setUsePackrat(true);
                } else {
                    setUsePackrat(false);
                    // install packrat (with short delay to allow
                    // the progress indicator to clear)
                    new Timer() {

                        @Override
                        public void run() {
                            dependencyManager_.withPackrat("Managing packages with packrat", new Command() {

                                @Override
                                public void execute() {
                                    setUsePackrat(true);
                                }
                            });
                        }
                    }.schedule(250);
                }
            } else {
                setUsePackrat(false);
                // install build tools (with short delay to allow
                // the progress indicator to clear)
                new Timer() {

                    @Override
                    public void run() {
                        server_.installBuildTools("Managing packages with Packrat", new SimpleRequestCallback<Boolean>() {
                        });
                    }
                }.schedule(250);
            }
        }

        @Override
        public void onError(ServerError error) {
            setUsePackrat(false);
            indicator.onError(error.getUserMessage());
        }
    });
}
Also used : PackratPrerequisites(org.rstudio.studio.client.packrat.model.PackratPrerequisites) Timer(com.google.gwt.user.client.Timer) Command(com.google.gwt.user.client.Command) ProgressIndicator(org.rstudio.core.client.widget.ProgressIndicator) ServerError(org.rstudio.studio.client.server.ServerError)

Example 88 with Timer

use of com.google.gwt.user.client.Timer in project rstudio by rstudio.

the class ExportPlotSizeEditor method prepareForExport.

public void prepareForExport(final Command onReady) {
    if (getPreviewRequiresUpdate()) {
        updatePreview();
        new Timer() {

            @Override
            public void run() {
                onReady.execute();
            }
        }.schedule(1000);
        ;
    } else {
        onReady.execute();
    }
}
Also used : Timer(com.google.gwt.user.client.Timer)

Example 89 with Timer

use of com.google.gwt.user.client.Timer in project rstudio by rstudio.

the class RemoteServerEventListener method doListen.

private void doListen() {
    // abort if we are no longer running
    if (!isListening_)
        return;
    // setup request callback (save reference for cancellation)
    activeRequestCallback_ = new ServerRequestCallback<JsArray<ClientEvent>>() {

        @Override
        public void onResponseReceived(JsArray<ClientEvent> events) {
            // keep watchdog appraised of successful receipt of events
            watchdog_.notifyResponseReceived();
            try {
                // only processs events if we are still listening
                if (isListening_ && (events != null)) {
                    for (int i = 0; i < events.length(); i++) {
                        // is dispatched
                        if (!isListening_)
                            return;
                        // disppatch event
                        ClientEvent event = events.get(i);
                        dispatchEvent(event);
                        lastEventId_ = event.getId();
                    }
                }
            }// listen() again after processing
             catch (Throwable e) {
                GWT.log("ERROR: Processing client events", e);
            }
            // listen for more events
            listen();
        }

        @Override
        public void onError(ServerError error) {
            // stop listening for events
            stop();
            // if this was server unavailable then signal event and return
            if (error.getCode() == ServerError.UNAVAILABLE) {
                ServerUnavailableEvent event = new ServerUnavailableEvent();
                server_.getEventBus().fireEvent(event);
                return;
            }
            // result in our server getting hammered with requests)
            if (listenErrorCount_++ <= 5) {
                Timer startTimer = new Timer() {

                    @Override
                    public void run() {
                        // by some other means (e.g. ensureListening, etc)
                        if (!isListening_)
                            start();
                    }
                };
                startTimer.schedule(500);
            } else // otherwise reset the listen error count and remain stopped
            {
                listenErrorCount_ = 0;
            }
        }
    };
    // retry handler (restart listener)
    RetryHandler retryHandler = new RetryHandler() {

        public void onRetry() {
            // need to do a full restart to ensure that the existing
            // activeRequest_ and activeRequestCallback_ are cleaned up
            // and all state is reset correctly
            restart();
        }

        public void onError(RpcError error) {
            // error while attempting to recover, to be on the safe side
            // we simply stop listening for events. if rather than stopping 
            // we restarted we would open ourselves up to a situation
            // where we keep hitting the same error over and over again.
            stop();
        }
    };
    // send request
    activeRequest_ = server_.getEvents(lastEventId_, activeRequestCallback_, retryHandler);
}
Also used : JsArray(com.google.gwt.core.client.JsArray) Timer(com.google.gwt.user.client.Timer) ServerError(org.rstudio.studio.client.server.ServerError) RpcError(org.rstudio.core.client.jsonrpc.RpcError)

Example 90 with Timer

use of com.google.gwt.user.client.Timer in project rstudio by rstudio.

the class RemoteServerEventListener method listen.

private void listen() {
    // bounce listen to ensure it is never added to the browser's internal 
    // list of requests bound to the current page load. being on this list
    // (at least in webkit, perhaps in others) results in at least 2 and 
    // perhaps other problems:
    //
    //  1) perpetual "Loading..." indicator displayed to user (user can
    //     also then "cancel" the event request!); and
    //
    //  2) terimation of the request without warning by the browser when
    //     the user hits the Back button within a frame hosted on the page
    //     (note in this case we get no error so think the request is still
    //     running -- see Watchdog for workaround to this general class of 
    //     issues)
    // determine bounce ms (do a bigger bounce for the second listen
    // request as this is the one which gets us stuck in "perpetual loading")
    int bounceMs = 1;
    if (++listenCount_ == 2)
        bounceMs = kSecondListenBounceMs;
    Timer listenTimer = new Timer() {

        @Override
        public void run() {
            doListen();
        }
    };
    listenTimer.schedule(bounceMs);
}
Also used : Timer(com.google.gwt.user.client.Timer)

Aggregations

Timer (com.google.gwt.user.client.Timer)133 Command (com.google.gwt.user.client.Command)7 Element (com.google.gwt.dom.client.Element)6 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)4 Style (com.google.gwt.dom.client.Style)4 Request (com.google.gwt.http.client.Request)4 RequestBuilder (com.google.gwt.http.client.RequestBuilder)4 RequestCallback (com.google.gwt.http.client.RequestCallback)4 RequestException (com.google.gwt.http.client.RequestException)4 Response (com.google.gwt.http.client.Response)4 JSONString (com.google.gwt.json.client.JSONString)4 Widget (com.google.gwt.user.client.ui.Widget)4 ArrayList (java.util.ArrayList)4 ServerError (org.rstudio.studio.client.server.ServerError)4 Label (com.google.gwt.user.client.ui.Label)3 VerticalPanel (com.google.gwt.user.client.ui.VerticalPanel)3 Date (java.util.Date)3 SessionInfo (org.rstudio.studio.client.workbench.model.SessionInfo)3 SliderEvent (com.extjs.gxt.ui.client.event.SliderEvent)2 Animation (com.google.gwt.animation.client.Animation)2