コード例 #1
0
 /**
  * Gathers the checked states of the given widget and its descendents, following a pre-order
  * traversal of the tree.
  *
  * @param result a writable list of elements (element type: <code>Object</code>)
  * @param widget the widget
  */
 private void internalCollectChecked(List result, Widget widget) {
   Item[] items = getChildren(widget);
   for (int i = 0; i < items.length; i++) {
     Item item = items[i];
     if (item instanceof TreeItem && ((TreeItem) item).getChecked()) {
       Object data = item.getData();
       if (data != null) {
         result.add(data);
       }
     }
     internalCollectChecked(result, item);
   }
 }
コード例 #2
0
 /**
  * Returns a list of checked elements in this viewer's tree, including currently hidden ones that
  * are marked as checked but are under a collapsed ancestor.
  *
  * <p>This method is typically used when preserving the interesting state of a viewer; <code>
  * setCheckedElements</code> is used during the restore.
  *
  * @return the array of checked elements
  * @see #setCheckedElements
  */
 public Object[] getCheckedElements() {
   ArrayList v = new ArrayList();
   Control tree = getControl();
   internalCollectChecked(v, tree);
   return v.toArray();
 }