public Group get(int index) { final int realIndex = getRealIndex(_groupsInfo.get(index)[0]); return (realIndex >= 0 && realIndex < getChildren().size()) ? (Group) getChildren().get(realIndex) : null; } };
public void beforeChildAdded(Component child, Component refChild) { if (!(child instanceof Row)) throw new UiException("Unsupported child for rows: " + child); if (child instanceof Groupfoot) { if (!hasGroup()) throw new UiException("Groupfoot cannot exist alone, you have to add a Group first"); if (refChild == null) { if (getLastChild() instanceof Groupfoot) throw new UiException("Only one Goupfooter is allowed per Group"); } } super.beforeChildAdded(child, refChild); }
/** Returns the grid that contains this rows. * <p>It is the same as {@link #getParent}. */ public Grid getGrid() { return (Grid) getParent(); }
/*package*/ Group getGroup(int index) { if (_groupsInfo.isEmpty()) return null; final int[] g = getGroupsInfoAt(index); if (g != null) { final int realIndex = getRealIndex(g[0]); //if realIndex < 0 means g is half loaded, Group head is not in server if (realIndex >= 0 && realIndex < getChildren().size()) { Row row = (Row) getChildren().get(realIndex); return (Group) row; } } return null; }
fixGroupIndex(index, -1, false); if (remove != null) { _groupsInfo.remove(remove); final int idx = remove[2]; if (idx != -1) { final int realIndex = getRealIndex(idx) - 1; //bug #2936064 if (realIndex >= 0 && realIndex < getChildren().size()) removeChild(getChildren().get(realIndex)); } else if (hasGroup()) { final int[] g = getGroupsInfoAt(index); if (g != null) { g[1]--; if (g[2] != -1) g[2]--; fixGroupIndex(index, -1, false); } else fixGroupIndex(index, -1, false); if (child instanceof Groupfoot) { final int[] g1 = getGroupsInfoAt(index); if (g1 != null) { // group info maybe remove cause of grouphead removed in previous op g1[2] = -1; fixRowIndices(index, -1); if (hasGroupsModel() && getChildren().size() <= 0) { //remove to empty, reset _groupsInfo _groupsInfo = new LinkedList<int[]>();
/** * Fix Childitem._index since j-th item. * * @param j * the start index (inclusion) * @param to * the end index (inclusion). If -1, up to the end. */ private void fixRowIndices(int j, int to) { int realj = getRealIndex(j); if (realj < 0) realj = 0; List items = getChildren(); if (realj < items.size()) { for (Iterator it = items.listIterator(realj); it.hasNext() && (to < 0 || j <= to); ++j) ((Row) it.next()).setIndexDirectly(j); } }
final Rows rows = grid.getRows(); if (rows != null) { if (rows.hasGroup()) { for (Group group : new ArrayList<Group>(rows.getGroups())) final List<Component> children = new LinkedList<Component>(rows.getChildren()); rows.getChildren().clear(); sortCollection(children, cmprx); for (Component c : children) rows.appendChild(c); grid.getRows().invalidate();
public boolean insertBefore(Component child, Component refChild) { final Grid grid = getGrid(); final boolean isReorder = child.getParent() == this; //bug #3051305: Active Page not update when drag & drop item to the end if (isReorder) { checkInvalidateForMoved(child, true); } Row newItem = (Row) child; final int jfrom = hasGroup() && newItem.getParent() == this ? newItem.getIndex() : -1; fixGroupsInfoBeforeInsert(newItem, (Row) refChild, isReorder); if (super.insertBefore(child, refChild)) { final int jto = refChild instanceof Row ? ((Row) refChild).getIndex() : -1, fixFrom = jfrom < 0 || (jto >= 0 && jfrom > jto) ? jto : jfrom; if (fixFrom < 0) { newItem.setIndexDirectly( getChildren().size() - 1 + (grid != null ? grid.getDataLoader().getOffset() : 0)); } else { fixGroupIndex(fixFrom, jfrom >= 0 && jto >= 0 ? jfrom > jto ? jfrom : jto : -1, !isReorder); } fixGroupsInfoAfterInsert(newItem); //bug #3049167: Totalsize increase when drag & drop in paging Listbox/Grid if (!isReorder) { afterInsert(child); } return true; } return false; }
/** Checks whether to invalidate, when a child has been added or * or will be removed. * @param bRemove if child will be removed */ private void checkInvalidateForMoved(Component child, boolean bRemove) { //No need to invalidate if //1) act == last and child in act //2) act != last and child after act //Except removing last element which in act and act has only one element final Grid grid = getGrid(); if (grid != null && grid.inPagingMold() && !isInvalidated()) { final List<Component> children = getChildren(); final int sz = children.size(), pgsz = grid.getPageSize(); int n = sz - (grid.getActivePage() + 1) * pgsz; if (n <= 0) { //must be last page n += pgsz; //check in-act (otherwise, check after-act) if (bRemove && n <= 1) { //last element, in act and remove invalidate(); return; } } else if (n > 50) n = 50; //check at most 50 items (for better performance) for (ListIterator<Component> it = children.listIterator(sz); --n >= 0 && it.hasPrevious();) if (it.previous() == child) return; //no need to invalidate invalidate(); } }
Rows rows = _grid.getRows(); final int newsz = model.getSize(); final int oldsz = rows != null ? rows.getChildren().size() : 0; final Paginal pgi = _grid.getPaginal(); final boolean inPaging = inPagingMold(); rows.invalidate(); Component comp = rows.getChildren().get(max); next = comp.getNextSibling(); while (--cnt >= 0) { Component row = rows.getChildren().get(min); while (--cnt >= 0) { next = row.getNextSibling(); rows.insertBefore(newUnloadedItem(renderer, min), next); ++addcnt; rows.invalidate(); rows = new Rows(); rows.setParent(_grid); if (renderer == null) renderer = (RowRenderer) getRealRenderer(); rows.insertBefore(newUnloadedItem(renderer, min), next);
/*package*/ void fixGroupIndex(int j, int to, boolean infront) { int realj = getRealIndex(j); if (realj < 0) { realj = 0; } if (realj < getChildren().size()) { final int beginning = j; for (Iterator<Component> it = getChildren().listIterator(realj); it.hasNext() && (to < 0 || j <= to); ++j) { Component o = it.next(); ((Row) o).setIndexDirectly(j); if (_isReplacingRow) //@see Grid.Renderer#render break; //set only the first Row, skip handling GroupInfo // if beginning is a group, we don't need to change its groupInfo, // because // it is not reliable when infront is true. if ((!infront || beginning != j) && o instanceof Group) { int[] g = getLastGroupsInfoAt(j + (infront ? -1 : 1)); if (g != null) { g[0] = j; if (g[2] != -1) g[2] += (infront ? 1 : -1); } } } } }
/** Sorts the rows. If with group, each group is sorted independently. */ @SuppressWarnings("unchecked") private static void sort0(Grid grid, Comparator cmpr) { final Rows rows = grid.getRows(); if (rows.hasGroup()) for (Group g : rows.getGroups()) { int index = g.getIndex() + 1; Components.sort(rows.getChildren(), index, index + g.getItemCount(), cmpr); } else Components.sort(rows.getChildren(), cmpr); }
if (isReorder) { final int idx = newItem.getIndex(); final int[] ginfo = getGroupsInfoAt(idx); if (ginfo != null) { ginfo[1]--; final int[] g = _groupsInfo.get(getGroupCount() - 1); g[2] = getChildren().size() - (isReorder ? 2 : 1); } else { final int idx = ((Row) refChild).getIndex(); final int[] g = getGroupsInfoAt(idx); if (g == null) throw new UiException("Groupfoot cannot exist alone, you have to add a Group first"); if (isReorder) { final int nindex = newItem.getIndex(); final int[] ginfo = getGroupsInfoAt(nindex); if (ginfo != null) { ginfo[1]--;
int index = group.getIndex(); if (_groupsInfo.isEmpty()) _groupsInfo.add(new int[] { group.getIndex(), getChildren().size() - index, -1 }); else { int idx = 0; } else if (hasGroup()) { int index = newItem.getIndex(); final int[] g = getGroupsInfoAt(index); if (g != null) { g[1]++;
final int newsz = event.getModel().getSize(), oldsz = rows == null ? 0 : rows.getChildren().size(); int min = event.getIndex0(), max = event.getIndex1(), cnt; rows.invalidate(); final Component next = min < oldsz ? rows.getChildren().get(min) : null; while (--cnt >= 0) { if (renderer == null) renderer = (RowRenderer) getRealRenderer(); rows.insertBefore(newUnloadedItem(renderer, min++), next); rows.invalidate(); Component comp = rows.getChildren().get(max); while (--cnt >= 0) { Component p = comp.getPreviousSibling();
/** * Add a row containing the specified header (left column) and value container (right column). * * @param header Text for header column * @param container Object containing text value(s) */ protected void addRow(String header, Component container) { Row row = new Row(); grid.getRows().appendChild(row); Div div = new Div(); Label label = new Label(header + ":"); label.setMultiline(true); label.setMaxlength(40); label.setStyle("font-weight:bold;word-wrap:word-break"); row.appendChild(div); row.appendChild(label); row.appendChild(container); }
/** * Returns the group that follows the specified group, or null if there is none. * * @param group The returned group is the first one following this group. If this value is null, * returns the first group encountered. * @return The next group. */ private Group nextGroup(Group group) { Component cmpt = group == null ? grid.getRows().getFirstChild() : group.getNextSibling(); while (cmpt != null && !(cmpt instanceof Group)) { cmpt = cmpt.getNextSibling(); } return (Group) cmpt; }
/** * Returns the last row added. * * @return The last row added. */ private Row getLastRow() { return (Row) grid.getRows().getLastChild(); }
if (rows == null) return false; //Avoid grid with null group if (rows.hasGroup()) { for (Group group : new ArrayList<Group>(rows.getGroups())) final List<Component> children = new LinkedList<Component>(rows.getChildren()); rows.getChildren().clear(); sortCollection(children, cmprx); rows.appendChild(group); rows.appendChild(row); previous = row; grid.getRows().invalidate(); return true;
private Row addRow() { Row row = new Row(); grdVitals.getRows().appendChild(row); int colCount = getColCount(); for (int i = 1; i <= colCount; i++) { Span span = new Span(); row.appendChild(span); span.setSclass(SCLASS_UNMARKED); Component child; if (i == 1 || i == colCount) { child = new Label(); } else { Textbox tb = new Textbox(); child = tb; tb.addForward(Events.ON_CHANGE, root, "onDataChange"); } span.appendChild(child); } return row; }