private Listcell getCell(int col, int row) { Listitem item; while (row >= lstVitals.getItemCount()) { item = new Listitem(); item.setVisible(false); item.setParent(lstVitals); } item = lstVitals.getItemAtIndex(row); while (col >= item.getChildren().size()) { Listcell cell = new Listcell(""); cell.setParent(item); } return (Listcell) item.getChildren().get(col); }
public Listitem newListitem(Listbox listbox) { //clone from template final Listitem clone = (Listitem) _template.clone(); //TODO: see if databinder has this kind of Listitem, if not, add new CollectionListItem //avoid duplicate id error, will set to new id when render() //Bug #1962153: Data binding generates duplicate id in some case (add "_") if (clone.getId().length() > 0) { clone.setId(null); } //link cloned component with template //each Listitem and and it decendants share the same templatemap Map<Object, Object> templatemap = new HashMap<Object, Object>(8); BindingRendererUtil.linkTemplates(clone, _template, templatemap, _binder); //link this template map to parent templatemap (Listbox in Listbox) Map parenttemplatemap = (Map) listbox.getAttribute(DataBinder.TEMPLATEMAP); if (parenttemplatemap != null) { templatemap.put(DataBinder.TEMPLATEMAP, parenttemplatemap); } //kept clone kids somewhere to avoid create too many components in browser final List<Component> kids = new ArrayList<Component>(clone.getChildren()); clone.setAttribute(KIDS, kids); clone.getChildren().clear(); return clone; }
item.insertBefore(item.getChildren().get(from), item.getChildren().get(to));
public void render(Listitem item, java.lang.Object bean, int index) { final List<Component> kids = cast((List) item.getAttribute(KIDS)); item.getChildren().addAll(kids); //item.removeAttribute(KIDS); //remove template mark of cloned component and its decendant _binder.setupTemplateComponent(item, null); //setup clone id BindingRendererUtil.setupCloneIds(item); //bind bean to the associated listitem and its decendant final String varname = (String) _template.getAttribute(DataBinder.VARNAME); final Map<Object, Object> templatemap = cast((Map) item.getAttribute(DataBinder.TEMPLATEMAP)); templatemap.put(varname, bean); //apply the data binding _binder.loadComponent(item); //feature# 3026221: Databinder shall fire onCreate when cloning each items DataBinder.postOnCreateEvents(item); //since 5.0.4 } }
v2 = handleCase((Comparable) li2.getValue()); } else { List lcs1 = li1.getChildren(); if (index >= lcs1.size()) v1 = null; v1 = handleCase(_byval ? lc.getValue() : lc.getLabel()); List lcs2 = li2.getChildren(); if (index >= lcs2.size()) v2 = null;
@Wire private Window menu; @Wire private Listbox box; private Listhead lHead; @Override public void doAfterCompose(Component comp) throws Exception { super.doAfterCompose(comp); // get the Listboxhead in which we like to change the the col order lHead = (Listhead) menu.getParent().query("#lbox > #lHead"); // set the model for Listbox box in the pop up box.setModel(new ListModelList<>(lHead.getChildren())); } @Listen("onDrop = listitem") public void onDropInMenu(DropEvent ev) { // get the draged and dropped again Listitem dragged = (Listitem) ev.getDragged(); Listitem droppedOn = (Listitem) ev.getTarget(); // then get their indexes. int from = box.getItems().indexOf(dragged); int to = box.getItems().indexOf(droppedOn); // swap the positions lHead.insertBefore(lHead.getChildren().get(from), lHead.getChildren().get(to)); // swap related Listcell in all Listitem instances for (Listitem item : lHead.getListbox().getItems()) { item.insertBefore(item.getChildren().get(from), item.getChildren().get(to)); } // swap the items in pop up Lisbox as well box.insertBefore(dragged, droppedOn); }
} finally { setReplacingItem(oldFlag); if (item.getChildren().isEmpty()) cell.setParent(item);
if (previous == null || compare(cmprx, previous, item) != 0) { final List<Listcell> cells = item.getChildren(); if (cells.size() < index) throw new IndexOutOfBoundsException("Index: " + index + " but size: " + cells.size());