home *** CD-ROM | disk | FTP | other *** search
- #---------------------------------------------------------------------------
- #
- # (c) Cadre Technologies Inc. 1996
- #
- # File: @(#)treenode.tcl /main/hindenburg/13
- # Author: <generated>
- # Description:
- #---------------------------------------------------------------------------
- # SccsId = @(#)treenode.tcl /main/hindenburg/13 5 Dec 1996 Copyright 1996 Cadre Technologies Inc.
-
- # Start user added include file section
- # End user added include file section
-
-
- Class TreeNode : {BrowsNode} {
- constructor
- method destructor
- method appendChildren
- method getParent
- method open
- method rebuild
- method removeChildren
- method update
- method addChildLabel
- method removeChildLabel
- method addOldChild
- method removeOldChild
- attribute count
- attribute childLabelSet
- attribute browsUiObj
- attribute oldChildSet
- }
-
- constructor TreeNode {class this name browsUiObj} {
- set this [BrowsNode::constructor $class $this $name]
- $this browsUiObj $browsUiObj
- $this childLabelSet [List new]
- $this oldChildSet [List new]
- # Start constructor user section
-
- global ${browsUiObj}::treeNode
- set ${browsUiObj}::treeNode $this
-
- $this count 0
- $this update
- $this config \
- -activeState 0 \
- -selectState 0 \
- -activated {%this open} \
- -folded {%this removeChildren} \
- -unFolded {%this appendChildren}
-
- # Append children if current one is unfolded
- if {! [$this foldState]} {
- $this appendChildren
- }
-
- # End constructor user section
- return $this
- }
-
- method TreeNode::destructor {this} {
- # Start destructor user section
-
- if {(! [isCommand .main]) ||
- (! [isCommand [.main currentObj]])} return
- if {"[.main currentObj]" == "$this"} {
- $this activeState 0
- [.main infoView] currentObj ""
- }
-
- if [info exists [$this browsUiObj]::treeNode] {
- unset [$this browsUiObj]::treeNode
- }
-
- # End destructor user section
- }
-
-
- # Append the children of the current object in the
- # tree view if unfolded.
- #
- method TreeNode::appendChildren {this {scrollFlag 1}} {
- if {! [[$this browsUiObj] hasChildren]} {
- return
- }
-
- busy {
- set browsUiObj [$this browsUiObj]
-
- # initialize
- BrowserProcs::initializeInfo $browsUiObj $this
- if [$browsUiObj isA Document] {
- $browsUiObj initialize [$this getParent ConfigVersion]
- }
- set errorStack [$browsUiObj initializeChildSet ""]
- if {"$errorStack" != ""} {
- if [info exists errorInfo] {
- set errorTrace $errorInfo
- set errorCodeCopy $errorCode
- resetErrorVars
- } else {
- set errorTrace ""
- set errorCodeCopy ""
- }
- }
-
- set index 0
- [$this oldChildSet] contents [$this childSet]
- [$this oldChildSet] foreach node {
- set browsUiObjSet([$node browsUiObj]) $node
- }
- foreach association [[$browsUiObj browserObjType]::associations] {
- case "$association" in {
- {controlledClasses externalFiles phaseVersions sections} {
- set sort 0
- }
- {default} {
- set sort 1
- [$this childLabelSet] contents ""
- }
- }
- foreach child [$browsUiObj getChildSet $association] {
- if [info exists browsUiObjSet($child)] {
- set node $browsUiObjSet($child)
- } else {
- set node ""
- }
-
- if {"$node" == ""} {
- set node $this.node[$this count]
- $this count [expr [$this count] + 1]
- TreeNode new $node $child
- } else {
- $node update
- $this removeOldChild $node
- }
-
- if $sort {
- $this addChildLabel [list "[$node label]" $node]
- } else {
- $node index $index
- incr index 1
- }
- }
-
- if {! $sort} continue
-
- # Sort the nodes on label
- [$this childLabelSet] sort
- [$this childLabelSet] foreach tuple {
- [lindex $tuple 1] index $index
- incr index 1
- }
- }
- [$this oldChildSet] foreach node {
- $node delete
- }
- if $scrollFlag {
- $this makeVisible
- }
- }
-
- if {"$errorStack" != ""} {
- global errorInfo errorCode
- set errorInfo $errorTrace
- set errorCode $errorCodeCopy
- wmtkerror $errorStack
- }
- }
-
- method TreeNode::getParent {this type} {
- set browsUiObj ""
- set found 0
- for {set parent [$this parent]} \
- {"$parent" != ""} \
- {set parent [$parent parent]} {
- set browsUiObj [$parent browsUiObj]
- if {"$browsUiObj" == ""} break
- if [$browsUiObj isA $type] {
- set found 1
- break
- }
- }
- if $found {
- return $browsUiObj
- }
- return ""
- }
-
-
- # Open this tree object: display information of the
- # children of the current object in the flat view.
- #
- method TreeNode::open {this} {
- busy {
- set oldCurrentObj [.main currentObj]
- if {[[$this browsUiObj] hasChildren]} {
- set catched [catch {.main setCurrentObj $this} errorStack]
- if {"$errorStack" != ""} {
- if [info exists errorInfo] {
- set errorTrace $errorInfo
- set errorCodeCopy $errorCode
- resetErrorVars
- } else {
- set errorTrace ""
- set errorCodeCopy ""
- }
- }
- if $catched {
- .main setCurrentObj $oldCurrentObj
- if [isCommand $oldCurrentObj] {
- $oldCurrentObj selectState 1
- }
- }
- } else {
- set errorStack ""
- if [isCommand $oldCurrentObj] {
- $oldCurrentObj activeState 1
- }
- $this activeState 0
- .main selectionChanged
- }
- set newCurrentObj [.main currentObj]
- if {$oldCurrentObj != $newCurrentObj} {
- $newCurrentObj config \
- -activeState 1 \
- -selectState 1
-
- [$this tree] rebuild
-
- for {set parent [$newCurrentObj parent]} \
- {"$parent" != ""} \
- {set parent [$parent parent]} {
- $parent foldState 0
- }
-
- .main addFileHistory $newCurrentObj \
- [[ClientContext::global] currentLevelString]
- }
- }
-
- if {"$errorStack" != ""} {
- global errorInfo errorCode
- set errorInfo $errorTrace
- set errorCode $errorCodeCopy
- wmtkerror $errorStack
- }
- }
-
- method TreeNode::rebuild {this} {
- set browsUiObj [$this browsUiObj]
- if {! [isCommand $browsUiObj]} {
- return
- }
-
- if [$this foldState] {
- return
- }
-
- $this appendChildren 0
- foreach node [$this childSet] {
- $node rebuild
- }
- }
-
-
- # Remove all child tree objects.
- #
- method TreeNode::removeChildren {this} {
- $this makeVisible
-
- # Make this one active if the current activated is its (grand)child.
- set currentObj [.main currentObj]
- if {! [isCommand $currentObj]} return
- if {$currentObj == $this} return
- set found 0
- for {set parent [$currentObj parent]} \
- {"$parent" != ""} \
- {set parent [$parent parent]} {
- if {$parent == $this} {
- set found 1
- break
- }
- }
- if $found {
- $this open
- }
- }
-
- method TreeNode::update {this} {
- set browsUiObj [$this browsUiObj]
- BrowserProcs::initializeInfo $browsUiObj $this
-
- set name [$browsUiObj getInfo Name]
- if [$browsUiObj typeInLabel] {
- append name ".[$browsUiObj getInfo Type]"
- }
- if [$browsUiObj versionInLabel] {
- append name " (V[$browsUiObj versionNumber])"
- }
- $this config \
- -label $name \
- -hasChildren [$browsUiObj hasChildren]
-
- # Set icons and default foldState
- set uiType "[$browsUiObj getInfo Type]"
- set objType "[$browsUiObj uiClass]"
- set typeSpec [getObjectSpec [.main objectHdlr] "$objType" "$uiType"]
- if {"$typeSpec" != ""} {
- set icon [$typeSpec normalIcon]
- set activeIcon [$typeSpec activeIcon]
- set foldState [$this foldState]
- if $foldState {
- set foldState [$typeSpec foldState]
- }
- } else {
- set icon ""
- set activeIcon ""
- set foldState 1
- }
- $this config \
- -icon $icon \
- -activeIcon $activeIcon \
- -foldState $foldState
- }
-
- # Do not delete this line -- regeneration end marker
-
- method TreeNode::addChildLabel {this newChildLabel} {
- [$this childLabelSet] append $newChildLabel
-
- }
-
- method TreeNode::removeChildLabel {this oldChildLabel} {
- [$this childLabelSet] removeValue $oldChildLabel
- }
-
- method TreeNode::addOldChild {this newOldChild} {
- [$this oldChildSet] append $newOldChild
-
- }
-
- method TreeNode::removeOldChild {this oldOldChild} {
- [$this oldChildSet] removeValue $oldOldChild
- }
-
-