home *** CD-ROM | disk | FTP | other *** search
/ PC World 1997 November / PCWorld_1997-11_cd.bin / software / programy / komix / DATA.Z / csnode.tcl < prev    next >
Text File  |  1996-11-11  |  5KB  |  197 lines

  1. #---------------------------------------------------------------------------
  2. #
  3. #      (c)     Cayenne Software Inc.    1996
  4. #
  5. #      File:           @(#)csnode.tcl    /main/hindenburg/8
  6. #      Author:         <generated>
  7. #      Description:
  8. #---------------------------------------------------------------------------
  9. # SccsId = @(#)csnode.tcl    /main/hindenburg/8   11 Nov 1996 Copyright 1996 Cayenne Software Inc.
  10.  
  11. # Start user added include file section
  12. require "repinfosec.tcl"
  13. # End user added include file section
  14.  
  15.  
  16. Class CSNode : {BrowsNode} {
  17.     constructor
  18.     method destructor
  19.     method name
  20.     method uniqueName
  21.     method confirmShutdown
  22.     method removeChildren
  23.     method childName
  24.     method childObjects
  25.     method createChild
  26.     method beginUpdate
  27.     method doUpdate
  28.     method endUpdate
  29.     method update
  30.     method display
  31.     attribute canDelete
  32.     attribute canReload
  33.     attribute canChangeEntry
  34.     attribute canChangeParams
  35.     attribute canShutdown
  36.     attribute prevSelection
  37.     attribute view
  38.     attribute info
  39.     attribute shutdownDialog
  40. }
  41.  
  42. constructor CSNode {class this name} {
  43.     set this [BrowsNode::constructor $class $this $name]
  44.     # Start constructor user section
  45.  
  46.         $this view [[$this tree] view]
  47.         $this info [RepInfoSection new [$this view]]
  48.  
  49.         # Defaults, can be overridden by children.
  50.         #
  51.         $this selected { %this display }
  52.         $this activated { %this update; %this display }
  53.         $this hasChildren 1
  54.         $this foldState 0
  55.  
  56.         $this canDelete 0
  57.         $this canReload 0
  58.         $this canChangeEntry 0
  59.         $this canChangeParams 0
  60.         $this canShutdown 0
  61.  
  62.     # End constructor user section
  63.     return $this
  64. }
  65.  
  66. method CSNode::destructor {this} {
  67.     # Start destructor user section
  68.     # End destructor user section
  69. }
  70.  
  71. method CSNode::name {this} {
  72.     return [$this label]
  73. }
  74.  
  75. method CSNode::uniqueName {this} {
  76.     return [$this name]
  77. }
  78.  
  79. method CSNode::confirmShutdown {this title msg {help ""}} {
  80.     if {[$this shutdownDialog] == ""} {
  81.         $this shutdownDialog [WarningDialog new \
  82.             [$this view].shutdowndlg-[$this uniqueName] \
  83.             -title $title \
  84.             -message $msg \
  85.             -okPressed "$this shutdown 0"]
  86.  
  87.         if {$help != ""} {
  88.             [$this shutdownDialog] helpPressed "[$this view] helpOnName $help"
  89.         } else {
  90.             [$this shutdownDialog] delHelpButton
  91.         }
  92.     }
  93.     [$this shutdownDialog] popUp
  94. }
  95.  
  96. method CSNode::removeChildren {this} {
  97.     foreach child [$this childSet] {
  98.     $child delete
  99.     }
  100. }
  101.  
  102. method CSNode::childName {this object} {
  103.     return $object
  104. }
  105.  
  106. method CSNode::childObjects {this} {
  107.     return {}
  108. }
  109.  
  110. method CSNode::createChild {this object} {
  111.     return ""
  112. }
  113.  
  114. method CSNode::beginUpdate {this {rebuild 1}} {
  115.     [$this info] clear
  116.     $this prevSelection [[$this tree] selected]
  117.  
  118.     if $rebuild {
  119.     $this removeChildren
  120.     }
  121.  
  122.     $this hasChildren 1
  123. }
  124.  
  125. method CSNode::doUpdate {this {rebuild 1}} {
  126.     if $rebuild {
  127.         foreach object [$this childObjects] {
  128.             set node [$this createChild $object]
  129.             if {$node != ""} {
  130.                 $node update 1
  131.             }
  132.         }
  133.     } else {
  134.     set oldChildSet [$this childSet]
  135.     set newChildSet {}
  136.  
  137.     foreach object [$this childObjects] {
  138.         set nodeName [$this childName $object]
  139.         set i [lsearch -exact $oldChildSet $this.$nodeName]
  140.         if {$i != -1} {
  141.         set node [lindex $oldChildSet $i]
  142.         $node update 0
  143.         lappend newChildSet $node
  144.         } else {
  145.         set node [$this createChild $object]
  146.         if {$node != ""} {
  147.             $node update 1
  148.             lappend newChildSet $node
  149.         }
  150.         }
  151.     }
  152.  
  153.     foreach node $oldChildSet {
  154.         if {[lsearch -exact $newChildSet $node] == -1} {
  155.         $node delete
  156.         }
  157.     }
  158.     }
  159. }
  160.  
  161. method CSNode::endUpdate {this {rebuild 1}} {
  162.     [$this info] format
  163.  
  164.     if [lempty [$this childSet]] {
  165.     $this hasChildren 0
  166.     } else {
  167.     $this hasChildren 1
  168.     }
  169.  
  170.     if {[info commands [$this prevSelection]] == ""} {
  171.         [$this view] selectionChanged
  172.     }
  173. }
  174.  
  175. method CSNode::update {this {rebuild 1}} {
  176.     $this beginUpdate $rebuild
  177.  
  178.     if [catch {$this doUpdate $rebuild} error] {
  179.         [$this info] clear
  180.         [$this info] addHeader "Could not access:"
  181.         foreach line [split $error \n] {
  182.         [$this info] addLine $line
  183.         }
  184.     }
  185.  
  186.     $this endUpdate $rebuild
  187. }
  188.  
  189. method CSNode::display {this} {
  190.     # Default: contents of the RepInfoSection of this node.
  191.     #
  192.     [[$this view] info] text [[$this info] contents]
  193. }
  194.  
  195. # Do not delete this line -- regeneration end marker
  196.  
  197.