Tree
doit
false
226227228229230231232233234
} public void update() { TreeItem[] items = tree.getAllItems(); for (int i = 0; i < items.length; i++) { TreeItem item = items[i]; updateInternal(item); } }
232233234235236237238239240241
updateInternal(item); } } public void update(Object elem) { TreeItem item = (TreeItem) findItem(elem); if (item != null) { updateInternal(item); } }
246247248249250251252253254255
protected List getSelectedFromWidget() { ArrayList elems = new ArrayList(); TreeItem[] items = tree.getSelection(); for (int i = 0; i < items.length; i++) { TreeItem item = items[i]; elems.add(item.getData()); } return elems; }
282283284285286287288289290291292293294295
return temp.toArray(); } private void fireCheckStateChanged(BaseEvent be) { if (checkChangeListener != null) { TreeItem item = (TreeItem) be.item; CheckStateChangedEvent evt = new CheckStateChangedEvent(this, item.getData(), item.isChecked()); Iterator it = checkChangeListener.iterator(); while (it.hasNext()) { ((ICheckStateListener) it.next()).checkStateChanged(evt); }
384385386387388389390391392393394395396397398399400401
hasChildren = ((ITreeContentProvider) getContentProvider()).hasChildren(elem); } ILabelProvider lp = (ILabelProvider) getLabelProvider(); TreeItem item = new TreeItem(); item.setData(elem); item.setText(lp.getText(elem)); item.setIconStyle(lp.getIconStyle(elem)); item.setLeaf(!hasChildren); if (checkable) { item.setChecked(((ICheckable)getContentProvider()).getChecked(elem)); } if (position == -1) { parent.add(item); } else {
402403404405406407408409410411412413414415416417
parent.insert(item, position); } } private void renderTree() { TreeItem root = tree.getRootItem(); root.setData(input); int count = root.getItemCount(); for (int i = 0; i < count; i++) { root.remove(root.getItem(0)); } Object[] elems = elements; elems = sortElements(elems); for (int i = 0; i < elems.length; i++) {
428429430431432433434435436437438439440441442443444445
private void sortChildren(TreeItem parent) { Object[] elems = new Object[parent.getItemCount()]; Element p = parent.getContainer(); for (int i = 0; i < elems.length; i++) { TreeItem item = parent.getItem(i); DOM.removeChild(p, item.getElement()); elems[i] = item.getData(); } sortElements(elems); for (int i = 0; i < elems.length; i++) { TreeItem item = (TreeItem) findItem(elems[i]); Element elem = item.getElement(); DOM.appendChild(p, elem); } }
505152535455565758596061
public TreeViewer(Tree tree) { this.tree = tree; hookWidget(tree); tree.addListener(Events.BeforeExpand, new Listener() { public void handleEvent(BaseEvent be) { TreeItem item = (TreeItem) be.widget; Object loaded = item.getData("loaded"); if (loaded == null) { be.doit = false; loadChildren(item, true); } }
6869707172737475
* * @param parent the parent element * @param child the child element */ public void add(Object parent, Object child) { TreeItem p = (TreeItem) findItem(parent); internalAdd(p, child, p.getItemCount()); }
828384858687888990919293
} public Widget findItem(Object elem) { TreeItem[] items = tree.getAllItems(); for (int i = 0; i < items.length; i++) { TreeItem item = items[i]; if (item.getData() == elem) { return item; } } return null; }