package components.tree { import data.DataSource; /** * NameLabel is a 'default' (suitable for most situations) class responsible for * determining a label for an XML element. The possible label attributes are used in the following * order: labelFunction, labelField and label. */ public class TitleLabel implements LabelRule { public var dataSource:DataSource; /** * The name of the XML element this rule applies to. */ public var name:Object = null; /** * Determine label. */ public function getLabel(node:XML):String { if(dataSource != null) { var props:XML = dataSource.getProps(node); if(props != null) { if(name is Array) { for each(var currentName:Object in name as Array) { var currentLabel:String = doGetLabel(props, currentName); if(currentLabel != null) { return currentLabel; } } } else { return doGetLabel(props, name); } } } // Rule doesn't match therefore no label is returned. return null; } private function doGetLabel(props:XML, currentName:Object) : String { if(props.name() == currentName) { return dataSource.getTitle(props); } return null; } } }