Example usage for com.google.gwt.dom.client Element getFirstChildElement

List of usage examples for com.google.gwt.dom.client Element getFirstChildElement

Introduction

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

Prototype

@Override
    public Element getFirstChildElement() 

Source Link

Usage

From source file:accelerator.client.ui.cell.StyleCompositeCell.java

License:Open Source License

/**
 * {@inheritDoc}/*from   ww  w.j  a  v  a  2  s.  c om*/
 */
@Override
protected Element getContainerElement(Element parent) {
    return parent.getFirstChildElement();
}

From source file:app.dnd.drag.DraggableCellDecorator.java

License:Apache License

/**
 * Get the parent element of the decorated cell.
 *
 * @param parent the parent of this cell
 * @return the decorated cell's parent//www  .j  a va  2 s  .  co m
 */
private Element getCellParent(Element parent) {
    final Element element = parent.getFirstChildElement().getFirstChildElement();
    return element.getChild(1).cast();
}

From source file:cc.alcina.framework.gwt.client.cell.FunctionalCell.java

License:Apache License

@Override
public void onBrowserEvent(Context context, Element parent, FunctionalTuple value, NativeEvent event,
        ValueUpdater<FunctionalTuple> valueUpdater) {
    super.onBrowserEvent(context, parent, value, event, valueUpdater);
    if (CLICK.equals(event.getType())) {
        EventTarget eventTarget = event.getEventTarget();
        if (!Element.is(eventTarget)) {
            return;
        }/*  w w  w .j  a  v a2  s .c  o m*/
        if (parent.getFirstChildElement().isOrHasChild(Element.as(eventTarget))) {
            event.stopPropagation();
        }
    }
}

From source file:cc.alcina.framework.gwt.client.util.WidgetUtils.java

License:Apache License

private static int getBestOffsetHeight(Element e, boolean parentPass, boolean allowParentPass) {
    int h = e.getPropertyInt("offsetHeight");
    if (h != 0 || e.getParentElement() == null) {
        return h;
    }/*from   ww w.  j a v a  2s  . co  m*/
    if (e.getFirstChildElement() == null && !parentPass) {
        return getBestOffsetHeight(e, true);
    }
    if (!allowParentPass) {
        return 0;
    }
    return getBestOffsetHeight(parentPass ? e.getParentElement() : e.getFirstChildElement(), parentPass);
}

From source file:cc.alcina.framework.gwt.client.util.WidgetUtils.java

License:Apache License

private static int getBestOffsetWidth(Element e, boolean parentPass) {
    int h = e.getPropertyInt("offsetWidth");
    if (h != 0 || e.getParentElement() == null) {
        return h;
    }//from   ww w.  j a v a 2 s  .  co  m
    if (e.getFirstChildElement() == null && !parentPass) {
        return getBestOffsetWidth(e, true);
    }
    return getBestOffsetWidth(parentPass ? e.getParentElement() : e.getFirstChildElement(), parentPass);
}

From source file:com.akanoo.client.views.SharingPopupView.java

License:Apache License

private void setupCellList(CellList.Resources cellListResources) {
    selectionModel = new MultiSelectionModel<UserInfo>(UserInfo.keyprovider);

    // Construct a composite cell for contacts that includes a checkbox.
    List<HasCell<UserInfo, ?>> hasCells = new ArrayList<HasCell<UserInfo, ?>>();
    hasCells.add(new HasCell<UserInfo, Boolean>() {

        private CheckboxCell cell = new CheckboxCell(true, false);

        public Cell<Boolean> getCell() {
            return cell;
        }//from  www .  jav  a  2  s .c  o  m

        public FieldUpdater<UserInfo, Boolean> getFieldUpdater() {
            return null;
        }

        public Boolean getValue(UserInfo object) {
            return selectionModel.isSelected(object);
        }
    });
    hasCells.add(new HasCell<UserInfo, UserInfo>() {

        private UserCell cell = new UserCell();

        public Cell<UserInfo> getCell() {
            return cell;
        }

        public FieldUpdater<UserInfo, UserInfo> getFieldUpdater() {
            return null;
        }

        public UserInfo getValue(UserInfo object) {
            return object;
        }
    });
    CompositeCell<UserInfo> friendCell = new CompositeCell<UserInfo>(hasCells) {
        @Override
        public void render(Context context, UserInfo value, SafeHtmlBuilder sb) {
            sb.appendHtmlConstant("<table><tbody><tr>");
            super.render(context, value, sb);
            sb.appendHtmlConstant("</tr></tbody></table>");
        }

        @Override
        protected Element getContainerElement(Element parent) {
            // Return the first TR element in the table.
            return parent.getFirstChildElement().getFirstChildElement().getFirstChildElement();
        }

        @Override
        protected <X> void render(Context context, UserInfo value, SafeHtmlBuilder sb,
                HasCell<UserInfo, X> hasCell) {
            Cell<X> cell = hasCell.getCell();
            sb.appendHtmlConstant("<td>");
            cell.render(context, hasCell.getValue(value), sb);
            sb.appendHtmlConstant("</td>");
        }
    };

    shares = new CellList<UserInfo>(friendCell, cellListResources, UserInfo.keyprovider);
    shares.setSelectionModel(selectionModel, DefaultSelectionEventManager.<UserInfo>createCheckboxManager());

    dataProvider = new ListDataProvider<UserInfo>(UserInfo.keyprovider);
    dataProvider.addDataDisplay(shares);

    selectionModel.addSelectionChangeHandler(this);
}

From source file:com.alkacon.acacia.client.FormParent.java

License:Open Source License

/**
 * @see com.alkacon.acacia.client.I_InlineFormParent#replaceHtml(java.lang.String)
 *///w ww. j a v a  2  s. c o m
public void replaceHtml(String html) {

    // detach all children first
    while (getChildren().size() > 0) {
        getChildren().get(getChildren().size() - 1).removeFromParent();
    }
    Element tempDiv = DOM.createDiv();
    tempDiv.setInnerHTML(html);
    getElement().setInnerHTML(tempDiv.getFirstChildElement().getInnerHTML());
}

From source file:com.alkacon.geranium.client.util.DomUtil.java

License:Open Source License

/**
 * This method will create an {@link com.google.gwt.user.client.Element} for the given HTML. 
 * The HTML should have a single root tag, if not, the first tag will be used and all others discarded.<p>
 * Script-tags will be removed.<p>
 * /*from   ww w. j a va2  s  .  c om*/
 * @param html the HTML to use for the element
 * 
 * @return the created element
 * 
 * @throws Exception if something goes wrong 
 */
public static com.google.gwt.user.client.Element createElement(String html) throws Exception {

    com.google.gwt.user.client.Element wrapperDiv = DOM.createDiv();
    wrapperDiv.setInnerHTML(html);
    com.google.gwt.user.client.Element elementRoot = (com.google.gwt.user.client.Element) wrapperDiv
            .getFirstChildElement();
    DOM.removeChild(wrapperDiv, elementRoot);
    // just in case we have a script tag outside the root HTML-tag
    while ((elementRoot != null) && (elementRoot.getTagName().toLowerCase().equals(Tag.script.name()))) {
        elementRoot = (com.google.gwt.user.client.Element) wrapperDiv.getFirstChildElement();
        DOM.removeChild(wrapperDiv, elementRoot);
    }
    if (elementRoot == null) {
        DebugLog.getInstance()
                .printLine("Could not create element as the given HTML has no appropriate root element");
        throw new IllegalArgumentException(
                "Could not create element as the given HTML has no appropriate root element");
    }
    return elementRoot;

}

From source file:com.alkacon.geranium.client.util.PositionBean.java

License:Open Source License

/**
 * Returns a position info representing the dimensions of all visible child elements of the given panel (excluding elements with position:absolute).
 * If the panel has no visible child elements, it's outer dimensions are returned.<p>
 * /* w  w w.j  av a 2s.  c om*/
 * @param panel the panel
 * @param levels the levels to traverse down the DOM tree
 * @param includeSelf <code>true</code> to include the outer dimensions of the given panel
 * 
 * @return the position info
 */
public static PositionBean getInnerDimensions(Element panel, int levels, boolean includeSelf) {

    boolean first = true;
    int top = 0;
    int left = 0;
    int bottom = 0;
    int right = 0;
    // if overflow is set to hidden, use the outer dimensions
    if (!Overflow.HIDDEN.getCssName().equals(DomUtil.getCurrentStyle(panel, Style.overflow))) {
        if (!includeSelf) {
            // check for any text content
            NodeList<Node> children = panel.getChildNodes();
            for (int i = 0; i < children.getLength(); i++) {
                if ((children.getItem(i).getNodeType() == Node.TEXT_NODE)
                        && (children.getItem(i).getNodeValue().trim().length() > 0)) {
                    includeSelf = true;
                    break;
                }
            }
        }
        if (includeSelf) {
            top = panel.getAbsoluteTop();
            left = panel.getAbsoluteLeft();
            bottom = top + panel.getOffsetHeight();
            right = left + panel.getOffsetWidth();
            first = false;
        }
        Element child = panel.getFirstChildElement();
        while (child != null) {
            String tagName = child.getTagName();
            if (tagName.equalsIgnoreCase("br") || tagName.equalsIgnoreCase("tr")
                    || tagName.equalsIgnoreCase("thead") || tagName.equalsIgnoreCase("tfoot")
                    || tagName.equalsIgnoreCase("script") || tagName.equalsIgnoreCase("style")) {
                // ignore tags with no relevant position info
                child = child.getNextSiblingElement();
                continue;
            }
            String positioning = DomUtil.getCurrentStyle(child, Style.position);
            if (!Display.NONE.getCssName().equals(DomUtil.getCurrentStyle(child, Style.display))
                    && !(positioning.equalsIgnoreCase(Position.ABSOLUTE.getCssName())
                            || positioning.equalsIgnoreCase(Position.FIXED.getCssName()))) {
                PositionBean childDimensions = levels > 0 ? getInnerDimensions(child, levels - 1, true)
                        : generatePositionInfo(panel);
                if (first) {
                    first = false;
                    top = childDimensions.getTop();
                    left = childDimensions.getLeft();
                    bottom = top + childDimensions.getHeight();
                    right = left + childDimensions.getWidth();
                } else {
                    int wTop = childDimensions.getTop();
                    top = top < wTop ? top : wTop;
                    int wLeft = childDimensions.getLeft();
                    left = left < wLeft ? left : wLeft;
                    int wBottom = wTop + childDimensions.getHeight();
                    bottom = bottom > wBottom ? bottom : wBottom;
                    int wRight = wLeft + childDimensions.getWidth();
                    right = right > wRight ? right : wRight;
                }
            }
            child = child.getNextSiblingElement();
        }
    }
    if (!first) {
        PositionBean result = new PositionBean();
        result.setHeight(bottom - top);
        result.setWidth(right - left);
        result.setTop(top);
        result.setLeft(left);
        return result;
    } else {
        return generatePositionInfo(panel);
    }
}

From source file:com.bearsoft.gwt.ui.widgets.grid.cells.DivDecoratorCell.java

/**
 * Get the parent element of the decorated cell.
 * //www .  ja  v a  2 s. co m
 * @param parent
 *            the parent of this cell
 * @return the decorated cell's parent
 */
protected Element getCellParent(Element parent) {
    return parent.getFirstChildElement().getFirstChildElement();
}