Class HierarchicalHelper

java.lang.Object
org.eclipse.nebula.widgets.nattable.hierarchical.HierarchicalHelper

public final class HierarchicalHelper extends Object
Helper class to de-normalize a collection of objects with hierarchical object relations into a simple collection.
Since:
1.6
See Also:
  • Field Details

    • PROPERTY_SEPARATOR_REGEX

      public static final String PROPERTY_SEPARATOR_REGEX
      The regular expression that is used to separate properties for accessing fields on different levels of a HierarchicalWrapper.
      See Also:
  • Method Details

    • deNormalize

      public static List<HierarchicalWrapper> deNormalize(List<?> input, boolean addParentObject, String... propertyNames)
      De-normalizes a given list of objects with a hierarchical object graph to a flattened list. The flattened list therefore contains redundant data for each entry that has the same parent objects. It will created HierarchicalWrapper objects for this, which contain references to the original objects. Therefore property changes will be directly reflected in the hierarchical object graph.

      To identify the nested objects, the property names are inspected if they contain dots for hierarchical object paths. For example parent.children.name says that the parent has a property that is a collection (children) where each entry in the children collection is an object that has a property name. In this example there will be an entry in the flattened list for each child, where the parent is repeated in each wrapper object.

      Parameters:
      input - The collection of objects with a hierarchical object graph.
      addParentObject - true to add row objects for parent objects that do no have object references for deeper levels, false to have no dedicated row object for parent objects.
      propertyNames - The property names to access the properties in the object graph.
      Returns:
      The flattened list of the hierarchical object graph.
    • deNormalize

      public static List<HierarchicalWrapper> deNormalize(List<?> input, boolean addParentObject, List<String> propertyNames)
      De-normalizes a given list of objects with a hierarchical object graph to a flattened list. The flattened list therefore contains redundant data for each entry that has the same parent objects. It will created HierarchicalWrapper objects for this, which contain references to the original objects. Therefore property changes will be directly reflected in the hierarchical object graph.

      To identify the nested objects, the property names are inspected if they contain dots for hierarchical object paths. For example parent.children.name says that the parent has a property that is a collection (children) where each entry in the children collection is an object that has a property name. In this example there will be an entry in the flattened list for each child, where the parent is repeated in each wrapper object.

      Parameters:
      input - The collection of objects with a hierarchical object graph.
      addParentObject - true to add row objects for parent objects that do no have object references for deeper levels, false to have no dedicated row object for parent objects.
      propertyNames - The property names to access the properties in the object graph.
      Returns:
      The flattened list of the hierarchical object graph.
    • getLevelObjectByProperty

      public static Object getLevelObjectByProperty(HierarchicalWrapper wrapper, String propertyName)
      Returns the level object from the given HierarchicalWrapper object by the given property name.
      Parameters:
      wrapper - The HierarchicalWrapper from which the level object should be retrieved.
      propertyName - The name of the property to identify the level object from.
      Returns:
      The level object from the HierarchicalWrapper according to the given property name.
    • getLevelIndexMapping

      public static Map<Integer,List<Integer>> getLevelIndexMapping(String[] propertyNames)
      Calculates the mapping of hierarchy levels to column indexes belonging to the level.
      Parameters:
      propertyNames - The property names to access the properties in the object graph.
      Returns:
      The mapping of the level to the list of all column indexes belonging to a level.