Marko,
First, thanks for the help.
I’ve been trying to boil my code down to the bare essentials in order to get this to work. What I have is simply an application that shows a list of departments for a specific employer, under which are nodes for each employee in that department, under which are nodes for each employee’s dependents. I also have a filter button that filters a specific department. This is working to a degree - the only top level node that is shown is the department, but none of its child nodes appear. Here is the code that I’m using (it is Scala, but reads pretty similarly to Java at the moment).
For the tree’s container:
private def employerDepartments: HierarchicalContainer = {
val container = new HierarchicalContainer
container.addContainerProperty("Department", classOf[Department]
, null)
container.addContainerProperty("Employee", classOf[Employee]
, null)
container.addContainerProperty("Person", classOf[Person]
, null)
container.addContainerProperty("Name", classOf[String]
, "")
val departments: List[Department]
= Department.departments
for (department <- departments) {
val departmentId: AnyRef = addDepartment(container, department)
for (employee <- department.getEmployees) {
val employeeId: AnyRef = addEmployee(container, employee, departmentId)
for (dependent <- employee.getDependents) {
addDependent(container, dependent, employeeId)
}
}
}
container
}
private def addDependent(container: HierarchicalContainer, dependent: Person, employeeId: AnyRef): AnyRef = {
val id: AnyRef = container.addItem()
container.getContainerProperty(id, "Person").setValue(dependent)
container.getContainerProperty(id, "Name").setValue(dependent.getName)
container.setParent(id, employeeId)
container.setChildrenAllowed(id, false)
id
}
private def addEmployee(container: HierarchicalContainer, employee: Employee, departmentId: AnyRef): AnyRef = {
val id: AnyRef = container.addItem()
container.getContainerProperty(id, "Employee").setValue(employee)
container.getContainerProperty(id, "Name").setValue(employee.getName)
container.setParent(id, departmentId)
container.setChildrenAllowed(departmentId, true)
id
}
private def addDepartment(container: HierarchicalContainer, department: Department): AnyRef = {
val id: AnyRef = container.addItem()
container.getContainerProperty(id, "Department").setValue(department)
container.getContainerProperty(id, "Name").setValue(department.getName)
id
}
For the filter:
class DepartmentFilter(departmentName: String) extends Filter {
def passesFilter(itemId: AnyRef, item: Item) = {
val p: Property = item.getItemProperty("Department");
if(p != null && p.getValue != null) {
p.getValue match {
case department: Department =>
val result = department.name == departmentName
result
case x =>
true
}
}
else
false
}
def appliesToProperty(propertyId: AnyRef) = true
}
Any light that could be shed on this would be greatly appreciated.