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