/** Clears the selection. */ public void clearSelection() { if (!_selItems.isEmpty()) { for (Treeitem item : _selItems) item.setSelectedDirectly(false); _selItems.clear(); _sel = null; smartUpdate("selectedItem", null); } }
/** Fixes the status of new added child. */ private void fixNewChild(Treeitem item) { if (item.isSelected()) { if (_sel != null && !_multiple) { item.setSelectedDirectly(false); item.invalidate(); } else { if (_sel == null) _sel = item; _selItems.add(item); } } }
/** Fixes all info about the selected status. */ private void fixSelectedSet() { _sel = null; _selItems.clear(); for (Treeitem item : getItems()) { if (item.isSelected()) { if (_sel == null) { _sel = item; } else if (!_multiple) { item.setSelectedDirectly(false); continue; } _selItems.add(item); } } }
/** Sets whether multiple selections are allowed. * <p>Notice that, if a model is assigned, it will change the model's * state (by {@link TreeSelectableModel#setMultiple}). */ public void setMultiple(boolean multiple) { if (_multiple != multiple) { _multiple = multiple; if (!_multiple && _selItems.size() > 1) { final Treeitem item = getSelectedItem(); for (Iterator<Treeitem> it = _selItems.iterator(); it.hasNext();) { final Treeitem ti = it.next(); if (ti != item) { ti.setSelectedDirectly(false); it.remove(); } } //No need to update selId because z.multiple will do the job } if (_model != null) ((TreeSelectableModel) _model).setMultiple(multiple); smartUpdate("multiple", _multiple); } }
/** Deselects the given item without deselecting other items. */ public void removeItemFromSelection(Treeitem item) { if (item.getTree() != this) throw new UiException("Not a child: " + item); if (item.isSelected()) { if (!_multiple) { clearSelection(); } else { item.setSelectedDirectly(false); _selItems.remove(item); if (_sel == item) //bug fix:3131173 _sel = _selItems.size() > 0 ? _selItems.iterator().next() : null; smartUpdateSelection(); } } }
/** Deselects all of the currently selected items and selects * the given item. * <p>It is the same as {@link #setSelectedItem}. * @param item the item to select. If null, all items are deselected. */ public void selectItem(Treeitem item) { if (item == null) { clearSelection(); } else { if (item.getTree() != this) throw new UiException("Not a child: " + item); if (_sel != item || (_multiple && _selItems.size() > 1)) { for (Treeitem ti : _selItems) ti.setSelectedDirectly(false); _selItems.clear(); _sel = item; item.setSelectedDirectly(true); _selItems.add(item); smartUpdate("selectedItem", item); } if (inPagingMold()) setActivePage(item); } }
/** Selects the given item, without deselecting any other items * that are already selected.. */ public void addItemToSelection(Treeitem item) { if (item.getTree() != this) throw new UiException("Not a child: " + item); if (!item.isSelected()) { if (!_multiple) { selectItem(item); } else { item.setSelectedDirectly(true); _selItems.add(item); if (_sel == null) _sel = _selItems.iterator().next(); smartUpdateSelection(); } } }
/** Selects all items. */ public void selectAll() { if (!_multiple) throw new UiException("Appliable only to the multiple seltype: " + this); //we don't invoke getItemCount first because it is slow! boolean first = true; for (Treeitem item : getItems()) { if (!item.isSelected()) { _selItems.add(item); item.setSelectedDirectly(true); } if (first) { _sel = item; first = false; } } smartUpdate("selectAll", true); }