Search in sources :

Example 1 with RepeatingCommand

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

the class MathJaxLoader method ensureMathJaxLoaded.

public static void ensureMathJaxLoaded() {
    if (MATHJAX_LOADED)
        return;
    initializeMathJaxConfig();
    ScriptElement mathJaxEl = createMathJaxScriptElement();
    HeadElement headEl = Document.get().getHead();
    headEl.appendChild(mathJaxEl);
    Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {

        @Override
        public boolean execute() {
            if (isMathJaxReady()) {
                MATHJAX_LOADED = true;
                for (Callback callback : MATHJAX_CALLBACKS) callback.onLoaded(false);
                onMathJaxLoaded();
                return false;
            }
            RETRY_COUNT++;
            return RETRY_COUNT < 50;
        }
    }, 500);
}
Also used : HeadElement(com.google.gwt.dom.client.HeadElement) RepeatingCommand(com.google.gwt.core.client.Scheduler.RepeatingCommand) ScriptElement(com.google.gwt.dom.client.ScriptElement)

Example 2 with RepeatingCommand

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

the class DiagnosticsBackgroundPopup method start.

public void start() {
    isRunning_ = true;
    stopRequested_ = false;
    if (handler_ != null) {
        handler_.removeHandler();
        handler_ = null;
    }
    handler_ = Event.addNativePreviewHandler(new NativePreviewHandler() {

        @Override
        public void onPreviewNativeEvent(NativePreviewEvent event) {
            if (event.getTypeInt() == Event.ONMOUSEMOVE) {
                movedMouseMostRecently_ = true;
                Element target = Element.as(event.getNativeEvent().getEventTarget());
                if (target.hasClassName("ace_gutter-cell")) {
                    lastMouseCoords_ = null;
                    hidePopup();
                    return;
                }
                lastMouseCoords_ = ScreenCoordinates.create(event.getNativeEvent().getClientX(), event.getNativeEvent().getClientY());
                if (activeMarker_ != null && !activeMarker_.getRange().containsRightExclusive(editor_.toDocumentPosition(lastMouseCoords_))) {
                    hidePopup();
                }
            } else {
                movedMouseMostRecently_ = false;
            }
        }
    });
    Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {

        @Override
        public boolean execute() {
            if (stopRequested_)
                return stopExecution();
            // restarted later)
            if (!docDisplay_.isFocused())
                return stopExecution();
            long currentTime = System.currentTimeMillis();
            long lastModifiedTime = docDisplay_.getLastModifiedTime();
            long lastCursorChangedTime = docDisplay_.getLastCursorChangedTime();
            // cursor was moved recently, then bail
            if ((currentTime - lastModifiedTime) < 500)
                return completeExecution();
            if ((currentTime - lastCursorChangedTime) < 500)
                return completeExecution();
            Markers markers = editor_.getSession().getMarkers(true);
            Position currentPos;
            if (movedMouseMostRecently_) {
                if (lastMouseCoords_ == null)
                    return completeExecution();
                currentPos = editor_.toDocumentPosition(lastMouseCoords_);
            } else {
                currentPos = docDisplay_.getCursorPosition();
            }
            int[] keys = markers.getIds();
            for (int i = 0; i < keys.length; i++) {
                Marker marker = markers.get(keys[i]);
                if (marker.getRange().containsRightExclusive(currentPos)) {
                    displayMarkerDiagnostics(marker);
                    return completeExecution();
                }
            }
            return completeExecution();
        }
    }, 500);
}
Also used : NativePreviewHandler(com.google.gwt.user.client.Event.NativePreviewHandler) NativePreviewEvent(com.google.gwt.user.client.Event.NativePreviewEvent) Position(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Position) Element(com.google.gwt.dom.client.Element) RepeatingCommand(com.google.gwt.core.client.Scheduler.RepeatingCommand) Markers(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Markers) Marker(org.rstudio.studio.client.workbench.views.source.editors.text.ace.Marker)

Example 3 with RepeatingCommand

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

the class HelpPane method setLocation.

private void setLocation(final String url) {
    // allow subsequent calls to setLocation to override any previous 
    // call (necessary so two consecutive calls like we get during
    // some startup scenarios don't result in the first url displaying
    // rather than the second)
    targetUrl_ = url;
    RepeatingCommand navigateCommand = new RepeatingCommand() {

        @Override
        public boolean execute() {
            if (getIFrameEx() != null && getIFrameEx().getContentWindow() != null) {
                if (targetUrl_.equals(getUrl())) {
                    getIFrameEx().getContentWindow().reload();
                } else {
                    frame_.setUrl(targetUrl_);
                    replaceFrameUrl(frame_.getIFrame().cast(), targetUrl_);
                }
                return false;
            } else {
                return true;
            }
        }
    };
    if (navigateCommand.execute())
        Scheduler.get().scheduleFixedDelay(navigateCommand, 100);
}
Also used : RepeatingCommand(com.google.gwt.core.client.Scheduler.RepeatingCommand)

Example 4 with RepeatingCommand

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

the class AceEditorWidget method onLoad.

@Override
protected void onLoad() {
    super.onLoad();
    editor_.getRenderer().updateFontSize();
    onResize();
    fireEvent(new EditorLoadedEvent(editor_));
    events_.fireEvent(new EditorLoadedEvent(editor_));
    int delayMs = initToEmptyString_ ? 100 : 500;
    // On Windows desktop sometimes we inexplicably end up at the wrong size
    // if the editor is being resized while it's loading (such as when a new
    // document is created while the source pane is hidden)
    Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {

        public boolean execute() {
            if (isAttached())
                onResize();
            removeStyleName("loading");
            return false;
        }
    }, delayMs);
}
Also used : RepeatingCommand(com.google.gwt.core.client.Scheduler.RepeatingCommand) Breakpoint(org.rstudio.studio.client.common.debugging.model.Breakpoint)

Example 5 with RepeatingCommand

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

the class PdfJsWindow method navigateTo.

public static void navigateTo(final PdfJsWindow win, final PdfLocation pdfLocation) {
    double factor = win.getCurrentScale() * 96 / 72;
    final double x = pdfLocation.getX() * factor;
    final double y = pdfLocation.getY() * factor;
    final double w = pdfLocation.getWidth() * factor;
    final double h = pdfLocation.getHeight() * factor;
    final Value<Integer> retries = new Value<Integer>(0);
    // Sometimes pageContainer is null during load, so retry every 100ms
    // until it's not, or we've tried 40 times.
    Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {

        @Override
        public boolean execute() {
            Element pageContainer = win.getDocument().getElementById("pageContainer" + pdfLocation.getPage());
            if (pageContainer == null) {
                retries.setValue(retries.getValue() + 1);
                return retries.getValue() < 40;
            }
            if (pdfLocation.isFromClick()) {
                final DivElement div = win.getDocument().createDivElement();
                div.getStyle().setPosition(Style.Position.ABSOLUTE);
                div.getStyle().setTop(y, Unit.PX);
                div.getStyle().setLeft(x, Unit.PX);
                div.getStyle().setWidth(w, Unit.PX);
                div.getStyle().setHeight(h, Unit.PX);
                div.getStyle().setBackgroundColor("rgba(0, 126, 246, 0.1)");
                div.getStyle().setProperty("transition", "opacity 4s");
                // use DomUtils to set transition styles so gwt doesn't assert
                // an invalid style name (no camelCase) in debug mode
                DomUtils.setStyle(div, "-moz-transition", "opacity 4s");
                DomUtils.setStyle(div, "-webkit-transition", "opacity 4s");
                pageContainer.appendChild(div);
                Scheduler.get().scheduleFixedDelay(new Scheduler.RepeatingCommand() {

                    @Override
                    public boolean execute() {
                        div.getStyle().setOpacity(0.0);
                        return false;
                    }
                }, 2000);
            }
            // scroll to the page
            win.goToPage(pdfLocation.getPage());
            // if the target isn't on-screen then scroll to it
            SyncTexCoordinates boundary = getBoundaryCoordinates(win, false);
            if (boundary != null && pdfLocation.getY() > boundary.getY()) {
                Element container = getViewerContainer(win);
                container.setScrollTop(Math.max(0, DomUtils.topRelativeTo(getViewerContainer(win), pageContainer) + (int) y - 180));
            }
            win.focus();
            return false;
        }
    }, 100);
}
Also used : DivElement(com.google.gwt.dom.client.DivElement) RepeatingCommand(com.google.gwt.core.client.Scheduler.RepeatingCommand) DivElement(com.google.gwt.dom.client.DivElement) Element(com.google.gwt.dom.client.Element) Value(org.rstudio.studio.client.common.Value)

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