//handleSelectionAdded(tree, prev);
}
@SuppressWarnings("unchecked")
public void onEvent(Event event) throws Exception {
Tree tree = (Tree) event.getTarget();
Set<Treeitem> delta = new HashSet<Treeitem>(); // 暫存的集合
Set<Treeitem> current = new HashSet<Treeitem>(); // 現存的集合
// 將畫面中選取的所有項目, 放到現存集合中
current.addAll(tree.getSelectedItems());
System.out.println("Start");
System.out.println("event data is " + logItems(current));
System.out.println("prev was " + logItems(prev));
System.out.println("current is " + logItems(current));
logger.debug("-----------------------------------------------");
// 找出新增的節點
delta.addAll(current);
delta.removeAll(prev);
System.out.println("Added node is " + logItems(delta));
// 如果新增節點有下屬節點,把它加到tree的選取節點中
handleSelectionAdded(tree, delta);
System.out.println("Now: " + logItems(tree.getSelectedItems()));
// 找出移除的節點
delta.clear();
delta.addAll(prev);
delta.removeAll(current);
System.out.println("Removed node is " + logItems(delta));
// 如果移除節點有下屬節點, 也把它移除掉
handleSelectionRemoved(tree, delta);
System.out.println("Now: " + logItems(tree.getSelectedItems()));
// 經過新增、移除後, 最後的結果是
prev.clear();
prev.addAll(tree.getSelectedItems());
System.out.println("final is " + logItems(prev));
System.out.println("end");
}