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

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

Introduction

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

Prototype

public int getLength() 

Source Link

Usage

From source file:fr.putnami.pwt.core.theme.client.DefaultThemeController.java

License:Open Source License

/**
 * Removes all link tags in the head if not initialized.
 *//* w  w w . java 2 s  .  c  o  m*/
private void removeCssLinks() {
    if (this.isInit) {
        return;
    }
    this.isInit = true;
    // Remove all existing link element
    NodeList<Element> links = this.getHead().getElementsByTagName(LinkElement.TAG);
    int size = links.getLength();
    for (int i = 0; i < size; i++) {
        LinkElement elem = LinkElement.as(links.getItem(0));
        if ("stylesheet".equals(elem.getRel())) {
            elem.removeFromParent();
        }
    }
}

From source file:fr.putnami.pwt.core.widget.client.DocumentMeta.java

License:Open Source License

/**
 * Return the first meta tag from the head section with name matching. <br>
 * If createIfMissing the tag is created and added at the end of the head section.<br>
 * <p>/*  ww  w .  j a v a2 s . c  om*/
 * <strong>Note : </strong> the name is case insensitive
 * </p>
 *
 * @param name the name attribute of the metta tag
 * @param createIfMissing create the tag in the head section if missing
 * @return meta tag element or null
 */
public static MetaElement getDescriptionTag(String name, boolean createIfMissing) {
    Document doc = Document.get();
    HeadElement head = doc.getHead();
    assert head != null : "No head section found in the document";
    assert name != null : "the name must not be null";

    NodeList<Element> tags = head.getElementsByTagName("meta");
    MetaElement metaTag = null;
    for (int i = 0; i < tags.getLength(); i++) {
        metaTag = (MetaElement) tags.getItem(i);
        if (name.equalsIgnoreCase(metaTag.getName())) {
            return metaTag;
        }
    }
    if (createIfMissing) {
        metaTag = doc.createMetaElement();
        metaTag.setName(name);
        head.appendChild(metaTag);
    }
    return metaTag;
}

From source file:gwt.dojo.showcase.client.Showcase.java

License:Apache License

private void loadAndSwitchView(final ListItem listItem) {

    final RequestCallback requestCallback = new RequestCallback() {
        @Override/*from   w w w  .ja  v  a  2 s  . c o m*/
        public void onResponseReceived(Request request, Response response) {
            if (200 == response.getStatusCode()) {
                try {
                    // Process the response in response.getText()

                    // fillInDemoSource();
                    DivElement rightPane = Document.get().getElementById("rightPane").cast();
                    DivElement tmpContainer = Document.get().createDivElement();
                    tmpContainer.setInnerHTML(response.getText());
                    rightPane.appendChild(tmpContainer);
                    JsArray ws = MobileParser.parse(tmpContainer);
                    for (int i = 0, n = ws.length(); i < n; i++) {
                        if (ws.getJsObject(i).hasProperty("startup")) {
                            _WidgetBase w = ws.getJsObject(i);
                            w.startup();
                        }
                    }

                    // reparent
                    rightPane.removeChild(tmpContainer);
                    NodeList<Node> children = tmpContainer.getChildNodes();
                    for (int i = 0, n = children.getLength(); i < n; i++) {
                        Element elem = tmpContainer.getChild(i).cast();
                        rightPane.appendChild(elem);
                    }

                    showProgressIndicator(false);
                    Scheduler.get().scheduleDeferred(new ScheduledCommand() {
                        @Override
                        public void execute() {
                            initView(listItem);
                            listItem.transitionTo(listItem.getString("viewId"));
                            // triggreTransition(listItem,
                            // listItem.getString("id"));
                        }
                    });
                } catch (Exception e) {
                    Window.alert("Error: " + e);
                }
            } else {
                // Handle the error. Can get the status text from
                // response.getStatusText()
                onError(request, new RequestException("HTTP Error: " + response.getStatusCode()));
            }
        }

        @Override
        public void onError(Request request, Throwable exception) {
            Window.alert("Failed to load demo.");
            showProgressIndicator(false);
            inTransitionOrLoading = false;
        }
    };

    showProgressIndicator(true);

    String url = listItem.getString("demourl");
    RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode(url));

    Request request = null;
    try {
        request = builder.sendRequest(null, requestCallback);
    } catch (RequestException e) {
        requestCallback.onError(request, e);
    }
}

From source file:gwt.material.design.client.base.helper.DOMHelper.java

License:Apache License

public static Element getElementByAttribute(NodeList<Element> elems, String attr, String value) {
    if (elems != null) {
        for (int i = 0; i < elems.getLength(); i++) {
            Element child = elems.getItem(i);
            if (child.getAttribute(attr).equals(value)) {
                return child;
            }/* w  ww .j a  va  2 s .co  m*/
        }
    }
    return null;
}

From source file:gwt.material.design.client.ui.MaterialRange.java

License:Apache License

/**
 * Try to identify the embedded range elements input field (see ui xml)
 * @return The found element or null if none found.
 *///  w  ww .j  a  v a 2  s .c  om
private Element getRangeElement() {
    if (rangeElement == null) {
        NodeList<Element> elements = this.getElement().getElementsByTagName(INPUT);
        if (elements != null && elements.getLength() > 0) {
            rangeElement = elements.getItem(0);
        }
    }
    return rangeElement;
}

From source file:info.geekinaction.autoalert.view.AutoAlertViewImpl.java

License:Open Source License

/**
 * @see IAutoAlertView#init()/*from   w  w  w .j a  v  a  2 s . c  o m*/
 */
public void init() {

    // Register click handlers for native anchors.
    NodeList<Element> anchorList = getElementsByName(SIDEBAR_ANCHOR_NAME);
    for (int index = 0; index < anchorList.getLength(); index++) {
        Element elem = anchorList.getItem(index);
        ElementWrapperPanel wrapper = new ElementWrapperPanel(elem);
        wrapper.addClickHandler(controller);
    }

    // Make this panel visible.
    setVisible(true);

    // Add composite widgets to root panels. 
    RootPanel.get(APP_DIV_ID).add(this);
    RootPanel.get(TITLE_DIV_ID).add(contentTitle);

    selectDisplay(AutoAlertDisplay.INSTANCE_INFO, MESSAGES.sidebarGeneralInfo());

}

From source file:info.magnolia.ui.vaadin.gwt.client.dialog.connector.DialogContainingFormConnector.java

License:Open Source License

private void doResize() {
    Widget content = getContent().getWidget();
    if (content instanceof FormViewImpl) {
        FormViewImpl formView = (FormViewImpl) content;
        Element element = view.asWidget().getElement();
        NodeList<Node> childNodes = element.getChild(0).getChildNodes();
        int footerHeight = 0, headerHeight = 0, marginHeight = 0;
        List<String> marginElements = Arrays.asList("dialog-description", "dialog-error", "dialog-content",
                "dialog-footer");
        for (int i = 0; i < childNodes.getLength(); i++) {
            Node item = childNodes.getItem(i);
            if (item.getNodeType() == Node.ELEMENT_NODE) {
                Element child = (Element) item;
                if (child.getClassName().equalsIgnoreCase("dialog-footer")) {
                    footerHeight = child.getOffsetHeight();
                } else if (child.getClassName().isEmpty()) {
                    headerHeight = child.getOffsetHeight();
                }//from w ww.  ja v a  2  s .c om
                if (marginElements.contains(child.getClassName())) {
                    marginHeight += 2;
                }
            }
        }
        int topMargin = element.getOffsetTop();
        int bottomMargin = 0;
        if ("light".equals(getState().modalityLevel)) {
            bottomMargin = LIGHT_DIALOG_BOTTOM_MARGIN;
        }
        formView.setMaxHeight(view.asWidget().getElement().getOffsetHeight() - footerHeight - headerHeight
                - marginHeight - topMargin - bottomMargin);
    }
}

From source file:io.apiman.manager.ui.client.local.pages.common.SelectBox.java

License:Apache License

/**
 * Sets the select box's options.//from   w w  w .  j av a  2  s  .  c  om
 * @param options
 */
public void setOptions(List<T> options) {
    clear();
    this.options = options;

    for (T option : options) {
        String name = optionName(option);
        String value = optionValue(option);
        String dataContent = optionDataContent(option);
        if (value == null)
            this.addItem(name);
        else
            this.addItem(name, value);
        if (dataContent != null) {
            SelectElement select = getElement().cast();
            NodeList<OptionElement> o = select.getOptions();
            OptionElement item = o.getItem(o.getLength() - 1);
            item.setAttribute("data-content", dataContent); //$NON-NLS-1$
        }
    }
    if (isAttached()) {
        refreshUI(getElement());
    }
}

From source file:io.fns.calculator.client.RestModule.java

License:Apache License

@Provides
@Singleton/* w w  w  . java2  s  .  c o  m*/
public XSRFToken provideXSRFToken() {
    XSRFToken xsrfToken = new XSRFToken();

    // get the CSRF token from the HTML document and initialize the
    // XSRFToken
    NodeList<MetaElement> metaTags = Document.get().getElementsByTagName(MetaElement.TAG).cast();
    for (int i = 0; i < metaTags.getLength(); i++) {
        if (metaTags.getItem(i).getName().equals("X-CSRF-TOKEN")) {
            xsrfToken.setToken(metaTags.getItem(i).getContent());
            break;
        }
    }

    return xsrfToken;
}

From source file:loomp.oca.client.ui.OcaEditor.java

License:Open Source License

/** @return the window element containing the editor content */
public Element getTextEditorWindow() {
    NodeList<Node> nodes = getElement().getChildNodes();
    for (int i = 0; i < nodes.getLength(); i++) {
        Node n = nodes.getItem(i);
        if (n.getNodeName().equalsIgnoreCase("iframe"))
            return (Element) n;
    }/* w w  w  .jav a  2 s.co m*/
    GWT.log("OE: Unable to locate iframe");
    return null;
}