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:net.s17fabu.vip.gwt.showcase.client.Showcase.java

License:Apache License

/**
 * Update the style sheets to reflect the current theme and direction.
 *//*from w  w w  .  ja v a 2  s .co  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  ww  . j  a  v  a2 s  .  c o 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;
                }// w ww .  j  av  a  2 s  . c  o m
            }
        }
    }
    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   www . j  a v  a  2 s.  co m*/
            tab.removeClassName(style.activeSection());
        }
    }
}

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

License:Open Source License

private void setHeaderWidthInformation(boolean shouldAffix) {

    // header//from  w w  w  .  ja  v a  2  s.  c  o m
    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();
            }
        }
    }
}

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

License:Open Source License

public void saveHeaderWidthInformation() {
    headerWidth = table.getTableHeadElement().getOffsetWidth();
    final NodeList<TableRowElement> headerRows = table.getTableHeadElement().getRows();
    for (int i = 0; i < headerRows.getLength(); i++) {
        final TableRowElement row = headerRows.getItem(i);
        headerRowToWidthMap.put(i, row.getOffsetWidth());

        final NodeList<TableCellElement> cells = row.getCells();
        for (int j = 0; j < cells.getLength(); j++) {
            final TableCellElement cell = cells.getItem(j);
            headerCellToWidthMap.put(new Pair<>(i, j), cell.getOffsetWidth());
        }/*from   www.ja va 2 s.  co  m*/
    }
}

From source file:org.adamtacy.client.ui.effects.impl.Resize.java

License:Apache License

private void createInternalEffectsPerElement(Element currEl) {

    NodeList<Node> nodes = currEl.getChildNodes();
    if (nodes != null) {
        for (int i = 0; i < nodes.getLength(); i++) {
            Node n = nodes.getItem(i);
            if (n.getNodeType() == Node.ELEMENT_NODE) {
                createInternalEffectsPerElement((Element) nodes.getItem(i));
            }/*  w w w .  j a v  a 2 s  . c  o m*/
        }
    }

    Vector<ChangeInterface> temp = new Vector<ChangeInterface>();

    String name = currEl.getNodeName();
    if (triggerDOM.contains(name)) {
        GWT.log("Resize Effect is Processing: " + name, null);

        int startVal;
        int endVal;
        // Deal with Widths
        startVal = getStartWidth(currEl);
        endVal = getEndWidth(currEl);
        if (startVal != endVal) {
            NChangeScalarAction theWidthChange = new NChangeScalarAction(startVal + "px", endVal + "px");
            temp.add(theWidthChange);
            theWidthChange.setUp(currEl, "width", 0);
        }

        // Deal with Heights
        startVal = getStartHeight(currEl);
        endVal = getEndHeight(currEl);
        if (startVal != endVal) {
            NChangeScalarAction theHeightChange = new NChangeScalarAction(startVal + "px", endVal + "px");
            temp.add(theHeightChange);
            theHeightChange.setUp(currEl, "height", 0);
        }

        // Deal with Fonts
        String res = StyleImplementation.getComputedStyle(currEl, "fontSize");

        if (res != null) {
            // We have a font to play with
            String unit = StyleImplementation.getUnits(res);
            double value = -1;
            if (unit == null || unit.equals("")) {
                // Assume we're dealing with a named font-size, as there are no units
                // so, find where this name is in our vector of font size names
                int scale = fontSizes.indexOf(res);
                // If we found it, calculate the font size
                if (scale > -1) {
                    value = (double) Math
                            .round(Math.pow(fontSizeScalingFactor, (scale - standardIndex)) * standardFontSize);
                    unit = standardFontUnit;
                }
            } else {
                // Not a named font-size, so get the value
                value = (new Double(StyleImplementation.getValue(res, unit))).doubleValue();
            }
            if (value > -1) {
                NChangeScalarAction theFontChange = new NChangeScalarAction((int) (value * startXRatio) + unit,
                        (int) (value * endXRatio) + unit);
                theFontChange.setUp(currEl, "fontSize", 0);
                temp.add(theFontChange);
            } else {
                GWT.log("Don't know what to do with this font-size definition: " + res, null);
            }
        }

        // Do we need to manage bounding box aspects, e.g. margin etc?
        if (managesMargin)
            temp.addAll(getBoxChanges("margin", currEl));
        if (managesBorder)
            temp.addAll(getBoxChanges("border", currEl));
        if (managesPadding)
            temp.addAll(getBoxChanges("padding", currEl));

        // Put all ChangeInterfaces together into the determinedEffects object for future management
        determinedEffects.put(currEl, temp);

    } else {
        GWT.log("Resize Effect is Not Processing: " + name, null);
    }
    temp = null;
}

From source file:org.artificer.ui.client.local.util.DOMUtil.java

License:Apache License

/**
 * Gets an element from the given parent element by ID.
 * @param context//from   w ww .  j  a  v a  2  s  . co  m
 * @param id
 */
public static Element findElementById(Element context, String id) {
    NodeList<Node> nodes = context.getChildNodes();
    for (int i = 0; i < nodes.getLength(); i++) {
        Node node = nodes.getItem(i);
        if (((node.getNodeType() == Node.ELEMENT_NODE))) {
            if (id.equals(((Element) node).getAttribute("id"))) {
                return (Element) node;
            } else {
                Element elem = findElementById((Element) node, id);
                if (elem != null) {
                    return elem;
                }
            }
        }
    }
    return null;
}

From source file:org.atmosphere.gwt.client.impl.IFrameCometTransport.java

License:Apache License

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

From source file:org.bonitasoft.console.client.mvp.TemplateRepeat.java

License:Open Source License

@Override
public boolean resetFocus(Context context, Element parent, T value) {
    final NodeList<Element> elements = parent.getElementsByTagName("input");
    if (elements.getLength() > 0) {
        InputElement.as(elements.getItem(0)).focus();
        return true;
    }//  ww  w .j  a v a2 s .  com
    return false;
}