Search in sources :

Example 1 with NotebookHtmlMetadata

use of org.rstudio.studio.client.rmarkdown.model.NotebookHtmlMetadata in project rstudio by rstudio.

the class ChunkOutputStream method extractPages.

public List<ChunkOutputPage> extractPages() {
    // flush any errors so they are properly accounted for
    flushQueuedErrors();
    List<ChunkOutputPage> pages = new ArrayList<ChunkOutputPage>();
    List<Widget> removed = new ArrayList<Widget>();
    for (Widget w : this) {
        // extract ordinal and metadata
        JavaScriptObject metadata = null;
        String ord = w.getElement().getAttribute(ORDINAL_ATTRIBUTE);
        int ordinal = 0;
        if (!StringUtil.isNullOrEmpty(ord))
            ordinal = StringUtil.parseInt(ord, 0);
        if (metadata_.containsKey(ordinal))
            metadata = metadata_.get(ordinal);
        if (w instanceof ChunkDataWidget) {
            ChunkDataWidget widget = (ChunkDataWidget) w;
            ChunkDataPage data = new ChunkDataPage(widget, (NotebookFrameMetadata) metadata.cast(), ordinal);
            pages.add(data);
            removed.add(w);
            continue;
        } else if (w instanceof ChunkOrdinalWidget) {
            pages.add(new ChunkOrdinalPage(ordinal));
            removed.add(w);
            continue;
        }
        // extract the inner element if this is a fixed-ratio widget (or just
        // use raw if it's not)
        Widget inner = w;
        if (w instanceof FixedRatioWidget)
            inner = ((FixedRatioWidget) w).getWidget();
        if (inner instanceof ChunkPlotWidget) {
            ChunkPlotWidget plot = (ChunkPlotWidget) inner;
            ChunkPlotPage page = new ChunkPlotPage(plot.plotUrl(), plot.getMetadata(), ordinal, null, chunkOutputSize_);
            pages.add(page);
            removed.add(w);
        } else if (inner instanceof ChunkOutputFrame) {
            ChunkOutputFrame frame = (ChunkOutputFrame) inner;
            ChunkHtmlPage html = new ChunkHtmlPage(frame.getUrl(), (NotebookHtmlMetadata) metadata.cast(), ordinal, null, chunkOutputSize_);
            // cancel any pending page load
            frame.cancelPendingLoad();
            pages.add(html);
            removed.add(w);
        }
    }
    for (Widget r : removed) this.remove(r);
    return pages;
}
Also used : ArrayList(java.util.ArrayList) PreWidget(org.rstudio.core.client.widget.PreWidget) FixedRatioWidget(org.rstudio.core.client.widget.FixedRatioWidget) Widget(com.google.gwt.user.client.ui.Widget) NotebookHtmlMetadata(org.rstudio.studio.client.rmarkdown.model.NotebookHtmlMetadata) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) FixedRatioWidget(org.rstudio.core.client.widget.FixedRatioWidget)

Aggregations

JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)1 Widget (com.google.gwt.user.client.ui.Widget)1 ArrayList (java.util.ArrayList)1 FixedRatioWidget (org.rstudio.core.client.widget.FixedRatioWidget)1 PreWidget (org.rstudio.core.client.widget.PreWidget)1 NotebookHtmlMetadata (org.rstudio.studio.client.rmarkdown.model.NotebookHtmlMetadata)1