List of usage examples for com.google.gwt.user.client DOM getChildCount
public static int getChildCount(Element parent)
From source file:asquare.gwt.tk.client.util.DomUtil.java
License:Apache License
/** * Creates a list of all elements contained by the specified element * (inclusive) which have the specified CSS class (in GWT terms * <em>stylename</em>).//from w w w. ja v a2s .c om * * @param element the element which is at the root of the hierarchy that you wish to search * @param className the name of the CSS class to search for * @param result a writable list which will be returned as the result (for recursion). * Typically, you pass <code>null</code> and the list will * be created on the fly. * @return <b>result</b> a list containing 0 or more HTML elements */ public static List<Element> findElementsWithClass(Element element, String className, List<Element> result) { if (result == null) { result = new ArrayList<Element>(); } String cls = DOM.getElementProperty(element, "className"); if (cls != null && cls.indexOf(className) >= 0) { result.add(element); } int childCount = DOM.getChildCount(element); for (int i = 0; i < childCount; i++) { findElementsWithClass(DOM.getChild(element, i), className, result); } return result; }
From source file:com.conx.logistics.kernel.ui.common.gwt.client.ui.VConXQuickLaunchMenu.java
License:Apache License
/** * Removes all menu items from this menu bar. *//*from w w w . jav a2s.c om*/ public void clearItems() { final Element container = getItemContainerElement(); while (DOM.getChildCount(container) > 0) { DOM.removeChild(container, DOM.getChild(container, 0)); } items.clear(); }
From source file:com.extjs.gxt.ui.client.core.Template.java
License:sencha.com license
/** * Applies the supplied values to the template and inserts the new node(s) at * the given index.//from w w w. ja v a2 s.c o m * * @param el the context element * @param index the insert index * @param values the values * @return the new element */ public Element insert(Element el, int index, Params values) { int count = DOM.getChildCount(el); Element before = el.getChildNodes().getItem(index).cast(); if (count == 0 || before == null) { return appendInternal(t, el, values.getValues()); } else { return insertBefore(before, values); } }
From source file:com.extjs.gxt.ui.client.util.TreeBuilder.java
License:Open Source License
private static void process(TreeItem item, Element parent) { int size = DOM.getChildCount(parent); for (int i = 0; i < size; i++) { Element li = DOM.getChild(parent, i); TreeItem childItem = new TreeItem(); String id = DOM.getElementAttribute(li, "id"); if (id != null && !id.equals("")) { childItem.setId(id);/*from w w w. j av a 2 s. c o m*/ } childItem.setText(DOM.getElementProperty(li, "title")); item.add(childItem); for (int j = 0; j < DOM.getChildCount(li); j++) { Element subList = DOM.getChild(li, j); process(childItem, subList); } } }
From source file:com.extjs.gxt.ui.client.widget.Component.java
License:sencha.com license
/** * Renders the element. Typically, this method does not need to be called * directly. A component will rendered by its parent if it is a container, or * rendered when attached if added to a gwt panel. * //w w w. ja va 2 s .c om * @param target the element this component should be rendered into * @param index the index within the container <b>before</b> which this * component will be inserted (defaults to appending to the end of * the container if value is -1) */ public void render(Element target, int index) { if (rendered || !fireEvent(Events.BeforeRender)) { return; } initState(); beforeRender(); if (plugins != null) { for (ComponentPlugin plugin : plugins) { plugin.init(this); } } rendered = true; createStyles(baseStyle); if (!setElementRender) { if (index == -1) { index = DOM.getChildCount(target); } onRender(target, index); } assert el != null : getClass().getName() + " must call setElement in onRender"; if (events != 0) { sinkEvents(events); } if (ariaSupport != null) { if (ariaSupport.labelledBy != null) { ariaSupport.setLabelledBy(ariaSupport.labelledBy); } if (ariaSupport.label != null) { ariaSupport.setLabel(ariaSupport.label); } if (ariaSupport.describedBy != null) { ariaSupport.setDescribedBy(ariaSupport.describedBy); } if (ariaSupport.description != null) { ariaSupport.setDescription(ariaSupport.description); } if (ariaSupport.presentation) { setAriaRole("presentation"); focusManagerSupport.setIgnore(true); } if (ariaSupport.role != null) { ariaSupport.setRole(ariaSupport.role); } Map<String, String> states = ariaSupport.states; for (String name : states.keySet()) { ariaSupport.setState(name, states.get(name)); } } if (id == null) { id = el.getId(); } else { getElement().setId(id); } if (tabIndex != -1) { setTabIndex(tabIndex); } if (baseStyle != null) { fly(getStyleElement()).addStyleName(baseStyle); } if (cls != null) { setStyleName(cls); cls = null; } if (styleNames != null) { for (String s : styleNames) { fly(getStyleElement()).addStyleName(s); } styleNames = null; } addStyleName("x-component"); if (title != null) { setTitle(title); } if (styles != null && !styles.equals("")) { el.applyStyles(styles); styles = null; } if (focused) { DeferredCommand.addCommand(new Command() { public void execute() { focus(); } }); } if (borders != Style.DEFAULT) { setBorders(borders == 1); } if (focusable && GXT.isWebKit) { focusEl = new El(createHiddenInput()); getElement().appendChild(focusEl.dom); } afterRender = true; afterRender(); if (hidden) { hide(); } if (disabled) { disable(); } fireEvent(Events.Render); }
From source file:com.google.code.p.gwtchismes.client.GWTCHelper.java
License:Apache License
/** * Loads a css resource including it in the head block * @param url// w ww .ja va 2s. com * full path of the css resource */ public static void insertCSS(String url) { if (DOM.getElementById(url) != null) return; Element head = null; Element body = RootPanel.getBodyElement(); Element doc = DOM.getParent(body); for (int i = 0; i < DOM.getChildCount(doc); i++) { Element child = DOM.getChild(doc, i); if (child.toString().toLowerCase().contains("head")) { head = child; break; } } if (head == null) { head = DOM.createElement("head"); DOM.appendChild(doc, head); } Element css = DOM.createElement("link"); DOM.setElementAttribute(css, "rel", "stylesheet"); DOM.setElementAttribute(css, "type", "text/css"); DOM.setElementAttribute(css, "href", url); DOM.setElementAttribute(css, "id", url); DOM.appendChild(head, css); }
From source file:com.google.code.p.gwtchismes.client.GWTCHelper.java
License:Apache License
/** * Browse an element tree looking for the first element that matches attribute=value * @param element// w w w . j a va2 s.co m * @param attribute * @param value * @return * the first matched element */ public static Element getFirstElementByAttr(Element element, String attribute, String value) { int n = DOM.getChildCount(element); for (int i = 0; i < n; i++) { Element e = DOM.getChild(element, i); String v = DOM.getElementAttribute(e, attribute); if (v != null && v.matches(value)) return e; if (DOM.getChildCount(element) > 0) e = getFirstElementByAttr(e, attribute, value); if (e != null) return e; } return null; }
From source file:com.google.code.p.gwtchismes.client.GWTCHelper.java
License:Apache License
public static List<Element> findElementsWithClass(Element element, String className, List<Element> result) { if (result == null) { result = new Vector<Element>(); }// w w w. ja va 2 s . c o m String cls = DOM.getElementProperty(element, "className"); if (cls != null && cls.indexOf(className) >= 0) { result.add(element); } int childCount = DOM.getChildCount(element); for (int i = 0; i < childCount; i++) { findElementsWithClass(DOM.getChild(element, i), className, result); } return result; }
From source file:com.google.gerrit.client.changes.ApprovalTable.java
License:Apache License
void display(ChangeInfo change) { lastChange = change;/* w w w .j a v a 2 s.c om*/ reviewerSuggestOracle.setChange(change.legacy_id()); Map<Integer, ApprovalDetail> byUser = new LinkedHashMap<Integer, ApprovalDetail>(); Map<Integer, AccountInfo> accounts = new LinkedHashMap<Integer, AccountInfo>(); List<String> missingLabels = initLabels(change, accounts, byUser); removeAllChildren(missing.getElement()); for (String label : missingLabels) { addMissingLabel(Util.M.needApproval(label)); } if (byUser.isEmpty()) { table.setVisible(false); } else { List<String> labels = new ArrayList<String>(change.labels()); Collections.sort(labels); displayHeader(labels); table.resizeRows(1 + byUser.size()); int i = 1; for (ApprovalDetail ad : ApprovalDetail.sort(byUser.values(), change.owner()._account_id())) { displayRow(i++, ad, labels, accounts.get(ad.getAccount().get())); } table.setVisible(true); } if (Gerrit.getConfig().testChangeMerge() && change.status() != Change.Status.MERGED && !change.mergeable()) { addMissingLabel(Util.C.messageNeedsRebaseOrHasDependency()); } missing.setVisible(DOM.getChildCount(missing.getElement()) > 0); addReviewer.setVisible(Gerrit.isSignedIn()); }
From source file:com.google.gerrit.client.changes.ApprovalTable.java
License:Apache License
private void removeAllChildren(Element el) { for (int i = DOM.getChildCount(el) - 1; i >= 0; i--) { DOM.removeChild(el, DOM.getChild(el, i)); }//from www .j ava2s. c o m }