Flatten tree in adapter