Element tree fixes

Fixes two display issues with the Element Tree:

1. Category nesting - if you have for example, Category 1 -> Category 2 -> Element, with no elements in Category 1 then it would never show Category 2 (thus making the element unreachable).

2. Categories with a sub-category would always be shown in an Element's tree even if it didn't contain any elements of that type.

Issues fixed: #767, #2880, #4238, #6586, #8178, #8938, and #11311