GuidoPopupMenu leafPopup {
GuidoMenuItem Delete {
-label FIO_DELETE_LABEL
-icon icons/ExitGraphics.gif
-action mouseReleased {[deletePlane $form $::planes_tree]}
}
}
proc getCurrentName {} {
return [$::noun getCurrentValue]
}
proc getNextLeaf {tree groupName leafName} {
set best ""
set rootNode [$tree getRootNode]
set c [$rootNode getChildCount]
for {set i 0} {$i < $c} {incr i} {
set child [$rootNode getChildAt $i]
if {[string compare [$child getLabelText] $groupName] == 0} {
set d [$child getChildCount]
for {set j 0} {$j < $d} {incr j} {
set grandChild [$child getChildAt $j]
if {[string compare [$grandChild getCurrentValue] $leafName] == 0} {
if {[expr $j + 1] < $d} {
set best "[[$child getChildAt [expr $j + 1]] getLabelText]"
} elseif {$d > 1 && $j > 0} {
set best "[[$child getChildAt [expr $j - 1]] getLabelText]"
} elseif {[expr $i + 1] < $c} {
set child [$rootNode getChildAt [expr $i + 1]]
set best "[[$child getChildAt 0] getLabelText]"
} elseif {$c > 1 && $i > 0} {
set child [$rootNode getChildAt [expr $i - 1]]
set d [$child getChildCount]
incr d -1
set best "[[$child getChildAt $d] getLabelText]"
} else {
set best ""
}
set j $d
set i $c
}
}
}
}
return $best
}
proc removeLeaf {tree groupName leafName} {
set rootNode [$tree getRootNode]
set c [$rootNode getChildCount]
for {set i 0} {$i < $c} {incr i} {
set child [$rootNode getChildAt $i]
set d [$child getChildCount]
for {set j 0} {$j < $d} {incr j} {
set grandChild [$child getChildAt $j]
if {[string compare [$grandChild getCurrentValue] $leafName] == 0 && [string compare [$child getLabelText] $groupName] == 0} {
$child removeChild $grandChild
set j $d
set i $c
}
}
if {[$child getChildCount] == 0} {
$rootNode removeChild $child
}
}
if {[$rootNode getChildCount] == 0} {
$::noun_group setCurrentValue ""
$::noun setCurrentValue ""
$::verb setCurrentValue ""
$::depend setCurrentValue "false"
}
}
proc loadSelectedData {tree groupName leafName} {
$::noun_group setCurrentValue $groupName
$::noun setCurrentValue $leafName
$::verb setCurrentValue "Editing:"
fetchPlane $tree
}
proc selectLeaf {tree groupName leafName loadData} {
set rootNode [$tree getRootNode]
set c [$rootNode getChildCount]
for {set i 0} {$i < $c} {incr i} {
set child [$rootNode getChildAt $i]
set treeGroup [$child getLabelText]
set d [$child getChildCount]
for {set j 0} {$j < $d} {incr j} {
set grandChild [$child getChildAt $j]
if {[string compare [$grandChild getCurrentValue] $leafName] == 0 && [string compare $treeGroup $groupName] == 0} {
set ::nested true
$tree setSelectedNode $child
$tree expandPath "$::containerName\\[$child getCurrentValue]\\[$grandChild getCurrentValue]"
set ::nested false
if {$loadData == "true" &&
[string compare "[$child getLabelText]" "New"] != 0} {
loadSelectedData $tree $groupName $leafName
}
set j $d
set i $c
}
}
}
}
proc leafExists {tree branchName leafName} {
set rootNode [$tree getRootNode]
set c [$rootNode getChildCount]
for {set i 0} {$i < $c} {incr i} {
set child [$rootNode getChildAt $i]
set d [$child getChildCount]
if {[string compare [$child getLabelText] $branchName] == 0} {
for {set j 0} {$j < $d} {incr j} {
set grandChild [$child getChildAt $j]
if {[string compare [$grandChild getCurrentValue] $leafName] == 0} {
return "true"
}
}
}
}
return "false"
}
proc branchExists {tree branchName} {
set result "false"
set rootNode [$tree getRootNode]
set c [$rootNode getChildCount]
for {set i 0} {$i < $c} {incr i} {
set child [$rootNode getChildAt $i]
if {[string compare [$child getLabelText] $branchName] == 0} {
set result "true"
break
}
}
return $result
}
proc formClosed {form tree} {
if {"[$form getStatus]" == "apply"} {
if {"[changedData]" == "true"} {
set planeName "[getCurrentName]"
if {[validate]} {
saveOutstandingChanges $form $tree $planeName $planeName
}
}
}
}
proc leafChanged {form tree} {
if {$::nested == "false"} {
if {"[changedData]" == "true"} {
set planeName "[getCurrentName]"
set confirm [confirmSaveInput $form $tree $planeName]
if {$confirm == "Yes"} {
if {[validate]} {
saveOutstandingChanges $form $tree $planeName $planeName
loadSelectedData $tree "" ""
} else {
set selectGroup [[[$tree getSelectedNode] getParent] getLabelText]
selectLeaf $tree $selectGroup $planeName false
}
} elseif {$confirm == "No"} {
if {[string compare [getBranchName $tree] "New"] == 0} {
removeLeaf $tree New $planeName
}
loadSelectedData $tree "" ""
} elseif {$confirm == "Cancel"} {
set selectGroup [[[$tree getSelectedNode] getParent] getLabelText]
selectLeaf $tree $selectGroup $planeName false
}
} else {
loadSelectedData $tree "" ""
}
}
}
proc nameInput {tree getGroup groupName} {
upvar $groupName useGroupName
GuidoForm newPlaneForm {
-label "New plane"
-layout CentreLineLayout
-default_buttons
-tip "FRM_GETPLANENAME_1"
if {$getGroup == "true"} {
GuidoComboBox group {
-label "PLANES_LABEL_GROUP"
-null false
-max_length 32
-display_length 15
-exclusive false
-tip "FRM_GETPLANENAME_2"
-format group
}
set rootNode [$tree getRootNode]
set c [$rootNode getChildCount]
for {set i 0} {$i < $c} {incr i} {
set child [$rootNode getChildAt $i]
$group addItem [$child getLabelText]
}
}
GuidoField name {
-default ""
-display_length 12
-format plane
-label "PLANES_LABEL_PLANE_NAME"
-max_length 256
-null false
}
}
$newPlaneForm show modal
if {[$newPlaneForm getStatus] == "apply"} {
if {$getGroup == "true"} {
set useGroupName [$group getCurrentValue]
set return_name [$name getCurrentValue]
} else {
set return_name [$name getCurrentValue]
}
$newPlaneForm destroy
return $return_name
} else {
$newPlaneForm destroy
return ""
}
}
proc confirmDeleteInput {deleteName} {
GuidoForm deletePlaneConfirm {
-default_buttons "Yes" "No"
-label "Confirm Plane Deletion"
-tip "Confirm that you wish to delete the plane."
-layout FlowLayout
GuidoLabel Warning_Label {
-icon "icons/Warning.gif"
}
GuidoLabel warning {
-height 1
-no_mlt
}
}
$warning setCurrentValue [GuidoMessage translate PLANES_CONFIRM_DELETE $deleteName]
$deletePlaneConfirm show modal
set return_code [$deletePlaneConfirm getStatus]
$deletePlaneConfirm destroy
return $return_code
}
proc deletePlane {form tree} {
set deleteName [getCurrentName]
set deleteGroup [[[$tree getSelectedNode] getParent] getLabelText]
if {[string compare $deleteName ""] != 0} {
set deleteConfirmed false
if {[string compare $deleteGroup "New"] == 0} {
set deleteConfirmed true
} elseif {[confirmDeleteInput $deleteName] == "apply"} {
set deleteConfirmed true
}
if {"$deleteConfirmed" == "true"} {
GuidoExecServer "$::removeFunction" [subst {name = "$deleteGroup/$deleteName"}]
set nextLeaf [getNextLeaf $tree $deleteGroup $deleteName]
removeLeaf $tree $deleteGroup $deleteName
if {[string compare $nextLeaf ""] != 0} {
set parts [split $nextLeaf /]
set group [lindex $parts 0]
set leaf [lindex $parts 1]
selectLeaf $tree $group $leaf true
}
}
}
}
proc deletePlanesInput {tree} {
GuidoForm deletePlanesInput {
-default_buttons
-label "Delete Multiple Planes"
-tip "FRM_COMMONPLANE_1"
-layout BorderLayout
GuidoScrollPane scroll {
-height 15
GuidoTree planes_tree_local {
-label $::containerName
-editable false
-no_mlt
set buffer [GuidoExecServer PlaneTreeStructure [subst {type = "$::containerName"}]]
set nSeries "[GuidoGetParamBufferValue $buffer nSeries ]"
set editPlane "[GuidoGetParamBufferValue $buffer editPlane ]"
set rootNode [$planes_tree_local getRootNode]
for {set i 0} {$i < $nSeries} {incr i} {
set pname "[GuidoGetParamBufferValue $buffer series_$i]"
GuidoTreeBranch branch_$i {
-label_no_mlt "$pname"
set nPlanes "[GuidoGetParamBufferValue $buffer nPlanes_$i]"
for {set j 0} {$j < $nPlanes} {incr j} {
set name "[GuidoGetParamBufferValue $buffer "plane\_$i\_$j"]"
GuidoTreeLeaf leaf\_$i\_$j {
-menu_enabled true
-menu $::leafPopup
-default $name
-label $name
-no_mlt
}
}
}
}
}
for {set i 0} {$i < $nSeries} {incr i} {
set child [$rootNode getChildAt $i]
$planes_tree_local setSelectedNode $child
set name [GuidoGetParamBufferValue $buffer "plane\_$i\_0"]
$planes_tree_local expandPath "$::containerName\\$pname\\$name"
}
$planes_tree_local setSelectedNode $rootNode
$planes_tree_local setTreeIcons $::iconFile $::iconFile $::iconFileZ
}
}
$deletePlanesInput show modal
if {[$deletePlanesInput getStatus] == "apply"} {
set rootNode [$planes_tree_local getRootNode]
for {set jdx 0} {$jdx < [$planes_tree_local getSelectionCount]} {incr jdx} {
set node [$planes_tree_local getSelectedNodes $jdx]
if {[$node isLeaf]} {
set deleteGroup [[$node getParent] getLabelText]
GuidoExecServer "$::removeFunction" [subst {name = "$deleteGroup/[$node getLabelText]"}]
set nextLeaf [getNextLeaf $tree $deleteGroup [getCurrentName]]
removeLeaf $tree $deleteGroup [$node getLabelText]
if {[string compare [$node getLabelText] [getCurrentName]] == 0 &&
[string compare $nextLeaf ""] != 0} {
set parts [split $nextLeaf /]
set group [lindex $parts 0]
set leaf [lindex $parts 1]
selectLeaf $tree $group $leaf true
}
}
}
}
set status [$deletePlanesInput getStatus]
$deletePlanesInput destroy
return $status
}
proc deletePlanes {form tree} {
deletePlanesInput $tree
}
proc savePlaneAs {form tree} {
if {[validate]} {
set newName [nameInput $tree false groupName]
if {[string compare $newName ""] != 0} {
set buffer [GuidoExecServer "PlaneExists" [subst {type = "$::containerName" group = "[$::series getCurrentValue]" name = "$newName"}]]
if {"[GuidoGetParamBufferValue $buffer exists]" == "true"} {
GuidoMessage warning PLANE_EXISTS $newName
} else {
set planeName "[getCurrentName]"
saveOutstandingChanges $form $tree $planeName $newName
if {[string compare [getBranchName $tree] "New"] == 0} {
removeLeaf $tree New $planeName
}
}
}
}
}
proc savePlane {form tree} {
set planeName "[getCurrentName]"
if {[validate]} {
saveOutstandingChanges $form $tree $planeName $planeName
}
}
proc createBranch {tree branchName} {
if {[branchExists $tree $branchName] == "false"} {
incr ::newNodes
set new_branch \$newBranch$::newNodes
GuidoTreeBranch newBranch$::newNodes {
-label_no_mlt $branchName
}
set rootNode [$tree getRootNode]
$rootNode addChild [subst $new_branch] -1
}
}
proc createLeaf {form tree branchName leafName} {
if {[leafExists $tree $branchName $leafName] == "false"} {
createBranch $tree $branchName
incr ::newNodes
GuidoTreeLeaf movedLeaf$::newNodes {
-menu_enabled true
-menu $::leafPopup
-default $leafName
-label $leafName
-no_mlt
-action focusGained {[leafChanged $form $tree]}
}
set rootNode [$tree getRootNode]
set c [$rootNode getChildCount]
for {set i 0} {$i < $c} {incr i} {
set child [$rootNode getChildAt $i]
if {[string compare "[$child getLabelText]" "$branchName"] == 0} {
set new_leaf \$movedLeaf$::newNodes
$child addChild [subst $new_leaf] -1
break
}
}
selectLeaf $tree $branchName $leafName true
}
}
proc getBranchName {tree} {
return [$::noun_group getCurrentValue]
}
proc saveOutstandingChanges {form tree planeName savedPlaneName} {
set status [doSavePlane $savedPlaneName]
if {$status == "0"} {
if {[string compare [getBranchName $tree] "New"] == 0} {
removeLeaf $tree New $planeName
createLeaf $form $tree [$::series getCurrentValue] $savedPlaneName
} else {
if {$::seriesInitial != [$::series getCurrentValue]} {
removeLeaf $tree $::seriesInitial $planeName
GuidoExecServer "$::removeFunction" [subst {name = "$::seriesInitial/$planeName"}]
}
createLeaf $form $tree [$::series getCurrentValue] $savedPlaneName
}
selectLeaf $tree [$::series getCurrentValue] $savedPlaneName true
set ::initialValues false
setInitial
}
}
proc confirmSaveInput {form tree planeName} {
if {[string compare [getBranchName $tree] "New"] == 0} {
set translated_val [GuidoMessage translate NEW_PLANE_CONFIRM $planeName]
} else {
set translated_val [GuidoMessage translate PLANE_CHANGED $planeName]
}
set result [$form confirm $translated_val]
return $result
}
proc newPlane {form tree} {
if {"[changedData]" == "true"} {
set planeName "[getCurrentName]"
set confirm [confirmSaveInput $form $tree $planeName]
if {$confirm == "Yes"} {
saveOutstandingChanges $form $tree $planeName $planeName
} elseif {$confirm == "No"} {
if {[string compare [getBranchName $tree] "New"] == 0} {
removeLeaf $tree New $planeName
}
} elseif {$confirm == "Cancel"} {
return
}
}
set newName [nameInput $tree true groupName]
if {[string compare $newName ""] != 0} {
set buffer [GuidoExecServer "PlaneExists" [subst {type = "$::containerName" group = $groupName name = "$newName"}]]
if {"[GuidoGetParamBufferValue $buffer exists]" == "true"} {
GuidoMessage warning PLANE_EXISTS $newName
} else {
createLeaf $form $tree New $newName
blankFields
$::series setCurrentValue $groupName
changedData
set ::seriesInitial -1
$::verb setCurrentValue "Creating:"
$::noun_group setCurrentValue New
$::noun setCurrentValue $newName
}
}
}
proc notImplemented {} {
puts "Not yet implemented."
}
