Thursday, 29 September 2011

ADF TreeModel utility methods

In all my latest dealings with the RichTree component in ADF I've found the following three (3) utility methods to be very handy (let's say they were implemented in a utility class called: Utility):

  // Returns the last RowKey object from the given set
  private static Object lastRowKeyFromSet(RowKeySet set) {
    Iterator it = set.iterator();
    Object rowKeyPointer = null;
    while (it.hasNext()) {
      rowKeyPointer = it.next();
    }
    return rowKeyPointer;
  }




  // Returns a String value of the given node attribute as found in the specified TreeModel at the specified row index.
  public static String retrieveNodeAttributeFromRowIndexForTreeModel(String attributeName, int rowIndex,
    TreeModel treeModel) {
    String attr = null;

    if(rowIndex > -1) {
      Object rowData = treeModel.getRowData(rowIndex);
      JUCtrlHierNodeBinding nodeBinding = (JUCtrlHierNodeBinding) rowData;

      if(nodeBinding != null) {
        attr = (String) nodeBinding.getAttribute(attributeName);
      }
    }
    return attr;
  }


  // Returns a String value of the given node attribute as found in the specified TreeModel at the last row key
  // as per the specified row key set.
  public static String retrieveNodeAttributeFromRowKeySetForTreeModel(String attributeName, RowKeySet set,
    TreeModel treeModel) {
    String attr = null;

    if ((set != null) && (set.size() > 0)) {     
      Object currentRowKey = Utility.lastRowKeyFromSet(set);     
      JUCtrlHierNodeBinding nodeBinding = (JUCtrlHierNodeBinding) treeModel.getRowData(currentRowKey);     
      if (nodeBinding != null) {       
        attr = (String) nodeBinding.getAttribute(attributeName);       
      }
    }   
    return attr;
  }


Hope you find it handy!

No comments:

Post a Comment