List of usage examples for com.google.gwt.dom.client NodeList getLength
public int getLength()
From source file:com.extjs.gxt.ui.client.widget.ColorPalette.java
License:sencha.com license
private int indexOf(NodeList<Element> elements, Element elem) { for (int i = 0; i < elements.getLength(); i++) { if (elements.getItem(i) == elem) { return i; }/*w ww . ja va 2 s .c om*/ } return -1; }
From source file:com.extjs.gxt.ui.client.widget.DataView.java
License:Open Source License
protected void renderAll() { if (template == null) { template = new Template(defaultTemplate); }/*ww w .j ava 2s .c o m*/ StringBuffer sb = new StringBuffer(); for (DataViewItem item : getItems()) { sb.append(bulkRenderItem(item)); } getElement().setInnerHTML(sb.toString()); NodeList<Element> elems = el().select(itemSelector); for (int i = 0; i < elems.getLength(); i++) { DataViewItem item = getItem(i); item.setElement(elems.getItem(i)); } }
From source file:com.extjs.gxt.ui.client.widget.DatePicker.java
License:sencha.com license
@Override protected void onRender(Element target, int index) { setElement(DOM.createDiv(), target, index); disableTextSelection(true);//from w w w .j ava 2 s . com header = new Header(); header.render(getElement()); days = new Grid(1, 7); days.setStyleName("x-date-days"); days.setCellPadding(0); days.setCellSpacing(0); days.setBorderWidth(0); String[] dn = constants.narrowWeekdays(); String[] longdn = constants.weekdays(); firstDOW = getCalculatedStartDay(); days.setHTML(0, 0, "<span>" + dn[(0 + firstDOW) % 7] + "</span>"); days.setHTML(0, 1, "<span>" + dn[(1 + firstDOW) % 7] + "</span>"); days.setHTML(0, 2, "<span>" + dn[(2 + firstDOW) % 7] + "</span>"); days.setHTML(0, 3, "<span>" + dn[(3 + firstDOW) % 7] + "</span>"); days.setHTML(0, 4, "<span>" + dn[(4 + firstDOW) % 7] + "</span>"); days.setHTML(0, 5, "<span>" + dn[(5 + firstDOW) % 7] + "</span>"); days.setHTML(0, 6, "<span>" + dn[(6 + firstDOW) % 7] + "</span>"); days.getRowFormatter().getElement(0).setAttribute("role", "row"); for (int i = 0; i < 7; i++) { days.getCellFormatter().getElement(0, i).setAttribute("role", "columnheader"); days.getCellFormatter().getElement(0, i).setAttribute("aria-label", longdn[i]); } grid = new Grid(6, 7); grid.setStyleName("x-date-inner"); grid.setCellSpacing(0); grid.setCellPadding(0); grid.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { Event evt = DOM.eventGetCurrentEvent(); ComponentEvent be = new ComponentEvent(DatePicker.this, evt); onDayClick(be); } }); String s = GXT.isAriaEnabled() ? "<a role=gridcell tabindex=0><span role=presentation></span></a>" : "<a href=#><span></span></a>"; for (int row = 0; row < 6; row++) { if (GXT.isAriaEnabled()) { grid.getRowFormatter().getElement(row).setAttribute("role", "row"); } for (int col = 0; col < 7; col++) { grid.setHTML(row, col, s); if (GXT.isAriaEnabled()) { grid.getCellFormatter().getElement(row, col).setAttribute("role", "presentation"); } } } footer = new com.google.gwt.user.client.ui.HorizontalPanel(); footer.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER); footer.setWidth("100%"); todayBtn = new Button(messages.getTodayText(), new SelectionListener<ButtonEvent>() { public void componentSelected(ButtonEvent ce) { selectToday(); } }); if (messages.getTodayTip() != null) { todayBtn.setToolTip(messages.getTodayTip()); } footer.add(todayBtn); todayBtn.getElement().getParentElement().setClassName("x-date-bottom"); monthPicker = new El(DOM.createDiv()); monthPicker.dom.setClassName("x-date-mp"); gridWrapper = new El((Element) Document.get().createElement("DIV")); gridWrapper.dom.setAttribute("role", "grid"); gridWrapper.appendChild(days.getElement()); gridWrapper.appendChild(grid.getElement()); getElement().appendChild(header.getElement()); getElement().appendChild(gridWrapper.dom); getElement().appendChild(footer.getElement()); getElement().appendChild(monthPicker.dom); El btntext = monthBtn.el().selectNode("button"); btntext.setId(XDOM.getUniqueId()); gridWrapper.dom.setAttribute("aria-labelledby", btntext.getId()); setWidth(177); cells = Util.toElementArray(el().select("table.x-date-inner tbody td")); textNodes = Util.toElementArray(el().select("table.x-date-inner tbody span")); activeDate = value != null ? value : new DateWrapper(); update(activeDate); if (GXT.isAriaEnabled()) { String[] tags = new String[] { "table", "tbody", "tr", "td" }; for (int i = 0; i < tags.length; i++) { NodeList<Element> elems = el().select(tags[i]); for (int j = 0; j < elems.getLength(); j++) { if (elems.getItem(j).getAttribute("role").equals("")) { elems.getItem(j).setAttribute("role", "presentation"); } if (i == 3) { elems.getItem(j).setId(XDOM.getUniqueId()); } } } } el().makePositionable(); el().setTabIndex(0); el().setElementAttribute("hideFocus", "true"); sinkEvents(Event.ONCLICK | Event.MOUSEEVENTS | Event.ONFOCUS); new KeyNav<ComponentEvent>(this) { @Override public void onDown(ComponentEvent ce) { onKeyDown(ce); } @Override public void onEnd(ComponentEvent ce) { onKeyEnd(ce); } @Override public void onEnter(ComponentEvent ce) { onKeyEnter(ce); } @Override public void onHome(ComponentEvent ce) { onKeyHome(ce); } @Override public void onKeyPress(ComponentEvent ce) { // space bar pressed if (ce.getKeyCode() == 32) { selectToday(); } } @Override public void onLeft(ComponentEvent ce) { onKeyLeft(ce); } @Override public void onPageDown(ComponentEvent ce) { onKeyPageDown(ce); } @Override public void onPageUp(ComponentEvent ce) { onKeyPageUp(ce); } @Override public void onRight(ComponentEvent ce) { onKeyRight(ce); } @Override public void onUp(ComponentEvent ce) { onKeyUp(ce); } }; }
From source file:com.extjs.gxt.ui.client.widget.grid.ColumnHeader.java
License:sencha.com license
protected void cleanCells() { NodeList<Element> tds = DomQuery.select("tr.x-grid3-hd-row > td", table.getElement()); for (int i = 0; i < tds.getLength(); i++) { Element td = tds.getItem(i); if (!td.hasChildNodes()) { El.fly(td).removeFromParent(); }/* w w w . j av a 2 s. c o m*/ } }
From source file:com.extjs.gxt.ui.client.widget.grid.GridSelectionModel.java
License:sencha.com license
protected void onKeyDown(GridEvent<M> e) { if (GXT.isFocusManagerEnabled()) { if (selectedGroup == null && (selectedHeader != null || selected.size() == 0)) { e.cancelBubble();//from ww w. j a v a 2 s . c o m if (e.isAltKey()) { grid.getView().getHeader().showColumnMenu(selectedHeader.column); return; } if (selectedHeader != null) { selectedHeader.deactivate(); } select(0, false); return; } if (grouped) { GroupingView view = (GroupingView) grid.getView(); NodeList<Element> groups = view.getGroups().cast(); int gc = view.getGroups().getLength(); if (selectedGroup != null) { int gindex = indexOf(groups, selectedGroup); if (!view.isExpanded(selectedGroup)) { if (gindex < gc - 1) { view.onGroupSelect(selectedGroup, false); selectedGroup = groups.getItem(gindex + 1); view.onGroupSelect(selectedGroup, true); } return; } view.onGroupSelect(selectedGroup, false); Element r = view.getGroupRow(selectedGroup, 0).cast(); selectedGroup = null; if (r != null) { int idx = view.findRowIndex(r); select(idx, false); view.focusRow(idx); return; } } if (lastSelected != null) { Element row = view.getRow(lastSelected).cast(); Element group = view.findGroup(row).cast(); int totalGroups = groups.getLength(); int groupIndex = indexOf(groups, group); NodeList<Element> groupRows = group.getChildNodes().getItem(1).getChildNodes().cast(); int rowsInGroup = group.getChildNodes().getItem(1).getChildNodes().getLength(); int rowInGroupIndex = indexOf(groupRows, row); if (rowInGroupIndex == rowsInGroup - 1) { if (groupIndex < totalGroups - 1) { deselectAll(); selectedGroup = groups.getItem(groupIndex + 1); view.onGroupSelect(selectedGroup, true); return; } } } } } if (!e.isControlKey() && selected.size() == 0 && getLastFocused() == null) { select(0, false); } else { int idx = listStore.indexOf(getLastFocused()); if (idx >= 0) { if (e.isControlKey() || (e.isShiftKey() && isSelected(listStore.getAt(idx + 1)))) { if (!e.isControlKey()) { deselect(idx); } M lF = listStore.getAt(idx + 1); if (lF != null) { setLastFocused(lF); grid.getView().focusCell(idx + 1, 0, false); } } else { if (e.isShiftKey() && lastSelected != getLastFocused()) { select(listStore.indexOf(lastSelected), idx + 1, true); grid.getView().focusCell(idx + 1, 0, false); } else { if (idx + 1 < listStore.getCount()) { selectNext(e.isShiftKey()); grid.getView().focusCell(idx + 1, 0, false); } } } } } e.preventDefault(); }
From source file:com.extjs.gxt.ui.client.widget.grid.GridSelectionModel.java
License:sencha.com license
private int indexOf(NodeList<Element> elems, Element elem) { for (int i = 0; i < elems.getLength(); i++) { if (elems.getItem(i) == elem) { return i; }//from w w w . j a v a 2s. com } return -1; }
From source file:com.extjs.gxt.ui.client.widget.grid.GridView.java
License:sencha.com license
protected void processRows(int startRow, boolean skipStripe) { if (ds.getCount() < 1) { return;// w w w . j a v a2s .co m } skipStripe = skipStripe || !grid.isStripeRows(); NodeList<Element> rows = getRows(); String cls = "x-grid3-row-alt"; for (int i = 0, len = rows.getLength(); i < len; i++) { Element row = rows.getItem(i); row.setPropertyInt("rowIndex", i); if (!skipStripe) { boolean isAlt = (i + 1) % 2 == 0; boolean hasAlt = row.getClassName() != null && row.getClassName().indexOf(cls) != -1; if (isAlt == hasAlt) { continue; } if (isAlt) { El.fly(row).addStyleName(cls); } else { El.fly(row).removeStyleName(cls); } } } }
From source file:com.extjs.gxt.ui.client.widget.grid.GridView.java
License:sencha.com license
protected void updateAllColumnWidths() { int tw = getTotalWidth(); int clen = cm.getColumnCount(); Stack<Integer> ws = new Stack<Integer>(); header.updateAllColumnWidths();/*w w w. jav a 2 s. c o m*/ for (int i = 0; i < clen; i++) { ws.push(getColumnWidth(i)); if (footer != null) { footer.updateColumnWidth(i, cm.getColumnWidth(i)); } } NodeList<Element> ns = getRows(); for (int i = 0, len = ns.getLength(); i < len; i++) { Element row = ns.getItem(i); row.getStyle().setPropertyPx("width", tw); if (row.getFirstChild() != null) { row.getFirstChildElement().getStyle().setPropertyPx("width", tw); TableSectionElement e = row.getFirstChild().cast(); TableRowElement nodeList = e.getRows().getItem(0); for (int j = 0; j < clen; j++) { ((Element) nodeList.getChildNodes().getItem(j)).getStyle().setPropertyPx("width", ws.get(j)); } } } templateOnAllColumnWidthsUpdated(ws, tw); syncHScroll(); }
From source file:com.extjs.gxt.ui.client.widget.grid.GridView.java
License:sencha.com license
protected void updateColumnHidden(int index, boolean hidden) { int tw = getTotalWidth(); String display = hidden ? "none" : ""; El.fly(innerHd.dom.getFirstChildElement()).setWidth(getOffsetWidth()); El.fly(innerHd.dom.getFirstChildElement().getFirstChildElement()).setWidth(tw); header.updateColumnHidden(index, hidden); if (footer != null) { footer.updateTotalWidth(getOffsetWidth(), tw); footer.updateColumnHidden(index, hidden); }//from w w w . ja va2s. c o m NodeList<Element> ns = getRows(); for (int i = 0, len = ns.getLength(); i < len; i++) { Element elem = ns.getItem(i); elem.getStyle().setProperty("width", tw + "px"); TableSectionElement e = (TableSectionElement) elem.getFirstChild(); if (e != null) { e.getStyle().setProperty("width", tw + "px"); Element cell = e.getRows().getItem(0).getChildNodes().getItem(index).cast(); cell.getStyle().setProperty("display", display); } } templateOnColumnHiddenUpdated(index, hidden, tw); lastViewWidth = -1; layout(); syncHScroll(); }
From source file:com.extjs.gxt.ui.client.widget.grid.GridView.java
License:sencha.com license
protected void updateColumnWidth(int col, int width) { int tw = getTotalWidth(); int w = getColumnWidth(col); header.updateTotalWidth(-1, tw);/*from ww w. ja v a 2 s . c om*/ header.updateColumnWidth(col, width); if (footer != null) { footer.updateTotalWidth(getOffsetWidth(), tw); footer.updateColumnWidth(col, width); } NodeList<Element> ns = getRows(); for (int i = 0, len = ns.getLength(); i < len; i++) { Element row = ns.getItem(i); row.getStyle().setPropertyPx("width", tw); if (row.getFirstChild() != null) { row.getFirstChildElement().getStyle().setPropertyPx("width", tw); TableSectionElement e = row.getFirstChild().cast(); ((Element) e.getRows().getItem(0).getChildNodes().getItem(col)).getStyle().setPropertyPx("width", w); } } templateOnColumnWidthUpdated(col, w, tw); syncHScroll(); }