static TreeItem NextItem(Tree tree, TreeItem item) { if (item == null) return null; if (item.getExpanded()) { return item.getItem(0); } else { TreeItem childItem = item; TreeItem parentItem = childItem.getParentItem(); int index = parentItem == null ? tree.indexOf(childItem) : parentItem.indexOf(childItem); int count = parentItem == null ? tree.getItemCount() : parentItem.getItemCount(); while (true) { if (index + 1 < count) { return parentItem == null ? tree.getItem(index + 1) : parentItem.getItem(index + 1); } else { if (parentItem == null) { return null; } else { childItem = parentItem; parentItem = childItem.getParentItem(); index = parentItem == null ? tree.indexOf(childItem) : parentItem.indexOf(childItem); count = parentItem == null ? tree.getItemCount() : parentItem.getItemCount(); } } } } }
public FileInfo findFileInfo(TreeItem item) { assert Thread.currentThread() == fDisplay.getThread(); if (item == null) return fRootInfo; TreeItem parent = item.getParentItem(); FileInfo info = findFileInfo(parent); if (info == null) return null; if (info.children == null) return null; if (info.children_error != null) return null; int i = parent == null ? fileTree.indexOf(item) : parent.indexOf(item); if (i < 0 || i >= info.children.length) return null; assert info.children[i].index == i; return info.children[i]; }
static TreeItem PreviousItem(Tree tree, TreeItem item) { if (item == null) return null; TreeItem childItem = item; TreeItem parentItem = childItem.getParentItem(); int index = parentItem == null ? tree.indexOf(childItem) : parentItem.indexOf(childItem); if (index == 0) { return parentItem; } else { TreeItem nextItem = parentItem == null ? tree.getItem(index - 1) : parentItem.getItem(index - 1); int count = nextItem.getItemCount(); while (count > 0 && nextItem.getExpanded()) { nextItem = nextItem.getItem(count - 1); count = nextItem.getItemCount(); } return nextItem; } }
/** return the item of real context parameter. */ private static IContextParameter searchNearItemParam( final TreeItem[] items, final TreeItem searchItem) { if (items == null || searchItem == null) { return null; } for (int i = items.length - 1; i >= 0; i--) { TreeItem item = items[i]; IContextParameter param = searchNearItemParam(item.getItems(), searchItem); if (param != null) { return param; } // if (item == searchItem) { if (i > 0) { // before item return searchEndItemParam(items[i - 1]); } else { // first in current if (i + 1 < items.length) { // next item return searchEndItemParam(items[i + 1]); } else { // only one left TreeItem parentItem = item.getParentItem(); if (parentItem != null) { final Tree parentTree = item.getParent(); final int index = parentTree.indexOf(parentItem); if (index > -1) { // in tree root if (index > 0) { return searchEndItemParam(parentTree.getItem(index - 1)); } else { // is first return null; } } else { // not found return null; } } } } } } return null; }