List of usage examples for com.google.gwt.dom.client Element getChild
@Override
public Node getChild(int index)
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// w w w.ja v a 2 s.c o m */ private Element getCellParent(Element parent) { final Element element = parent.getFirstChildElement().getFirstChildElement(); return element.getChild(1).cast(); }
From source file:com.alkacon.geranium.client.util.DomUtil.java
License:Open Source License
/** * Positions an element inside the given parent, reordering the content of the parent and returns the new position index.<p> * This is none absolute positioning. Use for drag and drop reordering of drop targets.<p> * Use <code>-1</code> for x or y to ignore one ordering orientation.<p> * //from w w w . j a v a 2 s . c o m * @param element the child element * @param parent the parent element * @param currentIndex the current index position of the element, use -1 if element is not attached to the parent yet * @param x the client x position, use <code>-1</code> to ignore x position * @param y the client y position, use <code>-1</code> to ignore y position * * @return the new index position */ public static int positionElementInside(Element element, Element parent, int currentIndex, int x, int y) { if ((x == -1) && (y == -1)) { // this is wrong usage, do nothing DebugLog.getInstance().printLine("this is wrong usage, doing nothing"); return currentIndex; } int indexCorrection = 0; int previousTop = 0; for (int index = 0; index < parent.getChildCount(); index++) { Node node = parent.getChild(index); if (node.getNodeType() != Node.ELEMENT_NODE) { continue; } Element child = (Element) node; if (child == element) { indexCorrection = 1; } String positioning = DomUtil.getCurrentStyle(child, Style.position); if (Position.ABSOLUTE.getCssName().equals(positioning) || Position.FIXED.getCssName().equals(positioning)) { // only not 'position:absolute' elements into account, // not visible children will be excluded in the next condition continue; } int left = 0; int width = 0; int top = 0; int height = 0; if (y != -1) { // check if the mouse pointer is within the height of the element top = DomUtil.getRelativeY(y, child); height = child.getOffsetHeight(); if ((top <= 0) || (top >= height)) { previousTop = top; continue; } } if (x != -1) { // check if the mouse pointer is within the width of the element left = DomUtil.getRelativeX(x, child); width = child.getOffsetWidth(); if ((left <= 0) || (left >= width)) { previousTop = top; continue; } } boolean floatSort = false; String floating = ""; if ((top != 0) && (top == previousTop)) { floating = getCurrentStyle(child, Style.floatCss); if ("left".equals(floating) || "right".equals(floating)) { floatSort = true; } } previousTop = top; if (child == element) { return currentIndex; } if ((y == -1) || floatSort) { boolean insertBefore = false; if (left < (width / 2)) { if (!(floatSort && "right".equals(floating))) { insertBefore = true; } } else if (floatSort && "right".equals(floating)) { insertBefore = true; } if (insertBefore) { parent.insertBefore(element, child); currentIndex = index - indexCorrection; return currentIndex; } else { parent.insertAfter(element, child); currentIndex = (index + 1) - indexCorrection; return currentIndex; } } if (top < (height / 2)) { parent.insertBefore(element, child); currentIndex = index - indexCorrection; return currentIndex; } else { parent.insertAfter(element, child); currentIndex = (index + 1) - indexCorrection; return currentIndex; } } // not over any child position if ((currentIndex >= 0) && (element.getParentElement() == parent)) { // element is already attached to this parent and no new position available // don't do anything return currentIndex; } int top = DomUtil.getRelativeY(y, parent); int offsetHeight = parent.getOffsetHeight(); if ((top >= (offsetHeight / 2))) { // over top half, insert as first child parent.insertFirst(element); currentIndex = 0; return currentIndex; } // over bottom half, insert as last child parent.appendChild(element); currentIndex = parent.getChildCount() - 1; return currentIndex; }
From source file:com.arcbees.chosen.client.gwt.ChosenListBox.java
License:Apache License
/** * Inserts an item into a group at the specified location. Additionally, the item can have an extra class name as * well as indent level assigned to it.//w w w . ja v a2s .com * <p/> * <b>NB!</b> It is important to set text into the option after the option has been appended to the DOM * <br/>that's known bug in IE @see <a href="http://bugs.jquery.com/ticket/3041">jQuery bug tracker</a> * <p/> * * @param item the item label to display * @param value the value of the item in the HTML form context * @param className the class name to append to the option (pass {@code null} to append no class name) * @param dir allows specifying an RTL, LTR or inherited direction ({@code null} is LTR) * @param indentLevel the number of times to indent the item from the left (pass 0 for no indentation) * @param groupIndex the index of the group to insert the item into (if out of bounds, the last group will be used) * @param itemIndex the index of the item within a group (if out of bounds, item will be placed last in the group) */ public void insertStyledItemToGroup(String item, String value, String className, Direction dir, int indentLevel, int groupIndex, int itemIndex) { int pos = groupIndex; if (indentLevel < 0) { throw new IllegalArgumentException("[indentLevel] must be non-negative."); } GQuery optgroupList = $(OPTGROUP_TAG, getElement()); int groupCount = optgroupList.size(); if (groupCount == 0) { // simply insert the item to the listbox insertItem(item, dir, value, itemIndex); return; } if (pos < 0 || pos > groupCount - 1) { pos = groupCount - 1; } GQuery optgroup = optgroupList.eq(pos); OptionElement option = Document.get().createOptionElement(); if (!(className == null || className.trim().isEmpty())) { option.addClassName(className); } if (indentLevel > 0) { // Calculate total indentation, not forgetting that being in a group is adding one extra indent step int leftPadding = options.getResources().css().indent() * (indentLevel + 1); option.setAttribute("style", "padding-left: " + leftPadding + "px;"); } Element optGroupElement = optgroup.get(0); int itemCount = optGroupElement.getChildCount(); if (itemIndex < 0 || itemIndex > itemCount - 1) { optgroup.append(option); } else { GQuery before = $(optGroupElement.getChild(itemIndex)); before.before(option); } // setText must be after the element has been appended to the DOM - see javadoc setOptionText(option, item, dir); option.setValue(value); }
From source file:com.bfr.client.selection.RangeEndPoint.java
License:Apache License
private static FindLocRes findLocation(Document doc, Element ele, int relX, int relY) { FindLocRes res = null;//from w ww .j a va 2s .c o m if (contains(ele, relX, relY) && isVisible(doc, ele)) { if (ele.hasChildNodes()) { // Iterate through children until we hit an exact match for (int i = 0; (i < ele.getChildCount()) && ((res == null) || !res.isExact()); i++) { FindLocRes tmp; Node child = ele.getChild(i); if (child.getNodeType() == Node.ELEMENT_NODE) { tmp = findLocation(doc, (Element) child, relX, relY); } else { tmp = findLocation(doc, (Text) child, relX, relY); } res = FindLocRes.replace(res, tmp); } } else { // If this contains but has no children, then this is it res = new FindLocRes(new RangeEndPoint(ele)); } } return res; }
From source file:com.databasepreservation.visualization.shared.client.widgets.wcag.WCAGUtilities.java
public void makeAccessible(Element element) { if (element.getAttribute("align") != null) { String className = ""; if (element.getAttribute("align").equals("right")) { className = "alignRight"; } else if (element.getAttribute("align").equals("left")) { className = "alignLeft"; } else if (element.getAttribute("align").equals("center")) { className = "alignCenter"; } else {/* ww w . j ava 2 s . co m*/ className = "alignJustify"; } element.removeAttribute("align"); element.addClassName(className); } if (INPUT_TAGNAMES.contains(element.getTagName())) { addAttributeIfNonExistent(element, "title", "t_" + Random.nextInt(1000), true); } if (element.getChildCount() > 0) { for (int i = 0; i < element.getChildCount(); i++) { if (element.getChild(i).getNodeType() == Node.ELEMENT_NODE) { makeAccessible((Element) element.getChild(i)); } } } }
From source file:com.ephesoft.gxt.core.client.ui.widget.ScrollableSuggestDisplay.java
License:Open Source License
/** * Scrolls the selectedItem in to the view. It ensures that selected item is always visible in the SuggestionDisplay. *//*from w w w . j a v a 2 s .c om*/ private void scrollSelectedItemIntoView() { //TODO Refactoring. NULL Checks missing if (null != suggestionMenu) { final Element divElement = suggestionMenu.getElement(); final Node tableNode = divElement.getChild(divElement.getChildCount() - 1); final NodeList<Node> optionsList = HTMLDomUtil.getGrandChildren(tableNode, 1); Element tableRowElement = null; if (optionsList != null) { for (int optionIndex = 0; optionIndex < optionsList.getLength(); optionIndex++) { tableRowElement = (Element) optionsList.getItem(optionIndex); if (((Element) tableRowElement.getChild(0)).getClassName() .contains(StyleConstant.SUGGEST_BOX_SELECTED_ITEM_CLASS_APPENDER)) { tableRowElement.scrollIntoView(); break; } } } } }
From source file:com.googlecode.mgwt.examples.showcase.client.activities.button.BCFunctionButtonViewGwtImpl.java
License:Apache License
public static void parseIdsToMap(Element element, HashMap<String, Element> idMap) { int nodeCount = element.getChildCount(); for (int i = 0; i < nodeCount; i++) { Element e = (Element) element.getChild(i); if (e.getId() != null) { idMap.put(e.getId(), e);/*from w w w . j ava 2s. c om*/ } } }
From source file:com.gwtm.ui.client.widgets.FlipSwitch.java
License:Apache License
private void updateFlipPosition(int duration) { Utils.Fx.setTransitionDuration(getFilpElement(), duration); Element flip = getFilpElement(); // make the value be visible during design time if (Beans.isDesignTime()) { Element flipDiv = (Element) flip.getChild(1); if (value) { flipDiv.removeAttribute("style"); } else {/*from w ww. j a v a 2 s . c om*/ flipDiv.setAttribute("style", "position:absolute; left:0; height:2em; margin-left:.5px;"); } } else { if (value) { Utils.Fx.setTranslateX(flip, getOnPosition()); } else { Utils.Fx.setTranslateX(flip, getOffPosition()); } } }
From source file:com.gwtmobile.ui.client.widgets.FlipSwitch.java
License:Apache License
private void updateFlipPosition(int duration) { Utils.setTransitionDuration(getFilpElement(), duration); Element flip = getFilpElement(); // make the value be visible during design time if (Beans.isDesignTime()) { Element flipDiv = (Element) flip.getChild(1); if (value) { flipDiv.removeAttribute("style"); } else {/*from www . ja va2 s. c o m*/ flipDiv.setAttribute("style", "position:absolute; left:0; height:2em; margin-left:.5px;"); } } else { if (value) { Utils.setTranslateX(flip, getOnPosition()); } else { Utils.setTranslateX(flip, getOffPosition()); } } }
From source file:com.haulmont.cuba.web.toolkit.ui.client.tableshared.TableWidgetDelegate.java
License:Apache License
public void setFocus(String itemKey, String columnKey) { HasWidgets row = tableWidget.getRenderedRowByKey(itemKey); int columnIndex = Arrays.asList(tableWidget.getVisibleColOrder()).indexOf(columnKey); for (Widget childWidget : row) { Element element = ((Widget) row).getElement(); if (element.getChild(columnIndex).getFirstChild() == childWidget.getElement().getParentNode()) { this.focusWidget(childWidget); break; }/*w w w .ja v a 2 s.co m*/ } }