home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1998 October
/
PCWorld_1998-10_cd.bin
/
software
/
prehled
/
komix
/
DATA.Z
/
treenode.tcl
< prev
next >
Wrap
Text File
|
1997-11-25
|
12KB
|
506 lines
#---------------------------------------------------------------------------
#
# (c) Cayenne Software Inc. 1997
#
# File: @(#)treenode.tcl /main/titanic/33
# Author: <generated>
# Description:
#---------------------------------------------------------------------------
# SccsId = @(#)treenode.tcl /main/titanic/33 25 Nov 1997 Copyright 1997 Cayenne Software Inc.
# Start user added include file section
# End user added include file section
Class TreeNode : {BrowsNode} {
constructor
method destructor
method appendChildren
method getParent
method getPreviousNode
method getLevelPath
method switchContext
method open
method rebuild
method remove
method removeChildren
method update
method addChildLabel
method removeChildLabel
method addOldChild
method removeOldChild
attribute count
attribute childLabelSet
attribute oldChildSet
attribute browsUiObj
}
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
}
# promote to DragTreeNode if node can be dragged
if [$browsUiObj canBeDragged] {
require "dragtreeno.tcl"
DragTreeNode promote $this
}
# End constructor user section
return $this
}
method TreeNode::destructor {this} {
# Start destructor user section
# End destructor user section
}
# Append the children of the current object in the
# tree view if unfolded.
#
method TreeNode::appendChildren {this {scrollFlag 1}} {
set clientContext [ClientContext::global]
set oldLevelPath [$clientContext currentLevelIdString]
set switched 0
# execute this code in context of this node.
set newLevelPath [$this getLevelPath]
if {$newLevelPath != "" && $newLevelPath != $oldLevelPath} {
$this switchContext $newLevelPath
set switched 1
}
# object may have been promoted already by previous open
# call module_promoter again, maybe this will repair the damage
set browsUiObj [$this browsUiObj]
module_promoter [$browsUiObj browserObjType] $browsUiObj
if {! [$browsUiObj hasChildren]} {
if $switched {
$this switchContext $oldLevelPath
}
return
}
busy {
# initialize
BrowserProcs::initializeInfo $browsUiObj $this
set errorStack [$browsUiObj initializeChildSet ""]
if {"$errorStack" != ""} {
if [info exists errorInfo] {
set errorInfoCopy $errorInfo
} else {
set errorInfoCopy ""
}
if [info exists errorCode] {
set errorCodeCopy $errorCode
} else {
set errorCodeCopy ""
}
resetErrorVars
}
set index 0
[$this oldChildSet] contents [$this childSet]
[$this oldChildSet] foreach node {
set browsUiObjSet([$node browsUiObj]) $node
set oldIndex($node) [$node index]
}
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] {
# Skip non-containers
if {! [$child hasChildren]} {
BrowserProcs::initializeInfo $child $this
continue
}
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
$this addOldChild $node
} else {
$node update
}
if {"[$node icon]" == ""} continue
$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 {
if [info exists oldIndex($node)] {
set startIndex $oldIndex($node)
} else {
set startIndex -1
}
$node remove $startIndex
}
if $scrollFlag {
$this makeVisible
}
}
if {"$errorStack" != ""} {
global errorInfo errorCode
set errorInfo $errorInfoCopy
set errorCode $errorCodeCopy
wmtkerror $errorStack
}
if {$switched && $newLevelPath == [$clientContext currentLevelIdString]} {
$this switchContext $oldLevelPath
}
}
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 ""
}
method TreeNode::getPreviousNode {this {force 0} {startIndex -1}} {
# Cannot determine previous for root nodes
set parent [$this parent]
if {"$parent" == ""} {
return $this
}
global treeNodeStartIndex treeNodeIndex
if {! [info exists treeNodeStartIndex]} {
if {$startIndex < 0} {
set startIndex [$this index]
}
set treeNodeStartIndex $startIndex
set treeNodeIndex $treeNodeStartIndex
}
# Select this node first because setCurrentObj uses the selectedObjSet
$this selectState 1
if {$force || [catch {.main setCurrentObj $this}]} {
set doNextIndex [expr 1 - $force]
set childSet [$parent childSet]
if $force {
if {$treeNodeIndex >= [llength $childSet]} {
set treeNodeIndex 0
}
set node [lindex $childSet $treeNodeIndex]
if {$node == $this} {
set doNextIndex 1
}
}
if $doNextIndex {
if {$treeNodeIndex <= $treeNodeStartIndex && $treeNodeIndex > 0} {
incr treeNodeIndex -1
} else {
if {$treeNodeIndex == 0} {
set treeNodeIndex $treeNodeStartIndex
}
incr treeNodeIndex
}
set node [lindex $childSet $treeNodeIndex]
}
if {"$node" != ""} {
return [$node getPreviousNode]
}
unset treeNodeStartIndex
return [$parent getPreviousNode]
}
unset treeNodeStartIndex
$this activeState 1
return $this
}
# Return level ID path of this tree node.
#
method TreeNode::getLevelPath {this} {
# determine levelpath of this node
set treeNode $this
set levelPath ""
while { $treeNode != "" } {
if {[[$treeNode browsUiObj] isA CustomLevelVersion]} {
set levelPathPart [[$treeNode browsUiObj] identity]
set levelPath "/${levelPathPart}$levelPath"
}
set treeNode [$treeNode parent]
}
return $levelPath
}
# Perform context switch to specified levelPath.
#
method TreeNode::switchContext {this levelPath} {
set clientContext [ClientContext::global]
$clientContext notifyDisable
if [info exists errorInfo] {
set errorInfoCopy $errorInfo
} else {
set errorInfoCopy ""
}
if [info exists errorCode] {
set errorCodeCopy $errorCode
} else {
set errorCodeCopy ""
}
if [catch {$clientContext setLevelIds $levelPath}] {
global errorInfo errorCode
set errorInfo $errorInfoCopy
set errorCode $errorCodeCopy
}
$clientContext notifyEnable
[.main moduleHdlr] setCurrentContext
[.main objectHdlr] setCurrentContext
}
# Open this tree object: display information of the
# children of the current object in the flat view.
#
method TreeNode::open {this} {
global makeSelectionUpToDate
set makeSelectionUpToDate 0
busy {
set catched 1
set errorStack ""
set oldCurrentObj [.main _currentObj]
if {[[$this browsUiObj] hasChildren]} {
set catched [catch {set errorStack [.main setCurrentObj $this]} msg]
if $catched {
set errorStack $msg
if [info exists errorInfo] {
set errorInfoCopy $errorInfo
} else {
set errorInfoCopy ""
}
if [info exists errorCode] {
set errorCodeCopy $errorCode
} else {
set errorCodeCopy ""
}
resetErrorVars
}
}
if {$catched && [isCommand $oldCurrentObj]} {
set oldCurrentObj [$oldCurrentObj getPreviousNode]
.main selectionChanged
}
set newCurrentObj [.main _currentObj]
if {$oldCurrentObj != $newCurrentObj} {
set selectionChanged [expr 1 - [$newCurrentObj selectState]]
$newCurrentObj config \
-activeState 1 \
-selectState 1
if $selectionChanged {
.main selectionChanged
}
for {set parent [$newCurrentObj parent]} \
{"$parent" != ""} \
{set parent [$parent parent]} {
$parent foldState 0
}
.main insertHistEntry [.main mkHistEntry \
[[ClientContext::global] currentLevelString] 1 $newCurrentObj]
}
}
set makeSelectionUpToDate 1
if {"$errorStack" != ""} {
if $catched {
global errorInfo errorCode
set errorInfo $errorInfoCopy
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
}
}
method TreeNode::remove {this {startIndex -1}} {
set currentObj [.main _currentObj]
if {(! [isCommand .main]) || (! [isCommand $currentObj])} return
if [inTree $currentObj $this] {
set node [$this getPreviousNode 1 $startIndex]
.main insertHistEntry [.main mkHistEntry \
[[ClientContext::global] currentLevelString] 1 $node]
}
if [info exists [$this browsUiObj]::treeNode] {
unset [$this browsUiObj]::treeNode
}
$this delete
}
# 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" 0]
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
}