List of usage examples for com.google.gwt.user.client DOM getChildIndex
public static int getChildIndex(Element parent, Element child)
From source file:com.emitrom.gwt4.touch2.demo.client.core.CSS.java
License:Open Source License
/** * Adds a stylesheet to the document. //from w ww . j a va2 s . c o m * * @param id the id * @param url the stylesheet url */ public static void addStyleSheet(String id, String url) { Element link = DOM.createElement("link"); link.setPropertyString("rel", "stylesheet"); link.setPropertyString("type", "text/css"); link.setPropertyString("id", id); link.setPropertyString("href", url); link.setPropertyString("disabled", ""); Element elem = getHeadElement(); Element all = null; for (int i = 0; i < elem.getChildNodes().getLength(); i++) { Node node = elem.getChildNodes().getItem(i).cast(); if (node instanceof Element) { Element child = (Element) node; String tag = child.getTagName(); if (tag != null && child.getTagName().equalsIgnoreCase("link")) { String href = child.getAttribute("href"); if (href.length() != 0 && href.indexOf("gxt-all.css") != -1) { all = child; break; } } } } if (all != null) { int idx = DOM.getChildIndex(elem, all); DOM.insertChild(elem, link, idx + 1); } else { DOM.appendChild(elem, link); } }
From source file:com.extjs.gxt.ui.client.util.CSS.java
License:sencha.com license
/** * Adds a stylesheet to the document.// ww w .j av a 2 s . c o m * * @param id the id * @param url the stylesheet url */ public static void addStyleSheet(String id, String url) { Element link = DOM.createElement("link"); link.setPropertyString("rel", "stylesheet"); link.setPropertyString("type", "text/css"); link.setPropertyString("id", id); link.setPropertyString("href", url); link.setPropertyString("disabled", ""); Element elem = XDOM.getHead(); Element all = null; for (int i = 0; i < elem.getChildNodes().getLength(); i++) { Node node = elem.getChildNodes().getItem(i).cast(); if (node instanceof Element) { Element child = (Element) node; String tag = child.getTagName(); if (tag != null && child.getTagName().equalsIgnoreCase("link")) { String href = child.getAttribute("href"); if (href.length() != 0 && href.indexOf("gxt-all.css") != -1) { all = child; break; } } } } if (all != null) { int idx = DOM.getChildIndex(elem, all); DOM.insertChild(elem, link, idx + 1); } else { DOM.appendChild(elem, link); } }
From source file:com.extjs.gxt.ui.client.widget.Component.java
License:sencha.com license
@Override protected void onAttach() { // added to a gwt panel, not rendered if (!rendered) { // render and swap the proxy element String widgetIndex = dummy.getPropertyString("__uiObjectID"); Element parent = DOM.getParent(dummy); int index = DOM.getChildIndex(parent, dummy); parent.removeChild(dummy);//from w ww .j ava 2 s . c o m render(parent, index); if (widgetIndex != null) { getElement().setPropertyInt("__uiObjectID", Integer.parseInt(widgetIndex)); } } super.onAttach(); }
From source file:com.google.gerrit.client.ui.FancyFlexTable.java
License:Apache License
/** @return the row of the child element; -1 if the child is not in the table. */ protected int rowOf(final Element target) { final Element td = getParentCell(target); if (td == null) { return -1; }//from w w w .j a v a 2s . com final Element tr = DOM.getParent(td); final Element body = DOM.getParent(tr); return DOM.getChildIndex(body, tr); }
From source file:com.google.gerrit.client.ui.FancyFlexTable.java
License:Apache License
/** @return the cell of the child element; -1 if the child is not in the table. */ protected int columnOf(final Element target) { final Element td = getParentCell(target); if (td == null) { return -1; }/* w w w. j a v a2 s. com*/ final Element tr = DOM.getParent(td); return DOM.getChildIndex(tr, td); }
From source file:com.gwtm.ui.client.widgets.CheckBoxGroup.java
License:Apache License
@Override public void onClick(ClickEvent e) { final EventTarget target = e.getNativeEvent().getEventTarget(); String targetTagName = ((Element) target.cast()).getTagName().toUpperCase(); Utils.Console("onClick target " + targetTagName); if (targetTagName.equals("LABEL")) { return; // if check box label is click, another (simulated) click event with // check box INPUT as target will fire after this one. So this click event // can be safely ignored. }//from w w w . jav a2 s . com Element div = Element.as(target); while (!div.getNodeName().toUpperCase().equals("SPAN") || div.getParentElement() != this.getElement()) { div = div.getParentElement(); if (div == null) { Utils.Console("CheckBoxGroup onClick: span not found"); return; } } final int index = DOM.getChildIndex(this.getElement(), (com.google.gwt.user.client.Element) div); com.google.gwt.user.client.ui.CheckBox checkbox = (com.google.gwt.user.client.ui.CheckBox) getWidget(index); Utils.Console("onClick " + checkbox.getValue()); if (targetTagName.equals("INPUT")) { Utils.Console("onClick value changed"); checkbox.setValue(checkbox.getValue()); // if target is check box INPUT, check box value is // already changed when click event is fired. // just need to set its current value back to the check box // to update style. } else { checkbox.setValue(!checkbox.getValue()); } Scheduler.get().scheduleDeferred(new ScheduledCommand() { @Override public void execute() { // SelectionChangedEvent selectionChangedEvent = new SelectionChangedEvent(index, target); // fireEvent(selectionChangedEvent); ValueChangeEvent.fire(CheckBoxGroup.this, index); } }); }
From source file:com.gwtmobile.ui.client.utils.Utils.java
License:Apache License
public static int getTargetItemIndex(Element parent, EventTarget target) { Element div = Element.as(target); if (div == parent) { Utils.Console("Is click on list working? " + target.toString()); return -1; }//from w w w. j a va 2 s . c o m while (div.getParentElement() != parent) { div = div.getParentElement(); if (div == null) { return -1; } } int index = DOM.getChildIndex((com.google.gwt.user.client.Element) parent, (com.google.gwt.user.client.Element) div); return index; }
From source file:com.gwtmobile.ui.client.widgets.CheckBoxGroup.java
License:Apache License
@Override public void onClick(ClickEvent e) { final EventTarget target = e.getNativeEvent().getEventTarget(); String targetTagName = ((Element) target.cast()).getTagName().toUpperCase(); Utils.Console("onClick target " + targetTagName); if (targetTagName.equals("LABEL")) { return; // if check box label is click, another (simulated) click event with // check box INPUT as target will fire after this one. So this click event // can be safely ignored. }/* w w w.j a v a2 s .com*/ Element div = Element.as(target); while (!div.getNodeName().toUpperCase().equals("SPAN") || div.getParentElement() != this.getElement()) { div = div.getParentElement(); if (div == null) { Utils.Console("CheckBoxGroup onClick: span not found"); return; } } final int index = DOM.getChildIndex(this.getElement(), (com.google.gwt.user.client.Element) div); com.google.gwt.user.client.ui.CheckBox checkbox = (com.google.gwt.user.client.ui.CheckBox) getWidget(index); Utils.Console("onClick " + checkbox.getValue()); if (targetTagName.equals("INPUT")) { Utils.Console("onClick value changed"); checkbox.setValue(checkbox.getValue()); // if target is check box INPUT, check box value is // already changed when click event is fired. // just need to set its current value back to the check box // to update style. } else { checkbox.setValue(!checkbox.getValue()); } Scheduler.get().scheduleDeferred(new ScheduledCommand() { @Override public void execute() { SelectionChangedEvent selectionChangedEvent = new SelectionChangedEvent(index, target); fireEvent(selectionChangedEvent); } }); }
From source file:com.haulmont.cuba.web.toolkit.ui.client.table.CubaScrollTableConnector.java
License:Apache License
@Override public TooltipInfo getTooltipInfo(Element element) { if (getState().columnDescriptions != null) { Element targetHeaderElement = findCurrentOrParentTd(element); if (targetHeaderElement != null && targetHeaderElement.hasClassName("v-table-header-cell")) { // if column has description int childIndex = DOM.getChildIndex(targetHeaderElement.getParentElement(), targetHeaderElement); String columnKey = getWidget().tHead.getHeaderCell(childIndex).getColKey(); if (columnKey != null) { String columnDescription = getState().columnDescriptions.get(columnKey); if (columnDescription != null && !columnDescription.isEmpty()) { return new TooltipInfo(columnDescription); }/* www .j a v a2 s . c o m*/ } } } if (getState().aggregationDescriptions != null) { Element targetAggregatedElement = findCurrentOrParentTd(element); if (targetAggregatedElement != null && (targetAggregatedElement.hasClassName("v-table-aggregation-cell") || targetAggregatedElement.getFirstChildElement().hasClassName("v-table-footer-container"))) { int childIndex = DOM.getChildIndex(targetAggregatedElement.getParentElement(), targetAggregatedElement); String columnKey = getWidget().tHead.getHeaderCell(childIndex).getColKey(); if (columnKey != null) { String columnTooltip = getState().aggregationDescriptions.get(columnKey); if (columnTooltip != null && !columnTooltip.isEmpty()) { return new TooltipInfo(columnTooltip); } } } } if (element != getWidget().getElement()) { Object node = WidgetUtil.findWidget(element, CubaScrollTableWidget.CubaScrollTableBody.CubaScrollTableRow.class); if (node != null) { CubaScrollTableWidget.CubaScrollTableBody.CubaScrollTableRow row = (CubaScrollTableWidget.CubaScrollTableBody.CubaScrollTableRow) node; return row.getTooltip(element); } } return super.getTooltipInfo(element); }
From source file:com.haulmont.cuba.web.toolkit.ui.client.treetable.CubaTreeTableConnector.java
License:Apache License
@Override public TooltipInfo getTooltipInfo(Element element) { if (getState().columnDescriptions != null) { Element targetHeaderElement = findCurrentOrParentTd(element); if (targetHeaderElement != null) { // if column has description int childIndex = DOM.getChildIndex(targetHeaderElement.getParentElement(), targetHeaderElement); String columnKey = getWidget().tHead.getHeaderCell(childIndex).getColKey(); if (columnKey != null) { String columnDescription = getState().columnDescriptions.get(columnKey); if (columnDescription != null && !columnDescription.isEmpty()) { return new TooltipInfo(columnDescription); }/*from w w w .j a v a 2 s. c om*/ } } } if (getState().aggregationDescriptions != null) { Element targetAggregatedElement = findCurrentOrParentTd(element); if (targetAggregatedElement != null && (targetAggregatedElement.hasClassName("v-table-aggregation-cell") || targetAggregatedElement.hasClassName("v-table-footer-container"))) { int childIndex = DOM.getChildIndex(targetAggregatedElement.getParentElement(), targetAggregatedElement); String columnKey = getWidget().tHead.getHeaderCell(childIndex).getColKey(); if (columnKey != null) { String columnTooltip = getState().aggregationDescriptions.get(columnKey); if (columnTooltip != null && !columnTooltip.isEmpty()) { return new TooltipInfo(columnTooltip); } } } } if (element != getWidget().getElement()) { Object node = WidgetUtil.findWidget(element, CubaTreeTableWidget.CubaTreeTableBody.CubaTreeTableRow.class); if (node != null) { CubaTreeTableWidget.CubaTreeTableBody.CubaTreeTableRow row = (CubaTreeTableWidget.CubaTreeTableBody.CubaTreeTableRow) node; return row.getTooltip(element); } } return super.getTooltipInfo(element); }