Example usage for com.google.gwt.dom.client NodeList getItem

List of usage examples for com.google.gwt.dom.client NodeList getItem

Introduction

In this page you can find the example usage for com.google.gwt.dom.client NodeList getItem.

Prototype

public T getItem(int index) 

Source Link

Usage

From source file:org.rstudio.studio.client.workbench.views.help.model.HelpInfo.java

License:Open Source License

private void parseArguments(HashMap<String, String> args, Element heading) {
    Element table = (Element) DomUtils.findNode(heading, true, true, new NodePredicate() {
        public boolean test(Node n) {
            if (n.getNodeType() != Node.ELEMENT_NODE)
                return false;

            Element el = (Element) n;

            return el.getTagName().toUpperCase().equals("TABLE")
                    && "R argblock".equals(el.getAttribute("summary"));
        }/*from w w w . j  a  v  a 2s .c  o  m*/
    });

    if (table == null) {
        assert false : "Unexpected help format, no argblock table found";
        return;
    }

    TableElement t = (TableElement) table;
    NodeList<TableRowElement> rows = t.getRows();
    for (int i = 0; i < rows.getLength(); i++) {
        TableRowElement row = rows.getItem(i);
        NodeList<TableCellElement> cells = row.getCells();

        TableCellElement argNameCell = cells.getItem(0);
        TableCellElement argValueCell = cells.getItem(1);

        String argNameText = argNameCell.getInnerText();
        String argValueHtml = argValueCell.getInnerHTML();

        // argNameCell may be multiple comma-delimited arguments;
        // split them up if necessary (duplicate the help across args)
        String[] argNameTextSplat = argNameText.split("\\s*,\\s*");
        for (int j = 0; j < argNameTextSplat.length; j++)
            args.put(argNameTextSplat[j], argValueHtml);

    }
}

From source file:org.rstudio.studio.client.workbench.views.plots.ui.export.impl.CopyPlotToClipboardDesktopDialog.java

License:Open Source License

protected void copyAsBitmap(Operation onCompleted) {
    ImageFrame imageFrame = getSizeEditor().getImageFrame();
    final WindowEx win = imageFrame.getElement().<IFrameElementEx>cast().getContentWindow();

    Document doc = win.getDocument();
    NodeList<Element> images = doc.getElementsByTagName("img");
    if (images.getLength() > 0) {
        ElementEx img = images.getItem(0).cast();

        Desktop.getFrame().copyImageToClipboard(img.getClientLeft(), img.getClientTop(), img.getClientWidth(),
                img.getClientHeight());/* w w w  .j av  a  2  s.co m*/
    }

    onCompleted.execute();
}

From source file:org.rstudio.studio.client.workbench.views.plots.ui.export.PlotsPanePreviewer.java

License:Open Source License

public Rectangle getPreviewClientRect() {
    WindowEx win = imageFrame_.getElement().<IFrameElementEx>cast().getContentWindow();
    Document doc = win.getDocument();
    NodeList<Element> images = doc.getElementsByTagName("img");
    if (images.getLength() > 0) {
        ElementEx img = images.getItem(0).cast();
        return new Rectangle(img.getClientLeft(), img.getClientTop(), img.getClientWidth(),
                img.getClientHeight());//from   ww w  .jav a  2s .c  om
    } else {
        return new Rectangle(0, 0, 0, 0);
    }
}

From source file:org.sakaiproject.sgs2.client.Sgs2.java

License:Educational Community License

private void configureSakaiParentIframe(int setHeight) {

    // Resize parent Sakai iframe
    Document doc = getWindowParentDocument();
    NodeList<Element> nodeList = doc.getElementsByTagName("iframe");
    for (int i = 0; i < nodeList.getLength(); i++) {
        IFrameElement iframe = (IFrameElement) nodeList.getItem(i);
        if (iframe.getId().startsWith("Main")) {
            iframe.setAttribute("height", setHeight + "px");
            iframe.setAttribute("style", "height: " + setHeight + "px;");
            // IE Fix
            iframe.getStyle().setPropertyPx("height", setHeight);
            break;
        }/*from w w w .j a  va2 s  . c  om*/
    }
}

From source file:org.silverpeas.mobile.client.components.base.PageContent.java

License:Open Source License

protected void setViewport() {
    NodeList<Element> metas = Document.get().getHead().getElementsByTagName("meta");
    for (int i = 0; i < metas.getLength(); i++) {
        if (metas.getItem(i).getAttribute("name").equals("viewport")) {
            metas.getItem(i).setAttribute("content",
                    "width=device-width, target-densitydpi=device-dpi, initial-scale=1.0, maximum-scale=1.0, user-scalable=0");
        }/*w ww.  ja  v a  2 s .  c  o  m*/
    }
}

From source file:org.silverpeas.mobile.client.components.IframePage.java

License:Open Source License

@Override
protected void setViewport() {
    NodeList<Element> metas = Document.get().getHead().getElementsByTagName("meta");
    for (int i = 0; i < metas.getLength(); i++) {
        if (metas.getItem(i).getAttribute("name").equals("viewport")) {
            metas.getItem(i).setAttribute("content",
                    "width=device-width, target-densitydpi=device-dpi, initial-scale=1.0, maximum-scale=5.0, user-scalable=1");
        }//w  w w. j a  va  2  s .co  m
    }
}

From source file:org.silverpeas.mobile.client.SpMobil.java

License:Open Source License

/**
 * Init. spmobile./*from  ww w.  j  a  va 2 s .c  o  m*/
 */
public void onModuleLoad() {
    instance = this;
    shortcutAppId = Window.Location.getParameter("shortcutAppId");
    shortcutContentType = Window.Location.getParameter("shortcutContentType");
    shortcutContentId = Window.Location.getParameter("shortcutContentId");
    msg = GWT.create(ApplicationMessages.class);
    EventBus.getInstance().addHandler(ExceptionEvent.TYPE, new ErrorManager());
    EventBus.getInstance().addHandler(AbstractAuthenticationErrorEvent.TYPE, this);

    loadIds(null);

    NodeList<Element> tags = Document.get().getElementsByTagName("meta");
    for (int i = 0; i < tags.getLength(); i++) {
        MetaElement metaTag = ((MetaElement) tags.getItem(i));
        if (metaTag.getName().equals("viewport")) {
            viewport = metaTag.getContent();
        }
    }

    orientation = MobilUtils.getOrientation();
    Window.addResizeHandler(new ResizeHandler() {
        @Override
        public void onResize(final ResizeEvent resizeEvent) {

            if (!MobilUtils.getOrientation().equals(orientation)) {
                orientation = MobilUtils.getOrientation();
                EventBus.getInstance().fireEvent(new OrientationChangeEvent(orientation));
            }

        }
    });

    // Instanciate apps
    apps.add(new DocumentsApp());
    apps.add(new MediaApp());
    apps.add(new NewsApp());
    apps.add(new NavigationApp());
    apps.add(new TasksApp());
    apps.add(new FavoritesApp());
    apps.add(new WebPageApp());
    apps.add(new BlogApp());
    apps.add(new WorkflowApp());
    apps.add(new HyperLinkApp());
    apps.add(new AgendaApp());
}

From source file:org.silverpeas.mobile.client.SpMobil.java

License:Open Source License

public static void showFullScreen(final Widget content, final boolean zoomable, String bodyClass,
        String bodyId) {/*from  ww  w.ja  va  2  s . c  o  m*/
    PageHistory.getInstance().gotoToFullScreen("viewer");
    RootPanel.get().clear();
    RootPanel.get().add(content);

    if (zoomable) {
        NodeList<Element> tags = Document.get().getElementsByTagName("meta");
        for (int i = 0; i < tags.getLength(); i++) {
            MetaElement metaTag = ((MetaElement) tags.getItem(i));
            if (metaTag.getName().equals("viewport")) {
                metaTag.setContent("");
            }
        }
    }
    SpMobil.bodyClass = Document.get().getBody().getClassName();
    SpMobil.bodyId = Document.get().getBody().getId();
    Document.get().getBody().setClassName(bodyClass);
    Document.get().getBody().setId(bodyId);
    Document.get().getBody().getStyle().setPaddingTop(0, Style.Unit.PX);
}

From source file:org.silverpeas.mobile.client.SpMobil.java

License:Open Source License

public static void restoreMainPage() {
    RootPanel.get().clear();//from w w w  .  ja  v a  2s  .co m
    RootPanel.get().add(SpMobil.getMainPage());

    Document.get().getBody().setId(bodyId);
    Document.get().getBody().setClassName(bodyClass);
    Document.get().getBody().getStyle().clearPaddingTop();

    NodeList<Element> tags = Document.get().getElementsByTagName("meta");
    for (int i = 0; i < tags.getLength(); i++) {
        MetaElement metaTag = ((MetaElement) tags.getItem(i));
        if (metaTag.getName().equals("viewport")) {
            metaTag.setContent(viewport);
        }
    }

}

From source file:org.uberfire.client.plugin.RuntimePluginsServiceProxyClientImpl.java

License:Apache License

private void findAndFetchContent(final String relativeUri, final String filenameExtension,
        final String fileType, final ParameterizedCommand<Collection<String>> doWhenFinished) {
    RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, relativeUri);
    try {/*from  w  ww  . j a v  a  2s .c o m*/
        rb.sendRequest(null, new RequestCallback() {

            @Override
            public void onResponseReceived(Request request, Response response) {
                final List<String> pluginUrls = new ArrayList<String>();
                final List<String> pluginContents = new ArrayList<String>();
                final int[] contentErrors = new int[1];

                Element detachedDiv = DOM.createDiv();
                detachedDiv.setInnerHTML(response.getText());
                NodeList<com.google.gwt.dom.client.Element> links = detachedDiv.getElementsByTagName("a");
                for (int i = 0; i < links.getLength(); i++) {
                    AnchorElement aElem = (AnchorElement) links.getItem(i);

                    // DOM spec says these are already absolutized for us. Nice!
                    String href = aElem.getHref();

                    if (href.endsWith(filenameExtension)) {
                        pluginUrls.add(href);
                    }
                }

                if (pluginUrls.size() == 0) {
                    doWhenFinished.execute(Collections.<String>emptyList());
                    return;
                }

                for (final String href : pluginUrls) {
                    RequestBuilder contentRb = new RequestBuilder(RequestBuilder.GET, href);
                    try {
                        contentRb.sendRequest(null, new RequestCallback() {

                            @Override
                            public void onResponseReceived(Request request, Response response) {
                                if (response.getStatusCode() == 200) {
                                    pluginContents.add(response.getText());
                                } else {
                                    contentErrors[0]++;
                                }
                                if (pluginContents.size() >= pluginUrls.size() + contentErrors[0]) {
                                    doWhenFinished.execute(pluginContents);
                                }
                            }

                            @Override
                            public void onError(Request request, Throwable exception) {
                                logger.warn("Error in " + fileType + " content request for " + href);
                                contentErrors[0]++;
                                if (pluginContents.size() >= pluginUrls.size() + contentErrors[0]) {
                                    doWhenFinished.execute(pluginContents);
                                }
                            }
                        });
                    } catch (RequestException ex) {
                        logger.warn("Failed to send request for " + fileType + " " + href, ex);
                        contentErrors[0]++;
                        if (pluginContents.size() >= pluginUrls.size() + contentErrors[0]) {
                            doWhenFinished.execute(pluginContents);
                        }
                    }
                }
            }

            @Override
            public void onError(Request request, Throwable ex) {
                logger.warn("Error in " + fileType + " list request. Not loading JS " + fileType + "s.", ex);
                doWhenFinished.execute(Collections.<String>emptyList());
            }
        });
    } catch (RequestException ex) {
        logger.warn("Couldn't load JS " + fileType + ". Continuing without runtime " + fileType + "s.", ex);
        doWhenFinished.execute(Collections.<String>emptyList());
    }
}