public void updateStructure ( ) { if ( size ( ) > 1 ) { Collections . sort ( this ) ; m_projectFile . getChildTasks ( ) . clear ( ) ; Task lastTask = null ; int lastLevel = - 1 ; boolean autoWbs = m_projectFile . getProjectConfig ( ) . getAutoWBS ( ) ; boolean autoOutlineNumber = m_projectFile . getProjectConfig ( ) . getAutoOutlineNumber ( ) ; for ( Task task : this ) { task . clearChildTasks ( ) ; Task parent = null ; if ( ! task . getNull ( ) ) { int level = NumberHelper . getInt ( task . getOutlineLevel ( ) ) ; if ( lastTask != null ) { if ( level == lastLevel || task . getNull ( ) ) { parent = lastTask . getParentTask ( ) ; level = lastLevel ; } else { if ( level > lastLevel ) { parent = lastTask ; } else { while ( level <= lastLevel ) { parent = lastTask . getParentTask ( ) ; if ( parent == null ) { break ; } lastLevel = NumberHelper . getInt ( parent . getOutlineLevel ( ) ) ; lastTask = parent ; } } } } lastTask = task ; lastLevel = level ; if ( autoWbs || task . getWBS ( ) == null ) { task . generateWBS ( parent ) ; } if ( autoOutlineNumber ) { task . generateOutlineNumber ( parent ) ; } } if ( parent == null ) { m_projectFile . getChildTasks ( ) . add ( task ) ; } else { parent . addChildTask ( task ) ; } } } }
This method is used to recreate the hierarchical structure of the project file from scratch . The method sorts the list of all tasks then iterates through it creating the parent - child structure defined by the outline level field .