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:info.geekinaction.autoalert.view.AutoAlertViewImpl.java

License:Open Source License

/**
 * @see IAutoAlertView#init()//from   www.  ja  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();
                }//w ww. jav 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.// ww  w.  j  av  a  2s.  co m
 * @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/*from w  w w  .j  a va  2 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;
    }/*from w w  w. ja va 2  s . c om*/
    GWT.log("OE: Unable to locate iframe");
    return null;
}

From source file:net.s17fabu.vip.gwt.showcase.client.Showcase.java

License:Apache License

/**
 * Update the style sheets to reflect the current theme and direction.
 *//*ww w  . j a v a 2s. c o m*/
private void updateStyleSheets() {
    // Generate the names of the style sheets to include
    String gwtStyleSheet = "gwt/" + CUR_THEME + "/" + CUR_THEME + ".css";
    String showcaseStyleSheet = CUR_THEME + "/Showcase.css";
    if (LocaleInfo.getCurrentLocale().isRTL()) {
        gwtStyleSheet = gwtStyleSheet.replace(".css", "_rtl.css");
        showcaseStyleSheet = showcaseStyleSheet.replace(".css", "_rtl.css");
    }

    // Find existing style sheets that need to be removed
    boolean styleSheetsFound = false;
    final HeadElement headElem = StyleSheetLoader.getHeadElement();
    final List<Element> toRemove = new ArrayList<Element>();
    NodeList<Node> children = headElem.getChildNodes();
    for (int i = 0; i < children.getLength(); i++) {
        Node node = children.getItem(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            Element elem = Element.as(node);
            if (elem.getTagName().equalsIgnoreCase("link")
                    && elem.getPropertyString("rel").equalsIgnoreCase("stylesheet")) {
                styleSheetsFound = true;
                String href = elem.getPropertyString("href");
                // If the correct style sheets are already loaded, then we should have
                // nothing to remove.
                if (!href.contains(gwtStyleSheet) && !href.contains(showcaseStyleSheet)) {
                    toRemove.add(elem);
                }
            }
        }
    }

    // Return if we already have the correct style sheets
    if (styleSheetsFound && toRemove.size() == 0) {
        return;
    }

    // Detach the app while we manipulate the styles to avoid rendering issues
    RootPanel.get().remove(app);

    // Remove the old style sheets
    for (Element elem : toRemove) {
        headElem.removeChild(elem);
    }

    // Load the GWT theme style sheet
    String modulePath = GWT.getModuleBaseURL();
    Command callback = new Command() {
        /**
         * The number of style sheets that have been loaded and executed this
         * command.
         */
        private int numStyleSheetsLoaded = 0;

        public void execute() {
            // Wait until all style sheets have loaded before re-attaching the app
            numStyleSheetsLoaded++;
            if (numStyleSheetsLoaded < 2) {
                return;
            }

            // Different themes use different background colors for the body
            // element, but IE only changes the background of the visible content
            // on the page instead of changing the background color of the entire
            // page. By changing the display style on the body element, we force
            // IE to redraw the background correctly.
            RootPanel.getBodyElement().getStyle().setProperty("display", "none");
            RootPanel.getBodyElement().getStyle().setProperty("display", "");
            RootPanel.get().add(app);
        }
    };
    StyleSheetLoader.loadStyleSheet(modulePath + gwtStyleSheet, getCurrentReferenceStyleName("gwt"), callback);

    // Load the showcase specific style sheet after the GWT theme style sheet so
    // that custom styles supercede the theme styles.
    StyleSheetLoader.loadStyleSheet(modulePath + showcaseStyleSheet,
            getCurrentReferenceStyleName("Application"), callback);
}

From source file:net.zschech.gwt.comet.client.impl.IEHTMLFileCometTransport.java

License:Apache License

private void collect() {
    NodeList<Node> childNodes = body.getChildNodes();
    if (childNodes.getLength() > 1) {
        body.removeChild(childNodes.getItem(0));
    }/*from   w  w  w . j  av a 2s .co m*/
}

From source file:nz.co.doltech.gwt.sdm.SuperDevCompiler.java

License:Apache License

public Element getDevModeOnScriptElement() {
    HeadElement head = Document.get().getHead();
    NodeList<Node> childNodes = head.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node childNode = childNodes.getItem(i);
        if (Element.is(childNode)) {
            Element child = childNode.cast();
            if (ScriptElement.is(child)) {
                ScriptElement scriptElement = ScriptElement.as(child);
                String scriptSrc = scriptElement.getSrc();
                if (scriptSrc != null && scriptSrc.contains("dev_mode_on.js")) {
                    return child;
                }/*from  w  w w . jav a 2s .  c om*/
            }
        }
    }
    return null;
}

From source file:org.activityinfo.ui.client.page.app.SectionTabStrip.java

License:Open Source License

public void setSelection(Section section) {
    NodeList<com.google.gwt.user.client.Element> tabs = El.fly(sectionDiv).select("." + style.section());
    for (int i = 0; i != tabs.getLength(); ++i) {
        Element tab = tabs.getItem(i).cast();
        if (section != null && i == section.ordinal()) {
            tab.addClassName(style.activeSection());
        } else {/*from w w  w.  j a  va 2 s . c om*/
            tab.removeClassName(style.activeSection());
        }
    }
}

From source file:org.activityinfo.ui.client.widget.CellTableHeaderWidthApplier.java

License:Open Source License

private void setHeaderWidthInformation(boolean shouldAffix) {

    // header/*  w  ww. j  av  a  2  s .com*/
    if (shouldAffix) {
        table.getTableHeadElement().getStyle().setWidth(headerWidth, Style.Unit.PX);
    } else {
        table.getTableHeadElement().getStyle().clearWidth();
    }

    final NodeList<TableRowElement> headerRows = table.getTableHeadElement().getRows();
    for (int i = 0; i < headerRows.getLength(); i++) {
        final TableRowElement row = headerRows.getItem(i);

        // rows
        if (shouldAffix) {
            row.getStyle().setWidth(headerRowToWidthMap.get(i), Style.Unit.PX);
        } else {
            row.getStyle().clearWidth();
        }

        // cells
        final NodeList<TableCellElement> cells = row.getCells();
        for (int j = 0; j < cells.getLength(); j++) {
            final TableCellElement cell = cells.getItem(j);

            if (shouldAffix) {
                cell.getStyle().setWidth(headerCellToWidthMap.get(new Pair<>(i, j)), Style.Unit.PX);
            } else {
                cell.getStyle().clearWidth();
            }
        }
    }
}