| Class | TaskJuggler::PropertyList |
| In: |
lib/taskjuggler/PropertyList.rb
|
| Parent: | Object |
The PropertyList is a utility class that can be used to hold a list of properties. It‘s derived from an Array, so it can hold the properties in a well defined order. The order can be determined by an arbitrary number of sorting levels. A sorting level specifies an attribute who‘s value should be used for sorting, a scenario index if necessary and the sorting direction (up/down). All nodes in the PropertyList must belong to the same PropertySet.
| propertySet | [R] | |
| query | [W] | |
| query | [R] | |
| scenarioIdx | [R] | |
| sortingCriteria | [R] | |
| sortingLevels | [R] | |
| sortingUp | [R] |
A PropertyList is always bound to a certain PropertySet. All properties in the list must be of that set.
# File lib/taskjuggler/PropertyList.rb, line 33 def initialize(arg, copyItems = true) @items = copyItems ? arg.to_ary : [] if arg.is_a?(PropertySet) # Create a PropertyList from the given PropertySet. @propertySet = arg # To keep the list sorted, we may have to access Property attributes. # Pre-scheduling, we can only use static attributes. Post-scheduling, # we can include dynamic attributes as well. This query template will # be used to query attributes when it has been set. Otherwise the list # can only be sorted by static attributes. @query = nil resetSorting addSortingCriteria('seqno', true, -1) sort! else # Create a PropertyList from a given other PropertyList. @propertySet = arg.propertySet @query = arg.query ? arg.query.dup : nil @sortingLevels = arg.sortingLevels @sortingCriteria = arg.sortingCriteria.dup @sortingUp = arg.sortingUp.dup @scenarioIdx = arg.scenarioIdx.dup end end
Append another Array of PropertyTreeNodes or a PropertyList to this. The list will be sorted again.
# File lib/taskjuggler/PropertyList.rb, line 97 def append(list) if $DEBUG list.each do |node| unless node.propertySet == @propertySet raise "Fatal Error: All nodes must belong to the same PropertySet." end end end @items.concat(list) sort! end
# File lib/taskjuggler/PropertyList.rb, line 65 def includeAdopted adopted = [] @items.each do |p| p.adoptees.each do |ap| adopted += includeAdoptedR(ap, p) end end append(adopted) end
This class should be a derived class of Array. But since it re-defines sort!() and still needs to call Array::sort!() I took a different route. All missing methods will be propagated to the @items Array.
# File lib/taskjuggler/PropertyList.rb, line 61 def method_missing(func, *args, &block) @items.method(func).call(*args, &block) end
Clear all sorting levels.
# File lib/taskjuggler/PropertyList.rb, line 88 def resetSorting @sortingLevels = 0 @sortingCriteria = [] @sortingUp = [] @scenarioIdx = [] end
Set all sorting levels as Array of triplets.
# File lib/taskjuggler/PropertyList.rb, line 80 def setSorting(modes) resetSorting modes.each do |mode| addSortingCriteria(*mode) end end
Sort the properties according to the currently defined sorting criteria.
# File lib/taskjuggler/PropertyList.rb, line 118 def sort! if treeMode? # Tree sorting is somewhat complex. It will be based on the 'tree' # attribute of the PropertyTreeNodes but we have to update them first # based on the other sorting criteria. # Remove the tree sorting mode first. sc = @sortingCriteria.delete_at(0) su = @sortingUp.delete_at(0) si = @scenarioIdx.delete_at(0) @sortingLevels -= 1 # Sort the list based on the rest of the modes. sortInternal # The update the 'index' attributes of the PropertyTreeNodes. index # An then the 'tree' attributes. indexTree # Restore the 'tree' sorting mode again. @sortingCriteria.insert(0, sc) @sortingUp.insert(0, su) @scenarioIdx.insert(0, si) @sortingLevels += 1 # Sort again, now based on the updated 'tree' attributes. sortInternal else sortInternal end # Update indexes. index end