ViewerMisc { public static @SwtThread <T> RxBox<ImmutableSet<T>> multiSelectionSet(StructuredViewer viewer) { RxBox<ImmutableSet<T>> box = RxBox.of(ImmutableSet.of()); multiSelectionSet(viewer, box); return box; }  static @SwtThread RxBox<Optional<T>> singleSelection(StructuredViewer viewer); static void singleSelection(StructuredViewer viewer, RxBox<Optional<T>> box); static @SwtThread RxBox<ImmutableSet<T>> multiSelectionSet(StructuredViewer viewer); static void multiSelectionSet(StructuredViewer viewer, RxBox<ImmutableSet<T>> box); static @SwtThread RxBox<ImmutableList<T>> multiSelectionList(StructuredViewer viewer); @SuppressWarnings("unchecked") static void multiSelectionList(StructuredViewer viewer, RxBox<ImmutableList<T>> box); @SuppressWarnings("unchecked") static void setTreeContentProvider(TreeViewer viewer, TreeDef.Parented<T> treeDef); @SuppressWarnings("unchecked") static void setLazyTreeContentProvider(TreeViewer viewer, TreeDef.Parented<T> treeDef);  }
@Test public void testMultiSelectionSet() { String message = StringPrinter.buildStringFromLines( "- The table and the tree should keep their selection in sync.", "- The table and the tree should allow multi-selection.", "- The categories in the tree should not be selectable."); InteractiveTest.testCoat(message, cmp -> { TableAndTree tableAndTree = new TableAndTree(cmp, SWT.MULTI); RxBox<ImmutableSet<TreeNode<String>>> treeSelection = ViewerMisc.<TreeNode<String>> multiSelectionSet(tableAndTree.tree) .enforce(Immutables.mutatorSet(mutable -> mutable.removeIf(node -> !isName(node)))); RxBox<ImmutableSet<TreeNode<String>>> tableSelection = ViewerMisc.multiSelectionSet(tableAndTree.table); Rx.subscribe(treeSelection, tableSelection::set); Rx.subscribe(tableSelection, treeSelection::set); }); }